chip.c 451 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465
  1. /*
  2. * Copyright(c) 2015 - 2018 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. #include "debugfs.h"
  65. #include "fault.h"
  66. #define NUM_IB_PORTS 1
  67. uint kdeth_qp;
  68. module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
  69. MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
  70. uint num_vls = HFI1_MAX_VLS_SUPPORTED;
  71. module_param(num_vls, uint, S_IRUGO);
  72. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  73. /*
  74. * Default time to aggregate two 10K packets from the idle state
  75. * (timer not running). The timer starts at the end of the first packet,
  76. * so only the time for one 10K packet and header plus a bit extra is needed.
  77. * 10 * 1024 + 64 header byte = 10304 byte
  78. * 10304 byte / 12.5 GB/s = 824.32ns
  79. */
  80. uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
  81. module_param(rcv_intr_timeout, uint, S_IRUGO);
  82. MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
  83. uint rcv_intr_count = 16; /* same as qib */
  84. module_param(rcv_intr_count, uint, S_IRUGO);
  85. MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
  86. ushort link_crc_mask = SUPPORTED_CRCS;
  87. module_param(link_crc_mask, ushort, S_IRUGO);
  88. MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
  89. uint loopback;
  90. module_param_named(loopback, loopback, uint, S_IRUGO);
  91. MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
  92. /* Other driver tunables */
  93. uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
  94. static ushort crc_14b_sideband = 1;
  95. static uint use_flr = 1;
  96. uint quick_linkup; /* skip LNI */
  97. struct flag_table {
  98. u64 flag; /* the flag */
  99. char *str; /* description string */
  100. u16 extra; /* extra information */
  101. u16 unused0;
  102. u32 unused1;
  103. };
  104. /* str must be a string constant */
  105. #define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
  106. #define FLAG_ENTRY0(str, flag) {flag, str, 0}
  107. /* Send Error Consequences */
  108. #define SEC_WRITE_DROPPED 0x1
  109. #define SEC_PACKET_DROPPED 0x2
  110. #define SEC_SC_HALTED 0x4 /* per-context only */
  111. #define SEC_SPC_FREEZE 0x8 /* per-HFI only */
  112. #define DEFAULT_KRCVQS 2
  113. #define MIN_KERNEL_KCTXTS 2
  114. #define FIRST_KERNEL_KCTXT 1
  115. /*
  116. * RSM instance allocation
  117. * 0 - Verbs
  118. * 1 - User Fecn Handling
  119. * 2 - Vnic
  120. */
  121. #define RSM_INS_VERBS 0
  122. #define RSM_INS_FECN 1
  123. #define RSM_INS_VNIC 2
  124. /* Bit offset into the GUID which carries HFI id information */
  125. #define GUID_HFI_INDEX_SHIFT 39
  126. /* extract the emulation revision */
  127. #define emulator_rev(dd) ((dd)->irev >> 8)
  128. /* parallel and serial emulation versions are 3 and 4 respectively */
  129. #define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
  130. #define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
  131. /* RSM fields for Verbs */
  132. /* packet type */
  133. #define IB_PACKET_TYPE 2ull
  134. #define QW_SHIFT 6ull
  135. /* QPN[7..1] */
  136. #define QPN_WIDTH 7ull
  137. /* LRH.BTH: QW 0, OFFSET 48 - for match */
  138. #define LRH_BTH_QW 0ull
  139. #define LRH_BTH_BIT_OFFSET 48ull
  140. #define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
  141. #define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
  142. #define LRH_BTH_SELECT
  143. #define LRH_BTH_MASK 3ull
  144. #define LRH_BTH_VALUE 2ull
  145. /* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
  146. #define LRH_SC_QW 0ull
  147. #define LRH_SC_BIT_OFFSET 56ull
  148. #define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
  149. #define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
  150. #define LRH_SC_MASK 128ull
  151. #define LRH_SC_VALUE 0ull
  152. /* SC[n..0] QW 0, OFFSET 60 - for select */
  153. #define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
  154. /* QPN[m+n:1] QW 1, OFFSET 1 */
  155. #define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
  156. /* RSM fields for Vnic */
  157. /* L2_TYPE: QW 0, OFFSET 61 - for match */
  158. #define L2_TYPE_QW 0ull
  159. #define L2_TYPE_BIT_OFFSET 61ull
  160. #define L2_TYPE_OFFSET(off) ((L2_TYPE_QW << QW_SHIFT) | (off))
  161. #define L2_TYPE_MATCH_OFFSET L2_TYPE_OFFSET(L2_TYPE_BIT_OFFSET)
  162. #define L2_TYPE_MASK 3ull
  163. #define L2_16B_VALUE 2ull
  164. /* L4_TYPE QW 1, OFFSET 0 - for match */
  165. #define L4_TYPE_QW 1ull
  166. #define L4_TYPE_BIT_OFFSET 0ull
  167. #define L4_TYPE_OFFSET(off) ((L4_TYPE_QW << QW_SHIFT) | (off))
  168. #define L4_TYPE_MATCH_OFFSET L4_TYPE_OFFSET(L4_TYPE_BIT_OFFSET)
  169. #define L4_16B_TYPE_MASK 0xFFull
  170. #define L4_16B_ETH_VALUE 0x78ull
  171. /* 16B VESWID - for select */
  172. #define L4_16B_HDR_VESWID_OFFSET ((2 << QW_SHIFT) | (16ull))
  173. /* 16B ENTROPY - for select */
  174. #define L2_16B_ENTROPY_OFFSET ((1 << QW_SHIFT) | (32ull))
  175. /* defines to build power on SC2VL table */
  176. #define SC2VL_VAL( \
  177. num, \
  178. sc0, sc0val, \
  179. sc1, sc1val, \
  180. sc2, sc2val, \
  181. sc3, sc3val, \
  182. sc4, sc4val, \
  183. sc5, sc5val, \
  184. sc6, sc6val, \
  185. sc7, sc7val) \
  186. ( \
  187. ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
  188. ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
  189. ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
  190. ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
  191. ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
  192. ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
  193. ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
  194. ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
  195. )
  196. #define DC_SC_VL_VAL( \
  197. range, \
  198. e0, e0val, \
  199. e1, e1val, \
  200. e2, e2val, \
  201. e3, e3val, \
  202. e4, e4val, \
  203. e5, e5val, \
  204. e6, e6val, \
  205. e7, e7val, \
  206. e8, e8val, \
  207. e9, e9val, \
  208. e10, e10val, \
  209. e11, e11val, \
  210. e12, e12val, \
  211. e13, e13val, \
  212. e14, e14val, \
  213. e15, e15val) \
  214. ( \
  215. ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
  216. ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
  217. ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
  218. ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
  219. ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
  220. ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
  221. ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
  222. ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
  223. ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
  224. ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
  225. ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
  226. ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
  227. ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
  228. ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
  229. ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
  230. ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
  231. )
  232. /* all CceStatus sub-block freeze bits */
  233. #define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
  234. | CCE_STATUS_RXE_FROZE_SMASK \
  235. | CCE_STATUS_TXE_FROZE_SMASK \
  236. | CCE_STATUS_TXE_PIO_FROZE_SMASK)
  237. /* all CceStatus sub-block TXE pause bits */
  238. #define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
  239. | CCE_STATUS_TXE_PAUSED_SMASK \
  240. | CCE_STATUS_SDMA_PAUSED_SMASK)
  241. /* all CceStatus sub-block RXE pause bits */
  242. #define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
  243. #define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
  244. #define CNTR_32BIT_MAX 0x00000000FFFFFFFF
  245. /*
  246. * CCE Error flags.
  247. */
  248. static struct flag_table cce_err_status_flags[] = {
  249. /* 0*/ FLAG_ENTRY0("CceCsrParityErr",
  250. CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
  251. /* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
  252. CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
  253. /* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
  254. CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
  255. /* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
  256. CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
  257. /* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
  258. CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
  259. /* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
  260. CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
  261. /* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
  262. CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
  263. /* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
  264. CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
  265. /* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
  266. CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
  267. /* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  268. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
  269. /*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  270. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
  271. /*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
  272. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
  273. /*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
  274. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
  275. /*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  276. CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
  277. /*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  278. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
  279. /*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  280. CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
  281. /*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  282. CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
  283. /*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  284. CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
  285. /*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
  286. CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
  287. /*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
  288. CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
  289. /*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
  290. CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
  291. /*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
  292. CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
  293. /*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
  294. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
  295. /*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
  296. CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
  297. /*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
  298. CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
  299. /*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
  300. CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
  301. /*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
  302. CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
  303. /*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
  304. CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
  305. /*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
  306. CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
  307. /*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
  308. CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
  309. /*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
  310. CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
  311. /*31*/ FLAG_ENTRY0("LATriggered",
  312. CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
  313. /*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
  314. CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
  315. /*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
  316. CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
  317. /*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
  318. CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
  319. /*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
  320. CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
  321. /*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
  322. CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
  323. /*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
  324. CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
  325. /*38*/ FLAG_ENTRY0("CceIntMapCorErr",
  326. CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
  327. /*39*/ FLAG_ENTRY0("CceIntMapUncErr",
  328. CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
  329. /*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
  330. CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
  331. /*41-63 reserved*/
  332. };
  333. /*
  334. * Misc Error flags
  335. */
  336. #define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
  337. static struct flag_table misc_err_status_flags[] = {
  338. /* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
  339. /* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
  340. /* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
  341. /* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
  342. /* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
  343. /* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
  344. /* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
  345. /* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
  346. /* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
  347. /* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
  348. /*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
  349. /*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
  350. /*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
  351. };
  352. /*
  353. * TXE PIO Error flags and consequences
  354. */
  355. static struct flag_table pio_err_status_flags[] = {
  356. /* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
  357. SEC_WRITE_DROPPED,
  358. SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
  359. /* 1*/ FLAG_ENTRY("PioWriteAddrParity",
  360. SEC_SPC_FREEZE,
  361. SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
  362. /* 2*/ FLAG_ENTRY("PioCsrParity",
  363. SEC_SPC_FREEZE,
  364. SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
  365. /* 3*/ FLAG_ENTRY("PioSbMemFifo0",
  366. SEC_SPC_FREEZE,
  367. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
  368. /* 4*/ FLAG_ENTRY("PioSbMemFifo1",
  369. SEC_SPC_FREEZE,
  370. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
  371. /* 5*/ FLAG_ENTRY("PioPccFifoParity",
  372. SEC_SPC_FREEZE,
  373. SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
  374. /* 6*/ FLAG_ENTRY("PioPecFifoParity",
  375. SEC_SPC_FREEZE,
  376. SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
  377. /* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
  378. SEC_SPC_FREEZE,
  379. SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
  380. /* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
  381. SEC_SPC_FREEZE,
  382. SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
  383. /* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
  384. SEC_SPC_FREEZE,
  385. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
  386. /*10*/ FLAG_ENTRY("PioSmPktResetParity",
  387. SEC_SPC_FREEZE,
  388. SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
  389. /*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
  390. SEC_SPC_FREEZE,
  391. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
  392. /*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
  393. SEC_SPC_FREEZE,
  394. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
  395. /*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
  396. 0,
  397. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
  398. /*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
  399. 0,
  400. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
  401. /*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
  402. SEC_SPC_FREEZE,
  403. SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
  404. /*16*/ FLAG_ENTRY("PioPpmcPblFifo",
  405. SEC_SPC_FREEZE,
  406. SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
  407. /*17*/ FLAG_ENTRY("PioInitSmIn",
  408. 0,
  409. SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
  410. /*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
  411. SEC_SPC_FREEZE,
  412. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
  413. /*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
  414. SEC_SPC_FREEZE,
  415. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
  416. /*20*/ FLAG_ENTRY("PioHostAddrMemCor",
  417. 0,
  418. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
  419. /*21*/ FLAG_ENTRY("PioWriteDataParity",
  420. SEC_SPC_FREEZE,
  421. SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
  422. /*22*/ FLAG_ENTRY("PioStateMachine",
  423. SEC_SPC_FREEZE,
  424. SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
  425. /*23*/ FLAG_ENTRY("PioWriteQwValidParity",
  426. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  427. SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
  428. /*24*/ FLAG_ENTRY("PioBlockQwCountParity",
  429. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  430. SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
  431. /*25*/ FLAG_ENTRY("PioVlfVlLenParity",
  432. SEC_SPC_FREEZE,
  433. SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
  434. /*26*/ FLAG_ENTRY("PioVlfSopParity",
  435. SEC_SPC_FREEZE,
  436. SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
  437. /*27*/ FLAG_ENTRY("PioVlFifoParity",
  438. SEC_SPC_FREEZE,
  439. SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
  440. /*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
  441. SEC_SPC_FREEZE,
  442. SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
  443. /*29*/ FLAG_ENTRY("PioPpmcSopLen",
  444. SEC_SPC_FREEZE,
  445. SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
  446. /*30-31 reserved*/
  447. /*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
  448. SEC_SPC_FREEZE,
  449. SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
  450. /*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
  451. SEC_SPC_FREEZE,
  452. SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
  453. /*34*/ FLAG_ENTRY("PioPccSopHeadParity",
  454. SEC_SPC_FREEZE,
  455. SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
  456. /*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
  457. SEC_SPC_FREEZE,
  458. SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
  459. /*36-63 reserved*/
  460. };
  461. /* TXE PIO errors that cause an SPC freeze */
  462. #define ALL_PIO_FREEZE_ERR \
  463. (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
  464. | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
  465. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
  466. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
  467. | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
  468. | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
  469. | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
  470. | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
  471. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
  472. | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
  473. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
  474. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
  475. | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
  476. | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
  477. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
  478. | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
  479. | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
  480. | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
  481. | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
  482. | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
  483. | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
  484. | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
  485. | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
  486. | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
  487. | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
  488. | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
  489. | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
  490. | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
  491. | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
  492. /*
  493. * TXE SDMA Error flags
  494. */
  495. static struct flag_table sdma_err_status_flags[] = {
  496. /* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
  497. SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
  498. /* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
  499. SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
  500. /* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
  501. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
  502. /* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
  503. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
  504. /*04-63 reserved*/
  505. };
  506. /* TXE SDMA errors that cause an SPC freeze */
  507. #define ALL_SDMA_FREEZE_ERR \
  508. (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
  509. | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
  510. | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
  511. /* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
  512. #define PORT_DISCARD_EGRESS_ERRS \
  513. (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
  514. | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
  515. | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
  516. /*
  517. * TXE Egress Error flags
  518. */
  519. #define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
  520. static struct flag_table egress_err_status_flags[] = {
  521. /* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
  522. /* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
  523. /* 2 reserved */
  524. /* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
  525. SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
  526. /* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
  527. /* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
  528. /* 6 reserved */
  529. /* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
  530. SEES(TX_PIO_LAUNCH_INTF_PARITY)),
  531. /* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
  532. SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
  533. /* 9-10 reserved */
  534. /*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
  535. SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
  536. /*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
  537. /*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
  538. /*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
  539. /*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
  540. /*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
  541. SEES(TX_SDMA0_DISALLOWED_PACKET)),
  542. /*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
  543. SEES(TX_SDMA1_DISALLOWED_PACKET)),
  544. /*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
  545. SEES(TX_SDMA2_DISALLOWED_PACKET)),
  546. /*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
  547. SEES(TX_SDMA3_DISALLOWED_PACKET)),
  548. /*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
  549. SEES(TX_SDMA4_DISALLOWED_PACKET)),
  550. /*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
  551. SEES(TX_SDMA5_DISALLOWED_PACKET)),
  552. /*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
  553. SEES(TX_SDMA6_DISALLOWED_PACKET)),
  554. /*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
  555. SEES(TX_SDMA7_DISALLOWED_PACKET)),
  556. /*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
  557. SEES(TX_SDMA8_DISALLOWED_PACKET)),
  558. /*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
  559. SEES(TX_SDMA9_DISALLOWED_PACKET)),
  560. /*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
  561. SEES(TX_SDMA10_DISALLOWED_PACKET)),
  562. /*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
  563. SEES(TX_SDMA11_DISALLOWED_PACKET)),
  564. /*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
  565. SEES(TX_SDMA12_DISALLOWED_PACKET)),
  566. /*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
  567. SEES(TX_SDMA13_DISALLOWED_PACKET)),
  568. /*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
  569. SEES(TX_SDMA14_DISALLOWED_PACKET)),
  570. /*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
  571. SEES(TX_SDMA15_DISALLOWED_PACKET)),
  572. /*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
  573. SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
  574. /*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
  575. SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
  576. /*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
  577. SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
  578. /*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
  579. SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
  580. /*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
  581. SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
  582. /*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
  583. SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
  584. /*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
  585. SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
  586. /*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
  587. SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
  588. /*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
  589. SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
  590. /*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
  591. /*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
  592. /*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
  593. /*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
  594. /*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
  595. /*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
  596. /*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
  597. /*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
  598. /*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
  599. /*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
  600. /*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
  601. /*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
  602. /*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
  603. /*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
  604. /*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
  605. /*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
  606. /*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
  607. /*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
  608. /*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
  609. /*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
  610. /*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
  611. /*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
  612. SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
  613. /*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
  614. SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
  615. };
  616. /*
  617. * TXE Egress Error Info flags
  618. */
  619. #define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
  620. static struct flag_table egress_err_info_flags[] = {
  621. /* 0*/ FLAG_ENTRY0("Reserved", 0ull),
  622. /* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
  623. /* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  624. /* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  625. /* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
  626. /* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
  627. /* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
  628. /* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
  629. /* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
  630. /* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
  631. /*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
  632. /*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
  633. /*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
  634. /*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
  635. /*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
  636. /*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
  637. /*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
  638. /*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
  639. /*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
  640. /*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
  641. /*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
  642. /*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
  643. };
  644. /* TXE Egress errors that cause an SPC freeze */
  645. #define ALL_TXE_EGRESS_FREEZE_ERR \
  646. (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
  647. | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
  648. | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
  649. | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
  650. | SEES(TX_LAUNCH_CSR_PARITY) \
  651. | SEES(TX_SBRD_CTL_CSR_PARITY) \
  652. | SEES(TX_CONFIG_PARITY) \
  653. | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
  654. | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
  655. | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
  656. | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
  657. | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
  658. | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
  659. | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
  660. | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
  661. | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
  662. | SEES(TX_CREDIT_RETURN_PARITY))
  663. /*
  664. * TXE Send error flags
  665. */
  666. #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
  667. static struct flag_table send_err_status_flags[] = {
  668. /* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
  669. /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
  670. /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
  671. };
  672. /*
  673. * TXE Send Context Error flags and consequences
  674. */
  675. static struct flag_table sc_err_status_flags[] = {
  676. /* 0*/ FLAG_ENTRY("InconsistentSop",
  677. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  678. SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
  679. /* 1*/ FLAG_ENTRY("DisallowedPacket",
  680. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  681. SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
  682. /* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
  683. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  684. SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
  685. /* 3*/ FLAG_ENTRY("WriteOverflow",
  686. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  687. SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
  688. /* 4*/ FLAG_ENTRY("WriteOutOfBounds",
  689. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  690. SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
  691. /* 5-63 reserved*/
  692. };
  693. /*
  694. * RXE Receive Error flags
  695. */
  696. #define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
  697. static struct flag_table rxe_err_status_flags[] = {
  698. /* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
  699. /* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
  700. /* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
  701. /* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
  702. /* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
  703. /* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
  704. /* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
  705. /* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
  706. /* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
  707. /* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
  708. /*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
  709. /*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
  710. /*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
  711. /*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
  712. /*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
  713. /*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
  714. /*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
  715. RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
  716. /*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
  717. /*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
  718. /*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
  719. RXES(RBUF_BLOCK_LIST_READ_UNC)),
  720. /*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
  721. RXES(RBUF_BLOCK_LIST_READ_COR)),
  722. /*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
  723. RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
  724. /*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
  725. RXES(RBUF_CSR_QENT_CNT_PARITY)),
  726. /*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
  727. RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
  728. /*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
  729. RXES(RBUF_CSR_QVLD_BIT_PARITY)),
  730. /*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
  731. /*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
  732. /*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
  733. RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
  734. /*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
  735. /*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
  736. /*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
  737. /*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
  738. /*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
  739. /*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
  740. /*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
  741. /*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
  742. RXES(RBUF_FL_INITDONE_PARITY)),
  743. /*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
  744. RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
  745. /*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
  746. /*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
  747. /*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
  748. /*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
  749. RXES(LOOKUP_DES_PART1_UNC_COR)),
  750. /*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
  751. RXES(LOOKUP_DES_PART2_PARITY)),
  752. /*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
  753. /*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
  754. /*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
  755. /*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
  756. /*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
  757. /*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
  758. /*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
  759. /*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
  760. /*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
  761. /*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
  762. /*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
  763. /*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
  764. /*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
  765. /*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
  766. /*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
  767. /*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
  768. /*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
  769. /*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
  770. /*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
  771. /*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
  772. /*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
  773. /*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
  774. };
  775. /* RXE errors that will trigger an SPC freeze */
  776. #define ALL_RXE_FREEZE_ERR \
  777. (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
  778. | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
  779. | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
  780. | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
  781. | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
  782. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
  783. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
  784. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
  785. | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
  786. | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
  787. | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
  788. | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
  789. | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
  790. | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
  791. | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
  792. | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
  793. | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
  794. | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
  795. | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
  796. | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
  797. | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
  798. | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
  799. | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
  800. | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
  801. | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
  802. | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
  803. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
  804. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
  805. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
  806. | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
  807. | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
  808. | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
  809. | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
  810. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
  811. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
  812. | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
  813. | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
  814. | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
  815. | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
  816. | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
  817. | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
  818. | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
  819. | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
  820. | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
  821. #define RXE_FREEZE_ABORT_MASK \
  822. (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
  823. RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
  824. RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
  825. /*
  826. * DCC Error Flags
  827. */
  828. #define DCCE(name) DCC_ERR_FLG_##name##_SMASK
  829. static struct flag_table dcc_err_flags[] = {
  830. FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
  831. FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
  832. FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
  833. FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
  834. FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
  835. FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
  836. FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
  837. FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
  838. FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
  839. FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
  840. FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
  841. FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
  842. FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
  843. FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
  844. FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
  845. FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
  846. FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
  847. FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
  848. FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
  849. FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
  850. FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
  851. FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
  852. FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
  853. FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
  854. FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
  855. FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
  856. FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
  857. FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
  858. FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
  859. FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
  860. FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
  861. FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
  862. FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
  863. FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
  864. FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
  865. FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
  866. FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
  867. FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
  868. FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
  869. FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
  870. FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
  871. FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
  872. FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
  873. FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
  874. FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
  875. FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
  876. };
  877. /*
  878. * LCB error flags
  879. */
  880. #define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
  881. static struct flag_table lcb_err_flags[] = {
  882. /* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
  883. /* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
  884. /* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
  885. /* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
  886. LCBE(ALL_LNS_FAILED_REINIT_TEST)),
  887. /* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
  888. /* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
  889. /* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
  890. /* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
  891. /* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
  892. /* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
  893. /*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
  894. /*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
  895. /*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
  896. /*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
  897. LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
  898. /*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
  899. /*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
  900. /*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
  901. /*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
  902. /*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
  903. /*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
  904. LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
  905. /*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
  906. /*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
  907. /*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
  908. /*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
  909. /*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
  910. /*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
  911. /*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
  912. LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
  913. /*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
  914. /*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
  915. LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
  916. /*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
  917. LCBE(REDUNDANT_FLIT_PARITY_ERR))
  918. };
  919. /*
  920. * DC8051 Error Flags
  921. */
  922. #define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
  923. static struct flag_table dc8051_err_flags[] = {
  924. FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
  925. FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
  926. FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
  927. FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
  928. FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
  929. FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
  930. FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
  931. FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
  932. FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
  933. D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
  934. FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
  935. };
  936. /*
  937. * DC8051 Information Error flags
  938. *
  939. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
  940. */
  941. static struct flag_table dc8051_info_err_flags[] = {
  942. FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
  943. FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
  944. FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
  945. FLAG_ENTRY0("Serdes internal loopback failure",
  946. FAILED_SERDES_INTERNAL_LOOPBACK),
  947. FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
  948. FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
  949. FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
  950. FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
  951. FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
  952. FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
  953. FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
  954. FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
  955. FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
  956. FLAG_ENTRY0("External Device Request Timeout",
  957. EXTERNAL_DEVICE_REQ_TIMEOUT),
  958. };
  959. /*
  960. * DC8051 Information Host Information flags
  961. *
  962. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
  963. */
  964. static struct flag_table dc8051_info_host_msg_flags[] = {
  965. FLAG_ENTRY0("Host request done", 0x0001),
  966. FLAG_ENTRY0("BC PWR_MGM message", 0x0002),
  967. FLAG_ENTRY0("BC SMA message", 0x0004),
  968. FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
  969. FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
  970. FLAG_ENTRY0("External device config request", 0x0020),
  971. FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
  972. FLAG_ENTRY0("LinkUp achieved", 0x0080),
  973. FLAG_ENTRY0("Link going down", 0x0100),
  974. FLAG_ENTRY0("Link width downgraded", 0x0200),
  975. };
  976. static u32 encoded_size(u32 size);
  977. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
  978. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
  979. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  980. u8 *continuous);
  981. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  982. u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
  983. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  984. u8 *remote_tx_rate, u16 *link_widths);
  985. static void read_vc_local_link_mode(struct hfi1_devdata *dd, u8 *misc_bits,
  986. u8 *flag_bits, u16 *link_widths);
  987. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  988. u8 *device_rev);
  989. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
  990. static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
  991. u8 *tx_polarity_inversion,
  992. u8 *rx_polarity_inversion, u8 *max_rate);
  993. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  994. unsigned int context, u64 err_status);
  995. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
  996. static void handle_dcc_err(struct hfi1_devdata *dd,
  997. unsigned int context, u64 err_status);
  998. static void handle_lcb_err(struct hfi1_devdata *dd,
  999. unsigned int context, u64 err_status);
  1000. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1001. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1002. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1003. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1004. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1005. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1006. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1007. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1008. static void set_partition_keys(struct hfi1_pportdata *ppd);
  1009. static const char *link_state_name(u32 state);
  1010. static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
  1011. u32 state);
  1012. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  1013. u64 *out_data);
  1014. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
  1015. static int thermal_init(struct hfi1_devdata *dd);
  1016. static void update_statusp(struct hfi1_pportdata *ppd, u32 state);
  1017. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  1018. int msecs);
  1019. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1020. int msecs);
  1021. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state);
  1022. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state);
  1023. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1024. int msecs);
  1025. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
  1026. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
  1027. static void handle_temp_err(struct hfi1_devdata *dd);
  1028. static void dc_shutdown(struct hfi1_devdata *dd);
  1029. static void dc_start(struct hfi1_devdata *dd);
  1030. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  1031. unsigned int *np);
  1032. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
  1033. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
  1034. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index);
  1035. static void update_xmit_counters(struct hfi1_pportdata *ppd, u16 link_width);
  1036. /*
  1037. * Error interrupt table entry. This is used as input to the interrupt
  1038. * "clear down" routine used for all second tier error interrupt register.
  1039. * Second tier interrupt registers have a single bit representing them
  1040. * in the top-level CceIntStatus.
  1041. */
  1042. struct err_reg_info {
  1043. u32 status; /* status CSR offset */
  1044. u32 clear; /* clear CSR offset */
  1045. u32 mask; /* mask CSR offset */
  1046. void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
  1047. const char *desc;
  1048. };
  1049. #define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
  1050. #define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
  1051. #define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
  1052. /*
  1053. * Helpers for building HFI and DC error interrupt table entries. Different
  1054. * helpers are needed because of inconsistent register names.
  1055. */
  1056. #define EE(reg, handler, desc) \
  1057. { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
  1058. handler, desc }
  1059. #define DC_EE1(reg, handler, desc) \
  1060. { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
  1061. #define DC_EE2(reg, handler, desc) \
  1062. { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
  1063. /*
  1064. * Table of the "misc" grouping of error interrupts. Each entry refers to
  1065. * another register containing more information.
  1066. */
  1067. static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
  1068. /* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
  1069. /* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
  1070. /* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
  1071. /* 3*/ { 0, 0, 0, NULL }, /* reserved */
  1072. /* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
  1073. /* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
  1074. /* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
  1075. /* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
  1076. /* the rest are reserved */
  1077. };
  1078. /*
  1079. * Index into the Various section of the interrupt sources
  1080. * corresponding to the Critical Temperature interrupt.
  1081. */
  1082. #define TCRIT_INT_SOURCE 4
  1083. /*
  1084. * SDMA error interrupt entry - refers to another register containing more
  1085. * information.
  1086. */
  1087. static const struct err_reg_info sdma_eng_err =
  1088. EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
  1089. static const struct err_reg_info various_err[NUM_VARIOUS] = {
  1090. /* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
  1091. /* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
  1092. /* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
  1093. /* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
  1094. /* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
  1095. /* rest are reserved */
  1096. };
  1097. /*
  1098. * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
  1099. * register can not be derived from the MTU value because 10K is not
  1100. * a power of 2. Therefore, we need a constant. Everything else can
  1101. * be calculated.
  1102. */
  1103. #define DCC_CFG_PORT_MTU_CAP_10240 7
  1104. /*
  1105. * Table of the DC grouping of error interrupts. Each entry refers to
  1106. * another register containing more information.
  1107. */
  1108. static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
  1109. /* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
  1110. /* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
  1111. /* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
  1112. /* 3*/ /* dc_lbm_int - special, see is_dc_int() */
  1113. /* the rest are reserved */
  1114. };
  1115. struct cntr_entry {
  1116. /*
  1117. * counter name
  1118. */
  1119. char *name;
  1120. /*
  1121. * csr to read for name (if applicable)
  1122. */
  1123. u64 csr;
  1124. /*
  1125. * offset into dd or ppd to store the counter's value
  1126. */
  1127. int offset;
  1128. /*
  1129. * flags
  1130. */
  1131. u8 flags;
  1132. /*
  1133. * accessor for stat element, context either dd or ppd
  1134. */
  1135. u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
  1136. int mode, u64 data);
  1137. };
  1138. #define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
  1139. #define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
  1140. #define CNTR_ELEM(name, csr, offset, flags, accessor) \
  1141. { \
  1142. name, \
  1143. csr, \
  1144. offset, \
  1145. flags, \
  1146. accessor \
  1147. }
  1148. /* 32bit RXE */
  1149. #define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1150. CNTR_ELEM(#name, \
  1151. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1152. 0, flags | CNTR_32BIT, \
  1153. port_access_u32_csr)
  1154. #define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
  1155. CNTR_ELEM(#name, \
  1156. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1157. 0, flags | CNTR_32BIT, \
  1158. dev_access_u32_csr)
  1159. /* 64bit RXE */
  1160. #define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1161. CNTR_ELEM(#name, \
  1162. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1163. 0, flags, \
  1164. port_access_u64_csr)
  1165. #define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
  1166. CNTR_ELEM(#name, \
  1167. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1168. 0, flags, \
  1169. dev_access_u64_csr)
  1170. #define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
  1171. #define OVR_ELM(ctx) \
  1172. CNTR_ELEM("RcvHdrOvr" #ctx, \
  1173. (RCV_HDR_OVFL_CNT + ctx * 0x100), \
  1174. 0, CNTR_NORMAL, port_access_u64_csr)
  1175. /* 32bit TXE */
  1176. #define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1177. CNTR_ELEM(#name, \
  1178. (counter * 8 + SEND_COUNTER_ARRAY32), \
  1179. 0, flags | CNTR_32BIT, \
  1180. port_access_u32_csr)
  1181. /* 64bit TXE */
  1182. #define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1183. CNTR_ELEM(#name, \
  1184. (counter * 8 + SEND_COUNTER_ARRAY64), \
  1185. 0, flags, \
  1186. port_access_u64_csr)
  1187. # define TX64_DEV_CNTR_ELEM(name, counter, flags) \
  1188. CNTR_ELEM(#name,\
  1189. counter * 8 + SEND_COUNTER_ARRAY64, \
  1190. 0, \
  1191. flags, \
  1192. dev_access_u64_csr)
  1193. /* CCE */
  1194. #define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
  1195. CNTR_ELEM(#name, \
  1196. (counter * 8 + CCE_COUNTER_ARRAY32), \
  1197. 0, flags | CNTR_32BIT, \
  1198. dev_access_u32_csr)
  1199. #define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
  1200. CNTR_ELEM(#name, \
  1201. (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
  1202. 0, flags | CNTR_32BIT, \
  1203. dev_access_u32_csr)
  1204. /* DC */
  1205. #define DC_PERF_CNTR(name, counter, flags) \
  1206. CNTR_ELEM(#name, \
  1207. counter, \
  1208. 0, \
  1209. flags, \
  1210. dev_access_u64_csr)
  1211. #define DC_PERF_CNTR_LCB(name, counter, flags) \
  1212. CNTR_ELEM(#name, \
  1213. counter, \
  1214. 0, \
  1215. flags, \
  1216. dc_access_lcb_cntr)
  1217. /* ibp counters */
  1218. #define SW_IBP_CNTR(name, cntr) \
  1219. CNTR_ELEM(#name, \
  1220. 0, \
  1221. 0, \
  1222. CNTR_SYNTH, \
  1223. access_ibp_##cntr)
  1224. /**
  1225. * hfi_addr_from_offset - return addr for readq/writeq
  1226. * @dd - the dd device
  1227. * @offset - the offset of the CSR within bar0
  1228. *
  1229. * This routine selects the appropriate base address
  1230. * based on the indicated offset.
  1231. */
  1232. static inline void __iomem *hfi1_addr_from_offset(
  1233. const struct hfi1_devdata *dd,
  1234. u32 offset)
  1235. {
  1236. if (offset >= dd->base2_start)
  1237. return dd->kregbase2 + (offset - dd->base2_start);
  1238. return dd->kregbase1 + offset;
  1239. }
  1240. /**
  1241. * read_csr - read CSR at the indicated offset
  1242. * @dd - the dd device
  1243. * @offset - the offset of the CSR within bar0
  1244. *
  1245. * Return: the value read or all FF's if there
  1246. * is no mapping
  1247. */
  1248. u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
  1249. {
  1250. if (dd->flags & HFI1_PRESENT)
  1251. return readq(hfi1_addr_from_offset(dd, offset));
  1252. return -1;
  1253. }
  1254. /**
  1255. * write_csr - write CSR at the indicated offset
  1256. * @dd - the dd device
  1257. * @offset - the offset of the CSR within bar0
  1258. * @value - value to write
  1259. */
  1260. void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
  1261. {
  1262. if (dd->flags & HFI1_PRESENT) {
  1263. void __iomem *base = hfi1_addr_from_offset(dd, offset);
  1264. /* avoid write to RcvArray */
  1265. if (WARN_ON(offset >= RCV_ARRAY && offset < dd->base2_start))
  1266. return;
  1267. writeq(value, base);
  1268. }
  1269. }
  1270. /**
  1271. * get_csr_addr - return te iomem address for offset
  1272. * @dd - the dd device
  1273. * @offset - the offset of the CSR within bar0
  1274. *
  1275. * Return: The iomem address to use in subsequent
  1276. * writeq/readq operations.
  1277. */
  1278. void __iomem *get_csr_addr(
  1279. const struct hfi1_devdata *dd,
  1280. u32 offset)
  1281. {
  1282. if (dd->flags & HFI1_PRESENT)
  1283. return hfi1_addr_from_offset(dd, offset);
  1284. return NULL;
  1285. }
  1286. static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
  1287. int mode, u64 value)
  1288. {
  1289. u64 ret;
  1290. if (mode == CNTR_MODE_R) {
  1291. ret = read_csr(dd, csr);
  1292. } else if (mode == CNTR_MODE_W) {
  1293. write_csr(dd, csr, value);
  1294. ret = value;
  1295. } else {
  1296. dd_dev_err(dd, "Invalid cntr register access mode");
  1297. return 0;
  1298. }
  1299. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
  1300. return ret;
  1301. }
  1302. /* Dev Access */
  1303. static u64 dev_access_u32_csr(const struct cntr_entry *entry,
  1304. void *context, int vl, int mode, u64 data)
  1305. {
  1306. struct hfi1_devdata *dd = context;
  1307. u64 csr = entry->csr;
  1308. if (entry->flags & CNTR_SDMA) {
  1309. if (vl == CNTR_INVALID_VL)
  1310. return 0;
  1311. csr += 0x100 * vl;
  1312. } else {
  1313. if (vl != CNTR_INVALID_VL)
  1314. return 0;
  1315. }
  1316. return read_write_csr(dd, csr, mode, data);
  1317. }
  1318. static u64 access_sde_err_cnt(const struct cntr_entry *entry,
  1319. void *context, int idx, int mode, u64 data)
  1320. {
  1321. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1322. if (dd->per_sdma && idx < dd->num_sdma)
  1323. return dd->per_sdma[idx].err_cnt;
  1324. return 0;
  1325. }
  1326. static u64 access_sde_int_cnt(const struct cntr_entry *entry,
  1327. void *context, int idx, int mode, u64 data)
  1328. {
  1329. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1330. if (dd->per_sdma && idx < dd->num_sdma)
  1331. return dd->per_sdma[idx].sdma_int_cnt;
  1332. return 0;
  1333. }
  1334. static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
  1335. void *context, int idx, int mode, u64 data)
  1336. {
  1337. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1338. if (dd->per_sdma && idx < dd->num_sdma)
  1339. return dd->per_sdma[idx].idle_int_cnt;
  1340. return 0;
  1341. }
  1342. static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
  1343. void *context, int idx, int mode,
  1344. u64 data)
  1345. {
  1346. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1347. if (dd->per_sdma && idx < dd->num_sdma)
  1348. return dd->per_sdma[idx].progress_int_cnt;
  1349. return 0;
  1350. }
  1351. static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
  1352. int vl, int mode, u64 data)
  1353. {
  1354. struct hfi1_devdata *dd = context;
  1355. u64 val = 0;
  1356. u64 csr = entry->csr;
  1357. if (entry->flags & CNTR_VL) {
  1358. if (vl == CNTR_INVALID_VL)
  1359. return 0;
  1360. csr += 8 * vl;
  1361. } else {
  1362. if (vl != CNTR_INVALID_VL)
  1363. return 0;
  1364. }
  1365. val = read_write_csr(dd, csr, mode, data);
  1366. return val;
  1367. }
  1368. static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
  1369. int vl, int mode, u64 data)
  1370. {
  1371. struct hfi1_devdata *dd = context;
  1372. u32 csr = entry->csr;
  1373. int ret = 0;
  1374. if (vl != CNTR_INVALID_VL)
  1375. return 0;
  1376. if (mode == CNTR_MODE_R)
  1377. ret = read_lcb_csr(dd, csr, &data);
  1378. else if (mode == CNTR_MODE_W)
  1379. ret = write_lcb_csr(dd, csr, data);
  1380. if (ret) {
  1381. dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
  1382. return 0;
  1383. }
  1384. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
  1385. return data;
  1386. }
  1387. /* Port Access */
  1388. static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
  1389. int vl, int mode, u64 data)
  1390. {
  1391. struct hfi1_pportdata *ppd = context;
  1392. if (vl != CNTR_INVALID_VL)
  1393. return 0;
  1394. return read_write_csr(ppd->dd, entry->csr, mode, data);
  1395. }
  1396. static u64 port_access_u64_csr(const struct cntr_entry *entry,
  1397. void *context, int vl, int mode, u64 data)
  1398. {
  1399. struct hfi1_pportdata *ppd = context;
  1400. u64 val;
  1401. u64 csr = entry->csr;
  1402. if (entry->flags & CNTR_VL) {
  1403. if (vl == CNTR_INVALID_VL)
  1404. return 0;
  1405. csr += 8 * vl;
  1406. } else {
  1407. if (vl != CNTR_INVALID_VL)
  1408. return 0;
  1409. }
  1410. val = read_write_csr(ppd->dd, csr, mode, data);
  1411. return val;
  1412. }
  1413. /* Software defined */
  1414. static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
  1415. u64 data)
  1416. {
  1417. u64 ret;
  1418. if (mode == CNTR_MODE_R) {
  1419. ret = *cntr;
  1420. } else if (mode == CNTR_MODE_W) {
  1421. *cntr = data;
  1422. ret = data;
  1423. } else {
  1424. dd_dev_err(dd, "Invalid cntr sw access mode");
  1425. return 0;
  1426. }
  1427. hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
  1428. return ret;
  1429. }
  1430. static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
  1431. int vl, int mode, u64 data)
  1432. {
  1433. struct hfi1_pportdata *ppd = context;
  1434. if (vl != CNTR_INVALID_VL)
  1435. return 0;
  1436. return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
  1437. }
  1438. static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
  1439. int vl, int mode, u64 data)
  1440. {
  1441. struct hfi1_pportdata *ppd = context;
  1442. if (vl != CNTR_INVALID_VL)
  1443. return 0;
  1444. return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
  1445. }
  1446. static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
  1447. void *context, int vl, int mode,
  1448. u64 data)
  1449. {
  1450. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1451. if (vl != CNTR_INVALID_VL)
  1452. return 0;
  1453. return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
  1454. }
  1455. static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
  1456. void *context, int vl, int mode, u64 data)
  1457. {
  1458. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1459. u64 zero = 0;
  1460. u64 *counter;
  1461. if (vl == CNTR_INVALID_VL)
  1462. counter = &ppd->port_xmit_discards;
  1463. else if (vl >= 0 && vl < C_VL_COUNT)
  1464. counter = &ppd->port_xmit_discards_vl[vl];
  1465. else
  1466. counter = &zero;
  1467. return read_write_sw(ppd->dd, counter, mode, data);
  1468. }
  1469. static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
  1470. void *context, int vl, int mode,
  1471. u64 data)
  1472. {
  1473. struct hfi1_pportdata *ppd = context;
  1474. if (vl != CNTR_INVALID_VL)
  1475. return 0;
  1476. return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
  1477. mode, data);
  1478. }
  1479. static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
  1480. void *context, int vl, int mode, u64 data)
  1481. {
  1482. struct hfi1_pportdata *ppd = context;
  1483. if (vl != CNTR_INVALID_VL)
  1484. return 0;
  1485. return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
  1486. mode, data);
  1487. }
  1488. u64 get_all_cpu_total(u64 __percpu *cntr)
  1489. {
  1490. int cpu;
  1491. u64 counter = 0;
  1492. for_each_possible_cpu(cpu)
  1493. counter += *per_cpu_ptr(cntr, cpu);
  1494. return counter;
  1495. }
  1496. static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
  1497. u64 __percpu *cntr,
  1498. int vl, int mode, u64 data)
  1499. {
  1500. u64 ret = 0;
  1501. if (vl != CNTR_INVALID_VL)
  1502. return 0;
  1503. if (mode == CNTR_MODE_R) {
  1504. ret = get_all_cpu_total(cntr) - *z_val;
  1505. } else if (mode == CNTR_MODE_W) {
  1506. /* A write can only zero the counter */
  1507. if (data == 0)
  1508. *z_val = get_all_cpu_total(cntr);
  1509. else
  1510. dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
  1511. } else {
  1512. dd_dev_err(dd, "Invalid cntr sw cpu access mode");
  1513. return 0;
  1514. }
  1515. return ret;
  1516. }
  1517. static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
  1518. void *context, int vl, int mode, u64 data)
  1519. {
  1520. struct hfi1_devdata *dd = context;
  1521. return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
  1522. mode, data);
  1523. }
  1524. static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
  1525. void *context, int vl, int mode, u64 data)
  1526. {
  1527. struct hfi1_devdata *dd = context;
  1528. return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
  1529. mode, data);
  1530. }
  1531. static u64 access_sw_pio_wait(const struct cntr_entry *entry,
  1532. void *context, int vl, int mode, u64 data)
  1533. {
  1534. struct hfi1_devdata *dd = context;
  1535. return dd->verbs_dev.n_piowait;
  1536. }
  1537. static u64 access_sw_pio_drain(const struct cntr_entry *entry,
  1538. void *context, int vl, int mode, u64 data)
  1539. {
  1540. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1541. return dd->verbs_dev.n_piodrain;
  1542. }
  1543. static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
  1544. void *context, int vl, int mode, u64 data)
  1545. {
  1546. struct hfi1_devdata *dd = context;
  1547. return dd->verbs_dev.n_txwait;
  1548. }
  1549. static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
  1550. void *context, int vl, int mode, u64 data)
  1551. {
  1552. struct hfi1_devdata *dd = context;
  1553. return dd->verbs_dev.n_kmem_wait;
  1554. }
  1555. static u64 access_sw_send_schedule(const struct cntr_entry *entry,
  1556. void *context, int vl, int mode, u64 data)
  1557. {
  1558. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1559. return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
  1560. mode, data);
  1561. }
  1562. /* Software counters for the error status bits within MISC_ERR_STATUS */
  1563. static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
  1564. void *context, int vl, int mode,
  1565. u64 data)
  1566. {
  1567. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1568. return dd->misc_err_status_cnt[12];
  1569. }
  1570. static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
  1571. void *context, int vl, int mode,
  1572. u64 data)
  1573. {
  1574. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1575. return dd->misc_err_status_cnt[11];
  1576. }
  1577. static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
  1578. void *context, int vl, int mode,
  1579. u64 data)
  1580. {
  1581. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1582. return dd->misc_err_status_cnt[10];
  1583. }
  1584. static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
  1585. void *context, int vl,
  1586. int mode, u64 data)
  1587. {
  1588. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1589. return dd->misc_err_status_cnt[9];
  1590. }
  1591. static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
  1592. void *context, int vl, int mode,
  1593. u64 data)
  1594. {
  1595. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1596. return dd->misc_err_status_cnt[8];
  1597. }
  1598. static u64 access_misc_efuse_read_bad_addr_err_cnt(
  1599. const struct cntr_entry *entry,
  1600. void *context, int vl, int mode, u64 data)
  1601. {
  1602. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1603. return dd->misc_err_status_cnt[7];
  1604. }
  1605. static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
  1606. void *context, int vl,
  1607. int mode, u64 data)
  1608. {
  1609. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1610. return dd->misc_err_status_cnt[6];
  1611. }
  1612. static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
  1613. void *context, int vl, int mode,
  1614. u64 data)
  1615. {
  1616. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1617. return dd->misc_err_status_cnt[5];
  1618. }
  1619. static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
  1620. void *context, int vl, int mode,
  1621. u64 data)
  1622. {
  1623. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1624. return dd->misc_err_status_cnt[4];
  1625. }
  1626. static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
  1627. void *context, int vl,
  1628. int mode, u64 data)
  1629. {
  1630. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1631. return dd->misc_err_status_cnt[3];
  1632. }
  1633. static u64 access_misc_csr_write_bad_addr_err_cnt(
  1634. const struct cntr_entry *entry,
  1635. void *context, int vl, int mode, u64 data)
  1636. {
  1637. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1638. return dd->misc_err_status_cnt[2];
  1639. }
  1640. static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1641. void *context, int vl,
  1642. int mode, u64 data)
  1643. {
  1644. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1645. return dd->misc_err_status_cnt[1];
  1646. }
  1647. static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
  1648. void *context, int vl, int mode,
  1649. u64 data)
  1650. {
  1651. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1652. return dd->misc_err_status_cnt[0];
  1653. }
  1654. /*
  1655. * Software counter for the aggregate of
  1656. * individual CceErrStatus counters
  1657. */
  1658. static u64 access_sw_cce_err_status_aggregated_cnt(
  1659. const struct cntr_entry *entry,
  1660. void *context, int vl, int mode, u64 data)
  1661. {
  1662. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1663. return dd->sw_cce_err_status_aggregate;
  1664. }
  1665. /*
  1666. * Software counters corresponding to each of the
  1667. * error status bits within CceErrStatus
  1668. */
  1669. static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
  1670. void *context, int vl, int mode,
  1671. u64 data)
  1672. {
  1673. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1674. return dd->cce_err_status_cnt[40];
  1675. }
  1676. static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
  1677. void *context, int vl, int mode,
  1678. u64 data)
  1679. {
  1680. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1681. return dd->cce_err_status_cnt[39];
  1682. }
  1683. static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
  1684. void *context, int vl, int mode,
  1685. u64 data)
  1686. {
  1687. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1688. return dd->cce_err_status_cnt[38];
  1689. }
  1690. static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
  1691. void *context, int vl, int mode,
  1692. u64 data)
  1693. {
  1694. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1695. return dd->cce_err_status_cnt[37];
  1696. }
  1697. static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
  1698. void *context, int vl, int mode,
  1699. u64 data)
  1700. {
  1701. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1702. return dd->cce_err_status_cnt[36];
  1703. }
  1704. static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
  1705. const struct cntr_entry *entry,
  1706. void *context, int vl, int mode, u64 data)
  1707. {
  1708. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1709. return dd->cce_err_status_cnt[35];
  1710. }
  1711. static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
  1712. const struct cntr_entry *entry,
  1713. void *context, int vl, int mode, u64 data)
  1714. {
  1715. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1716. return dd->cce_err_status_cnt[34];
  1717. }
  1718. static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1719. void *context, int vl,
  1720. int mode, u64 data)
  1721. {
  1722. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1723. return dd->cce_err_status_cnt[33];
  1724. }
  1725. static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1726. void *context, int vl, int mode,
  1727. u64 data)
  1728. {
  1729. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1730. return dd->cce_err_status_cnt[32];
  1731. }
  1732. static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
  1733. void *context, int vl, int mode, u64 data)
  1734. {
  1735. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1736. return dd->cce_err_status_cnt[31];
  1737. }
  1738. static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
  1739. void *context, int vl, int mode,
  1740. u64 data)
  1741. {
  1742. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1743. return dd->cce_err_status_cnt[30];
  1744. }
  1745. static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
  1746. void *context, int vl, int mode,
  1747. u64 data)
  1748. {
  1749. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1750. return dd->cce_err_status_cnt[29];
  1751. }
  1752. static u64 access_pcic_transmit_back_parity_err_cnt(
  1753. const struct cntr_entry *entry,
  1754. void *context, int vl, int mode, u64 data)
  1755. {
  1756. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1757. return dd->cce_err_status_cnt[28];
  1758. }
  1759. static u64 access_pcic_transmit_front_parity_err_cnt(
  1760. const struct cntr_entry *entry,
  1761. void *context, int vl, int mode, u64 data)
  1762. {
  1763. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1764. return dd->cce_err_status_cnt[27];
  1765. }
  1766. static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1767. void *context, int vl, int mode,
  1768. u64 data)
  1769. {
  1770. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1771. return dd->cce_err_status_cnt[26];
  1772. }
  1773. static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1774. void *context, int vl, int mode,
  1775. u64 data)
  1776. {
  1777. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1778. return dd->cce_err_status_cnt[25];
  1779. }
  1780. static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1781. void *context, int vl, int mode,
  1782. u64 data)
  1783. {
  1784. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1785. return dd->cce_err_status_cnt[24];
  1786. }
  1787. static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1788. void *context, int vl, int mode,
  1789. u64 data)
  1790. {
  1791. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1792. return dd->cce_err_status_cnt[23];
  1793. }
  1794. static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
  1795. void *context, int vl,
  1796. int mode, u64 data)
  1797. {
  1798. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1799. return dd->cce_err_status_cnt[22];
  1800. }
  1801. static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
  1802. void *context, int vl, int mode,
  1803. u64 data)
  1804. {
  1805. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1806. return dd->cce_err_status_cnt[21];
  1807. }
  1808. static u64 access_pcic_n_post_dat_q_parity_err_cnt(
  1809. const struct cntr_entry *entry,
  1810. void *context, int vl, int mode, u64 data)
  1811. {
  1812. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1813. return dd->cce_err_status_cnt[20];
  1814. }
  1815. static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
  1816. void *context, int vl,
  1817. int mode, u64 data)
  1818. {
  1819. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1820. return dd->cce_err_status_cnt[19];
  1821. }
  1822. static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1823. void *context, int vl, int mode,
  1824. u64 data)
  1825. {
  1826. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1827. return dd->cce_err_status_cnt[18];
  1828. }
  1829. static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1830. void *context, int vl, int mode,
  1831. u64 data)
  1832. {
  1833. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1834. return dd->cce_err_status_cnt[17];
  1835. }
  1836. static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1837. void *context, int vl, int mode,
  1838. u64 data)
  1839. {
  1840. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1841. return dd->cce_err_status_cnt[16];
  1842. }
  1843. static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1844. void *context, int vl, int mode,
  1845. u64 data)
  1846. {
  1847. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1848. return dd->cce_err_status_cnt[15];
  1849. }
  1850. static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
  1851. void *context, int vl,
  1852. int mode, u64 data)
  1853. {
  1854. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1855. return dd->cce_err_status_cnt[14];
  1856. }
  1857. static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
  1858. void *context, int vl, int mode,
  1859. u64 data)
  1860. {
  1861. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1862. return dd->cce_err_status_cnt[13];
  1863. }
  1864. static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
  1865. const struct cntr_entry *entry,
  1866. void *context, int vl, int mode, u64 data)
  1867. {
  1868. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1869. return dd->cce_err_status_cnt[12];
  1870. }
  1871. static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
  1872. const struct cntr_entry *entry,
  1873. void *context, int vl, int mode, u64 data)
  1874. {
  1875. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1876. return dd->cce_err_status_cnt[11];
  1877. }
  1878. static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
  1879. const struct cntr_entry *entry,
  1880. void *context, int vl, int mode, u64 data)
  1881. {
  1882. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1883. return dd->cce_err_status_cnt[10];
  1884. }
  1885. static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
  1886. const struct cntr_entry *entry,
  1887. void *context, int vl, int mode, u64 data)
  1888. {
  1889. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1890. return dd->cce_err_status_cnt[9];
  1891. }
  1892. static u64 access_cce_cli2_async_fifo_parity_err_cnt(
  1893. const struct cntr_entry *entry,
  1894. void *context, int vl, int mode, u64 data)
  1895. {
  1896. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1897. return dd->cce_err_status_cnt[8];
  1898. }
  1899. static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
  1900. void *context, int vl,
  1901. int mode, u64 data)
  1902. {
  1903. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1904. return dd->cce_err_status_cnt[7];
  1905. }
  1906. static u64 access_cce_cli0_async_fifo_parity_err_cnt(
  1907. const struct cntr_entry *entry,
  1908. void *context, int vl, int mode, u64 data)
  1909. {
  1910. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1911. return dd->cce_err_status_cnt[6];
  1912. }
  1913. static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
  1914. void *context, int vl, int mode,
  1915. u64 data)
  1916. {
  1917. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1918. return dd->cce_err_status_cnt[5];
  1919. }
  1920. static u64 access_cce_trgt_access_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->cce_err_status_cnt[4];
  1926. }
  1927. static u64 access_cce_trgt_async_fifo_parity_err_cnt(
  1928. const struct cntr_entry *entry,
  1929. void *context, int vl, int mode, u64 data)
  1930. {
  1931. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1932. return dd->cce_err_status_cnt[3];
  1933. }
  1934. static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1935. void *context, int vl,
  1936. int mode, u64 data)
  1937. {
  1938. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1939. return dd->cce_err_status_cnt[2];
  1940. }
  1941. static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1942. void *context, int vl,
  1943. int mode, u64 data)
  1944. {
  1945. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1946. return dd->cce_err_status_cnt[1];
  1947. }
  1948. static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
  1949. void *context, int vl, int mode,
  1950. u64 data)
  1951. {
  1952. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1953. return dd->cce_err_status_cnt[0];
  1954. }
  1955. /*
  1956. * Software counters corresponding to each of the
  1957. * error status bits within RcvErrStatus
  1958. */
  1959. static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
  1960. void *context, int vl, int mode,
  1961. u64 data)
  1962. {
  1963. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1964. return dd->rcv_err_status_cnt[63];
  1965. }
  1966. static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1967. void *context, int vl,
  1968. int mode, u64 data)
  1969. {
  1970. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1971. return dd->rcv_err_status_cnt[62];
  1972. }
  1973. static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1974. void *context, int vl, int mode,
  1975. u64 data)
  1976. {
  1977. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1978. return dd->rcv_err_status_cnt[61];
  1979. }
  1980. static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
  1981. void *context, int vl, int mode,
  1982. u64 data)
  1983. {
  1984. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1985. return dd->rcv_err_status_cnt[60];
  1986. }
  1987. static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1988. void *context, int vl,
  1989. int mode, u64 data)
  1990. {
  1991. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1992. return dd->rcv_err_status_cnt[59];
  1993. }
  1994. static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1995. void *context, int vl,
  1996. int mode, u64 data)
  1997. {
  1998. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1999. return dd->rcv_err_status_cnt[58];
  2000. }
  2001. static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2002. void *context, int vl, int mode,
  2003. u64 data)
  2004. {
  2005. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2006. return dd->rcv_err_status_cnt[57];
  2007. }
  2008. static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
  2009. void *context, int vl, int mode,
  2010. u64 data)
  2011. {
  2012. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2013. return dd->rcv_err_status_cnt[56];
  2014. }
  2015. static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
  2016. void *context, int vl, int mode,
  2017. u64 data)
  2018. {
  2019. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2020. return dd->rcv_err_status_cnt[55];
  2021. }
  2022. static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
  2023. const struct cntr_entry *entry,
  2024. void *context, int vl, int mode, u64 data)
  2025. {
  2026. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2027. return dd->rcv_err_status_cnt[54];
  2028. }
  2029. static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
  2030. const struct cntr_entry *entry,
  2031. void *context, int vl, int mode, u64 data)
  2032. {
  2033. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2034. return dd->rcv_err_status_cnt[53];
  2035. }
  2036. static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
  2037. void *context, int vl,
  2038. int mode, u64 data)
  2039. {
  2040. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2041. return dd->rcv_err_status_cnt[52];
  2042. }
  2043. static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
  2044. void *context, int vl,
  2045. int mode, u64 data)
  2046. {
  2047. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2048. return dd->rcv_err_status_cnt[51];
  2049. }
  2050. static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
  2051. void *context, int vl,
  2052. int mode, u64 data)
  2053. {
  2054. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2055. return dd->rcv_err_status_cnt[50];
  2056. }
  2057. static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
  2058. void *context, int vl,
  2059. int mode, u64 data)
  2060. {
  2061. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2062. return dd->rcv_err_status_cnt[49];
  2063. }
  2064. static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
  2065. void *context, int vl,
  2066. int mode, u64 data)
  2067. {
  2068. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2069. return dd->rcv_err_status_cnt[48];
  2070. }
  2071. static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
  2072. void *context, int vl,
  2073. int mode, u64 data)
  2074. {
  2075. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2076. return dd->rcv_err_status_cnt[47];
  2077. }
  2078. static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
  2079. void *context, int vl, int mode,
  2080. u64 data)
  2081. {
  2082. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2083. return dd->rcv_err_status_cnt[46];
  2084. }
  2085. static u64 access_rx_hq_intr_csr_parity_err_cnt(
  2086. const struct cntr_entry *entry,
  2087. void *context, int vl, int mode, u64 data)
  2088. {
  2089. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2090. return dd->rcv_err_status_cnt[45];
  2091. }
  2092. static u64 access_rx_lookup_csr_parity_err_cnt(
  2093. const struct cntr_entry *entry,
  2094. void *context, int vl, int mode, u64 data)
  2095. {
  2096. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2097. return dd->rcv_err_status_cnt[44];
  2098. }
  2099. static u64 access_rx_lookup_rcv_array_cor_err_cnt(
  2100. const struct cntr_entry *entry,
  2101. void *context, int vl, int mode, u64 data)
  2102. {
  2103. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2104. return dd->rcv_err_status_cnt[43];
  2105. }
  2106. static u64 access_rx_lookup_rcv_array_unc_err_cnt(
  2107. const struct cntr_entry *entry,
  2108. void *context, int vl, int mode, u64 data)
  2109. {
  2110. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2111. return dd->rcv_err_status_cnt[42];
  2112. }
  2113. static u64 access_rx_lookup_des_part2_parity_err_cnt(
  2114. const struct cntr_entry *entry,
  2115. void *context, int vl, int mode, u64 data)
  2116. {
  2117. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2118. return dd->rcv_err_status_cnt[41];
  2119. }
  2120. static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
  2121. const struct cntr_entry *entry,
  2122. void *context, int vl, int mode, u64 data)
  2123. {
  2124. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2125. return dd->rcv_err_status_cnt[40];
  2126. }
  2127. static u64 access_rx_lookup_des_part1_unc_err_cnt(
  2128. const struct cntr_entry *entry,
  2129. void *context, int vl, int mode, u64 data)
  2130. {
  2131. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2132. return dd->rcv_err_status_cnt[39];
  2133. }
  2134. static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
  2135. const struct cntr_entry *entry,
  2136. void *context, int vl, int mode, u64 data)
  2137. {
  2138. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2139. return dd->rcv_err_status_cnt[38];
  2140. }
  2141. static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
  2142. const struct cntr_entry *entry,
  2143. void *context, int vl, int mode, u64 data)
  2144. {
  2145. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2146. return dd->rcv_err_status_cnt[37];
  2147. }
  2148. static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
  2149. const struct cntr_entry *entry,
  2150. void *context, int vl, int mode, u64 data)
  2151. {
  2152. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2153. return dd->rcv_err_status_cnt[36];
  2154. }
  2155. static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
  2156. const struct cntr_entry *entry,
  2157. void *context, int vl, int mode, u64 data)
  2158. {
  2159. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2160. return dd->rcv_err_status_cnt[35];
  2161. }
  2162. static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
  2163. const struct cntr_entry *entry,
  2164. void *context, int vl, int mode, u64 data)
  2165. {
  2166. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2167. return dd->rcv_err_status_cnt[34];
  2168. }
  2169. static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
  2170. const struct cntr_entry *entry,
  2171. void *context, int vl, int mode, u64 data)
  2172. {
  2173. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2174. return dd->rcv_err_status_cnt[33];
  2175. }
  2176. static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
  2177. void *context, int vl, int mode,
  2178. u64 data)
  2179. {
  2180. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2181. return dd->rcv_err_status_cnt[32];
  2182. }
  2183. static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
  2184. void *context, int vl, int mode,
  2185. u64 data)
  2186. {
  2187. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2188. return dd->rcv_err_status_cnt[31];
  2189. }
  2190. static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
  2191. void *context, int vl, int mode,
  2192. u64 data)
  2193. {
  2194. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2195. return dd->rcv_err_status_cnt[30];
  2196. }
  2197. static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
  2198. void *context, int vl, int mode,
  2199. u64 data)
  2200. {
  2201. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2202. return dd->rcv_err_status_cnt[29];
  2203. }
  2204. static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
  2205. void *context, int vl,
  2206. int mode, u64 data)
  2207. {
  2208. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2209. return dd->rcv_err_status_cnt[28];
  2210. }
  2211. static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
  2212. const struct cntr_entry *entry,
  2213. void *context, int vl, int mode, u64 data)
  2214. {
  2215. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2216. return dd->rcv_err_status_cnt[27];
  2217. }
  2218. static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
  2219. const struct cntr_entry *entry,
  2220. void *context, int vl, int mode, u64 data)
  2221. {
  2222. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2223. return dd->rcv_err_status_cnt[26];
  2224. }
  2225. static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
  2226. const struct cntr_entry *entry,
  2227. void *context, int vl, int mode, u64 data)
  2228. {
  2229. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2230. return dd->rcv_err_status_cnt[25];
  2231. }
  2232. static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
  2233. const struct cntr_entry *entry,
  2234. void *context, int vl, int mode, u64 data)
  2235. {
  2236. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2237. return dd->rcv_err_status_cnt[24];
  2238. }
  2239. static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
  2240. const struct cntr_entry *entry,
  2241. void *context, int vl, int mode, u64 data)
  2242. {
  2243. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2244. return dd->rcv_err_status_cnt[23];
  2245. }
  2246. static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
  2247. const struct cntr_entry *entry,
  2248. void *context, int vl, int mode, u64 data)
  2249. {
  2250. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2251. return dd->rcv_err_status_cnt[22];
  2252. }
  2253. static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
  2254. const struct cntr_entry *entry,
  2255. void *context, int vl, int mode, u64 data)
  2256. {
  2257. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2258. return dd->rcv_err_status_cnt[21];
  2259. }
  2260. static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
  2261. const struct cntr_entry *entry,
  2262. void *context, int vl, int mode, u64 data)
  2263. {
  2264. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2265. return dd->rcv_err_status_cnt[20];
  2266. }
  2267. static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
  2268. const struct cntr_entry *entry,
  2269. void *context, int vl, int mode, u64 data)
  2270. {
  2271. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2272. return dd->rcv_err_status_cnt[19];
  2273. }
  2274. static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
  2275. void *context, int vl,
  2276. int mode, u64 data)
  2277. {
  2278. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2279. return dd->rcv_err_status_cnt[18];
  2280. }
  2281. static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
  2282. void *context, int vl,
  2283. int mode, u64 data)
  2284. {
  2285. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2286. return dd->rcv_err_status_cnt[17];
  2287. }
  2288. static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
  2289. const struct cntr_entry *entry,
  2290. void *context, int vl, int mode, u64 data)
  2291. {
  2292. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2293. return dd->rcv_err_status_cnt[16];
  2294. }
  2295. static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
  2296. const struct cntr_entry *entry,
  2297. void *context, int vl, int mode, u64 data)
  2298. {
  2299. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2300. return dd->rcv_err_status_cnt[15];
  2301. }
  2302. static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
  2303. void *context, int vl,
  2304. int mode, u64 data)
  2305. {
  2306. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2307. return dd->rcv_err_status_cnt[14];
  2308. }
  2309. static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
  2310. void *context, int vl,
  2311. int mode, u64 data)
  2312. {
  2313. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2314. return dd->rcv_err_status_cnt[13];
  2315. }
  2316. static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  2317. void *context, int vl, int mode,
  2318. u64 data)
  2319. {
  2320. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2321. return dd->rcv_err_status_cnt[12];
  2322. }
  2323. static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
  2324. void *context, int vl, int mode,
  2325. u64 data)
  2326. {
  2327. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2328. return dd->rcv_err_status_cnt[11];
  2329. }
  2330. static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
  2331. void *context, int vl, int mode,
  2332. u64 data)
  2333. {
  2334. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2335. return dd->rcv_err_status_cnt[10];
  2336. }
  2337. static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
  2338. void *context, int vl, int mode,
  2339. u64 data)
  2340. {
  2341. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2342. return dd->rcv_err_status_cnt[9];
  2343. }
  2344. static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
  2345. void *context, int vl, int mode,
  2346. u64 data)
  2347. {
  2348. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2349. return dd->rcv_err_status_cnt[8];
  2350. }
  2351. static u64 access_rx_rcv_qp_map_table_cor_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->rcv_err_status_cnt[7];
  2357. }
  2358. static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
  2359. const struct cntr_entry *entry,
  2360. void *context, int vl, int mode, u64 data)
  2361. {
  2362. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2363. return dd->rcv_err_status_cnt[6];
  2364. }
  2365. static u64 access_rx_rcv_data_cor_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->rcv_err_status_cnt[5];
  2371. }
  2372. static u64 access_rx_rcv_data_unc_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->rcv_err_status_cnt[4];
  2378. }
  2379. static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2380. void *context, int vl, int mode,
  2381. u64 data)
  2382. {
  2383. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2384. return dd->rcv_err_status_cnt[3];
  2385. }
  2386. static u64 access_rx_rcv_hdr_unc_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->rcv_err_status_cnt[2];
  2392. }
  2393. static u64 access_rx_dc_intf_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->rcv_err_status_cnt[1];
  2399. }
  2400. static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
  2401. void *context, int vl, int mode,
  2402. u64 data)
  2403. {
  2404. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2405. return dd->rcv_err_status_cnt[0];
  2406. }
  2407. /*
  2408. * Software counters corresponding to each of the
  2409. * error status bits within SendPioErrStatus
  2410. */
  2411. static u64 access_pio_pec_sop_head_parity_err_cnt(
  2412. const struct cntr_entry *entry,
  2413. void *context, int vl, int mode, u64 data)
  2414. {
  2415. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2416. return dd->send_pio_err_status_cnt[35];
  2417. }
  2418. static u64 access_pio_pcc_sop_head_parity_err_cnt(
  2419. const struct cntr_entry *entry,
  2420. void *context, int vl, int mode, u64 data)
  2421. {
  2422. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2423. return dd->send_pio_err_status_cnt[34];
  2424. }
  2425. static u64 access_pio_last_returned_cnt_parity_err_cnt(
  2426. const struct cntr_entry *entry,
  2427. void *context, int vl, int mode, u64 data)
  2428. {
  2429. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2430. return dd->send_pio_err_status_cnt[33];
  2431. }
  2432. static u64 access_pio_current_free_cnt_parity_err_cnt(
  2433. const struct cntr_entry *entry,
  2434. void *context, int vl, int mode, u64 data)
  2435. {
  2436. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2437. return dd->send_pio_err_status_cnt[32];
  2438. }
  2439. static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
  2440. void *context, int vl, int mode,
  2441. u64 data)
  2442. {
  2443. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2444. return dd->send_pio_err_status_cnt[31];
  2445. }
  2446. static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
  2447. void *context, int vl, int mode,
  2448. u64 data)
  2449. {
  2450. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2451. return dd->send_pio_err_status_cnt[30];
  2452. }
  2453. static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
  2454. void *context, int vl, int mode,
  2455. u64 data)
  2456. {
  2457. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2458. return dd->send_pio_err_status_cnt[29];
  2459. }
  2460. static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
  2461. const struct cntr_entry *entry,
  2462. void *context, int vl, int mode, u64 data)
  2463. {
  2464. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2465. return dd->send_pio_err_status_cnt[28];
  2466. }
  2467. static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2468. void *context, int vl, int mode,
  2469. u64 data)
  2470. {
  2471. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2472. return dd->send_pio_err_status_cnt[27];
  2473. }
  2474. static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
  2475. void *context, int vl, int mode,
  2476. u64 data)
  2477. {
  2478. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2479. return dd->send_pio_err_status_cnt[26];
  2480. }
  2481. static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
  2482. void *context, int vl,
  2483. int mode, u64 data)
  2484. {
  2485. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2486. return dd->send_pio_err_status_cnt[25];
  2487. }
  2488. static u64 access_pio_block_qw_count_parity_err_cnt(
  2489. const struct cntr_entry *entry,
  2490. void *context, int vl, int mode, u64 data)
  2491. {
  2492. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2493. return dd->send_pio_err_status_cnt[24];
  2494. }
  2495. static u64 access_pio_write_qw_valid_parity_err_cnt(
  2496. const struct cntr_entry *entry,
  2497. void *context, int vl, int mode, u64 data)
  2498. {
  2499. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2500. return dd->send_pio_err_status_cnt[23];
  2501. }
  2502. static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
  2503. void *context, int vl, int mode,
  2504. u64 data)
  2505. {
  2506. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2507. return dd->send_pio_err_status_cnt[22];
  2508. }
  2509. static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
  2510. void *context, int vl,
  2511. int mode, u64 data)
  2512. {
  2513. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2514. return dd->send_pio_err_status_cnt[21];
  2515. }
  2516. static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
  2517. void *context, int vl,
  2518. int mode, u64 data)
  2519. {
  2520. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2521. return dd->send_pio_err_status_cnt[20];
  2522. }
  2523. static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
  2524. void *context, int vl,
  2525. int mode, u64 data)
  2526. {
  2527. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2528. return dd->send_pio_err_status_cnt[19];
  2529. }
  2530. static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
  2531. const struct cntr_entry *entry,
  2532. void *context, int vl, int mode, u64 data)
  2533. {
  2534. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2535. return dd->send_pio_err_status_cnt[18];
  2536. }
  2537. static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
  2538. void *context, int vl, int mode,
  2539. u64 data)
  2540. {
  2541. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2542. return dd->send_pio_err_status_cnt[17];
  2543. }
  2544. static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
  2545. void *context, int vl, int mode,
  2546. u64 data)
  2547. {
  2548. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2549. return dd->send_pio_err_status_cnt[16];
  2550. }
  2551. static u64 access_pio_credit_ret_fifo_parity_err_cnt(
  2552. const struct cntr_entry *entry,
  2553. void *context, int vl, int mode, u64 data)
  2554. {
  2555. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2556. return dd->send_pio_err_status_cnt[15];
  2557. }
  2558. static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
  2559. const struct cntr_entry *entry,
  2560. void *context, int vl, int mode, u64 data)
  2561. {
  2562. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2563. return dd->send_pio_err_status_cnt[14];
  2564. }
  2565. static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
  2566. const struct cntr_entry *entry,
  2567. void *context, int vl, int mode, u64 data)
  2568. {
  2569. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2570. return dd->send_pio_err_status_cnt[13];
  2571. }
  2572. static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
  2573. const struct cntr_entry *entry,
  2574. void *context, int vl, int mode, u64 data)
  2575. {
  2576. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2577. return dd->send_pio_err_status_cnt[12];
  2578. }
  2579. static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
  2580. const struct cntr_entry *entry,
  2581. void *context, int vl, int mode, u64 data)
  2582. {
  2583. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2584. return dd->send_pio_err_status_cnt[11];
  2585. }
  2586. static u64 access_pio_sm_pkt_reset_parity_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_pio_err_status_cnt[10];
  2592. }
  2593. static u64 access_pio_pkt_evict_fifo_parity_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_pio_err_status_cnt[9];
  2599. }
  2600. static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
  2601. const struct cntr_entry *entry,
  2602. void *context, int vl, int mode, u64 data)
  2603. {
  2604. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2605. return dd->send_pio_err_status_cnt[8];
  2606. }
  2607. static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
  2608. const struct cntr_entry *entry,
  2609. void *context, int vl, int mode, u64 data)
  2610. {
  2611. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2612. return dd->send_pio_err_status_cnt[7];
  2613. }
  2614. static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2615. void *context, int vl, int mode,
  2616. u64 data)
  2617. {
  2618. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2619. return dd->send_pio_err_status_cnt[6];
  2620. }
  2621. static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2622. void *context, int vl, int mode,
  2623. u64 data)
  2624. {
  2625. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2626. return dd->send_pio_err_status_cnt[5];
  2627. }
  2628. static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
  2629. void *context, int vl, int mode,
  2630. u64 data)
  2631. {
  2632. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2633. return dd->send_pio_err_status_cnt[4];
  2634. }
  2635. static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
  2636. void *context, int vl, int mode,
  2637. u64 data)
  2638. {
  2639. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2640. return dd->send_pio_err_status_cnt[3];
  2641. }
  2642. static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
  2643. void *context, int vl, int mode,
  2644. u64 data)
  2645. {
  2646. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2647. return dd->send_pio_err_status_cnt[2];
  2648. }
  2649. static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
  2650. void *context, int vl,
  2651. int mode, u64 data)
  2652. {
  2653. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2654. return dd->send_pio_err_status_cnt[1];
  2655. }
  2656. static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
  2657. void *context, int vl, int mode,
  2658. u64 data)
  2659. {
  2660. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2661. return dd->send_pio_err_status_cnt[0];
  2662. }
  2663. /*
  2664. * Software counters corresponding to each of the
  2665. * error status bits within SendDmaErrStatus
  2666. */
  2667. static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
  2668. const struct cntr_entry *entry,
  2669. void *context, int vl, int mode, u64 data)
  2670. {
  2671. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2672. return dd->send_dma_err_status_cnt[3];
  2673. }
  2674. static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
  2675. const struct cntr_entry *entry,
  2676. void *context, int vl, int mode, u64 data)
  2677. {
  2678. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2679. return dd->send_dma_err_status_cnt[2];
  2680. }
  2681. static u64 access_sdma_csr_parity_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_dma_err_status_cnt[1];
  2687. }
  2688. static u64 access_sdma_rpy_tag_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_dma_err_status_cnt[0];
  2694. }
  2695. /*
  2696. * Software counters corresponding to each of the
  2697. * error status bits within SendEgressErrStatus
  2698. */
  2699. static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
  2700. const struct cntr_entry *entry,
  2701. void *context, int vl, int mode, u64 data)
  2702. {
  2703. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2704. return dd->send_egress_err_status_cnt[63];
  2705. }
  2706. static u64 access_tx_read_sdma_memory_csr_err_cnt(
  2707. const struct cntr_entry *entry,
  2708. void *context, int vl, int mode, u64 data)
  2709. {
  2710. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2711. return dd->send_egress_err_status_cnt[62];
  2712. }
  2713. static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
  2714. void *context, int vl, int mode,
  2715. u64 data)
  2716. {
  2717. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2718. return dd->send_egress_err_status_cnt[61];
  2719. }
  2720. static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
  2721. void *context, int vl,
  2722. int mode, u64 data)
  2723. {
  2724. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2725. return dd->send_egress_err_status_cnt[60];
  2726. }
  2727. static u64 access_tx_read_sdma_memory_cor_err_cnt(
  2728. const struct cntr_entry *entry,
  2729. void *context, int vl, int mode, u64 data)
  2730. {
  2731. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2732. return dd->send_egress_err_status_cnt[59];
  2733. }
  2734. static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2735. void *context, int vl, int mode,
  2736. u64 data)
  2737. {
  2738. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2739. return dd->send_egress_err_status_cnt[58];
  2740. }
  2741. static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
  2742. void *context, int vl, int mode,
  2743. u64 data)
  2744. {
  2745. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2746. return dd->send_egress_err_status_cnt[57];
  2747. }
  2748. static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
  2749. void *context, int vl, int mode,
  2750. u64 data)
  2751. {
  2752. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2753. return dd->send_egress_err_status_cnt[56];
  2754. }
  2755. static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
  2756. void *context, int vl, int mode,
  2757. u64 data)
  2758. {
  2759. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2760. return dd->send_egress_err_status_cnt[55];
  2761. }
  2762. static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
  2763. void *context, int vl, int mode,
  2764. u64 data)
  2765. {
  2766. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2767. return dd->send_egress_err_status_cnt[54];
  2768. }
  2769. static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
  2770. void *context, int vl, int mode,
  2771. u64 data)
  2772. {
  2773. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2774. return dd->send_egress_err_status_cnt[53];
  2775. }
  2776. static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
  2777. void *context, int vl, int mode,
  2778. u64 data)
  2779. {
  2780. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2781. return dd->send_egress_err_status_cnt[52];
  2782. }
  2783. static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
  2784. void *context, int vl, int mode,
  2785. u64 data)
  2786. {
  2787. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2788. return dd->send_egress_err_status_cnt[51];
  2789. }
  2790. static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
  2791. void *context, int vl, int mode,
  2792. u64 data)
  2793. {
  2794. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2795. return dd->send_egress_err_status_cnt[50];
  2796. }
  2797. static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
  2798. void *context, int vl, int mode,
  2799. u64 data)
  2800. {
  2801. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2802. return dd->send_egress_err_status_cnt[49];
  2803. }
  2804. static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
  2805. void *context, int vl, int mode,
  2806. u64 data)
  2807. {
  2808. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2809. return dd->send_egress_err_status_cnt[48];
  2810. }
  2811. static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
  2812. void *context, int vl, int mode,
  2813. u64 data)
  2814. {
  2815. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2816. return dd->send_egress_err_status_cnt[47];
  2817. }
  2818. static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
  2819. void *context, int vl, int mode,
  2820. u64 data)
  2821. {
  2822. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2823. return dd->send_egress_err_status_cnt[46];
  2824. }
  2825. static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
  2826. void *context, int vl, int mode,
  2827. u64 data)
  2828. {
  2829. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2830. return dd->send_egress_err_status_cnt[45];
  2831. }
  2832. static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
  2833. void *context, int vl,
  2834. int mode, u64 data)
  2835. {
  2836. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2837. return dd->send_egress_err_status_cnt[44];
  2838. }
  2839. static u64 access_tx_read_sdma_memory_unc_err_cnt(
  2840. const struct cntr_entry *entry,
  2841. void *context, int vl, int mode, u64 data)
  2842. {
  2843. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2844. return dd->send_egress_err_status_cnt[43];
  2845. }
  2846. static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2847. void *context, int vl, int mode,
  2848. u64 data)
  2849. {
  2850. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2851. return dd->send_egress_err_status_cnt[42];
  2852. }
  2853. static u64 access_tx_credit_return_partiy_err_cnt(
  2854. const struct cntr_entry *entry,
  2855. void *context, int vl, int mode, u64 data)
  2856. {
  2857. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2858. return dd->send_egress_err_status_cnt[41];
  2859. }
  2860. static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
  2861. const struct cntr_entry *entry,
  2862. void *context, int vl, int mode, u64 data)
  2863. {
  2864. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2865. return dd->send_egress_err_status_cnt[40];
  2866. }
  2867. static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
  2868. const struct cntr_entry *entry,
  2869. void *context, int vl, int mode, u64 data)
  2870. {
  2871. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2872. return dd->send_egress_err_status_cnt[39];
  2873. }
  2874. static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
  2875. const struct cntr_entry *entry,
  2876. void *context, int vl, int mode, u64 data)
  2877. {
  2878. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2879. return dd->send_egress_err_status_cnt[38];
  2880. }
  2881. static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
  2882. const struct cntr_entry *entry,
  2883. void *context, int vl, int mode, u64 data)
  2884. {
  2885. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2886. return dd->send_egress_err_status_cnt[37];
  2887. }
  2888. static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
  2889. const struct cntr_entry *entry,
  2890. void *context, int vl, int mode, u64 data)
  2891. {
  2892. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2893. return dd->send_egress_err_status_cnt[36];
  2894. }
  2895. static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
  2896. const struct cntr_entry *entry,
  2897. void *context, int vl, int mode, u64 data)
  2898. {
  2899. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2900. return dd->send_egress_err_status_cnt[35];
  2901. }
  2902. static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
  2903. const struct cntr_entry *entry,
  2904. void *context, int vl, int mode, u64 data)
  2905. {
  2906. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2907. return dd->send_egress_err_status_cnt[34];
  2908. }
  2909. static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
  2910. const struct cntr_entry *entry,
  2911. void *context, int vl, int mode, u64 data)
  2912. {
  2913. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2914. return dd->send_egress_err_status_cnt[33];
  2915. }
  2916. static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
  2917. const struct cntr_entry *entry,
  2918. void *context, int vl, int mode, u64 data)
  2919. {
  2920. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2921. return dd->send_egress_err_status_cnt[32];
  2922. }
  2923. static u64 access_tx_sdma15_disallowed_packet_err_cnt(
  2924. const struct cntr_entry *entry,
  2925. void *context, int vl, int mode, u64 data)
  2926. {
  2927. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2928. return dd->send_egress_err_status_cnt[31];
  2929. }
  2930. static u64 access_tx_sdma14_disallowed_packet_err_cnt(
  2931. const struct cntr_entry *entry,
  2932. void *context, int vl, int mode, u64 data)
  2933. {
  2934. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2935. return dd->send_egress_err_status_cnt[30];
  2936. }
  2937. static u64 access_tx_sdma13_disallowed_packet_err_cnt(
  2938. const struct cntr_entry *entry,
  2939. void *context, int vl, int mode, u64 data)
  2940. {
  2941. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2942. return dd->send_egress_err_status_cnt[29];
  2943. }
  2944. static u64 access_tx_sdma12_disallowed_packet_err_cnt(
  2945. const struct cntr_entry *entry,
  2946. void *context, int vl, int mode, u64 data)
  2947. {
  2948. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2949. return dd->send_egress_err_status_cnt[28];
  2950. }
  2951. static u64 access_tx_sdma11_disallowed_packet_err_cnt(
  2952. const struct cntr_entry *entry,
  2953. void *context, int vl, int mode, u64 data)
  2954. {
  2955. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2956. return dd->send_egress_err_status_cnt[27];
  2957. }
  2958. static u64 access_tx_sdma10_disallowed_packet_err_cnt(
  2959. const struct cntr_entry *entry,
  2960. void *context, int vl, int mode, u64 data)
  2961. {
  2962. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2963. return dd->send_egress_err_status_cnt[26];
  2964. }
  2965. static u64 access_tx_sdma9_disallowed_packet_err_cnt(
  2966. const struct cntr_entry *entry,
  2967. void *context, int vl, int mode, u64 data)
  2968. {
  2969. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2970. return dd->send_egress_err_status_cnt[25];
  2971. }
  2972. static u64 access_tx_sdma8_disallowed_packet_err_cnt(
  2973. const struct cntr_entry *entry,
  2974. void *context, int vl, int mode, u64 data)
  2975. {
  2976. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2977. return dd->send_egress_err_status_cnt[24];
  2978. }
  2979. static u64 access_tx_sdma7_disallowed_packet_err_cnt(
  2980. const struct cntr_entry *entry,
  2981. void *context, int vl, int mode, u64 data)
  2982. {
  2983. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2984. return dd->send_egress_err_status_cnt[23];
  2985. }
  2986. static u64 access_tx_sdma6_disallowed_packet_err_cnt(
  2987. const struct cntr_entry *entry,
  2988. void *context, int vl, int mode, u64 data)
  2989. {
  2990. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2991. return dd->send_egress_err_status_cnt[22];
  2992. }
  2993. static u64 access_tx_sdma5_disallowed_packet_err_cnt(
  2994. const struct cntr_entry *entry,
  2995. void *context, int vl, int mode, u64 data)
  2996. {
  2997. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2998. return dd->send_egress_err_status_cnt[21];
  2999. }
  3000. static u64 access_tx_sdma4_disallowed_packet_err_cnt(
  3001. const struct cntr_entry *entry,
  3002. void *context, int vl, int mode, u64 data)
  3003. {
  3004. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3005. return dd->send_egress_err_status_cnt[20];
  3006. }
  3007. static u64 access_tx_sdma3_disallowed_packet_err_cnt(
  3008. const struct cntr_entry *entry,
  3009. void *context, int vl, int mode, u64 data)
  3010. {
  3011. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3012. return dd->send_egress_err_status_cnt[19];
  3013. }
  3014. static u64 access_tx_sdma2_disallowed_packet_err_cnt(
  3015. const struct cntr_entry *entry,
  3016. void *context, int vl, int mode, u64 data)
  3017. {
  3018. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3019. return dd->send_egress_err_status_cnt[18];
  3020. }
  3021. static u64 access_tx_sdma1_disallowed_packet_err_cnt(
  3022. const struct cntr_entry *entry,
  3023. void *context, int vl, int mode, u64 data)
  3024. {
  3025. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3026. return dd->send_egress_err_status_cnt[17];
  3027. }
  3028. static u64 access_tx_sdma0_disallowed_packet_err_cnt(
  3029. const struct cntr_entry *entry,
  3030. void *context, int vl, int mode, u64 data)
  3031. {
  3032. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3033. return dd->send_egress_err_status_cnt[16];
  3034. }
  3035. static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
  3036. void *context, int vl, int mode,
  3037. u64 data)
  3038. {
  3039. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3040. return dd->send_egress_err_status_cnt[15];
  3041. }
  3042. static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
  3043. void *context, int vl,
  3044. int mode, u64 data)
  3045. {
  3046. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3047. return dd->send_egress_err_status_cnt[14];
  3048. }
  3049. static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
  3050. void *context, int vl, int mode,
  3051. u64 data)
  3052. {
  3053. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3054. return dd->send_egress_err_status_cnt[13];
  3055. }
  3056. static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
  3057. void *context, int vl, int mode,
  3058. u64 data)
  3059. {
  3060. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3061. return dd->send_egress_err_status_cnt[12];
  3062. }
  3063. static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
  3064. const struct cntr_entry *entry,
  3065. void *context, int vl, int mode, u64 data)
  3066. {
  3067. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3068. return dd->send_egress_err_status_cnt[11];
  3069. }
  3070. static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
  3071. void *context, int vl, int mode,
  3072. u64 data)
  3073. {
  3074. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3075. return dd->send_egress_err_status_cnt[10];
  3076. }
  3077. static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
  3078. void *context, int vl, int mode,
  3079. u64 data)
  3080. {
  3081. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3082. return dd->send_egress_err_status_cnt[9];
  3083. }
  3084. static u64 access_tx_sdma_launch_intf_parity_err_cnt(
  3085. const struct cntr_entry *entry,
  3086. void *context, int vl, int mode, u64 data)
  3087. {
  3088. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3089. return dd->send_egress_err_status_cnt[8];
  3090. }
  3091. static u64 access_tx_pio_launch_intf_parity_err_cnt(
  3092. const struct cntr_entry *entry,
  3093. void *context, int vl, int mode, u64 data)
  3094. {
  3095. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3096. return dd->send_egress_err_status_cnt[7];
  3097. }
  3098. static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
  3099. void *context, int vl, int mode,
  3100. u64 data)
  3101. {
  3102. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3103. return dd->send_egress_err_status_cnt[6];
  3104. }
  3105. static u64 access_tx_incorrect_link_state_err_cnt(
  3106. const struct cntr_entry *entry,
  3107. void *context, int vl, int mode, u64 data)
  3108. {
  3109. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3110. return dd->send_egress_err_status_cnt[5];
  3111. }
  3112. static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
  3113. void *context, int vl, int mode,
  3114. u64 data)
  3115. {
  3116. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3117. return dd->send_egress_err_status_cnt[4];
  3118. }
  3119. static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
  3120. const struct cntr_entry *entry,
  3121. void *context, int vl, int mode, u64 data)
  3122. {
  3123. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3124. return dd->send_egress_err_status_cnt[3];
  3125. }
  3126. static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
  3127. void *context, int vl, int mode,
  3128. u64 data)
  3129. {
  3130. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3131. return dd->send_egress_err_status_cnt[2];
  3132. }
  3133. static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
  3134. const struct cntr_entry *entry,
  3135. void *context, int vl, int mode, u64 data)
  3136. {
  3137. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3138. return dd->send_egress_err_status_cnt[1];
  3139. }
  3140. static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
  3141. const struct cntr_entry *entry,
  3142. void *context, int vl, int mode, u64 data)
  3143. {
  3144. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3145. return dd->send_egress_err_status_cnt[0];
  3146. }
  3147. /*
  3148. * Software counters corresponding to each of the
  3149. * error status bits within SendErrStatus
  3150. */
  3151. static u64 access_send_csr_write_bad_addr_err_cnt(
  3152. const struct cntr_entry *entry,
  3153. void *context, int vl, int mode, u64 data)
  3154. {
  3155. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3156. return dd->send_err_status_cnt[2];
  3157. }
  3158. static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  3159. void *context, int vl,
  3160. int mode, u64 data)
  3161. {
  3162. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3163. return dd->send_err_status_cnt[1];
  3164. }
  3165. static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
  3166. void *context, int vl, int mode,
  3167. u64 data)
  3168. {
  3169. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3170. return dd->send_err_status_cnt[0];
  3171. }
  3172. /*
  3173. * Software counters corresponding to each of the
  3174. * error status bits within SendCtxtErrStatus
  3175. */
  3176. static u64 access_pio_write_out_of_bounds_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_ctxt_err_status_cnt[4];
  3182. }
  3183. static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
  3184. void *context, int vl, int mode,
  3185. u64 data)
  3186. {
  3187. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3188. return dd->sw_ctxt_err_status_cnt[3];
  3189. }
  3190. static u64 access_pio_write_crosses_boundary_err_cnt(
  3191. const struct cntr_entry *entry,
  3192. void *context, int vl, int mode, u64 data)
  3193. {
  3194. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3195. return dd->sw_ctxt_err_status_cnt[2];
  3196. }
  3197. static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
  3198. void *context, int vl,
  3199. int mode, u64 data)
  3200. {
  3201. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3202. return dd->sw_ctxt_err_status_cnt[1];
  3203. }
  3204. static u64 access_pio_inconsistent_sop_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_ctxt_err_status_cnt[0];
  3210. }
  3211. /*
  3212. * Software counters corresponding to each of the
  3213. * error status bits within SendDmaEngErrStatus
  3214. */
  3215. static u64 access_sdma_header_request_fifo_cor_err_cnt(
  3216. const struct cntr_entry *entry,
  3217. void *context, int vl, int mode, u64 data)
  3218. {
  3219. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3220. return dd->sw_send_dma_eng_err_status_cnt[23];
  3221. }
  3222. static u64 access_sdma_header_storage_cor_err_cnt(
  3223. const struct cntr_entry *entry,
  3224. void *context, int vl, int mode, u64 data)
  3225. {
  3226. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3227. return dd->sw_send_dma_eng_err_status_cnt[22];
  3228. }
  3229. static u64 access_sdma_packet_tracking_cor_err_cnt(
  3230. const struct cntr_entry *entry,
  3231. void *context, int vl, int mode, u64 data)
  3232. {
  3233. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3234. return dd->sw_send_dma_eng_err_status_cnt[21];
  3235. }
  3236. static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
  3237. void *context, int vl, int mode,
  3238. u64 data)
  3239. {
  3240. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3241. return dd->sw_send_dma_eng_err_status_cnt[20];
  3242. }
  3243. static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
  3244. void *context, int vl, int mode,
  3245. u64 data)
  3246. {
  3247. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3248. return dd->sw_send_dma_eng_err_status_cnt[19];
  3249. }
  3250. static u64 access_sdma_header_request_fifo_unc_err_cnt(
  3251. const struct cntr_entry *entry,
  3252. void *context, int vl, int mode, u64 data)
  3253. {
  3254. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3255. return dd->sw_send_dma_eng_err_status_cnt[18];
  3256. }
  3257. static u64 access_sdma_header_storage_unc_err_cnt(
  3258. const struct cntr_entry *entry,
  3259. void *context, int vl, int mode, u64 data)
  3260. {
  3261. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3262. return dd->sw_send_dma_eng_err_status_cnt[17];
  3263. }
  3264. static u64 access_sdma_packet_tracking_unc_err_cnt(
  3265. const struct cntr_entry *entry,
  3266. void *context, int vl, int mode, u64 data)
  3267. {
  3268. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3269. return dd->sw_send_dma_eng_err_status_cnt[16];
  3270. }
  3271. static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
  3272. void *context, int vl, int mode,
  3273. u64 data)
  3274. {
  3275. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3276. return dd->sw_send_dma_eng_err_status_cnt[15];
  3277. }
  3278. static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
  3279. void *context, int vl, int mode,
  3280. u64 data)
  3281. {
  3282. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3283. return dd->sw_send_dma_eng_err_status_cnt[14];
  3284. }
  3285. static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
  3286. void *context, int vl, int mode,
  3287. u64 data)
  3288. {
  3289. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3290. return dd->sw_send_dma_eng_err_status_cnt[13];
  3291. }
  3292. static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
  3293. void *context, int vl, int mode,
  3294. u64 data)
  3295. {
  3296. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3297. return dd->sw_send_dma_eng_err_status_cnt[12];
  3298. }
  3299. static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
  3300. void *context, int vl, int mode,
  3301. u64 data)
  3302. {
  3303. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3304. return dd->sw_send_dma_eng_err_status_cnt[11];
  3305. }
  3306. static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
  3307. void *context, int vl, int mode,
  3308. u64 data)
  3309. {
  3310. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3311. return dd->sw_send_dma_eng_err_status_cnt[10];
  3312. }
  3313. static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
  3314. void *context, int vl, int mode,
  3315. u64 data)
  3316. {
  3317. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3318. return dd->sw_send_dma_eng_err_status_cnt[9];
  3319. }
  3320. static u64 access_sdma_packet_desc_overflow_err_cnt(
  3321. const struct cntr_entry *entry,
  3322. void *context, int vl, int mode, u64 data)
  3323. {
  3324. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3325. return dd->sw_send_dma_eng_err_status_cnt[8];
  3326. }
  3327. static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
  3328. void *context, int vl,
  3329. int mode, u64 data)
  3330. {
  3331. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3332. return dd->sw_send_dma_eng_err_status_cnt[7];
  3333. }
  3334. static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
  3335. void *context, int vl, int mode, u64 data)
  3336. {
  3337. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3338. return dd->sw_send_dma_eng_err_status_cnt[6];
  3339. }
  3340. static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
  3341. void *context, int vl, int mode,
  3342. u64 data)
  3343. {
  3344. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3345. return dd->sw_send_dma_eng_err_status_cnt[5];
  3346. }
  3347. static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
  3348. void *context, int vl, int mode,
  3349. u64 data)
  3350. {
  3351. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3352. return dd->sw_send_dma_eng_err_status_cnt[4];
  3353. }
  3354. static u64 access_sdma_tail_out_of_bounds_err_cnt(
  3355. const struct cntr_entry *entry,
  3356. void *context, int vl, int mode, u64 data)
  3357. {
  3358. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3359. return dd->sw_send_dma_eng_err_status_cnt[3];
  3360. }
  3361. static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
  3362. void *context, int vl, int mode,
  3363. u64 data)
  3364. {
  3365. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3366. return dd->sw_send_dma_eng_err_status_cnt[2];
  3367. }
  3368. static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
  3369. void *context, int vl, int mode,
  3370. u64 data)
  3371. {
  3372. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3373. return dd->sw_send_dma_eng_err_status_cnt[1];
  3374. }
  3375. static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
  3376. void *context, int vl, int mode,
  3377. u64 data)
  3378. {
  3379. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3380. return dd->sw_send_dma_eng_err_status_cnt[0];
  3381. }
  3382. static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
  3383. void *context, int vl, int mode,
  3384. u64 data)
  3385. {
  3386. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3387. u64 val = 0;
  3388. u64 csr = entry->csr;
  3389. val = read_write_csr(dd, csr, mode, data);
  3390. if (mode == CNTR_MODE_R) {
  3391. val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
  3392. CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
  3393. } else if (mode == CNTR_MODE_W) {
  3394. dd->sw_rcv_bypass_packet_errors = 0;
  3395. } else {
  3396. dd_dev_err(dd, "Invalid cntr register access mode");
  3397. return 0;
  3398. }
  3399. return val;
  3400. }
  3401. #define def_access_sw_cpu(cntr) \
  3402. static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
  3403. void *context, int vl, int mode, u64 data) \
  3404. { \
  3405. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3406. return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
  3407. ppd->ibport_data.rvp.cntr, vl, \
  3408. mode, data); \
  3409. }
  3410. def_access_sw_cpu(rc_acks);
  3411. def_access_sw_cpu(rc_qacks);
  3412. def_access_sw_cpu(rc_delayed_comp);
  3413. #define def_access_ibp_counter(cntr) \
  3414. static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
  3415. void *context, int vl, int mode, u64 data) \
  3416. { \
  3417. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3418. \
  3419. if (vl != CNTR_INVALID_VL) \
  3420. return 0; \
  3421. \
  3422. return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
  3423. mode, data); \
  3424. }
  3425. def_access_ibp_counter(loop_pkts);
  3426. def_access_ibp_counter(rc_resends);
  3427. def_access_ibp_counter(rnr_naks);
  3428. def_access_ibp_counter(other_naks);
  3429. def_access_ibp_counter(rc_timeouts);
  3430. def_access_ibp_counter(pkt_drops);
  3431. def_access_ibp_counter(dmawait);
  3432. def_access_ibp_counter(rc_seqnak);
  3433. def_access_ibp_counter(rc_dupreq);
  3434. def_access_ibp_counter(rdma_seq);
  3435. def_access_ibp_counter(unaligned);
  3436. def_access_ibp_counter(seq_naks);
  3437. static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
  3438. [C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
  3439. [C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
  3440. CNTR_NORMAL),
  3441. [C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
  3442. CNTR_NORMAL),
  3443. [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
  3444. RCV_TID_FLOW_GEN_MISMATCH_CNT,
  3445. CNTR_NORMAL),
  3446. [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
  3447. CNTR_NORMAL),
  3448. [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
  3449. RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
  3450. [C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
  3451. CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
  3452. [C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
  3453. CNTR_NORMAL),
  3454. [C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
  3455. CNTR_NORMAL),
  3456. [C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
  3457. CNTR_NORMAL),
  3458. [C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
  3459. CNTR_NORMAL),
  3460. [C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
  3461. CNTR_NORMAL),
  3462. [C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
  3463. CNTR_NORMAL),
  3464. [C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
  3465. CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
  3466. [C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
  3467. CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
  3468. [C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
  3469. CNTR_SYNTH),
  3470. [C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
  3471. access_dc_rcv_err_cnt),
  3472. [C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
  3473. CNTR_SYNTH),
  3474. [C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
  3475. CNTR_SYNTH),
  3476. [C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
  3477. CNTR_SYNTH),
  3478. [C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
  3479. DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
  3480. [C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
  3481. DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
  3482. CNTR_SYNTH),
  3483. [C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
  3484. DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
  3485. [C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
  3486. CNTR_SYNTH),
  3487. [C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
  3488. CNTR_SYNTH),
  3489. [C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
  3490. CNTR_SYNTH),
  3491. [C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
  3492. CNTR_SYNTH),
  3493. [C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
  3494. CNTR_SYNTH),
  3495. [C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
  3496. CNTR_SYNTH),
  3497. [C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
  3498. CNTR_SYNTH),
  3499. [C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
  3500. CNTR_SYNTH | CNTR_VL),
  3501. [C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
  3502. CNTR_SYNTH | CNTR_VL),
  3503. [C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
  3504. [C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
  3505. CNTR_SYNTH | CNTR_VL),
  3506. [C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
  3507. [C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
  3508. CNTR_SYNTH | CNTR_VL),
  3509. [C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
  3510. CNTR_SYNTH),
  3511. [C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
  3512. CNTR_SYNTH | CNTR_VL),
  3513. [C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
  3514. CNTR_SYNTH),
  3515. [C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
  3516. CNTR_SYNTH | CNTR_VL),
  3517. [C_DC_TOTAL_CRC] =
  3518. DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
  3519. CNTR_SYNTH),
  3520. [C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
  3521. CNTR_SYNTH),
  3522. [C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
  3523. CNTR_SYNTH),
  3524. [C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
  3525. CNTR_SYNTH),
  3526. [C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
  3527. CNTR_SYNTH),
  3528. [C_DC_CRC_MULT_LN] =
  3529. DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
  3530. CNTR_SYNTH),
  3531. [C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
  3532. CNTR_SYNTH),
  3533. [C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
  3534. CNTR_SYNTH),
  3535. [C_DC_SEQ_CRC_CNT] =
  3536. DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
  3537. CNTR_SYNTH),
  3538. [C_DC_ESC0_ONLY_CNT] =
  3539. DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
  3540. CNTR_SYNTH),
  3541. [C_DC_ESC0_PLUS1_CNT] =
  3542. DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
  3543. CNTR_SYNTH),
  3544. [C_DC_ESC0_PLUS2_CNT] =
  3545. DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
  3546. CNTR_SYNTH),
  3547. [C_DC_REINIT_FROM_PEER_CNT] =
  3548. DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
  3549. CNTR_SYNTH),
  3550. [C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
  3551. CNTR_SYNTH),
  3552. [C_DC_MISC_FLG_CNT] =
  3553. DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
  3554. CNTR_SYNTH),
  3555. [C_DC_PRF_GOOD_LTP_CNT] =
  3556. DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
  3557. [C_DC_PRF_ACCEPTED_LTP_CNT] =
  3558. DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
  3559. CNTR_SYNTH),
  3560. [C_DC_PRF_RX_FLIT_CNT] =
  3561. DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
  3562. [C_DC_PRF_TX_FLIT_CNT] =
  3563. DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
  3564. [C_DC_PRF_CLK_CNTR] =
  3565. DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
  3566. [C_DC_PG_DBG_FLIT_CRDTS_CNT] =
  3567. DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
  3568. [C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
  3569. DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
  3570. CNTR_SYNTH),
  3571. [C_DC_PG_STS_TX_SBE_CNT] =
  3572. DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
  3573. [C_DC_PG_STS_TX_MBE_CNT] =
  3574. DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
  3575. CNTR_SYNTH),
  3576. [C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
  3577. access_sw_cpu_intr),
  3578. [C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
  3579. access_sw_cpu_rcv_limit),
  3580. [C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
  3581. access_sw_vtx_wait),
  3582. [C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
  3583. access_sw_pio_wait),
  3584. [C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
  3585. access_sw_pio_drain),
  3586. [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
  3587. access_sw_kmem_wait),
  3588. [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
  3589. access_sw_send_schedule),
  3590. [C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
  3591. SEND_DMA_DESC_FETCHED_CNT, 0,
  3592. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3593. dev_access_u32_csr),
  3594. [C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
  3595. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3596. access_sde_int_cnt),
  3597. [C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
  3598. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3599. access_sde_err_cnt),
  3600. [C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
  3601. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3602. access_sde_idle_int_cnt),
  3603. [C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
  3604. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3605. access_sde_progress_int_cnt),
  3606. /* MISC_ERR_STATUS */
  3607. [C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
  3608. CNTR_NORMAL,
  3609. access_misc_pll_lock_fail_err_cnt),
  3610. [C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
  3611. CNTR_NORMAL,
  3612. access_misc_mbist_fail_err_cnt),
  3613. [C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
  3614. CNTR_NORMAL,
  3615. access_misc_invalid_eep_cmd_err_cnt),
  3616. [C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
  3617. CNTR_NORMAL,
  3618. access_misc_efuse_done_parity_err_cnt),
  3619. [C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
  3620. CNTR_NORMAL,
  3621. access_misc_efuse_write_err_cnt),
  3622. [C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
  3623. 0, CNTR_NORMAL,
  3624. access_misc_efuse_read_bad_addr_err_cnt),
  3625. [C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
  3626. CNTR_NORMAL,
  3627. access_misc_efuse_csr_parity_err_cnt),
  3628. [C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
  3629. CNTR_NORMAL,
  3630. access_misc_fw_auth_failed_err_cnt),
  3631. [C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
  3632. CNTR_NORMAL,
  3633. access_misc_key_mismatch_err_cnt),
  3634. [C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
  3635. CNTR_NORMAL,
  3636. access_misc_sbus_write_failed_err_cnt),
  3637. [C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
  3638. CNTR_NORMAL,
  3639. access_misc_csr_write_bad_addr_err_cnt),
  3640. [C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
  3641. CNTR_NORMAL,
  3642. access_misc_csr_read_bad_addr_err_cnt),
  3643. [C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
  3644. CNTR_NORMAL,
  3645. access_misc_csr_parity_err_cnt),
  3646. /* CceErrStatus */
  3647. [C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
  3648. CNTR_NORMAL,
  3649. access_sw_cce_err_status_aggregated_cnt),
  3650. [C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
  3651. CNTR_NORMAL,
  3652. access_cce_msix_csr_parity_err_cnt),
  3653. [C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
  3654. CNTR_NORMAL,
  3655. access_cce_int_map_unc_err_cnt),
  3656. [C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
  3657. CNTR_NORMAL,
  3658. access_cce_int_map_cor_err_cnt),
  3659. [C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
  3660. CNTR_NORMAL,
  3661. access_cce_msix_table_unc_err_cnt),
  3662. [C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
  3663. CNTR_NORMAL,
  3664. access_cce_msix_table_cor_err_cnt),
  3665. [C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
  3666. 0, CNTR_NORMAL,
  3667. access_cce_rxdma_conv_fifo_parity_err_cnt),
  3668. [C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
  3669. 0, CNTR_NORMAL,
  3670. access_cce_rcpl_async_fifo_parity_err_cnt),
  3671. [C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
  3672. CNTR_NORMAL,
  3673. access_cce_seg_write_bad_addr_err_cnt),
  3674. [C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
  3675. CNTR_NORMAL,
  3676. access_cce_seg_read_bad_addr_err_cnt),
  3677. [C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
  3678. CNTR_NORMAL,
  3679. access_la_triggered_cnt),
  3680. [C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
  3681. CNTR_NORMAL,
  3682. access_cce_trgt_cpl_timeout_err_cnt),
  3683. [C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
  3684. CNTR_NORMAL,
  3685. access_pcic_receive_parity_err_cnt),
  3686. [C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
  3687. CNTR_NORMAL,
  3688. access_pcic_transmit_back_parity_err_cnt),
  3689. [C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
  3690. 0, CNTR_NORMAL,
  3691. access_pcic_transmit_front_parity_err_cnt),
  3692. [C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
  3693. CNTR_NORMAL,
  3694. access_pcic_cpl_dat_q_unc_err_cnt),
  3695. [C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
  3696. CNTR_NORMAL,
  3697. access_pcic_cpl_hd_q_unc_err_cnt),
  3698. [C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
  3699. CNTR_NORMAL,
  3700. access_pcic_post_dat_q_unc_err_cnt),
  3701. [C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
  3702. CNTR_NORMAL,
  3703. access_pcic_post_hd_q_unc_err_cnt),
  3704. [C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
  3705. CNTR_NORMAL,
  3706. access_pcic_retry_sot_mem_unc_err_cnt),
  3707. [C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
  3708. CNTR_NORMAL,
  3709. access_pcic_retry_mem_unc_err),
  3710. [C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
  3711. CNTR_NORMAL,
  3712. access_pcic_n_post_dat_q_parity_err_cnt),
  3713. [C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
  3714. CNTR_NORMAL,
  3715. access_pcic_n_post_h_q_parity_err_cnt),
  3716. [C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
  3717. CNTR_NORMAL,
  3718. access_pcic_cpl_dat_q_cor_err_cnt),
  3719. [C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
  3720. CNTR_NORMAL,
  3721. access_pcic_cpl_hd_q_cor_err_cnt),
  3722. [C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
  3723. CNTR_NORMAL,
  3724. access_pcic_post_dat_q_cor_err_cnt),
  3725. [C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
  3726. CNTR_NORMAL,
  3727. access_pcic_post_hd_q_cor_err_cnt),
  3728. [C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
  3729. CNTR_NORMAL,
  3730. access_pcic_retry_sot_mem_cor_err_cnt),
  3731. [C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
  3732. CNTR_NORMAL,
  3733. access_pcic_retry_mem_cor_err_cnt),
  3734. [C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
  3735. "CceCli1AsyncFifoDbgParityError", 0, 0,
  3736. CNTR_NORMAL,
  3737. access_cce_cli1_async_fifo_dbg_parity_err_cnt),
  3738. [C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
  3739. "CceCli1AsyncFifoRxdmaParityError", 0, 0,
  3740. CNTR_NORMAL,
  3741. access_cce_cli1_async_fifo_rxdma_parity_err_cnt
  3742. ),
  3743. [C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
  3744. "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
  3745. CNTR_NORMAL,
  3746. access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
  3747. [C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
  3748. "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
  3749. CNTR_NORMAL,
  3750. access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
  3751. [C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
  3752. 0, CNTR_NORMAL,
  3753. access_cce_cli2_async_fifo_parity_err_cnt),
  3754. [C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
  3755. CNTR_NORMAL,
  3756. access_cce_csr_cfg_bus_parity_err_cnt),
  3757. [C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
  3758. 0, CNTR_NORMAL,
  3759. access_cce_cli0_async_fifo_parity_err_cnt),
  3760. [C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
  3761. CNTR_NORMAL,
  3762. access_cce_rspd_data_parity_err_cnt),
  3763. [C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
  3764. CNTR_NORMAL,
  3765. access_cce_trgt_access_err_cnt),
  3766. [C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
  3767. 0, CNTR_NORMAL,
  3768. access_cce_trgt_async_fifo_parity_err_cnt),
  3769. [C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
  3770. CNTR_NORMAL,
  3771. access_cce_csr_write_bad_addr_err_cnt),
  3772. [C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
  3773. CNTR_NORMAL,
  3774. access_cce_csr_read_bad_addr_err_cnt),
  3775. [C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
  3776. CNTR_NORMAL,
  3777. access_ccs_csr_parity_err_cnt),
  3778. /* RcvErrStatus */
  3779. [C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
  3780. CNTR_NORMAL,
  3781. access_rx_csr_parity_err_cnt),
  3782. [C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
  3783. CNTR_NORMAL,
  3784. access_rx_csr_write_bad_addr_err_cnt),
  3785. [C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
  3786. CNTR_NORMAL,
  3787. access_rx_csr_read_bad_addr_err_cnt),
  3788. [C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
  3789. CNTR_NORMAL,
  3790. access_rx_dma_csr_unc_err_cnt),
  3791. [C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
  3792. CNTR_NORMAL,
  3793. access_rx_dma_dq_fsm_encoding_err_cnt),
  3794. [C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
  3795. CNTR_NORMAL,
  3796. access_rx_dma_eq_fsm_encoding_err_cnt),
  3797. [C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
  3798. CNTR_NORMAL,
  3799. access_rx_dma_csr_parity_err_cnt),
  3800. [C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
  3801. CNTR_NORMAL,
  3802. access_rx_rbuf_data_cor_err_cnt),
  3803. [C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
  3804. CNTR_NORMAL,
  3805. access_rx_rbuf_data_unc_err_cnt),
  3806. [C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
  3807. CNTR_NORMAL,
  3808. access_rx_dma_data_fifo_rd_cor_err_cnt),
  3809. [C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
  3810. CNTR_NORMAL,
  3811. access_rx_dma_data_fifo_rd_unc_err_cnt),
  3812. [C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
  3813. CNTR_NORMAL,
  3814. access_rx_dma_hdr_fifo_rd_cor_err_cnt),
  3815. [C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
  3816. CNTR_NORMAL,
  3817. access_rx_dma_hdr_fifo_rd_unc_err_cnt),
  3818. [C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
  3819. CNTR_NORMAL,
  3820. access_rx_rbuf_desc_part2_cor_err_cnt),
  3821. [C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
  3822. CNTR_NORMAL,
  3823. access_rx_rbuf_desc_part2_unc_err_cnt),
  3824. [C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
  3825. CNTR_NORMAL,
  3826. access_rx_rbuf_desc_part1_cor_err_cnt),
  3827. [C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
  3828. CNTR_NORMAL,
  3829. access_rx_rbuf_desc_part1_unc_err_cnt),
  3830. [C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
  3831. CNTR_NORMAL,
  3832. access_rx_hq_intr_fsm_err_cnt),
  3833. [C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
  3834. CNTR_NORMAL,
  3835. access_rx_hq_intr_csr_parity_err_cnt),
  3836. [C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
  3837. CNTR_NORMAL,
  3838. access_rx_lookup_csr_parity_err_cnt),
  3839. [C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
  3840. CNTR_NORMAL,
  3841. access_rx_lookup_rcv_array_cor_err_cnt),
  3842. [C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
  3843. CNTR_NORMAL,
  3844. access_rx_lookup_rcv_array_unc_err_cnt),
  3845. [C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
  3846. 0, CNTR_NORMAL,
  3847. access_rx_lookup_des_part2_parity_err_cnt),
  3848. [C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
  3849. 0, CNTR_NORMAL,
  3850. access_rx_lookup_des_part1_unc_cor_err_cnt),
  3851. [C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
  3852. CNTR_NORMAL,
  3853. access_rx_lookup_des_part1_unc_err_cnt),
  3854. [C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
  3855. CNTR_NORMAL,
  3856. access_rx_rbuf_next_free_buf_cor_err_cnt),
  3857. [C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
  3858. CNTR_NORMAL,
  3859. access_rx_rbuf_next_free_buf_unc_err_cnt),
  3860. [C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
  3861. "RxRbufFlInitWrAddrParityErr", 0, 0,
  3862. CNTR_NORMAL,
  3863. access_rbuf_fl_init_wr_addr_parity_err_cnt),
  3864. [C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
  3865. 0, CNTR_NORMAL,
  3866. access_rx_rbuf_fl_initdone_parity_err_cnt),
  3867. [C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
  3868. 0, CNTR_NORMAL,
  3869. access_rx_rbuf_fl_write_addr_parity_err_cnt),
  3870. [C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
  3871. CNTR_NORMAL,
  3872. access_rx_rbuf_fl_rd_addr_parity_err_cnt),
  3873. [C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
  3874. CNTR_NORMAL,
  3875. access_rx_rbuf_empty_err_cnt),
  3876. [C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
  3877. CNTR_NORMAL,
  3878. access_rx_rbuf_full_err_cnt),
  3879. [C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
  3880. CNTR_NORMAL,
  3881. access_rbuf_bad_lookup_err_cnt),
  3882. [C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
  3883. CNTR_NORMAL,
  3884. access_rbuf_ctx_id_parity_err_cnt),
  3885. [C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
  3886. CNTR_NORMAL,
  3887. access_rbuf_csr_qeopdw_parity_err_cnt),
  3888. [C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
  3889. "RxRbufCsrQNumOfPktParityErr", 0, 0,
  3890. CNTR_NORMAL,
  3891. access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
  3892. [C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
  3893. "RxRbufCsrQTlPtrParityErr", 0, 0,
  3894. CNTR_NORMAL,
  3895. access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
  3896. [C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
  3897. 0, CNTR_NORMAL,
  3898. access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
  3899. [C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
  3900. 0, CNTR_NORMAL,
  3901. access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
  3902. [C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
  3903. 0, 0, CNTR_NORMAL,
  3904. access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
  3905. [C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
  3906. 0, CNTR_NORMAL,
  3907. access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
  3908. [C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
  3909. "RxRbufCsrQHeadBufNumParityErr", 0, 0,
  3910. CNTR_NORMAL,
  3911. access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
  3912. [C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
  3913. 0, CNTR_NORMAL,
  3914. access_rx_rbuf_block_list_read_cor_err_cnt),
  3915. [C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
  3916. 0, CNTR_NORMAL,
  3917. access_rx_rbuf_block_list_read_unc_err_cnt),
  3918. [C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
  3919. CNTR_NORMAL,
  3920. access_rx_rbuf_lookup_des_cor_err_cnt),
  3921. [C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
  3922. CNTR_NORMAL,
  3923. access_rx_rbuf_lookup_des_unc_err_cnt),
  3924. [C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
  3925. "RxRbufLookupDesRegUncCorErr", 0, 0,
  3926. CNTR_NORMAL,
  3927. access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
  3928. [C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
  3929. CNTR_NORMAL,
  3930. access_rx_rbuf_lookup_des_reg_unc_err_cnt),
  3931. [C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
  3932. CNTR_NORMAL,
  3933. access_rx_rbuf_free_list_cor_err_cnt),
  3934. [C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
  3935. CNTR_NORMAL,
  3936. access_rx_rbuf_free_list_unc_err_cnt),
  3937. [C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
  3938. CNTR_NORMAL,
  3939. access_rx_rcv_fsm_encoding_err_cnt),
  3940. [C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
  3941. CNTR_NORMAL,
  3942. access_rx_dma_flag_cor_err_cnt),
  3943. [C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
  3944. CNTR_NORMAL,
  3945. access_rx_dma_flag_unc_err_cnt),
  3946. [C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
  3947. CNTR_NORMAL,
  3948. access_rx_dc_sop_eop_parity_err_cnt),
  3949. [C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
  3950. CNTR_NORMAL,
  3951. access_rx_rcv_csr_parity_err_cnt),
  3952. [C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
  3953. CNTR_NORMAL,
  3954. access_rx_rcv_qp_map_table_cor_err_cnt),
  3955. [C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
  3956. CNTR_NORMAL,
  3957. access_rx_rcv_qp_map_table_unc_err_cnt),
  3958. [C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
  3959. CNTR_NORMAL,
  3960. access_rx_rcv_data_cor_err_cnt),
  3961. [C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
  3962. CNTR_NORMAL,
  3963. access_rx_rcv_data_unc_err_cnt),
  3964. [C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
  3965. CNTR_NORMAL,
  3966. access_rx_rcv_hdr_cor_err_cnt),
  3967. [C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
  3968. CNTR_NORMAL,
  3969. access_rx_rcv_hdr_unc_err_cnt),
  3970. [C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
  3971. CNTR_NORMAL,
  3972. access_rx_dc_intf_parity_err_cnt),
  3973. [C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
  3974. CNTR_NORMAL,
  3975. access_rx_dma_csr_cor_err_cnt),
  3976. /* SendPioErrStatus */
  3977. [C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
  3978. CNTR_NORMAL,
  3979. access_pio_pec_sop_head_parity_err_cnt),
  3980. [C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
  3981. CNTR_NORMAL,
  3982. access_pio_pcc_sop_head_parity_err_cnt),
  3983. [C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
  3984. 0, 0, CNTR_NORMAL,
  3985. access_pio_last_returned_cnt_parity_err_cnt),
  3986. [C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
  3987. 0, CNTR_NORMAL,
  3988. access_pio_current_free_cnt_parity_err_cnt),
  3989. [C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
  3990. CNTR_NORMAL,
  3991. access_pio_reserved_31_err_cnt),
  3992. [C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
  3993. CNTR_NORMAL,
  3994. access_pio_reserved_30_err_cnt),
  3995. [C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
  3996. CNTR_NORMAL,
  3997. access_pio_ppmc_sop_len_err_cnt),
  3998. [C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
  3999. CNTR_NORMAL,
  4000. access_pio_ppmc_bqc_mem_parity_err_cnt),
  4001. [C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
  4002. CNTR_NORMAL,
  4003. access_pio_vl_fifo_parity_err_cnt),
  4004. [C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
  4005. CNTR_NORMAL,
  4006. access_pio_vlf_sop_parity_err_cnt),
  4007. [C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
  4008. CNTR_NORMAL,
  4009. access_pio_vlf_v1_len_parity_err_cnt),
  4010. [C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
  4011. CNTR_NORMAL,
  4012. access_pio_block_qw_count_parity_err_cnt),
  4013. [C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
  4014. CNTR_NORMAL,
  4015. access_pio_write_qw_valid_parity_err_cnt),
  4016. [C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
  4017. CNTR_NORMAL,
  4018. access_pio_state_machine_err_cnt),
  4019. [C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
  4020. CNTR_NORMAL,
  4021. access_pio_write_data_parity_err_cnt),
  4022. [C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
  4023. CNTR_NORMAL,
  4024. access_pio_host_addr_mem_cor_err_cnt),
  4025. [C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
  4026. CNTR_NORMAL,
  4027. access_pio_host_addr_mem_unc_err_cnt),
  4028. [C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
  4029. CNTR_NORMAL,
  4030. access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
  4031. [C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
  4032. CNTR_NORMAL,
  4033. access_pio_init_sm_in_err_cnt),
  4034. [C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
  4035. CNTR_NORMAL,
  4036. access_pio_ppmc_pbl_fifo_err_cnt),
  4037. [C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
  4038. 0, CNTR_NORMAL,
  4039. access_pio_credit_ret_fifo_parity_err_cnt),
  4040. [C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
  4041. CNTR_NORMAL,
  4042. access_pio_v1_len_mem_bank1_cor_err_cnt),
  4043. [C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
  4044. CNTR_NORMAL,
  4045. access_pio_v1_len_mem_bank0_cor_err_cnt),
  4046. [C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
  4047. CNTR_NORMAL,
  4048. access_pio_v1_len_mem_bank1_unc_err_cnt),
  4049. [C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
  4050. CNTR_NORMAL,
  4051. access_pio_v1_len_mem_bank0_unc_err_cnt),
  4052. [C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
  4053. CNTR_NORMAL,
  4054. access_pio_sm_pkt_reset_parity_err_cnt),
  4055. [C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
  4056. CNTR_NORMAL,
  4057. access_pio_pkt_evict_fifo_parity_err_cnt),
  4058. [C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
  4059. "PioSbrdctrlCrrelFifoParityErr", 0, 0,
  4060. CNTR_NORMAL,
  4061. access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
  4062. [C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
  4063. CNTR_NORMAL,
  4064. access_pio_sbrdctl_crrel_parity_err_cnt),
  4065. [C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
  4066. CNTR_NORMAL,
  4067. access_pio_pec_fifo_parity_err_cnt),
  4068. [C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
  4069. CNTR_NORMAL,
  4070. access_pio_pcc_fifo_parity_err_cnt),
  4071. [C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
  4072. CNTR_NORMAL,
  4073. access_pio_sb_mem_fifo1_err_cnt),
  4074. [C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
  4075. CNTR_NORMAL,
  4076. access_pio_sb_mem_fifo0_err_cnt),
  4077. [C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
  4078. CNTR_NORMAL,
  4079. access_pio_csr_parity_err_cnt),
  4080. [C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
  4081. CNTR_NORMAL,
  4082. access_pio_write_addr_parity_err_cnt),
  4083. [C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
  4084. CNTR_NORMAL,
  4085. access_pio_write_bad_ctxt_err_cnt),
  4086. /* SendDmaErrStatus */
  4087. [C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
  4088. 0, CNTR_NORMAL,
  4089. access_sdma_pcie_req_tracking_cor_err_cnt),
  4090. [C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
  4091. 0, CNTR_NORMAL,
  4092. access_sdma_pcie_req_tracking_unc_err_cnt),
  4093. [C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
  4094. CNTR_NORMAL,
  4095. access_sdma_csr_parity_err_cnt),
  4096. [C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
  4097. CNTR_NORMAL,
  4098. access_sdma_rpy_tag_err_cnt),
  4099. /* SendEgressErrStatus */
  4100. [C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
  4101. CNTR_NORMAL,
  4102. access_tx_read_pio_memory_csr_unc_err_cnt),
  4103. [C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
  4104. 0, CNTR_NORMAL,
  4105. access_tx_read_sdma_memory_csr_err_cnt),
  4106. [C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
  4107. CNTR_NORMAL,
  4108. access_tx_egress_fifo_cor_err_cnt),
  4109. [C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
  4110. CNTR_NORMAL,
  4111. access_tx_read_pio_memory_cor_err_cnt),
  4112. [C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
  4113. CNTR_NORMAL,
  4114. access_tx_read_sdma_memory_cor_err_cnt),
  4115. [C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
  4116. CNTR_NORMAL,
  4117. access_tx_sb_hdr_cor_err_cnt),
  4118. [C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
  4119. CNTR_NORMAL,
  4120. access_tx_credit_overrun_err_cnt),
  4121. [C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
  4122. CNTR_NORMAL,
  4123. access_tx_launch_fifo8_cor_err_cnt),
  4124. [C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
  4125. CNTR_NORMAL,
  4126. access_tx_launch_fifo7_cor_err_cnt),
  4127. [C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
  4128. CNTR_NORMAL,
  4129. access_tx_launch_fifo6_cor_err_cnt),
  4130. [C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
  4131. CNTR_NORMAL,
  4132. access_tx_launch_fifo5_cor_err_cnt),
  4133. [C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
  4134. CNTR_NORMAL,
  4135. access_tx_launch_fifo4_cor_err_cnt),
  4136. [C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
  4137. CNTR_NORMAL,
  4138. access_tx_launch_fifo3_cor_err_cnt),
  4139. [C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
  4140. CNTR_NORMAL,
  4141. access_tx_launch_fifo2_cor_err_cnt),
  4142. [C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
  4143. CNTR_NORMAL,
  4144. access_tx_launch_fifo1_cor_err_cnt),
  4145. [C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
  4146. CNTR_NORMAL,
  4147. access_tx_launch_fifo0_cor_err_cnt),
  4148. [C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
  4149. CNTR_NORMAL,
  4150. access_tx_credit_return_vl_err_cnt),
  4151. [C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
  4152. CNTR_NORMAL,
  4153. access_tx_hcrc_insertion_err_cnt),
  4154. [C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
  4155. CNTR_NORMAL,
  4156. access_tx_egress_fifo_unc_err_cnt),
  4157. [C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
  4158. CNTR_NORMAL,
  4159. access_tx_read_pio_memory_unc_err_cnt),
  4160. [C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
  4161. CNTR_NORMAL,
  4162. access_tx_read_sdma_memory_unc_err_cnt),
  4163. [C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
  4164. CNTR_NORMAL,
  4165. access_tx_sb_hdr_unc_err_cnt),
  4166. [C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
  4167. CNTR_NORMAL,
  4168. access_tx_credit_return_partiy_err_cnt),
  4169. [C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
  4170. 0, 0, CNTR_NORMAL,
  4171. access_tx_launch_fifo8_unc_or_parity_err_cnt),
  4172. [C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
  4173. 0, 0, CNTR_NORMAL,
  4174. access_tx_launch_fifo7_unc_or_parity_err_cnt),
  4175. [C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
  4176. 0, 0, CNTR_NORMAL,
  4177. access_tx_launch_fifo6_unc_or_parity_err_cnt),
  4178. [C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
  4179. 0, 0, CNTR_NORMAL,
  4180. access_tx_launch_fifo5_unc_or_parity_err_cnt),
  4181. [C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
  4182. 0, 0, CNTR_NORMAL,
  4183. access_tx_launch_fifo4_unc_or_parity_err_cnt),
  4184. [C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
  4185. 0, 0, CNTR_NORMAL,
  4186. access_tx_launch_fifo3_unc_or_parity_err_cnt),
  4187. [C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
  4188. 0, 0, CNTR_NORMAL,
  4189. access_tx_launch_fifo2_unc_or_parity_err_cnt),
  4190. [C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
  4191. 0, 0, CNTR_NORMAL,
  4192. access_tx_launch_fifo1_unc_or_parity_err_cnt),
  4193. [C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
  4194. 0, 0, CNTR_NORMAL,
  4195. access_tx_launch_fifo0_unc_or_parity_err_cnt),
  4196. [C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
  4197. 0, 0, CNTR_NORMAL,
  4198. access_tx_sdma15_disallowed_packet_err_cnt),
  4199. [C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
  4200. 0, 0, CNTR_NORMAL,
  4201. access_tx_sdma14_disallowed_packet_err_cnt),
  4202. [C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
  4203. 0, 0, CNTR_NORMAL,
  4204. access_tx_sdma13_disallowed_packet_err_cnt),
  4205. [C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
  4206. 0, 0, CNTR_NORMAL,
  4207. access_tx_sdma12_disallowed_packet_err_cnt),
  4208. [C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
  4209. 0, 0, CNTR_NORMAL,
  4210. access_tx_sdma11_disallowed_packet_err_cnt),
  4211. [C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
  4212. 0, 0, CNTR_NORMAL,
  4213. access_tx_sdma10_disallowed_packet_err_cnt),
  4214. [C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
  4215. 0, 0, CNTR_NORMAL,
  4216. access_tx_sdma9_disallowed_packet_err_cnt),
  4217. [C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
  4218. 0, 0, CNTR_NORMAL,
  4219. access_tx_sdma8_disallowed_packet_err_cnt),
  4220. [C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
  4221. 0, 0, CNTR_NORMAL,
  4222. access_tx_sdma7_disallowed_packet_err_cnt),
  4223. [C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
  4224. 0, 0, CNTR_NORMAL,
  4225. access_tx_sdma6_disallowed_packet_err_cnt),
  4226. [C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
  4227. 0, 0, CNTR_NORMAL,
  4228. access_tx_sdma5_disallowed_packet_err_cnt),
  4229. [C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
  4230. 0, 0, CNTR_NORMAL,
  4231. access_tx_sdma4_disallowed_packet_err_cnt),
  4232. [C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
  4233. 0, 0, CNTR_NORMAL,
  4234. access_tx_sdma3_disallowed_packet_err_cnt),
  4235. [C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
  4236. 0, 0, CNTR_NORMAL,
  4237. access_tx_sdma2_disallowed_packet_err_cnt),
  4238. [C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
  4239. 0, 0, CNTR_NORMAL,
  4240. access_tx_sdma1_disallowed_packet_err_cnt),
  4241. [C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
  4242. 0, 0, CNTR_NORMAL,
  4243. access_tx_sdma0_disallowed_packet_err_cnt),
  4244. [C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
  4245. CNTR_NORMAL,
  4246. access_tx_config_parity_err_cnt),
  4247. [C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
  4248. CNTR_NORMAL,
  4249. access_tx_sbrd_ctl_csr_parity_err_cnt),
  4250. [C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
  4251. CNTR_NORMAL,
  4252. access_tx_launch_csr_parity_err_cnt),
  4253. [C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
  4254. CNTR_NORMAL,
  4255. access_tx_illegal_vl_err_cnt),
  4256. [C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
  4257. "TxSbrdCtlStateMachineParityErr", 0, 0,
  4258. CNTR_NORMAL,
  4259. access_tx_sbrd_ctl_state_machine_parity_err_cnt),
  4260. [C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
  4261. CNTR_NORMAL,
  4262. access_egress_reserved_10_err_cnt),
  4263. [C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
  4264. CNTR_NORMAL,
  4265. access_egress_reserved_9_err_cnt),
  4266. [C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
  4267. 0, 0, CNTR_NORMAL,
  4268. access_tx_sdma_launch_intf_parity_err_cnt),
  4269. [C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
  4270. CNTR_NORMAL,
  4271. access_tx_pio_launch_intf_parity_err_cnt),
  4272. [C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
  4273. CNTR_NORMAL,
  4274. access_egress_reserved_6_err_cnt),
  4275. [C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
  4276. CNTR_NORMAL,
  4277. access_tx_incorrect_link_state_err_cnt),
  4278. [C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
  4279. CNTR_NORMAL,
  4280. access_tx_linkdown_err_cnt),
  4281. [C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
  4282. "EgressFifoUnderrunOrParityErr", 0, 0,
  4283. CNTR_NORMAL,
  4284. access_tx_egress_fifi_underrun_or_parity_err_cnt),
  4285. [C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
  4286. CNTR_NORMAL,
  4287. access_egress_reserved_2_err_cnt),
  4288. [C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
  4289. CNTR_NORMAL,
  4290. access_tx_pkt_integrity_mem_unc_err_cnt),
  4291. [C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
  4292. CNTR_NORMAL,
  4293. access_tx_pkt_integrity_mem_cor_err_cnt),
  4294. /* SendErrStatus */
  4295. [C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
  4296. CNTR_NORMAL,
  4297. access_send_csr_write_bad_addr_err_cnt),
  4298. [C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
  4299. CNTR_NORMAL,
  4300. access_send_csr_read_bad_addr_err_cnt),
  4301. [C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
  4302. CNTR_NORMAL,
  4303. access_send_csr_parity_cnt),
  4304. /* SendCtxtErrStatus */
  4305. [C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
  4306. CNTR_NORMAL,
  4307. access_pio_write_out_of_bounds_err_cnt),
  4308. [C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
  4309. CNTR_NORMAL,
  4310. access_pio_write_overflow_err_cnt),
  4311. [C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
  4312. 0, 0, CNTR_NORMAL,
  4313. access_pio_write_crosses_boundary_err_cnt),
  4314. [C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
  4315. CNTR_NORMAL,
  4316. access_pio_disallowed_packet_err_cnt),
  4317. [C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
  4318. CNTR_NORMAL,
  4319. access_pio_inconsistent_sop_err_cnt),
  4320. /* SendDmaEngErrStatus */
  4321. [C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
  4322. 0, 0, CNTR_NORMAL,
  4323. access_sdma_header_request_fifo_cor_err_cnt),
  4324. [C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
  4325. CNTR_NORMAL,
  4326. access_sdma_header_storage_cor_err_cnt),
  4327. [C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
  4328. CNTR_NORMAL,
  4329. access_sdma_packet_tracking_cor_err_cnt),
  4330. [C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
  4331. CNTR_NORMAL,
  4332. access_sdma_assembly_cor_err_cnt),
  4333. [C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
  4334. CNTR_NORMAL,
  4335. access_sdma_desc_table_cor_err_cnt),
  4336. [C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
  4337. 0, 0, CNTR_NORMAL,
  4338. access_sdma_header_request_fifo_unc_err_cnt),
  4339. [C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
  4340. CNTR_NORMAL,
  4341. access_sdma_header_storage_unc_err_cnt),
  4342. [C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
  4343. CNTR_NORMAL,
  4344. access_sdma_packet_tracking_unc_err_cnt),
  4345. [C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
  4346. CNTR_NORMAL,
  4347. access_sdma_assembly_unc_err_cnt),
  4348. [C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
  4349. CNTR_NORMAL,
  4350. access_sdma_desc_table_unc_err_cnt),
  4351. [C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
  4352. CNTR_NORMAL,
  4353. access_sdma_timeout_err_cnt),
  4354. [C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
  4355. CNTR_NORMAL,
  4356. access_sdma_header_length_err_cnt),
  4357. [C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
  4358. CNTR_NORMAL,
  4359. access_sdma_header_address_err_cnt),
  4360. [C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
  4361. CNTR_NORMAL,
  4362. access_sdma_header_select_err_cnt),
  4363. [C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
  4364. CNTR_NORMAL,
  4365. access_sdma_reserved_9_err_cnt),
  4366. [C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
  4367. CNTR_NORMAL,
  4368. access_sdma_packet_desc_overflow_err_cnt),
  4369. [C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
  4370. CNTR_NORMAL,
  4371. access_sdma_length_mismatch_err_cnt),
  4372. [C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
  4373. CNTR_NORMAL,
  4374. access_sdma_halt_err_cnt),
  4375. [C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
  4376. CNTR_NORMAL,
  4377. access_sdma_mem_read_err_cnt),
  4378. [C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
  4379. CNTR_NORMAL,
  4380. access_sdma_first_desc_err_cnt),
  4381. [C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
  4382. CNTR_NORMAL,
  4383. access_sdma_tail_out_of_bounds_err_cnt),
  4384. [C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
  4385. CNTR_NORMAL,
  4386. access_sdma_too_long_err_cnt),
  4387. [C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
  4388. CNTR_NORMAL,
  4389. access_sdma_gen_mismatch_err_cnt),
  4390. [C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
  4391. CNTR_NORMAL,
  4392. access_sdma_wrong_dw_err_cnt),
  4393. };
  4394. static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
  4395. [C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
  4396. CNTR_NORMAL),
  4397. [C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
  4398. CNTR_NORMAL),
  4399. [C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
  4400. CNTR_NORMAL),
  4401. [C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
  4402. CNTR_NORMAL),
  4403. [C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
  4404. CNTR_NORMAL),
  4405. [C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
  4406. CNTR_NORMAL),
  4407. [C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
  4408. CNTR_NORMAL),
  4409. [C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
  4410. [C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
  4411. [C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
  4412. [C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
  4413. CNTR_SYNTH | CNTR_VL),
  4414. [C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
  4415. CNTR_SYNTH | CNTR_VL),
  4416. [C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
  4417. CNTR_SYNTH | CNTR_VL),
  4418. [C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
  4419. [C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
  4420. [C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4421. access_sw_link_dn_cnt),
  4422. [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4423. access_sw_link_up_cnt),
  4424. [C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
  4425. access_sw_unknown_frame_cnt),
  4426. [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4427. access_sw_xmit_discards),
  4428. [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
  4429. CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
  4430. access_sw_xmit_discards),
  4431. [C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
  4432. access_xmit_constraint_errs),
  4433. [C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
  4434. access_rcv_constraint_errs),
  4435. [C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
  4436. [C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
  4437. [C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
  4438. [C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
  4439. [C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
  4440. [C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
  4441. [C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
  4442. [C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
  4443. [C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
  4444. [C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
  4445. [C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
  4446. [C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
  4447. [C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
  4448. access_sw_cpu_rc_acks),
  4449. [C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
  4450. access_sw_cpu_rc_qacks),
  4451. [C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
  4452. access_sw_cpu_rc_delayed_comp),
  4453. [OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
  4454. [OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
  4455. [OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
  4456. [OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
  4457. [OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
  4458. [OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
  4459. [OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
  4460. [OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
  4461. [OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
  4462. [OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
  4463. [OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
  4464. [OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
  4465. [OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
  4466. [OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
  4467. [OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
  4468. [OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
  4469. [OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
  4470. [OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
  4471. [OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
  4472. [OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
  4473. [OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
  4474. [OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
  4475. [OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
  4476. [OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
  4477. [OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
  4478. [OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
  4479. [OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
  4480. [OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
  4481. [OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
  4482. [OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
  4483. [OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
  4484. [OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
  4485. [OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
  4486. [OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
  4487. [OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
  4488. [OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
  4489. [OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
  4490. [OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
  4491. [OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
  4492. [OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
  4493. [OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
  4494. [OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
  4495. [OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
  4496. [OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
  4497. [OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
  4498. [OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
  4499. [OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
  4500. [OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
  4501. [OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
  4502. [OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
  4503. [OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
  4504. [OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
  4505. [OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
  4506. [OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
  4507. [OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
  4508. [OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
  4509. [OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
  4510. [OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
  4511. [OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
  4512. [OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
  4513. [OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
  4514. [OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
  4515. [OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
  4516. [OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
  4517. [OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
  4518. [OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
  4519. [OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
  4520. [OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
  4521. [OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
  4522. [OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
  4523. [OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
  4524. [OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
  4525. [OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
  4526. [OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
  4527. [OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
  4528. [OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
  4529. [OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
  4530. [OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
  4531. [OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
  4532. [OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
  4533. };
  4534. /* ======================================================================== */
  4535. /* return true if this is chip revision revision a */
  4536. int is_ax(struct hfi1_devdata *dd)
  4537. {
  4538. u8 chip_rev_minor =
  4539. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4540. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4541. return (chip_rev_minor & 0xf0) == 0;
  4542. }
  4543. /* return true if this is chip revision revision b */
  4544. int is_bx(struct hfi1_devdata *dd)
  4545. {
  4546. u8 chip_rev_minor =
  4547. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4548. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4549. return (chip_rev_minor & 0xF0) == 0x10;
  4550. }
  4551. /*
  4552. * Append string s to buffer buf. Arguments curp and len are the current
  4553. * position and remaining length, respectively.
  4554. *
  4555. * return 0 on success, 1 on out of room
  4556. */
  4557. static int append_str(char *buf, char **curp, int *lenp, const char *s)
  4558. {
  4559. char *p = *curp;
  4560. int len = *lenp;
  4561. int result = 0; /* success */
  4562. char c;
  4563. /* add a comma, if first in the buffer */
  4564. if (p != buf) {
  4565. if (len == 0) {
  4566. result = 1; /* out of room */
  4567. goto done;
  4568. }
  4569. *p++ = ',';
  4570. len--;
  4571. }
  4572. /* copy the string */
  4573. while ((c = *s++) != 0) {
  4574. if (len == 0) {
  4575. result = 1; /* out of room */
  4576. goto done;
  4577. }
  4578. *p++ = c;
  4579. len--;
  4580. }
  4581. done:
  4582. /* write return values */
  4583. *curp = p;
  4584. *lenp = len;
  4585. return result;
  4586. }
  4587. /*
  4588. * Using the given flag table, print a comma separated string into
  4589. * the buffer. End in '*' if the buffer is too short.
  4590. */
  4591. static char *flag_string(char *buf, int buf_len, u64 flags,
  4592. struct flag_table *table, int table_size)
  4593. {
  4594. char extra[32];
  4595. char *p = buf;
  4596. int len = buf_len;
  4597. int no_room = 0;
  4598. int i;
  4599. /* make sure there is at least 2 so we can form "*" */
  4600. if (len < 2)
  4601. return "";
  4602. len--; /* leave room for a nul */
  4603. for (i = 0; i < table_size; i++) {
  4604. if (flags & table[i].flag) {
  4605. no_room = append_str(buf, &p, &len, table[i].str);
  4606. if (no_room)
  4607. break;
  4608. flags &= ~table[i].flag;
  4609. }
  4610. }
  4611. /* any undocumented bits left? */
  4612. if (!no_room && flags) {
  4613. snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
  4614. no_room = append_str(buf, &p, &len, extra);
  4615. }
  4616. /* add * if ran out of room */
  4617. if (no_room) {
  4618. /* may need to back up to add space for a '*' */
  4619. if (len == 0)
  4620. --p;
  4621. *p++ = '*';
  4622. }
  4623. /* add final nul - space already allocated above */
  4624. *p = 0;
  4625. return buf;
  4626. }
  4627. /* first 8 CCE error interrupt source names */
  4628. static const char * const cce_misc_names[] = {
  4629. "CceErrInt", /* 0 */
  4630. "RxeErrInt", /* 1 */
  4631. "MiscErrInt", /* 2 */
  4632. "Reserved3", /* 3 */
  4633. "PioErrInt", /* 4 */
  4634. "SDmaErrInt", /* 5 */
  4635. "EgressErrInt", /* 6 */
  4636. "TxeErrInt" /* 7 */
  4637. };
  4638. /*
  4639. * Return the miscellaneous error interrupt name.
  4640. */
  4641. static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
  4642. {
  4643. if (source < ARRAY_SIZE(cce_misc_names))
  4644. strncpy(buf, cce_misc_names[source], bsize);
  4645. else
  4646. snprintf(buf, bsize, "Reserved%u",
  4647. source + IS_GENERAL_ERR_START);
  4648. return buf;
  4649. }
  4650. /*
  4651. * Return the SDMA engine error interrupt name.
  4652. */
  4653. static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
  4654. {
  4655. snprintf(buf, bsize, "SDmaEngErrInt%u", source);
  4656. return buf;
  4657. }
  4658. /*
  4659. * Return the send context error interrupt name.
  4660. */
  4661. static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
  4662. {
  4663. snprintf(buf, bsize, "SendCtxtErrInt%u", source);
  4664. return buf;
  4665. }
  4666. static const char * const various_names[] = {
  4667. "PbcInt",
  4668. "GpioAssertInt",
  4669. "Qsfp1Int",
  4670. "Qsfp2Int",
  4671. "TCritInt"
  4672. };
  4673. /*
  4674. * Return the various interrupt name.
  4675. */
  4676. static char *is_various_name(char *buf, size_t bsize, unsigned int source)
  4677. {
  4678. if (source < ARRAY_SIZE(various_names))
  4679. strncpy(buf, various_names[source], bsize);
  4680. else
  4681. snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
  4682. return buf;
  4683. }
  4684. /*
  4685. * Return the DC interrupt name.
  4686. */
  4687. static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
  4688. {
  4689. static const char * const dc_int_names[] = {
  4690. "common",
  4691. "lcb",
  4692. "8051",
  4693. "lbm" /* local block merge */
  4694. };
  4695. if (source < ARRAY_SIZE(dc_int_names))
  4696. snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
  4697. else
  4698. snprintf(buf, bsize, "DCInt%u", source);
  4699. return buf;
  4700. }
  4701. static const char * const sdma_int_names[] = {
  4702. "SDmaInt",
  4703. "SdmaIdleInt",
  4704. "SdmaProgressInt",
  4705. };
  4706. /*
  4707. * Return the SDMA engine interrupt name.
  4708. */
  4709. static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
  4710. {
  4711. /* what interrupt */
  4712. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  4713. /* which engine */
  4714. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  4715. if (likely(what < 3))
  4716. snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
  4717. else
  4718. snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
  4719. return buf;
  4720. }
  4721. /*
  4722. * Return the receive available interrupt name.
  4723. */
  4724. static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
  4725. {
  4726. snprintf(buf, bsize, "RcvAvailInt%u", source);
  4727. return buf;
  4728. }
  4729. /*
  4730. * Return the receive urgent interrupt name.
  4731. */
  4732. static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
  4733. {
  4734. snprintf(buf, bsize, "RcvUrgentInt%u", source);
  4735. return buf;
  4736. }
  4737. /*
  4738. * Return the send credit interrupt name.
  4739. */
  4740. static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
  4741. {
  4742. snprintf(buf, bsize, "SendCreditInt%u", source);
  4743. return buf;
  4744. }
  4745. /*
  4746. * Return the reserved interrupt name.
  4747. */
  4748. static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
  4749. {
  4750. snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
  4751. return buf;
  4752. }
  4753. static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
  4754. {
  4755. return flag_string(buf, buf_len, flags,
  4756. cce_err_status_flags,
  4757. ARRAY_SIZE(cce_err_status_flags));
  4758. }
  4759. static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
  4760. {
  4761. return flag_string(buf, buf_len, flags,
  4762. rxe_err_status_flags,
  4763. ARRAY_SIZE(rxe_err_status_flags));
  4764. }
  4765. static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
  4766. {
  4767. return flag_string(buf, buf_len, flags, misc_err_status_flags,
  4768. ARRAY_SIZE(misc_err_status_flags));
  4769. }
  4770. static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
  4771. {
  4772. return flag_string(buf, buf_len, flags,
  4773. pio_err_status_flags,
  4774. ARRAY_SIZE(pio_err_status_flags));
  4775. }
  4776. static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
  4777. {
  4778. return flag_string(buf, buf_len, flags,
  4779. sdma_err_status_flags,
  4780. ARRAY_SIZE(sdma_err_status_flags));
  4781. }
  4782. static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
  4783. {
  4784. return flag_string(buf, buf_len, flags,
  4785. egress_err_status_flags,
  4786. ARRAY_SIZE(egress_err_status_flags));
  4787. }
  4788. static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
  4789. {
  4790. return flag_string(buf, buf_len, flags,
  4791. egress_err_info_flags,
  4792. ARRAY_SIZE(egress_err_info_flags));
  4793. }
  4794. static char *send_err_status_string(char *buf, int buf_len, u64 flags)
  4795. {
  4796. return flag_string(buf, buf_len, flags,
  4797. send_err_status_flags,
  4798. ARRAY_SIZE(send_err_status_flags));
  4799. }
  4800. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4801. {
  4802. char buf[96];
  4803. int i = 0;
  4804. /*
  4805. * For most these errors, there is nothing that can be done except
  4806. * report or record it.
  4807. */
  4808. dd_dev_info(dd, "CCE Error: %s\n",
  4809. cce_err_status_string(buf, sizeof(buf), reg));
  4810. if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
  4811. is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
  4812. /* this error requires a manual drop into SPC freeze mode */
  4813. /* then a fix up */
  4814. start_freeze_handling(dd->pport, FREEZE_SELF);
  4815. }
  4816. for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
  4817. if (reg & (1ull << i)) {
  4818. incr_cntr64(&dd->cce_err_status_cnt[i]);
  4819. /* maintain a counter over all cce_err_status errors */
  4820. incr_cntr64(&dd->sw_cce_err_status_aggregate);
  4821. }
  4822. }
  4823. }
  4824. /*
  4825. * Check counters for receive errors that do not have an interrupt
  4826. * associated with them.
  4827. */
  4828. #define RCVERR_CHECK_TIME 10
  4829. static void update_rcverr_timer(struct timer_list *t)
  4830. {
  4831. struct hfi1_devdata *dd = from_timer(dd, t, rcverr_timer);
  4832. struct hfi1_pportdata *ppd = dd->pport;
  4833. u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  4834. if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
  4835. ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
  4836. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  4837. set_link_down_reason(
  4838. ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
  4839. OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
  4840. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  4841. }
  4842. dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
  4843. mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4844. }
  4845. static int init_rcverr(struct hfi1_devdata *dd)
  4846. {
  4847. timer_setup(&dd->rcverr_timer, update_rcverr_timer, 0);
  4848. /* Assume the hardware counter has been reset */
  4849. dd->rcv_ovfl_cnt = 0;
  4850. return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4851. }
  4852. static void free_rcverr(struct hfi1_devdata *dd)
  4853. {
  4854. if (dd->rcverr_timer.function)
  4855. del_timer_sync(&dd->rcverr_timer);
  4856. }
  4857. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4858. {
  4859. char buf[96];
  4860. int i = 0;
  4861. dd_dev_info(dd, "Receive Error: %s\n",
  4862. rxe_err_status_string(buf, sizeof(buf), reg));
  4863. if (reg & ALL_RXE_FREEZE_ERR) {
  4864. int flags = 0;
  4865. /*
  4866. * Freeze mode recovery is disabled for the errors
  4867. * in RXE_FREEZE_ABORT_MASK
  4868. */
  4869. if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
  4870. flags = FREEZE_ABORT;
  4871. start_freeze_handling(dd->pport, flags);
  4872. }
  4873. for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
  4874. if (reg & (1ull << i))
  4875. incr_cntr64(&dd->rcv_err_status_cnt[i]);
  4876. }
  4877. }
  4878. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4879. {
  4880. char buf[96];
  4881. int i = 0;
  4882. dd_dev_info(dd, "Misc Error: %s",
  4883. misc_err_status_string(buf, sizeof(buf), reg));
  4884. for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
  4885. if (reg & (1ull << i))
  4886. incr_cntr64(&dd->misc_err_status_cnt[i]);
  4887. }
  4888. }
  4889. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4890. {
  4891. char buf[96];
  4892. int i = 0;
  4893. dd_dev_info(dd, "PIO Error: %s\n",
  4894. pio_err_status_string(buf, sizeof(buf), reg));
  4895. if (reg & ALL_PIO_FREEZE_ERR)
  4896. start_freeze_handling(dd->pport, 0);
  4897. for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
  4898. if (reg & (1ull << i))
  4899. incr_cntr64(&dd->send_pio_err_status_cnt[i]);
  4900. }
  4901. }
  4902. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4903. {
  4904. char buf[96];
  4905. int i = 0;
  4906. dd_dev_info(dd, "SDMA Error: %s\n",
  4907. sdma_err_status_string(buf, sizeof(buf), reg));
  4908. if (reg & ALL_SDMA_FREEZE_ERR)
  4909. start_freeze_handling(dd->pport, 0);
  4910. for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
  4911. if (reg & (1ull << i))
  4912. incr_cntr64(&dd->send_dma_err_status_cnt[i]);
  4913. }
  4914. }
  4915. static inline void __count_port_discards(struct hfi1_pportdata *ppd)
  4916. {
  4917. incr_cntr64(&ppd->port_xmit_discards);
  4918. }
  4919. static void count_port_inactive(struct hfi1_devdata *dd)
  4920. {
  4921. __count_port_discards(dd->pport);
  4922. }
  4923. /*
  4924. * We have had a "disallowed packet" error during egress. Determine the
  4925. * integrity check which failed, and update relevant error counter, etc.
  4926. *
  4927. * Note that the SEND_EGRESS_ERR_INFO register has only a single
  4928. * bit of state per integrity check, and so we can miss the reason for an
  4929. * egress error if more than one packet fails the same integrity check
  4930. * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
  4931. */
  4932. static void handle_send_egress_err_info(struct hfi1_devdata *dd,
  4933. int vl)
  4934. {
  4935. struct hfi1_pportdata *ppd = dd->pport;
  4936. u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
  4937. u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
  4938. char buf[96];
  4939. /* clear down all observed info as quickly as possible after read */
  4940. write_csr(dd, SEND_EGRESS_ERR_INFO, info);
  4941. dd_dev_info(dd,
  4942. "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
  4943. info, egress_err_info_string(buf, sizeof(buf), info), src);
  4944. /* Eventually add other counters for each bit */
  4945. if (info & PORT_DISCARD_EGRESS_ERRS) {
  4946. int weight, i;
  4947. /*
  4948. * Count all applicable bits as individual errors and
  4949. * attribute them to the packet that triggered this handler.
  4950. * This may not be completely accurate due to limitations
  4951. * on the available hardware error information. There is
  4952. * a single information register and any number of error
  4953. * packets may have occurred and contributed to it before
  4954. * this routine is called. This means that:
  4955. * a) If multiple packets with the same error occur before
  4956. * this routine is called, earlier packets are missed.
  4957. * There is only a single bit for each error type.
  4958. * b) Errors may not be attributed to the correct VL.
  4959. * The driver is attributing all bits in the info register
  4960. * to the packet that triggered this call, but bits
  4961. * could be an accumulation of different packets with
  4962. * different VLs.
  4963. * c) A single error packet may have multiple counts attached
  4964. * to it. There is no way for the driver to know if
  4965. * multiple bits set in the info register are due to a
  4966. * single packet or multiple packets. The driver assumes
  4967. * multiple packets.
  4968. */
  4969. weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
  4970. for (i = 0; i < weight; i++) {
  4971. __count_port_discards(ppd);
  4972. if (vl >= 0 && vl < TXE_NUM_DATA_VL)
  4973. incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
  4974. else if (vl == 15)
  4975. incr_cntr64(&ppd->port_xmit_discards_vl
  4976. [C_VL_15]);
  4977. }
  4978. }
  4979. }
  4980. /*
  4981. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4982. * register. Does it represent a 'port inactive' error?
  4983. */
  4984. static inline int port_inactive_err(u64 posn)
  4985. {
  4986. return (posn >= SEES(TX_LINKDOWN) &&
  4987. posn <= SEES(TX_INCORRECT_LINK_STATE));
  4988. }
  4989. /*
  4990. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4991. * register. Does it represent a 'disallowed packet' error?
  4992. */
  4993. static inline int disallowed_pkt_err(int posn)
  4994. {
  4995. return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
  4996. posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
  4997. }
  4998. /*
  4999. * Input value is a bit position of one of the SDMA engine disallowed
  5000. * packet errors. Return which engine. Use of this must be guarded by
  5001. * disallowed_pkt_err().
  5002. */
  5003. static inline int disallowed_pkt_engine(int posn)
  5004. {
  5005. return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
  5006. }
  5007. /*
  5008. * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
  5009. * be done.
  5010. */
  5011. static int engine_to_vl(struct hfi1_devdata *dd, int engine)
  5012. {
  5013. struct sdma_vl_map *m;
  5014. int vl;
  5015. /* range check */
  5016. if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
  5017. return -1;
  5018. rcu_read_lock();
  5019. m = rcu_dereference(dd->sdma_map);
  5020. vl = m->engine_to_vl[engine];
  5021. rcu_read_unlock();
  5022. return vl;
  5023. }
  5024. /*
  5025. * Translate the send context (sofware index) into a VL. Return -1 if the
  5026. * translation cannot be done.
  5027. */
  5028. static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
  5029. {
  5030. struct send_context_info *sci;
  5031. struct send_context *sc;
  5032. int i;
  5033. sci = &dd->send_contexts[sw_index];
  5034. /* there is no information for user (PSM) and ack contexts */
  5035. if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
  5036. return -1;
  5037. sc = sci->sc;
  5038. if (!sc)
  5039. return -1;
  5040. if (dd->vld[15].sc == sc)
  5041. return 15;
  5042. for (i = 0; i < num_vls; i++)
  5043. if (dd->vld[i].sc == sc)
  5044. return i;
  5045. return -1;
  5046. }
  5047. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5048. {
  5049. u64 reg_copy = reg, handled = 0;
  5050. char buf[96];
  5051. int i = 0;
  5052. if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
  5053. start_freeze_handling(dd->pport, 0);
  5054. else if (is_ax(dd) &&
  5055. (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
  5056. (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
  5057. start_freeze_handling(dd->pport, 0);
  5058. while (reg_copy) {
  5059. int posn = fls64(reg_copy);
  5060. /* fls64() returns a 1-based offset, we want it zero based */
  5061. int shift = posn - 1;
  5062. u64 mask = 1ULL << shift;
  5063. if (port_inactive_err(shift)) {
  5064. count_port_inactive(dd);
  5065. handled |= mask;
  5066. } else if (disallowed_pkt_err(shift)) {
  5067. int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
  5068. handle_send_egress_err_info(dd, vl);
  5069. handled |= mask;
  5070. }
  5071. reg_copy &= ~mask;
  5072. }
  5073. reg &= ~handled;
  5074. if (reg)
  5075. dd_dev_info(dd, "Egress Error: %s\n",
  5076. egress_err_status_string(buf, sizeof(buf), reg));
  5077. for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
  5078. if (reg & (1ull << i))
  5079. incr_cntr64(&dd->send_egress_err_status_cnt[i]);
  5080. }
  5081. }
  5082. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5083. {
  5084. char buf[96];
  5085. int i = 0;
  5086. dd_dev_info(dd, "Send Error: %s\n",
  5087. send_err_status_string(buf, sizeof(buf), reg));
  5088. for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
  5089. if (reg & (1ull << i))
  5090. incr_cntr64(&dd->send_err_status_cnt[i]);
  5091. }
  5092. }
  5093. /*
  5094. * The maximum number of times the error clear down will loop before
  5095. * blocking a repeating error. This value is arbitrary.
  5096. */
  5097. #define MAX_CLEAR_COUNT 20
  5098. /*
  5099. * Clear and handle an error register. All error interrupts are funneled
  5100. * through here to have a central location to correctly handle single-
  5101. * or multi-shot errors.
  5102. *
  5103. * For non per-context registers, call this routine with a context value
  5104. * of 0 so the per-context offset is zero.
  5105. *
  5106. * If the handler loops too many times, assume that something is wrong
  5107. * and can't be fixed, so mask the error bits.
  5108. */
  5109. static void interrupt_clear_down(struct hfi1_devdata *dd,
  5110. u32 context,
  5111. const struct err_reg_info *eri)
  5112. {
  5113. u64 reg;
  5114. u32 count;
  5115. /* read in a loop until no more errors are seen */
  5116. count = 0;
  5117. while (1) {
  5118. reg = read_kctxt_csr(dd, context, eri->status);
  5119. if (reg == 0)
  5120. break;
  5121. write_kctxt_csr(dd, context, eri->clear, reg);
  5122. if (likely(eri->handler))
  5123. eri->handler(dd, context, reg);
  5124. count++;
  5125. if (count > MAX_CLEAR_COUNT) {
  5126. u64 mask;
  5127. dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
  5128. eri->desc, reg);
  5129. /*
  5130. * Read-modify-write so any other masked bits
  5131. * remain masked.
  5132. */
  5133. mask = read_kctxt_csr(dd, context, eri->mask);
  5134. mask &= ~reg;
  5135. write_kctxt_csr(dd, context, eri->mask, mask);
  5136. break;
  5137. }
  5138. }
  5139. }
  5140. /*
  5141. * CCE block "misc" interrupt. Source is < 16.
  5142. */
  5143. static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
  5144. {
  5145. const struct err_reg_info *eri = &misc_errs[source];
  5146. if (eri->handler) {
  5147. interrupt_clear_down(dd, 0, eri);
  5148. } else {
  5149. dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
  5150. source);
  5151. }
  5152. }
  5153. static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
  5154. {
  5155. return flag_string(buf, buf_len, flags,
  5156. sc_err_status_flags,
  5157. ARRAY_SIZE(sc_err_status_flags));
  5158. }
  5159. /*
  5160. * Send context error interrupt. Source (hw_context) is < 160.
  5161. *
  5162. * All send context errors cause the send context to halt. The normal
  5163. * clear-down mechanism cannot be used because we cannot clear the
  5164. * error bits until several other long-running items are done first.
  5165. * This is OK because with the context halted, nothing else is going
  5166. * to happen on it anyway.
  5167. */
  5168. static void is_sendctxt_err_int(struct hfi1_devdata *dd,
  5169. unsigned int hw_context)
  5170. {
  5171. struct send_context_info *sci;
  5172. struct send_context *sc;
  5173. char flags[96];
  5174. u64 status;
  5175. u32 sw_index;
  5176. int i = 0;
  5177. sw_index = dd->hw_to_sw[hw_context];
  5178. if (sw_index >= dd->num_send_contexts) {
  5179. dd_dev_err(dd,
  5180. "out of range sw index %u for send context %u\n",
  5181. sw_index, hw_context);
  5182. return;
  5183. }
  5184. sci = &dd->send_contexts[sw_index];
  5185. sc = sci->sc;
  5186. if (!sc) {
  5187. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5188. sw_index, hw_context);
  5189. return;
  5190. }
  5191. /* tell the software that a halt has begun */
  5192. sc_stop(sc, SCF_HALTED);
  5193. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5194. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5195. send_context_err_status_string(flags, sizeof(flags),
  5196. status));
  5197. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5198. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5199. /*
  5200. * Automatically restart halted kernel contexts out of interrupt
  5201. * context. User contexts must ask the driver to restart the context.
  5202. */
  5203. if (sc->type != SC_USER)
  5204. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5205. /*
  5206. * Update the counters for the corresponding status bits.
  5207. * Note that these particular counters are aggregated over all
  5208. * 160 contexts.
  5209. */
  5210. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5211. if (status & (1ull << i))
  5212. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5213. }
  5214. }
  5215. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5216. unsigned int source, u64 status)
  5217. {
  5218. struct sdma_engine *sde;
  5219. int i = 0;
  5220. sde = &dd->per_sdma[source];
  5221. #ifdef CONFIG_SDMA_VERBOSITY
  5222. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5223. slashstrip(__FILE__), __LINE__, __func__);
  5224. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5225. sde->this_idx, source, (unsigned long long)status);
  5226. #endif
  5227. sde->err_cnt++;
  5228. sdma_engine_error(sde, status);
  5229. /*
  5230. * Update the counters for the corresponding status bits.
  5231. * Note that these particular counters are aggregated over
  5232. * all 16 DMA engines.
  5233. */
  5234. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5235. if (status & (1ull << i))
  5236. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5237. }
  5238. }
  5239. /*
  5240. * CCE block SDMA error interrupt. Source is < 16.
  5241. */
  5242. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5243. {
  5244. #ifdef CONFIG_SDMA_VERBOSITY
  5245. struct sdma_engine *sde = &dd->per_sdma[source];
  5246. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5247. slashstrip(__FILE__), __LINE__, __func__);
  5248. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5249. source);
  5250. sdma_dumpstate(sde);
  5251. #endif
  5252. interrupt_clear_down(dd, source, &sdma_eng_err);
  5253. }
  5254. /*
  5255. * CCE block "various" interrupt. Source is < 8.
  5256. */
  5257. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5258. {
  5259. const struct err_reg_info *eri = &various_err[source];
  5260. /*
  5261. * TCritInt cannot go through interrupt_clear_down()
  5262. * because it is not a second tier interrupt. The handler
  5263. * should be called directly.
  5264. */
  5265. if (source == TCRIT_INT_SOURCE)
  5266. handle_temp_err(dd);
  5267. else if (eri->handler)
  5268. interrupt_clear_down(dd, 0, eri);
  5269. else
  5270. dd_dev_info(dd,
  5271. "%s: Unimplemented/reserved interrupt %d\n",
  5272. __func__, source);
  5273. }
  5274. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5275. {
  5276. /* src_ctx is always zero */
  5277. struct hfi1_pportdata *ppd = dd->pport;
  5278. unsigned long flags;
  5279. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5280. if (reg & QSFP_HFI0_MODPRST_N) {
  5281. if (!qsfp_mod_present(ppd)) {
  5282. dd_dev_info(dd, "%s: QSFP module removed\n",
  5283. __func__);
  5284. ppd->driver_link_ready = 0;
  5285. /*
  5286. * Cable removed, reset all our information about the
  5287. * cache and cable capabilities
  5288. */
  5289. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5290. /*
  5291. * We don't set cache_refresh_required here as we expect
  5292. * an interrupt when a cable is inserted
  5293. */
  5294. ppd->qsfp_info.cache_valid = 0;
  5295. ppd->qsfp_info.reset_needed = 0;
  5296. ppd->qsfp_info.limiting_active = 0;
  5297. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5298. flags);
  5299. /* Invert the ModPresent pin now to detect plug-in */
  5300. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5301. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5302. if ((ppd->offline_disabled_reason >
  5303. HFI1_ODR_MASK(
  5304. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5305. (ppd->offline_disabled_reason ==
  5306. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5307. ppd->offline_disabled_reason =
  5308. HFI1_ODR_MASK(
  5309. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5310. if (ppd->host_link_state == HLS_DN_POLL) {
  5311. /*
  5312. * The link is still in POLL. This means
  5313. * that the normal link down processing
  5314. * will not happen. We have to do it here
  5315. * before turning the DC off.
  5316. */
  5317. queue_work(ppd->link_wq, &ppd->link_down_work);
  5318. }
  5319. } else {
  5320. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5321. __func__);
  5322. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5323. ppd->qsfp_info.cache_valid = 0;
  5324. ppd->qsfp_info.cache_refresh_required = 1;
  5325. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5326. flags);
  5327. /*
  5328. * Stop inversion of ModPresent pin to detect
  5329. * removal of the cable
  5330. */
  5331. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5332. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5333. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5334. ppd->offline_disabled_reason =
  5335. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5336. }
  5337. }
  5338. if (reg & QSFP_HFI0_INT_N) {
  5339. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5340. __func__);
  5341. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5342. ppd->qsfp_info.check_interrupt_flags = 1;
  5343. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5344. }
  5345. /* Schedule the QSFP work only if there is a cable attached. */
  5346. if (qsfp_mod_present(ppd))
  5347. queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
  5348. }
  5349. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5350. {
  5351. int ret;
  5352. ret = do_8051_command(dd, HCMD_MISC,
  5353. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5354. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5355. if (ret != HCMD_SUCCESS) {
  5356. dd_dev_err(dd, "%s: command failed with error %d\n",
  5357. __func__, ret);
  5358. }
  5359. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5360. }
  5361. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5362. {
  5363. int ret;
  5364. ret = do_8051_command(dd, HCMD_MISC,
  5365. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5366. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5367. if (ret != HCMD_SUCCESS) {
  5368. dd_dev_err(dd, "%s: command failed with error %d\n",
  5369. __func__, ret);
  5370. }
  5371. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5372. }
  5373. /*
  5374. * Set the LCB selector - allow host access. The DCC selector always
  5375. * points to the host.
  5376. */
  5377. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5378. {
  5379. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5380. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5381. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5382. }
  5383. /*
  5384. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5385. * points to the host.
  5386. */
  5387. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5388. {
  5389. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5390. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5391. }
  5392. /*
  5393. * Acquire LCB access from the 8051. If the host already has access,
  5394. * just increment a counter. Otherwise, inform the 8051 that the
  5395. * host is taking access.
  5396. *
  5397. * Returns:
  5398. * 0 on success
  5399. * -EBUSY if the 8051 has control and cannot be disturbed
  5400. * -errno if unable to acquire access from the 8051
  5401. */
  5402. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5403. {
  5404. struct hfi1_pportdata *ppd = dd->pport;
  5405. int ret = 0;
  5406. /*
  5407. * Use the host link state lock so the operation of this routine
  5408. * { link state check, selector change, count increment } can occur
  5409. * as a unit against a link state change. Otherwise there is a
  5410. * race between the state change and the count increment.
  5411. */
  5412. if (sleep_ok) {
  5413. mutex_lock(&ppd->hls_lock);
  5414. } else {
  5415. while (!mutex_trylock(&ppd->hls_lock))
  5416. udelay(1);
  5417. }
  5418. /* this access is valid only when the link is up */
  5419. if (ppd->host_link_state & HLS_DOWN) {
  5420. dd_dev_info(dd, "%s: link state %s not up\n",
  5421. __func__, link_state_name(ppd->host_link_state));
  5422. ret = -EBUSY;
  5423. goto done;
  5424. }
  5425. if (dd->lcb_access_count == 0) {
  5426. ret = request_host_lcb_access(dd);
  5427. if (ret) {
  5428. dd_dev_err(dd,
  5429. "%s: unable to acquire LCB access, err %d\n",
  5430. __func__, ret);
  5431. goto done;
  5432. }
  5433. set_host_lcb_access(dd);
  5434. }
  5435. dd->lcb_access_count++;
  5436. done:
  5437. mutex_unlock(&ppd->hls_lock);
  5438. return ret;
  5439. }
  5440. /*
  5441. * Release LCB access by decrementing the use count. If the count is moving
  5442. * from 1 to 0, inform 8051 that it has control back.
  5443. *
  5444. * Returns:
  5445. * 0 on success
  5446. * -errno if unable to release access to the 8051
  5447. */
  5448. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5449. {
  5450. int ret = 0;
  5451. /*
  5452. * Use the host link state lock because the acquire needed it.
  5453. * Here, we only need to keep { selector change, count decrement }
  5454. * as a unit.
  5455. */
  5456. if (sleep_ok) {
  5457. mutex_lock(&dd->pport->hls_lock);
  5458. } else {
  5459. while (!mutex_trylock(&dd->pport->hls_lock))
  5460. udelay(1);
  5461. }
  5462. if (dd->lcb_access_count == 0) {
  5463. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5464. __func__);
  5465. goto done;
  5466. }
  5467. if (dd->lcb_access_count == 1) {
  5468. set_8051_lcb_access(dd);
  5469. ret = request_8051_lcb_access(dd);
  5470. if (ret) {
  5471. dd_dev_err(dd,
  5472. "%s: unable to release LCB access, err %d\n",
  5473. __func__, ret);
  5474. /* restore host access if the grant didn't work */
  5475. set_host_lcb_access(dd);
  5476. goto done;
  5477. }
  5478. }
  5479. dd->lcb_access_count--;
  5480. done:
  5481. mutex_unlock(&dd->pport->hls_lock);
  5482. return ret;
  5483. }
  5484. /*
  5485. * Initialize LCB access variables and state. Called during driver load,
  5486. * after most of the initialization is finished.
  5487. *
  5488. * The DC default is LCB access on for the host. The driver defaults to
  5489. * leaving access to the 8051. Assign access now - this constrains the call
  5490. * to this routine to be after all LCB set-up is done. In particular, after
  5491. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5492. */
  5493. static void init_lcb_access(struct hfi1_devdata *dd)
  5494. {
  5495. dd->lcb_access_count = 0;
  5496. }
  5497. /*
  5498. * Write a response back to a 8051 request.
  5499. */
  5500. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5501. {
  5502. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5503. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5504. (u64)return_code <<
  5505. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5506. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5507. }
  5508. /*
  5509. * Handle host requests from the 8051.
  5510. */
  5511. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5512. {
  5513. struct hfi1_devdata *dd = ppd->dd;
  5514. u64 reg;
  5515. u16 data = 0;
  5516. u8 type;
  5517. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5518. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5519. return; /* no request */
  5520. /* zero out COMPLETED so the response is seen */
  5521. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5522. /* extract request details */
  5523. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5524. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5525. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5526. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5527. switch (type) {
  5528. case HREQ_LOAD_CONFIG:
  5529. case HREQ_SAVE_CONFIG:
  5530. case HREQ_READ_CONFIG:
  5531. case HREQ_SET_TX_EQ_ABS:
  5532. case HREQ_SET_TX_EQ_REL:
  5533. case HREQ_ENABLE:
  5534. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5535. type);
  5536. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5537. break;
  5538. case HREQ_LCB_RESET:
  5539. /* Put the LCB, RX FPE and TX FPE into reset */
  5540. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_INTO_RESET);
  5541. /* Make sure the write completed */
  5542. (void)read_csr(dd, DCC_CFG_RESET);
  5543. /* Hold the reset long enough to take effect */
  5544. udelay(1);
  5545. /* Take the LCB, RX FPE and TX FPE out of reset */
  5546. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_OUT_OF_RESET);
  5547. hreq_response(dd, HREQ_SUCCESS, 0);
  5548. break;
  5549. case HREQ_CONFIG_DONE:
  5550. hreq_response(dd, HREQ_SUCCESS, 0);
  5551. break;
  5552. case HREQ_INTERFACE_TEST:
  5553. hreq_response(dd, HREQ_SUCCESS, data);
  5554. break;
  5555. default:
  5556. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5557. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5558. break;
  5559. }
  5560. }
  5561. /*
  5562. * Set up allocation unit vaulue.
  5563. */
  5564. void set_up_vau(struct hfi1_devdata *dd, u8 vau)
  5565. {
  5566. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5567. /* do not modify other values in the register */
  5568. reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
  5569. reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
  5570. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5571. }
  5572. /*
  5573. * Set up initial VL15 credits of the remote. Assumes the rest of
  5574. * the CM credit registers are zero from a previous global or credit reset.
  5575. * Shared limit for VL15 will always be 0.
  5576. */
  5577. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
  5578. {
  5579. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5580. /* set initial values for total and shared credit limit */
  5581. reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
  5582. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
  5583. /*
  5584. * Set total limit to be equal to VL15 credits.
  5585. * Leave shared limit at 0.
  5586. */
  5587. reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  5588. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5589. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5590. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5591. }
  5592. /*
  5593. * Zero all credit details from the previous connection and
  5594. * reset the CM manager's internal counters.
  5595. */
  5596. void reset_link_credits(struct hfi1_devdata *dd)
  5597. {
  5598. int i;
  5599. /* remove all previous VL credit limits */
  5600. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5601. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5602. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5603. write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
  5604. /* reset the CM block */
  5605. pio_send_control(dd, PSC_CM_RESET);
  5606. /* reset cached value */
  5607. dd->vl15buf_cached = 0;
  5608. }
  5609. /* convert a vCU to a CU */
  5610. static u32 vcu_to_cu(u8 vcu)
  5611. {
  5612. return 1 << vcu;
  5613. }
  5614. /* convert a CU to a vCU */
  5615. static u8 cu_to_vcu(u32 cu)
  5616. {
  5617. return ilog2(cu);
  5618. }
  5619. /* convert a vAU to an AU */
  5620. static u32 vau_to_au(u8 vau)
  5621. {
  5622. return 8 * (1 << vau);
  5623. }
  5624. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5625. {
  5626. ppd->sm_trap_qp = 0x0;
  5627. ppd->sa_qp = 0x1;
  5628. }
  5629. /*
  5630. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5631. */
  5632. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5633. {
  5634. u64 reg;
  5635. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5636. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5637. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5638. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5639. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5640. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5641. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5642. reg = read_csr(dd, DCC_CFG_RESET);
  5643. write_csr(dd, DCC_CFG_RESET, reg |
  5644. DCC_CFG_RESET_RESET_LCB | DCC_CFG_RESET_RESET_RX_FPE);
  5645. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5646. if (!abort) {
  5647. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5648. write_csr(dd, DCC_CFG_RESET, reg);
  5649. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5650. }
  5651. }
  5652. /*
  5653. * This routine should be called after the link has been transitioned to
  5654. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5655. * reset).
  5656. *
  5657. * The expectation is that the caller of this routine would have taken
  5658. * care of properly transitioning the link into the correct state.
  5659. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5660. * before calling this function.
  5661. */
  5662. static void _dc_shutdown(struct hfi1_devdata *dd)
  5663. {
  5664. lockdep_assert_held(&dd->dc8051_lock);
  5665. if (dd->dc_shutdown)
  5666. return;
  5667. dd->dc_shutdown = 1;
  5668. /* Shutdown the LCB */
  5669. lcb_shutdown(dd, 1);
  5670. /*
  5671. * Going to OFFLINE would have causes the 8051 to put the
  5672. * SerDes into reset already. Just need to shut down the 8051,
  5673. * itself.
  5674. */
  5675. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5676. }
  5677. static void dc_shutdown(struct hfi1_devdata *dd)
  5678. {
  5679. mutex_lock(&dd->dc8051_lock);
  5680. _dc_shutdown(dd);
  5681. mutex_unlock(&dd->dc8051_lock);
  5682. }
  5683. /*
  5684. * Calling this after the DC has been brought out of reset should not
  5685. * do any damage.
  5686. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5687. * before calling this function.
  5688. */
  5689. static void _dc_start(struct hfi1_devdata *dd)
  5690. {
  5691. lockdep_assert_held(&dd->dc8051_lock);
  5692. if (!dd->dc_shutdown)
  5693. return;
  5694. /* Take the 8051 out of reset */
  5695. write_csr(dd, DC_DC8051_CFG_RST, 0ull);
  5696. /* Wait until 8051 is ready */
  5697. if (wait_fm_ready(dd, TIMEOUT_8051_START))
  5698. dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
  5699. __func__);
  5700. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5701. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_OUT_OF_RESET);
  5702. /* lcb_shutdown() with abort=1 does not restore these */
  5703. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5704. dd->dc_shutdown = 0;
  5705. }
  5706. static void dc_start(struct hfi1_devdata *dd)
  5707. {
  5708. mutex_lock(&dd->dc8051_lock);
  5709. _dc_start(dd);
  5710. mutex_unlock(&dd->dc8051_lock);
  5711. }
  5712. /*
  5713. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5714. */
  5715. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5716. {
  5717. u64 rx_radr, tx_radr;
  5718. u32 version;
  5719. if (dd->icode != ICODE_FPGA_EMULATION)
  5720. return;
  5721. /*
  5722. * These LCB defaults on emulator _s are good, nothing to do here:
  5723. * LCB_CFG_TX_FIFOS_RADR
  5724. * LCB_CFG_RX_FIFOS_RADR
  5725. * LCB_CFG_LN_DCLK
  5726. * LCB_CFG_IGNORE_LOST_RCLK
  5727. */
  5728. if (is_emulator_s(dd))
  5729. return;
  5730. /* else this is _p */
  5731. version = emulator_rev(dd);
  5732. if (!is_ax(dd))
  5733. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5734. if (version <= 0x12) {
  5735. /* release 0x12 and below */
  5736. /*
  5737. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5738. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5739. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5740. */
  5741. rx_radr =
  5742. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5743. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5744. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5745. /*
  5746. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5747. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5748. */
  5749. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5750. } else if (version <= 0x18) {
  5751. /* release 0x13 up to 0x18 */
  5752. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5753. rx_radr =
  5754. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5755. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5756. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5757. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5758. } else if (version == 0x19) {
  5759. /* release 0x19 */
  5760. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5761. rx_radr =
  5762. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5763. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5764. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5765. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5766. } else if (version == 0x1a) {
  5767. /* release 0x1a */
  5768. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5769. rx_radr =
  5770. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5771. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5772. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5773. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5774. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5775. } else {
  5776. /* release 0x1b and higher */
  5777. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5778. rx_radr =
  5779. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5780. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5781. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5782. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5783. }
  5784. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5785. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5786. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5787. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5788. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5789. }
  5790. /*
  5791. * Handle a SMA idle message
  5792. *
  5793. * This is a work-queue function outside of the interrupt.
  5794. */
  5795. void handle_sma_message(struct work_struct *work)
  5796. {
  5797. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5798. sma_message_work);
  5799. struct hfi1_devdata *dd = ppd->dd;
  5800. u64 msg;
  5801. int ret;
  5802. /*
  5803. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5804. * is stripped off
  5805. */
  5806. ret = read_idle_sma(dd, &msg);
  5807. if (ret)
  5808. return;
  5809. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5810. /*
  5811. * React to the SMA message. Byte[1] (0 for us) is the command.
  5812. */
  5813. switch (msg & 0xff) {
  5814. case SMA_IDLE_ARM:
  5815. /*
  5816. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5817. * State Transitions
  5818. *
  5819. * Only expected in INIT or ARMED, discard otherwise.
  5820. */
  5821. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5822. ppd->neighbor_normal = 1;
  5823. break;
  5824. case SMA_IDLE_ACTIVE:
  5825. /*
  5826. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5827. * State Transitions
  5828. *
  5829. * Can activate the node. Discard otherwise.
  5830. */
  5831. if (ppd->host_link_state == HLS_UP_ARMED &&
  5832. ppd->is_active_optimize_enabled) {
  5833. ppd->neighbor_normal = 1;
  5834. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5835. if (ret)
  5836. dd_dev_err(
  5837. dd,
  5838. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5839. __func__);
  5840. }
  5841. break;
  5842. default:
  5843. dd_dev_err(dd,
  5844. "%s: received unexpected SMA idle message 0x%llx\n",
  5845. __func__, msg);
  5846. break;
  5847. }
  5848. }
  5849. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5850. {
  5851. u64 rcvctrl;
  5852. unsigned long flags;
  5853. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5854. rcvctrl = read_csr(dd, RCV_CTRL);
  5855. rcvctrl |= add;
  5856. rcvctrl &= ~clear;
  5857. write_csr(dd, RCV_CTRL, rcvctrl);
  5858. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5859. }
  5860. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5861. {
  5862. adjust_rcvctrl(dd, add, 0);
  5863. }
  5864. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5865. {
  5866. adjust_rcvctrl(dd, 0, clear);
  5867. }
  5868. /*
  5869. * Called from all interrupt handlers to start handling an SPC freeze.
  5870. */
  5871. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5872. {
  5873. struct hfi1_devdata *dd = ppd->dd;
  5874. struct send_context *sc;
  5875. int i;
  5876. if (flags & FREEZE_SELF)
  5877. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5878. /* enter frozen mode */
  5879. dd->flags |= HFI1_FROZEN;
  5880. /* notify all SDMA engines that they are going into a freeze */
  5881. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5882. /* do halt pre-handling on all enabled send contexts */
  5883. for (i = 0; i < dd->num_send_contexts; i++) {
  5884. sc = dd->send_contexts[i].sc;
  5885. if (sc && (sc->flags & SCF_ENABLED))
  5886. sc_stop(sc, SCF_FROZEN | SCF_HALTED);
  5887. }
  5888. /* Send context are frozen. Notify user space */
  5889. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5890. if (flags & FREEZE_ABORT) {
  5891. dd_dev_err(dd,
  5892. "Aborted freeze recovery. Please REBOOT system\n");
  5893. return;
  5894. }
  5895. /* queue non-interrupt handler */
  5896. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5897. }
  5898. /*
  5899. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5900. * depending on the "freeze" parameter.
  5901. *
  5902. * No need to return an error if it times out, our only option
  5903. * is to proceed anyway.
  5904. */
  5905. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5906. {
  5907. unsigned long timeout;
  5908. u64 reg;
  5909. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5910. while (1) {
  5911. reg = read_csr(dd, CCE_STATUS);
  5912. if (freeze) {
  5913. /* waiting until all indicators are set */
  5914. if ((reg & ALL_FROZE) == ALL_FROZE)
  5915. return; /* all done */
  5916. } else {
  5917. /* waiting until all indicators are clear */
  5918. if ((reg & ALL_FROZE) == 0)
  5919. return; /* all done */
  5920. }
  5921. if (time_after(jiffies, timeout)) {
  5922. dd_dev_err(dd,
  5923. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5924. freeze ? "" : "un", reg & ALL_FROZE,
  5925. freeze ? ALL_FROZE : 0ull);
  5926. return;
  5927. }
  5928. usleep_range(80, 120);
  5929. }
  5930. }
  5931. /*
  5932. * Do all freeze handling for the RXE block.
  5933. */
  5934. static void rxe_freeze(struct hfi1_devdata *dd)
  5935. {
  5936. int i;
  5937. struct hfi1_ctxtdata *rcd;
  5938. /* disable port */
  5939. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5940. /* disable all receive contexts */
  5941. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5942. rcd = hfi1_rcd_get_by_index(dd, i);
  5943. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
  5944. hfi1_rcd_put(rcd);
  5945. }
  5946. }
  5947. /*
  5948. * Unfreeze handling for the RXE block - kernel contexts only.
  5949. * This will also enable the port. User contexts will do unfreeze
  5950. * handling on a per-context basis as they call into the driver.
  5951. *
  5952. */
  5953. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5954. {
  5955. u32 rcvmask;
  5956. u16 i;
  5957. struct hfi1_ctxtdata *rcd;
  5958. /* enable all kernel contexts */
  5959. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5960. rcd = hfi1_rcd_get_by_index(dd, i);
  5961. /* Ensure all non-user contexts(including vnic) are enabled */
  5962. if (!rcd ||
  5963. (i >= dd->first_dyn_alloc_ctxt && !rcd->is_vnic)) {
  5964. hfi1_rcd_put(rcd);
  5965. continue;
  5966. }
  5967. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5968. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5969. rcvmask |= HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
  5970. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5971. hfi1_rcvctrl(dd, rcvmask, rcd);
  5972. hfi1_rcd_put(rcd);
  5973. }
  5974. /* enable port */
  5975. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5976. }
  5977. /*
  5978. * Non-interrupt SPC freeze handling.
  5979. *
  5980. * This is a work-queue function outside of the triggering interrupt.
  5981. */
  5982. void handle_freeze(struct work_struct *work)
  5983. {
  5984. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5985. freeze_work);
  5986. struct hfi1_devdata *dd = ppd->dd;
  5987. /* wait for freeze indicators on all affected blocks */
  5988. wait_for_freeze_status(dd, 1);
  5989. /* SPC is now frozen */
  5990. /* do send PIO freeze steps */
  5991. pio_freeze(dd);
  5992. /* do send DMA freeze steps */
  5993. sdma_freeze(dd);
  5994. /* do send egress freeze steps - nothing to do */
  5995. /* do receive freeze steps */
  5996. rxe_freeze(dd);
  5997. /*
  5998. * Unfreeze the hardware - clear the freeze, wait for each
  5999. * block's frozen bit to clear, then clear the frozen flag.
  6000. */
  6001. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  6002. wait_for_freeze_status(dd, 0);
  6003. if (is_ax(dd)) {
  6004. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  6005. wait_for_freeze_status(dd, 1);
  6006. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  6007. wait_for_freeze_status(dd, 0);
  6008. }
  6009. /* do send PIO unfreeze steps for kernel contexts */
  6010. pio_kernel_unfreeze(dd);
  6011. /* do send DMA unfreeze steps */
  6012. sdma_unfreeze(dd);
  6013. /* do send egress unfreeze steps - nothing to do */
  6014. /* do receive unfreeze steps for kernel contexts */
  6015. rxe_kernel_unfreeze(dd);
  6016. /*
  6017. * The unfreeze procedure touches global device registers when
  6018. * it disables and re-enables RXE. Mark the device unfrozen
  6019. * after all that is done so other parts of the driver waiting
  6020. * for the device to unfreeze don't do things out of order.
  6021. *
  6022. * The above implies that the meaning of HFI1_FROZEN flag is
  6023. * "Device has gone into freeze mode and freeze mode handling
  6024. * is still in progress."
  6025. *
  6026. * The flag will be removed when freeze mode processing has
  6027. * completed.
  6028. */
  6029. dd->flags &= ~HFI1_FROZEN;
  6030. wake_up(&dd->event_queue);
  6031. /* no longer frozen */
  6032. }
  6033. /**
  6034. * update_xmit_counters - update PortXmitWait/PortVlXmitWait
  6035. * counters.
  6036. * @ppd: info of physical Hfi port
  6037. * @link_width: new link width after link up or downgrade
  6038. *
  6039. * Update the PortXmitWait and PortVlXmitWait counters after
  6040. * a link up or downgrade event to reflect a link width change.
  6041. */
  6042. static void update_xmit_counters(struct hfi1_pportdata *ppd, u16 link_width)
  6043. {
  6044. int i;
  6045. u16 tx_width;
  6046. u16 link_speed;
  6047. tx_width = tx_link_width(link_width);
  6048. link_speed = get_link_speed(ppd->link_speed_active);
  6049. /*
  6050. * There are C_VL_COUNT number of PortVLXmitWait counters.
  6051. * Adding 1 to C_VL_COUNT to include the PortXmitWait counter.
  6052. */
  6053. for (i = 0; i < C_VL_COUNT + 1; i++)
  6054. get_xmit_wait_counters(ppd, tx_width, link_speed, i);
  6055. }
  6056. /*
  6057. * Handle a link up interrupt from the 8051.
  6058. *
  6059. * This is a work-queue function outside of the interrupt.
  6060. */
  6061. void handle_link_up(struct work_struct *work)
  6062. {
  6063. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6064. link_up_work);
  6065. struct hfi1_devdata *dd = ppd->dd;
  6066. set_link_state(ppd, HLS_UP_INIT);
  6067. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  6068. read_ltp_rtt(dd);
  6069. /*
  6070. * OPA specifies that certain counters are cleared on a transition
  6071. * to link up, so do that.
  6072. */
  6073. clear_linkup_counters(dd);
  6074. /*
  6075. * And (re)set link up default values.
  6076. */
  6077. set_linkup_defaults(ppd);
  6078. /*
  6079. * Set VL15 credits. Use cached value from verify cap interrupt.
  6080. * In case of quick linkup or simulator, vl15 value will be set by
  6081. * handle_linkup_change. VerifyCap interrupt handler will not be
  6082. * called in those scenarios.
  6083. */
  6084. if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
  6085. set_up_vl15(dd, dd->vl15buf_cached);
  6086. /* enforce link speed enabled */
  6087. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  6088. /* oops - current speed is not enabled, bounce */
  6089. dd_dev_err(dd,
  6090. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  6091. ppd->link_speed_active, ppd->link_speed_enabled);
  6092. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  6093. OPA_LINKDOWN_REASON_SPEED_POLICY);
  6094. set_link_state(ppd, HLS_DN_OFFLINE);
  6095. start_link(ppd);
  6096. }
  6097. }
  6098. /*
  6099. * Several pieces of LNI information were cached for SMA in ppd.
  6100. * Reset these on link down
  6101. */
  6102. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  6103. {
  6104. ppd->neighbor_guid = 0;
  6105. ppd->neighbor_port_number = 0;
  6106. ppd->neighbor_type = 0;
  6107. ppd->neighbor_fm_security = 0;
  6108. }
  6109. static const char * const link_down_reason_strs[] = {
  6110. [OPA_LINKDOWN_REASON_NONE] = "None",
  6111. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
  6112. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  6113. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  6114. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  6115. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  6116. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  6117. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  6118. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  6119. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  6120. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  6121. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  6122. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  6123. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  6124. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  6125. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  6126. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  6127. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  6128. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  6129. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  6130. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  6131. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  6132. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  6133. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  6134. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  6135. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  6136. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  6137. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  6138. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  6139. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  6140. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  6141. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  6142. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  6143. "Excessive buffer overrun",
  6144. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  6145. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  6146. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  6147. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  6148. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  6149. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  6150. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6151. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6152. "Local media not installed",
  6153. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6154. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6155. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6156. "End to end not installed",
  6157. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6158. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6159. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6160. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6161. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6162. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6163. };
  6164. /* return the neighbor link down reason string */
  6165. static const char *link_down_reason_str(u8 reason)
  6166. {
  6167. const char *str = NULL;
  6168. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6169. str = link_down_reason_strs[reason];
  6170. if (!str)
  6171. str = "(invalid)";
  6172. return str;
  6173. }
  6174. /*
  6175. * Handle a link down interrupt from the 8051.
  6176. *
  6177. * This is a work-queue function outside of the interrupt.
  6178. */
  6179. void handle_link_down(struct work_struct *work)
  6180. {
  6181. u8 lcl_reason, neigh_reason = 0;
  6182. u8 link_down_reason;
  6183. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6184. link_down_work);
  6185. int was_up;
  6186. static const char ldr_str[] = "Link down reason: ";
  6187. if ((ppd->host_link_state &
  6188. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6189. ppd->port_type == PORT_TYPE_FIXED)
  6190. ppd->offline_disabled_reason =
  6191. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6192. /* Go offline first, then deal with reading/writing through 8051 */
  6193. was_up = !!(ppd->host_link_state & HLS_UP);
  6194. set_link_state(ppd, HLS_DN_OFFLINE);
  6195. xchg(&ppd->is_link_down_queued, 0);
  6196. if (was_up) {
  6197. lcl_reason = 0;
  6198. /* link down reason is only valid if the link was up */
  6199. read_link_down_reason(ppd->dd, &link_down_reason);
  6200. switch (link_down_reason) {
  6201. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6202. /* the link went down, no idle message reason */
  6203. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6204. ldr_str);
  6205. break;
  6206. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6207. /*
  6208. * The neighbor reason is only valid if an idle message
  6209. * was received for it.
  6210. */
  6211. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6212. dd_dev_info(ppd->dd,
  6213. "%sNeighbor link down message %d, %s\n",
  6214. ldr_str, neigh_reason,
  6215. link_down_reason_str(neigh_reason));
  6216. break;
  6217. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6218. dd_dev_info(ppd->dd,
  6219. "%sHost requested link to go offline\n",
  6220. ldr_str);
  6221. break;
  6222. default:
  6223. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6224. ldr_str, link_down_reason);
  6225. break;
  6226. }
  6227. /*
  6228. * If no reason, assume peer-initiated but missed
  6229. * LinkGoingDown idle flits.
  6230. */
  6231. if (neigh_reason == 0)
  6232. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6233. } else {
  6234. /* went down while polling or going up */
  6235. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6236. }
  6237. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6238. /* inform the SMA when the link transitions from up to down */
  6239. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6240. ppd->neigh_link_down_reason.sma == 0) {
  6241. ppd->local_link_down_reason.sma =
  6242. ppd->local_link_down_reason.latest;
  6243. ppd->neigh_link_down_reason.sma =
  6244. ppd->neigh_link_down_reason.latest;
  6245. }
  6246. reset_neighbor_info(ppd);
  6247. /* disable the port */
  6248. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6249. /*
  6250. * If there is no cable attached, turn the DC off. Otherwise,
  6251. * start the link bring up.
  6252. */
  6253. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6254. dc_shutdown(ppd->dd);
  6255. else
  6256. start_link(ppd);
  6257. }
  6258. void handle_link_bounce(struct work_struct *work)
  6259. {
  6260. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6261. link_bounce_work);
  6262. /*
  6263. * Only do something if the link is currently up.
  6264. */
  6265. if (ppd->host_link_state & HLS_UP) {
  6266. set_link_state(ppd, HLS_DN_OFFLINE);
  6267. start_link(ppd);
  6268. } else {
  6269. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6270. __func__, link_state_name(ppd->host_link_state));
  6271. }
  6272. }
  6273. /*
  6274. * Mask conversion: Capability exchange to Port LTP. The capability
  6275. * exchange has an implicit 16b CRC that is mandatory.
  6276. */
  6277. static int cap_to_port_ltp(int cap)
  6278. {
  6279. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6280. if (cap & CAP_CRC_14B)
  6281. port_ltp |= PORT_LTP_CRC_MODE_14;
  6282. if (cap & CAP_CRC_48B)
  6283. port_ltp |= PORT_LTP_CRC_MODE_48;
  6284. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6285. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6286. return port_ltp;
  6287. }
  6288. /*
  6289. * Convert an OPA Port LTP mask to capability mask
  6290. */
  6291. int port_ltp_to_cap(int port_ltp)
  6292. {
  6293. int cap_mask = 0;
  6294. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6295. cap_mask |= CAP_CRC_14B;
  6296. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6297. cap_mask |= CAP_CRC_48B;
  6298. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6299. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6300. return cap_mask;
  6301. }
  6302. /*
  6303. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6304. */
  6305. static int lcb_to_port_ltp(int lcb_crc)
  6306. {
  6307. int port_ltp = 0;
  6308. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6309. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6310. else if (lcb_crc == LCB_CRC_48B)
  6311. port_ltp = PORT_LTP_CRC_MODE_48;
  6312. else if (lcb_crc == LCB_CRC_14B)
  6313. port_ltp = PORT_LTP_CRC_MODE_14;
  6314. else
  6315. port_ltp = PORT_LTP_CRC_MODE_16;
  6316. return port_ltp;
  6317. }
  6318. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6319. {
  6320. if (ppd->pkeys[2] != 0) {
  6321. ppd->pkeys[2] = 0;
  6322. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6323. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6324. }
  6325. }
  6326. /*
  6327. * Convert the given link width to the OPA link width bitmask.
  6328. */
  6329. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6330. {
  6331. switch (width) {
  6332. case 0:
  6333. /*
  6334. * Simulator and quick linkup do not set the width.
  6335. * Just set it to 4x without complaint.
  6336. */
  6337. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6338. return OPA_LINK_WIDTH_4X;
  6339. return 0; /* no lanes up */
  6340. case 1: return OPA_LINK_WIDTH_1X;
  6341. case 2: return OPA_LINK_WIDTH_2X;
  6342. case 3: return OPA_LINK_WIDTH_3X;
  6343. default:
  6344. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6345. __func__, width);
  6346. /* fall through */
  6347. case 4: return OPA_LINK_WIDTH_4X;
  6348. }
  6349. }
  6350. /*
  6351. * Do a population count on the bottom nibble.
  6352. */
  6353. static const u8 bit_counts[16] = {
  6354. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6355. };
  6356. static inline u8 nibble_to_count(u8 nibble)
  6357. {
  6358. return bit_counts[nibble & 0xf];
  6359. }
  6360. /*
  6361. * Read the active lane information from the 8051 registers and return
  6362. * their widths.
  6363. *
  6364. * Active lane information is found in these 8051 registers:
  6365. * enable_lane_tx
  6366. * enable_lane_rx
  6367. */
  6368. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6369. u16 *rx_width)
  6370. {
  6371. u16 tx, rx;
  6372. u8 enable_lane_rx;
  6373. u8 enable_lane_tx;
  6374. u8 tx_polarity_inversion;
  6375. u8 rx_polarity_inversion;
  6376. u8 max_rate;
  6377. /* read the active lanes */
  6378. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6379. &rx_polarity_inversion, &max_rate);
  6380. read_local_lni(dd, &enable_lane_rx);
  6381. /* convert to counts */
  6382. tx = nibble_to_count(enable_lane_tx);
  6383. rx = nibble_to_count(enable_lane_rx);
  6384. /*
  6385. * Set link_speed_active here, overriding what was set in
  6386. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6387. * set the max_rate field in handle_verify_cap until v0.19.
  6388. */
  6389. if ((dd->icode == ICODE_RTL_SILICON) &&
  6390. (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
  6391. /* max_rate: 0 = 12.5G, 1 = 25G */
  6392. switch (max_rate) {
  6393. case 0:
  6394. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6395. break;
  6396. default:
  6397. dd_dev_err(dd,
  6398. "%s: unexpected max rate %d, using 25Gb\n",
  6399. __func__, (int)max_rate);
  6400. /* fall through */
  6401. case 1:
  6402. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6403. break;
  6404. }
  6405. }
  6406. dd_dev_info(dd,
  6407. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6408. enable_lane_tx, tx, enable_lane_rx, rx);
  6409. *tx_width = link_width_to_bits(dd, tx);
  6410. *rx_width = link_width_to_bits(dd, rx);
  6411. }
  6412. /*
  6413. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6414. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6415. * after link up. I.e. look elsewhere for downgrade information.
  6416. *
  6417. * Bits are:
  6418. * + bits [7:4] contain the number of active transmitters
  6419. * + bits [3:0] contain the number of active receivers
  6420. * These are numbers 1 through 4 and can be different values if the
  6421. * link is asymmetric.
  6422. *
  6423. * verify_cap_local_fm_link_width[0] retains its original value.
  6424. */
  6425. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6426. u16 *rx_width)
  6427. {
  6428. u16 widths, tx, rx;
  6429. u8 misc_bits, local_flags;
  6430. u16 active_tx, active_rx;
  6431. read_vc_local_link_mode(dd, &misc_bits, &local_flags, &widths);
  6432. tx = widths >> 12;
  6433. rx = (widths >> 8) & 0xf;
  6434. *tx_width = link_width_to_bits(dd, tx);
  6435. *rx_width = link_width_to_bits(dd, rx);
  6436. /* print the active widths */
  6437. get_link_widths(dd, &active_tx, &active_rx);
  6438. }
  6439. /*
  6440. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6441. * hardware information when the link first comes up.
  6442. *
  6443. * The link width is not available until after VerifyCap.AllFramesReceived
  6444. * (the trigger for handle_verify_cap), so this is outside that routine
  6445. * and should be called when the 8051 signals linkup.
  6446. */
  6447. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6448. {
  6449. u16 tx_width, rx_width;
  6450. /* get end-of-LNI link widths */
  6451. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6452. /* use tx_width as the link is supposed to be symmetric on link up */
  6453. ppd->link_width_active = tx_width;
  6454. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6455. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6456. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6457. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6458. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6459. /* cache the active egress rate (units {10^6 bits/sec]) */
  6460. ppd->current_egress_rate = active_egress_rate(ppd);
  6461. }
  6462. /*
  6463. * Handle a verify capabilities interrupt from the 8051.
  6464. *
  6465. * This is a work-queue function outside of the interrupt.
  6466. */
  6467. void handle_verify_cap(struct work_struct *work)
  6468. {
  6469. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6470. link_vc_work);
  6471. struct hfi1_devdata *dd = ppd->dd;
  6472. u64 reg;
  6473. u8 power_management;
  6474. u8 continuous;
  6475. u8 vcu;
  6476. u8 vau;
  6477. u8 z;
  6478. u16 vl15buf;
  6479. u16 link_widths;
  6480. u16 crc_mask;
  6481. u16 crc_val;
  6482. u16 device_id;
  6483. u16 active_tx, active_rx;
  6484. u8 partner_supported_crc;
  6485. u8 remote_tx_rate;
  6486. u8 device_rev;
  6487. set_link_state(ppd, HLS_VERIFY_CAP);
  6488. lcb_shutdown(dd, 0);
  6489. adjust_lcb_for_fpga_serdes(dd);
  6490. read_vc_remote_phy(dd, &power_management, &continuous);
  6491. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6492. &partner_supported_crc);
  6493. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6494. read_remote_device_id(dd, &device_id, &device_rev);
  6495. /* print the active widths */
  6496. get_link_widths(dd, &active_tx, &active_rx);
  6497. dd_dev_info(dd,
  6498. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6499. (int)power_management, (int)continuous);
  6500. dd_dev_info(dd,
  6501. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6502. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6503. (int)partner_supported_crc);
  6504. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6505. (u32)remote_tx_rate, (u32)link_widths);
  6506. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6507. (u32)device_id, (u32)device_rev);
  6508. /*
  6509. * The peer vAU value just read is the peer receiver value. HFI does
  6510. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6511. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6512. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6513. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6514. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6515. * subject to the Z value exception.
  6516. */
  6517. if (vau == 0)
  6518. vau = 1;
  6519. set_up_vau(dd, vau);
  6520. /*
  6521. * Set VL15 credits to 0 in global credit register. Cache remote VL15
  6522. * credits value and wait for link-up interrupt ot set it.
  6523. */
  6524. set_up_vl15(dd, 0);
  6525. dd->vl15buf_cached = vl15buf;
  6526. /* set up the LCB CRC mode */
  6527. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6528. /* order is important: use the lowest bit in common */
  6529. if (crc_mask & CAP_CRC_14B)
  6530. crc_val = LCB_CRC_14B;
  6531. else if (crc_mask & CAP_CRC_48B)
  6532. crc_val = LCB_CRC_48B;
  6533. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6534. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6535. else
  6536. crc_val = LCB_CRC_16B;
  6537. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6538. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6539. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6540. /* set (14b only) or clear sideband credit */
  6541. reg = read_csr(dd, SEND_CM_CTRL);
  6542. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6543. write_csr(dd, SEND_CM_CTRL,
  6544. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6545. } else {
  6546. write_csr(dd, SEND_CM_CTRL,
  6547. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6548. }
  6549. ppd->link_speed_active = 0; /* invalid value */
  6550. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  6551. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6552. switch (remote_tx_rate) {
  6553. case 0:
  6554. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6555. break;
  6556. case 1:
  6557. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6558. break;
  6559. }
  6560. } else {
  6561. /* actual rate is highest bit of the ANDed rates */
  6562. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6563. if (rate & 2)
  6564. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6565. else if (rate & 1)
  6566. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6567. }
  6568. if (ppd->link_speed_active == 0) {
  6569. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6570. __func__, (int)remote_tx_rate);
  6571. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6572. }
  6573. /*
  6574. * Cache the values of the supported, enabled, and active
  6575. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6576. * flags that are returned in the portinfo query differ from
  6577. * what's in the link_crc_mask, crc_sizes, and crc_val
  6578. * variables. Convert these here.
  6579. */
  6580. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6581. /* supported crc modes */
  6582. ppd->port_ltp_crc_mode |=
  6583. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6584. /* enabled crc modes */
  6585. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6586. /* active crc mode */
  6587. /* set up the remote credit return table */
  6588. assign_remote_cm_au_table(dd, vcu);
  6589. /*
  6590. * The LCB is reset on entry to handle_verify_cap(), so this must
  6591. * be applied on every link up.
  6592. *
  6593. * Adjust LCB error kill enable to kill the link if
  6594. * these RBUF errors are seen:
  6595. * REPLAY_BUF_MBE_SMASK
  6596. * FLIT_INPUT_BUF_MBE_SMASK
  6597. */
  6598. if (is_ax(dd)) { /* fixed in B0 */
  6599. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6600. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6601. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6602. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6603. }
  6604. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6605. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6606. /* give 8051 access to the LCB CSRs */
  6607. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6608. set_8051_lcb_access(dd);
  6609. /* tell the 8051 to go to LinkUp */
  6610. set_link_state(ppd, HLS_GOING_UP);
  6611. }
  6612. /**
  6613. * apply_link_downgrade_policy - Apply the link width downgrade enabled
  6614. * policy against the current active link widths.
  6615. * @ppd: info of physical Hfi port
  6616. * @refresh_widths: True indicates link downgrade event
  6617. * @return: True indicates a successful link downgrade. False indicates
  6618. * link downgrade event failed and the link will bounce back to
  6619. * default link width.
  6620. *
  6621. * Called when the enabled policy changes or the active link widths
  6622. * change.
  6623. * Refresh_widths indicates that a link downgrade occurred. The
  6624. * link_downgraded variable is set by refresh_widths and
  6625. * determines the success/failure of the policy application.
  6626. */
  6627. bool apply_link_downgrade_policy(struct hfi1_pportdata *ppd,
  6628. bool refresh_widths)
  6629. {
  6630. int do_bounce = 0;
  6631. int tries;
  6632. u16 lwde;
  6633. u16 tx, rx;
  6634. bool link_downgraded = refresh_widths;
  6635. /* use the hls lock to avoid a race with actual link up */
  6636. tries = 0;
  6637. retry:
  6638. mutex_lock(&ppd->hls_lock);
  6639. /* only apply if the link is up */
  6640. if (ppd->host_link_state & HLS_DOWN) {
  6641. /* still going up..wait and retry */
  6642. if (ppd->host_link_state & HLS_GOING_UP) {
  6643. if (++tries < 1000) {
  6644. mutex_unlock(&ppd->hls_lock);
  6645. usleep_range(100, 120); /* arbitrary */
  6646. goto retry;
  6647. }
  6648. dd_dev_err(ppd->dd,
  6649. "%s: giving up waiting for link state change\n",
  6650. __func__);
  6651. }
  6652. goto done;
  6653. }
  6654. lwde = ppd->link_width_downgrade_enabled;
  6655. if (refresh_widths) {
  6656. get_link_widths(ppd->dd, &tx, &rx);
  6657. ppd->link_width_downgrade_tx_active = tx;
  6658. ppd->link_width_downgrade_rx_active = rx;
  6659. }
  6660. if (ppd->link_width_downgrade_tx_active == 0 ||
  6661. ppd->link_width_downgrade_rx_active == 0) {
  6662. /* the 8051 reported a dead link as a downgrade */
  6663. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6664. link_downgraded = false;
  6665. } else if (lwde == 0) {
  6666. /* downgrade is disabled */
  6667. /* bounce if not at starting active width */
  6668. if ((ppd->link_width_active !=
  6669. ppd->link_width_downgrade_tx_active) ||
  6670. (ppd->link_width_active !=
  6671. ppd->link_width_downgrade_rx_active)) {
  6672. dd_dev_err(ppd->dd,
  6673. "Link downgrade is disabled and link has downgraded, downing link\n");
  6674. dd_dev_err(ppd->dd,
  6675. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6676. ppd->link_width_active,
  6677. ppd->link_width_downgrade_tx_active,
  6678. ppd->link_width_downgrade_rx_active);
  6679. do_bounce = 1;
  6680. link_downgraded = false;
  6681. }
  6682. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6683. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6684. /* Tx or Rx is outside the enabled policy */
  6685. dd_dev_err(ppd->dd,
  6686. "Link is outside of downgrade allowed, downing link\n");
  6687. dd_dev_err(ppd->dd,
  6688. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6689. lwde, ppd->link_width_downgrade_tx_active,
  6690. ppd->link_width_downgrade_rx_active);
  6691. do_bounce = 1;
  6692. link_downgraded = false;
  6693. }
  6694. done:
  6695. mutex_unlock(&ppd->hls_lock);
  6696. if (do_bounce) {
  6697. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6698. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6699. set_link_state(ppd, HLS_DN_OFFLINE);
  6700. start_link(ppd);
  6701. }
  6702. return link_downgraded;
  6703. }
  6704. /*
  6705. * Handle a link downgrade interrupt from the 8051.
  6706. *
  6707. * This is a work-queue function outside of the interrupt.
  6708. */
  6709. void handle_link_downgrade(struct work_struct *work)
  6710. {
  6711. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6712. link_downgrade_work);
  6713. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6714. if (apply_link_downgrade_policy(ppd, true))
  6715. update_xmit_counters(ppd, ppd->link_width_downgrade_tx_active);
  6716. }
  6717. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6718. {
  6719. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6720. ARRAY_SIZE(dcc_err_flags));
  6721. }
  6722. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6723. {
  6724. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6725. ARRAY_SIZE(lcb_err_flags));
  6726. }
  6727. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6728. {
  6729. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6730. ARRAY_SIZE(dc8051_err_flags));
  6731. }
  6732. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6733. {
  6734. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6735. ARRAY_SIZE(dc8051_info_err_flags));
  6736. }
  6737. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6738. {
  6739. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6740. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6741. }
  6742. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6743. {
  6744. struct hfi1_pportdata *ppd = dd->pport;
  6745. u64 info, err, host_msg;
  6746. int queue_link_down = 0;
  6747. char buf[96];
  6748. /* look at the flags */
  6749. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6750. /* 8051 information set by firmware */
  6751. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6752. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6753. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6754. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6755. host_msg = (info >>
  6756. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6757. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6758. /*
  6759. * Handle error flags.
  6760. */
  6761. if (err & FAILED_LNI) {
  6762. /*
  6763. * LNI error indications are cleared by the 8051
  6764. * only when starting polling. Only pay attention
  6765. * to them when in the states that occur during
  6766. * LNI.
  6767. */
  6768. if (ppd->host_link_state
  6769. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6770. queue_link_down = 1;
  6771. dd_dev_info(dd, "Link error: %s\n",
  6772. dc8051_info_err_string(buf,
  6773. sizeof(buf),
  6774. err &
  6775. FAILED_LNI));
  6776. }
  6777. err &= ~(u64)FAILED_LNI;
  6778. }
  6779. /* unknown frames can happen durning LNI, just count */
  6780. if (err & UNKNOWN_FRAME) {
  6781. ppd->unknown_frame_count++;
  6782. err &= ~(u64)UNKNOWN_FRAME;
  6783. }
  6784. if (err) {
  6785. /* report remaining errors, but do not do anything */
  6786. dd_dev_err(dd, "8051 info error: %s\n",
  6787. dc8051_info_err_string(buf, sizeof(buf),
  6788. err));
  6789. }
  6790. /*
  6791. * Handle host message flags.
  6792. */
  6793. if (host_msg & HOST_REQ_DONE) {
  6794. /*
  6795. * Presently, the driver does a busy wait for
  6796. * host requests to complete. This is only an
  6797. * informational message.
  6798. * NOTE: The 8051 clears the host message
  6799. * information *on the next 8051 command*.
  6800. * Therefore, when linkup is achieved,
  6801. * this flag will still be set.
  6802. */
  6803. host_msg &= ~(u64)HOST_REQ_DONE;
  6804. }
  6805. if (host_msg & BC_SMA_MSG) {
  6806. queue_work(ppd->link_wq, &ppd->sma_message_work);
  6807. host_msg &= ~(u64)BC_SMA_MSG;
  6808. }
  6809. if (host_msg & LINKUP_ACHIEVED) {
  6810. dd_dev_info(dd, "8051: Link up\n");
  6811. queue_work(ppd->link_wq, &ppd->link_up_work);
  6812. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6813. }
  6814. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6815. handle_8051_request(ppd);
  6816. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6817. }
  6818. if (host_msg & VERIFY_CAP_FRAME) {
  6819. queue_work(ppd->link_wq, &ppd->link_vc_work);
  6820. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6821. }
  6822. if (host_msg & LINK_GOING_DOWN) {
  6823. const char *extra = "";
  6824. /* no downgrade action needed if going down */
  6825. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6826. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6827. extra = " (ignoring downgrade)";
  6828. }
  6829. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6830. queue_link_down = 1;
  6831. host_msg &= ~(u64)LINK_GOING_DOWN;
  6832. }
  6833. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6834. queue_work(ppd->link_wq, &ppd->link_downgrade_work);
  6835. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6836. }
  6837. if (host_msg) {
  6838. /* report remaining messages, but do not do anything */
  6839. dd_dev_info(dd, "8051 info host message: %s\n",
  6840. dc8051_info_host_msg_string(buf,
  6841. sizeof(buf),
  6842. host_msg));
  6843. }
  6844. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6845. }
  6846. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6847. /*
  6848. * Lost the 8051 heartbeat. If this happens, we
  6849. * receive constant interrupts about it. Disable
  6850. * the interrupt after the first.
  6851. */
  6852. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6853. write_csr(dd, DC_DC8051_ERR_EN,
  6854. read_csr(dd, DC_DC8051_ERR_EN) &
  6855. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6856. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6857. }
  6858. if (reg) {
  6859. /* report the error, but do not do anything */
  6860. dd_dev_err(dd, "8051 error: %s\n",
  6861. dc8051_err_string(buf, sizeof(buf), reg));
  6862. }
  6863. if (queue_link_down) {
  6864. /*
  6865. * if the link is already going down or disabled, do not
  6866. * queue another. If there's a link down entry already
  6867. * queued, don't queue another one.
  6868. */
  6869. if ((ppd->host_link_state &
  6870. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6871. ppd->link_enabled == 0) {
  6872. dd_dev_info(dd, "%s: not queuing link down. host_link_state %x, link_enabled %x\n",
  6873. __func__, ppd->host_link_state,
  6874. ppd->link_enabled);
  6875. } else {
  6876. if (xchg(&ppd->is_link_down_queued, 1) == 1)
  6877. dd_dev_info(dd,
  6878. "%s: link down request already queued\n",
  6879. __func__);
  6880. else
  6881. queue_work(ppd->link_wq, &ppd->link_down_work);
  6882. }
  6883. }
  6884. }
  6885. static const char * const fm_config_txt[] = {
  6886. [0] =
  6887. "BadHeadDist: Distance violation between two head flits",
  6888. [1] =
  6889. "BadTailDist: Distance violation between two tail flits",
  6890. [2] =
  6891. "BadCtrlDist: Distance violation between two credit control flits",
  6892. [3] =
  6893. "BadCrdAck: Credits return for unsupported VL",
  6894. [4] =
  6895. "UnsupportedVLMarker: Received VL Marker",
  6896. [5] =
  6897. "BadPreempt: Exceeded the preemption nesting level",
  6898. [6] =
  6899. "BadControlFlit: Received unsupported control flit",
  6900. /* no 7 */
  6901. [8] =
  6902. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6903. };
  6904. static const char * const port_rcv_txt[] = {
  6905. [1] =
  6906. "BadPktLen: Illegal PktLen",
  6907. [2] =
  6908. "PktLenTooLong: Packet longer than PktLen",
  6909. [3] =
  6910. "PktLenTooShort: Packet shorter than PktLen",
  6911. [4] =
  6912. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6913. [5] =
  6914. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6915. [6] =
  6916. "BadL2: Illegal L2 opcode",
  6917. [7] =
  6918. "BadSC: Unsupported SC",
  6919. [9] =
  6920. "BadRC: Illegal RC",
  6921. [11] =
  6922. "PreemptError: Preempting with same VL",
  6923. [12] =
  6924. "PreemptVL15: Preempting a VL15 packet",
  6925. };
  6926. #define OPA_LDR_FMCONFIG_OFFSET 16
  6927. #define OPA_LDR_PORTRCV_OFFSET 0
  6928. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6929. {
  6930. u64 info, hdr0, hdr1;
  6931. const char *extra;
  6932. char buf[96];
  6933. struct hfi1_pportdata *ppd = dd->pport;
  6934. u8 lcl_reason = 0;
  6935. int do_bounce = 0;
  6936. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6937. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6938. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6939. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6940. /* set status bit */
  6941. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6942. }
  6943. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6944. }
  6945. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6946. struct hfi1_pportdata *ppd = dd->pport;
  6947. /* this counter saturates at (2^32) - 1 */
  6948. if (ppd->link_downed < (u32)UINT_MAX)
  6949. ppd->link_downed++;
  6950. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6951. }
  6952. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6953. u8 reason_valid = 1;
  6954. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6955. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6956. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6957. /* set status bit */
  6958. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6959. }
  6960. switch (info) {
  6961. case 0:
  6962. case 1:
  6963. case 2:
  6964. case 3:
  6965. case 4:
  6966. case 5:
  6967. case 6:
  6968. extra = fm_config_txt[info];
  6969. break;
  6970. case 8:
  6971. extra = fm_config_txt[info];
  6972. if (ppd->port_error_action &
  6973. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6974. do_bounce = 1;
  6975. /*
  6976. * lcl_reason cannot be derived from info
  6977. * for this error
  6978. */
  6979. lcl_reason =
  6980. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6981. }
  6982. break;
  6983. default:
  6984. reason_valid = 0;
  6985. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6986. extra = buf;
  6987. break;
  6988. }
  6989. if (reason_valid && !do_bounce) {
  6990. do_bounce = ppd->port_error_action &
  6991. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6992. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  6993. }
  6994. /* just report this */
  6995. dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
  6996. extra);
  6997. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  6998. }
  6999. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  7000. u8 reason_valid = 1;
  7001. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  7002. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  7003. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  7004. if (!(dd->err_info_rcvport.status_and_code &
  7005. OPA_EI_STATUS_SMASK)) {
  7006. dd->err_info_rcvport.status_and_code =
  7007. info & OPA_EI_CODE_SMASK;
  7008. /* set status bit */
  7009. dd->err_info_rcvport.status_and_code |=
  7010. OPA_EI_STATUS_SMASK;
  7011. /*
  7012. * save first 2 flits in the packet that caused
  7013. * the error
  7014. */
  7015. dd->err_info_rcvport.packet_flit1 = hdr0;
  7016. dd->err_info_rcvport.packet_flit2 = hdr1;
  7017. }
  7018. switch (info) {
  7019. case 1:
  7020. case 2:
  7021. case 3:
  7022. case 4:
  7023. case 5:
  7024. case 6:
  7025. case 7:
  7026. case 9:
  7027. case 11:
  7028. case 12:
  7029. extra = port_rcv_txt[info];
  7030. break;
  7031. default:
  7032. reason_valid = 0;
  7033. snprintf(buf, sizeof(buf), "reserved%lld", info);
  7034. extra = buf;
  7035. break;
  7036. }
  7037. if (reason_valid && !do_bounce) {
  7038. do_bounce = ppd->port_error_action &
  7039. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  7040. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  7041. }
  7042. /* just report this */
  7043. dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
  7044. " hdr0 0x%llx, hdr1 0x%llx\n",
  7045. extra, hdr0, hdr1);
  7046. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  7047. }
  7048. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  7049. /* informative only */
  7050. dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
  7051. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  7052. }
  7053. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  7054. /* informative only */
  7055. dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
  7056. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  7057. }
  7058. if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
  7059. reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
  7060. /* report any remaining errors */
  7061. if (reg)
  7062. dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
  7063. dcc_err_string(buf, sizeof(buf), reg));
  7064. if (lcl_reason == 0)
  7065. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  7066. if (do_bounce) {
  7067. dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
  7068. __func__);
  7069. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  7070. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  7071. }
  7072. }
  7073. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  7074. {
  7075. char buf[96];
  7076. dd_dev_info(dd, "LCB Error: %s\n",
  7077. lcb_err_string(buf, sizeof(buf), reg));
  7078. }
  7079. /*
  7080. * CCE block DC interrupt. Source is < 8.
  7081. */
  7082. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  7083. {
  7084. const struct err_reg_info *eri = &dc_errs[source];
  7085. if (eri->handler) {
  7086. interrupt_clear_down(dd, 0, eri);
  7087. } else if (source == 3 /* dc_lbm_int */) {
  7088. /*
  7089. * This indicates that a parity error has occurred on the
  7090. * address/control lines presented to the LBM. The error
  7091. * is a single pulse, there is no associated error flag,
  7092. * and it is non-maskable. This is because if a parity
  7093. * error occurs on the request the request is dropped.
  7094. * This should never occur, but it is nice to know if it
  7095. * ever does.
  7096. */
  7097. dd_dev_err(dd, "Parity error in DC LBM block\n");
  7098. } else {
  7099. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  7100. }
  7101. }
  7102. /*
  7103. * TX block send credit interrupt. Source is < 160.
  7104. */
  7105. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  7106. {
  7107. sc_group_release_update(dd, source);
  7108. }
  7109. /*
  7110. * TX block SDMA interrupt. Source is < 48.
  7111. *
  7112. * SDMA interrupts are grouped by type:
  7113. *
  7114. * 0 - N-1 = SDma
  7115. * N - 2N-1 = SDmaProgress
  7116. * 2N - 3N-1 = SDmaIdle
  7117. */
  7118. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  7119. {
  7120. /* what interrupt */
  7121. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  7122. /* which engine */
  7123. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  7124. #ifdef CONFIG_SDMA_VERBOSITY
  7125. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  7126. slashstrip(__FILE__), __LINE__, __func__);
  7127. sdma_dumpstate(&dd->per_sdma[which]);
  7128. #endif
  7129. if (likely(what < 3 && which < dd->num_sdma)) {
  7130. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  7131. } else {
  7132. /* should not happen */
  7133. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  7134. }
  7135. }
  7136. /*
  7137. * RX block receive available interrupt. Source is < 160.
  7138. */
  7139. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7140. {
  7141. struct hfi1_ctxtdata *rcd;
  7142. char *err_detail;
  7143. if (likely(source < dd->num_rcv_contexts)) {
  7144. rcd = hfi1_rcd_get_by_index(dd, source);
  7145. if (rcd) {
  7146. /* Check for non-user contexts, including vnic */
  7147. if (source < dd->first_dyn_alloc_ctxt || rcd->is_vnic)
  7148. rcd->do_interrupt(rcd, 0);
  7149. else
  7150. handle_user_interrupt(rcd);
  7151. hfi1_rcd_put(rcd);
  7152. return; /* OK */
  7153. }
  7154. /* received an interrupt, but no rcd */
  7155. err_detail = "dataless";
  7156. } else {
  7157. /* received an interrupt, but are not using that context */
  7158. err_detail = "out of range";
  7159. }
  7160. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7161. err_detail, source);
  7162. }
  7163. /*
  7164. * RX block receive urgent interrupt. Source is < 160.
  7165. */
  7166. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7167. {
  7168. struct hfi1_ctxtdata *rcd;
  7169. char *err_detail;
  7170. if (likely(source < dd->num_rcv_contexts)) {
  7171. rcd = hfi1_rcd_get_by_index(dd, source);
  7172. if (rcd) {
  7173. /* only pay attention to user urgent interrupts */
  7174. if (source >= dd->first_dyn_alloc_ctxt &&
  7175. !rcd->is_vnic)
  7176. handle_user_interrupt(rcd);
  7177. hfi1_rcd_put(rcd);
  7178. return; /* OK */
  7179. }
  7180. /* received an interrupt, but no rcd */
  7181. err_detail = "dataless";
  7182. } else {
  7183. /* received an interrupt, but are not using that context */
  7184. err_detail = "out of range";
  7185. }
  7186. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7187. err_detail, source);
  7188. }
  7189. /*
  7190. * Reserved range interrupt. Should not be called in normal operation.
  7191. */
  7192. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7193. {
  7194. char name[64];
  7195. dd_dev_err(dd, "unexpected %s interrupt\n",
  7196. is_reserved_name(name, sizeof(name), source));
  7197. }
  7198. static const struct is_table is_table[] = {
  7199. /*
  7200. * start end
  7201. * name func interrupt func
  7202. */
  7203. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7204. is_misc_err_name, is_misc_err_int },
  7205. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7206. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7207. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7208. is_sendctxt_err_name, is_sendctxt_err_int },
  7209. { IS_SDMA_START, IS_SDMA_END,
  7210. is_sdma_eng_name, is_sdma_eng_int },
  7211. { IS_VARIOUS_START, IS_VARIOUS_END,
  7212. is_various_name, is_various_int },
  7213. { IS_DC_START, IS_DC_END,
  7214. is_dc_name, is_dc_int },
  7215. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7216. is_rcv_avail_name, is_rcv_avail_int },
  7217. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7218. is_rcv_urgent_name, is_rcv_urgent_int },
  7219. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7220. is_send_credit_name, is_send_credit_int},
  7221. { IS_RESERVED_START, IS_RESERVED_END,
  7222. is_reserved_name, is_reserved_int},
  7223. };
  7224. /*
  7225. * Interrupt source interrupt - called when the given source has an interrupt.
  7226. * Source is a bit index into an array of 64-bit integers.
  7227. */
  7228. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7229. {
  7230. const struct is_table *entry;
  7231. /* avoids a double compare by walking the table in-order */
  7232. for (entry = &is_table[0]; entry->is_name; entry++) {
  7233. if (source < entry->end) {
  7234. trace_hfi1_interrupt(dd, entry, source);
  7235. entry->is_int(dd, source - entry->start);
  7236. return;
  7237. }
  7238. }
  7239. /* fell off the end */
  7240. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7241. }
  7242. /*
  7243. * General interrupt handler. This is able to correctly handle
  7244. * all interrupts in case INTx is used.
  7245. */
  7246. static irqreturn_t general_interrupt(int irq, void *data)
  7247. {
  7248. struct hfi1_devdata *dd = data;
  7249. u64 regs[CCE_NUM_INT_CSRS];
  7250. u32 bit;
  7251. int i;
  7252. irqreturn_t handled = IRQ_NONE;
  7253. this_cpu_inc(*dd->int_counter);
  7254. /* phase 1: scan and clear all handled interrupts */
  7255. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7256. if (dd->gi_mask[i] == 0) {
  7257. regs[i] = 0; /* used later */
  7258. continue;
  7259. }
  7260. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7261. dd->gi_mask[i];
  7262. /* only clear if anything is set */
  7263. if (regs[i])
  7264. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7265. }
  7266. /* phase 2: call the appropriate handler */
  7267. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7268. CCE_NUM_INT_CSRS * 64) {
  7269. is_interrupt(dd, bit);
  7270. handled = IRQ_HANDLED;
  7271. }
  7272. return handled;
  7273. }
  7274. static irqreturn_t sdma_interrupt(int irq, void *data)
  7275. {
  7276. struct sdma_engine *sde = data;
  7277. struct hfi1_devdata *dd = sde->dd;
  7278. u64 status;
  7279. #ifdef CONFIG_SDMA_VERBOSITY
  7280. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7281. slashstrip(__FILE__), __LINE__, __func__);
  7282. sdma_dumpstate(sde);
  7283. #endif
  7284. this_cpu_inc(*dd->int_counter);
  7285. /* This read_csr is really bad in the hot path */
  7286. status = read_csr(dd,
  7287. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7288. & sde->imask;
  7289. if (likely(status)) {
  7290. /* clear the interrupt(s) */
  7291. write_csr(dd,
  7292. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7293. status);
  7294. /* handle the interrupt(s) */
  7295. sdma_engine_interrupt(sde, status);
  7296. } else {
  7297. dd_dev_info_ratelimited(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7298. sde->this_idx);
  7299. }
  7300. return IRQ_HANDLED;
  7301. }
  7302. /*
  7303. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7304. * to insure that the write completed. This does NOT guarantee that
  7305. * queued DMA writes to memory from the chip are pushed.
  7306. */
  7307. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7308. {
  7309. struct hfi1_devdata *dd = rcd->dd;
  7310. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7311. mmiowb(); /* make sure everything before is written */
  7312. write_csr(dd, addr, rcd->imask);
  7313. /* force the above write on the chip and get a value back */
  7314. (void)read_csr(dd, addr);
  7315. }
  7316. /* force the receive interrupt */
  7317. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7318. {
  7319. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7320. }
  7321. /*
  7322. * Return non-zero if a packet is present.
  7323. *
  7324. * This routine is called when rechecking for packets after the RcvAvail
  7325. * interrupt has been cleared down. First, do a quick check of memory for
  7326. * a packet present. If not found, use an expensive CSR read of the context
  7327. * tail to determine the actual tail. The CSR read is necessary because there
  7328. * is no method to push pending DMAs to memory other than an interrupt and we
  7329. * are trying to determine if we need to force an interrupt.
  7330. */
  7331. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7332. {
  7333. u32 tail;
  7334. int present;
  7335. if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
  7336. present = (rcd->seq_cnt ==
  7337. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7338. else /* is RDMA rtail */
  7339. present = (rcd->head != get_rcvhdrtail(rcd));
  7340. if (present)
  7341. return 1;
  7342. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7343. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7344. return rcd->head != tail;
  7345. }
  7346. /*
  7347. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7348. * This routine will try to handle packets immediately (latency), but if
  7349. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7350. * chip receive interrupt is *not* cleared down until this or the thread (if
  7351. * invoked) is finished. The intent is to avoid extra interrupts while we
  7352. * are processing packets anyway.
  7353. */
  7354. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7355. {
  7356. struct hfi1_ctxtdata *rcd = data;
  7357. struct hfi1_devdata *dd = rcd->dd;
  7358. int disposition;
  7359. int present;
  7360. trace_hfi1_receive_interrupt(dd, rcd);
  7361. this_cpu_inc(*dd->int_counter);
  7362. aspm_ctx_disable(rcd);
  7363. /* receive interrupt remains blocked while processing packets */
  7364. disposition = rcd->do_interrupt(rcd, 0);
  7365. /*
  7366. * Too many packets were seen while processing packets in this
  7367. * IRQ handler. Invoke the handler thread. The receive interrupt
  7368. * remains blocked.
  7369. */
  7370. if (disposition == RCV_PKT_LIMIT)
  7371. return IRQ_WAKE_THREAD;
  7372. /*
  7373. * The packet processor detected no more packets. Clear the receive
  7374. * interrupt and recheck for a packet packet that may have arrived
  7375. * after the previous check and interrupt clear. If a packet arrived,
  7376. * force another interrupt.
  7377. */
  7378. clear_recv_intr(rcd);
  7379. present = check_packet_present(rcd);
  7380. if (present)
  7381. force_recv_intr(rcd);
  7382. return IRQ_HANDLED;
  7383. }
  7384. /*
  7385. * Receive packet thread handler. This expects to be invoked with the
  7386. * receive interrupt still blocked.
  7387. */
  7388. static irqreturn_t receive_context_thread(int irq, void *data)
  7389. {
  7390. struct hfi1_ctxtdata *rcd = data;
  7391. int present;
  7392. /* receive interrupt is still blocked from the IRQ handler */
  7393. (void)rcd->do_interrupt(rcd, 1);
  7394. /*
  7395. * The packet processor will only return if it detected no more
  7396. * packets. Hold IRQs here so we can safely clear the interrupt and
  7397. * recheck for a packet that may have arrived after the previous
  7398. * check and the interrupt clear. If a packet arrived, force another
  7399. * interrupt.
  7400. */
  7401. local_irq_disable();
  7402. clear_recv_intr(rcd);
  7403. present = check_packet_present(rcd);
  7404. if (present)
  7405. force_recv_intr(rcd);
  7406. local_irq_enable();
  7407. return IRQ_HANDLED;
  7408. }
  7409. /* ========================================================================= */
  7410. u32 read_physical_state(struct hfi1_devdata *dd)
  7411. {
  7412. u64 reg;
  7413. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7414. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7415. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7416. }
  7417. u32 read_logical_state(struct hfi1_devdata *dd)
  7418. {
  7419. u64 reg;
  7420. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7421. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7422. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7423. }
  7424. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7425. {
  7426. u64 reg;
  7427. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7428. /* clear current state, set new state */
  7429. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7430. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7431. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7432. }
  7433. /*
  7434. * Use the 8051 to read a LCB CSR.
  7435. */
  7436. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7437. {
  7438. u32 regno;
  7439. int ret;
  7440. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7441. if (acquire_lcb_access(dd, 0) == 0) {
  7442. *data = read_csr(dd, addr);
  7443. release_lcb_access(dd, 0);
  7444. return 0;
  7445. }
  7446. return -EBUSY;
  7447. }
  7448. /* register is an index of LCB registers: (offset - base) / 8 */
  7449. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7450. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7451. if (ret != HCMD_SUCCESS)
  7452. return -EBUSY;
  7453. return 0;
  7454. }
  7455. /*
  7456. * Provide a cache for some of the LCB registers in case the LCB is
  7457. * unavailable.
  7458. * (The LCB is unavailable in certain link states, for example.)
  7459. */
  7460. struct lcb_datum {
  7461. u32 off;
  7462. u64 val;
  7463. };
  7464. static struct lcb_datum lcb_cache[] = {
  7465. { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
  7466. { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
  7467. { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
  7468. };
  7469. static void update_lcb_cache(struct hfi1_devdata *dd)
  7470. {
  7471. int i;
  7472. int ret;
  7473. u64 val;
  7474. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7475. ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
  7476. /* Update if we get good data */
  7477. if (likely(ret != -EBUSY))
  7478. lcb_cache[i].val = val;
  7479. }
  7480. }
  7481. static int read_lcb_cache(u32 off, u64 *val)
  7482. {
  7483. int i;
  7484. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7485. if (lcb_cache[i].off == off) {
  7486. *val = lcb_cache[i].val;
  7487. return 0;
  7488. }
  7489. }
  7490. pr_warn("%s bad offset 0x%x\n", __func__, off);
  7491. return -1;
  7492. }
  7493. /*
  7494. * Read an LCB CSR. Access may not be in host control, so check.
  7495. * Return 0 on success, -EBUSY on failure.
  7496. */
  7497. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7498. {
  7499. struct hfi1_pportdata *ppd = dd->pport;
  7500. /* if up, go through the 8051 for the value */
  7501. if (ppd->host_link_state & HLS_UP)
  7502. return read_lcb_via_8051(dd, addr, data);
  7503. /* if going up or down, check the cache, otherwise, no access */
  7504. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
  7505. if (read_lcb_cache(addr, data))
  7506. return -EBUSY;
  7507. return 0;
  7508. }
  7509. /* otherwise, host has access */
  7510. *data = read_csr(dd, addr);
  7511. return 0;
  7512. }
  7513. /*
  7514. * Use the 8051 to write a LCB CSR.
  7515. */
  7516. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7517. {
  7518. u32 regno;
  7519. int ret;
  7520. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7521. (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
  7522. if (acquire_lcb_access(dd, 0) == 0) {
  7523. write_csr(dd, addr, data);
  7524. release_lcb_access(dd, 0);
  7525. return 0;
  7526. }
  7527. return -EBUSY;
  7528. }
  7529. /* register is an index of LCB registers: (offset - base) / 8 */
  7530. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7531. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7532. if (ret != HCMD_SUCCESS)
  7533. return -EBUSY;
  7534. return 0;
  7535. }
  7536. /*
  7537. * Write an LCB CSR. Access may not be in host control, so check.
  7538. * Return 0 on success, -EBUSY on failure.
  7539. */
  7540. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7541. {
  7542. struct hfi1_pportdata *ppd = dd->pport;
  7543. /* if up, go through the 8051 for the value */
  7544. if (ppd->host_link_state & HLS_UP)
  7545. return write_lcb_via_8051(dd, addr, data);
  7546. /* if going up or down, no access */
  7547. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7548. return -EBUSY;
  7549. /* otherwise, host has access */
  7550. write_csr(dd, addr, data);
  7551. return 0;
  7552. }
  7553. /*
  7554. * Returns:
  7555. * < 0 = Linux error, not able to get access
  7556. * > 0 = 8051 command RETURN_CODE
  7557. */
  7558. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  7559. u64 *out_data)
  7560. {
  7561. u64 reg, completed;
  7562. int return_code;
  7563. unsigned long timeout;
  7564. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7565. mutex_lock(&dd->dc8051_lock);
  7566. /* We can't send any commands to the 8051 if it's in reset */
  7567. if (dd->dc_shutdown) {
  7568. return_code = -ENODEV;
  7569. goto fail;
  7570. }
  7571. /*
  7572. * If an 8051 host command timed out previously, then the 8051 is
  7573. * stuck.
  7574. *
  7575. * On first timeout, attempt to reset and restart the entire DC
  7576. * block (including 8051). (Is this too big of a hammer?)
  7577. *
  7578. * If the 8051 times out a second time, the reset did not bring it
  7579. * back to healthy life. In that case, fail any subsequent commands.
  7580. */
  7581. if (dd->dc8051_timed_out) {
  7582. if (dd->dc8051_timed_out > 1) {
  7583. dd_dev_err(dd,
  7584. "Previous 8051 host command timed out, skipping command %u\n",
  7585. type);
  7586. return_code = -ENXIO;
  7587. goto fail;
  7588. }
  7589. _dc_shutdown(dd);
  7590. _dc_start(dd);
  7591. }
  7592. /*
  7593. * If there is no timeout, then the 8051 command interface is
  7594. * waiting for a command.
  7595. */
  7596. /*
  7597. * When writing a LCB CSR, out_data contains the full value to
  7598. * to be written, while in_data contains the relative LCB
  7599. * address in 7:0. Do the work here, rather than the caller,
  7600. * of distrubting the write data to where it needs to go:
  7601. *
  7602. * Write data
  7603. * 39:00 -> in_data[47:8]
  7604. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7605. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7606. */
  7607. if (type == HCMD_WRITE_LCB_CSR) {
  7608. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7609. /* must preserve COMPLETED - it is tied to hardware */
  7610. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
  7611. reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
  7612. reg |= ((((*out_data) >> 40) & 0xff) <<
  7613. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7614. | ((((*out_data) >> 48) & 0xffff) <<
  7615. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7616. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7617. }
  7618. /*
  7619. * Do two writes: the first to stabilize the type and req_data, the
  7620. * second to activate.
  7621. */
  7622. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7623. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7624. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7625. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7626. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7627. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7628. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7629. /* wait for completion, alternate: interrupt */
  7630. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7631. while (1) {
  7632. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7633. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7634. if (completed)
  7635. break;
  7636. if (time_after(jiffies, timeout)) {
  7637. dd->dc8051_timed_out++;
  7638. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7639. if (out_data)
  7640. *out_data = 0;
  7641. return_code = -ETIMEDOUT;
  7642. goto fail;
  7643. }
  7644. udelay(2);
  7645. }
  7646. if (out_data) {
  7647. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7648. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7649. if (type == HCMD_READ_LCB_CSR) {
  7650. /* top 16 bits are in a different register */
  7651. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7652. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7653. << (48
  7654. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7655. }
  7656. }
  7657. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7658. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7659. dd->dc8051_timed_out = 0;
  7660. /*
  7661. * Clear command for next user.
  7662. */
  7663. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7664. fail:
  7665. mutex_unlock(&dd->dc8051_lock);
  7666. return return_code;
  7667. }
  7668. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7669. {
  7670. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7671. }
  7672. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7673. u8 lane_id, u32 config_data)
  7674. {
  7675. u64 data;
  7676. int ret;
  7677. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7678. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7679. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7680. ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7681. if (ret != HCMD_SUCCESS) {
  7682. dd_dev_err(dd,
  7683. "load 8051 config: field id %d, lane %d, err %d\n",
  7684. (int)field_id, (int)lane_id, ret);
  7685. }
  7686. return ret;
  7687. }
  7688. /*
  7689. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7690. * set the result, even on error.
  7691. * Return 0 on success, -errno on failure
  7692. */
  7693. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7694. u32 *result)
  7695. {
  7696. u64 big_data;
  7697. u32 addr;
  7698. int ret;
  7699. /* address start depends on the lane_id */
  7700. if (lane_id < 4)
  7701. addr = (4 * NUM_GENERAL_FIELDS)
  7702. + (lane_id * 4 * NUM_LANE_FIELDS);
  7703. else
  7704. addr = 0;
  7705. addr += field_id * 4;
  7706. /* read is in 8-byte chunks, hardware will truncate the address down */
  7707. ret = read_8051_data(dd, addr, 8, &big_data);
  7708. if (ret == 0) {
  7709. /* extract the 4 bytes we want */
  7710. if (addr & 0x4)
  7711. *result = (u32)(big_data >> 32);
  7712. else
  7713. *result = (u32)big_data;
  7714. } else {
  7715. *result = 0;
  7716. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7717. __func__, lane_id, field_id);
  7718. }
  7719. return ret;
  7720. }
  7721. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7722. u8 continuous)
  7723. {
  7724. u32 frame;
  7725. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7726. | power_management << POWER_MANAGEMENT_SHIFT;
  7727. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7728. GENERAL_CONFIG, frame);
  7729. }
  7730. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7731. u16 vl15buf, u8 crc_sizes)
  7732. {
  7733. u32 frame;
  7734. frame = (u32)vau << VAU_SHIFT
  7735. | (u32)z << Z_SHIFT
  7736. | (u32)vcu << VCU_SHIFT
  7737. | (u32)vl15buf << VL15BUF_SHIFT
  7738. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7739. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7740. GENERAL_CONFIG, frame);
  7741. }
  7742. static void read_vc_local_link_mode(struct hfi1_devdata *dd, u8 *misc_bits,
  7743. u8 *flag_bits, u16 *link_widths)
  7744. {
  7745. u32 frame;
  7746. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_MODE, GENERAL_CONFIG,
  7747. &frame);
  7748. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7749. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7750. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7751. }
  7752. static int write_vc_local_link_mode(struct hfi1_devdata *dd,
  7753. u8 misc_bits,
  7754. u8 flag_bits,
  7755. u16 link_widths)
  7756. {
  7757. u32 frame;
  7758. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7759. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7760. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7761. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_MODE, GENERAL_CONFIG,
  7762. frame);
  7763. }
  7764. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7765. u8 device_rev)
  7766. {
  7767. u32 frame;
  7768. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7769. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7770. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7771. }
  7772. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7773. u8 *device_rev)
  7774. {
  7775. u32 frame;
  7776. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7777. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7778. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7779. & REMOTE_DEVICE_REV_MASK;
  7780. }
  7781. int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
  7782. {
  7783. u32 frame;
  7784. u32 mask;
  7785. mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
  7786. read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
  7787. /* Clear, then set field */
  7788. frame &= ~mask;
  7789. frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
  7790. return load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
  7791. frame);
  7792. }
  7793. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
  7794. u8 *ver_patch)
  7795. {
  7796. u32 frame;
  7797. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7798. *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
  7799. STS_FM_VERSION_MAJOR_MASK;
  7800. *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
  7801. STS_FM_VERSION_MINOR_MASK;
  7802. read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
  7803. *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
  7804. STS_FM_VERSION_PATCH_MASK;
  7805. }
  7806. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7807. u8 *continuous)
  7808. {
  7809. u32 frame;
  7810. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7811. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7812. & POWER_MANAGEMENT_MASK;
  7813. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7814. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7815. }
  7816. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7817. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7818. {
  7819. u32 frame;
  7820. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7821. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7822. *z = (frame >> Z_SHIFT) & Z_MASK;
  7823. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7824. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7825. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7826. }
  7827. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7828. u8 *remote_tx_rate,
  7829. u16 *link_widths)
  7830. {
  7831. u32 frame;
  7832. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7833. &frame);
  7834. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7835. & REMOTE_TX_RATE_MASK;
  7836. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7837. }
  7838. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7839. {
  7840. u32 frame;
  7841. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7842. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7843. }
  7844. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7845. {
  7846. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7847. }
  7848. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7849. {
  7850. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7851. }
  7852. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7853. {
  7854. u32 frame;
  7855. int ret;
  7856. *link_quality = 0;
  7857. if (dd->pport->host_link_state & HLS_UP) {
  7858. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7859. &frame);
  7860. if (ret == 0)
  7861. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7862. & LINK_QUALITY_MASK;
  7863. }
  7864. }
  7865. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7866. {
  7867. u32 frame;
  7868. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7869. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7870. }
  7871. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7872. {
  7873. u32 frame;
  7874. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7875. *ldr = (frame & 0xff);
  7876. }
  7877. static int read_tx_settings(struct hfi1_devdata *dd,
  7878. u8 *enable_lane_tx,
  7879. u8 *tx_polarity_inversion,
  7880. u8 *rx_polarity_inversion,
  7881. u8 *max_rate)
  7882. {
  7883. u32 frame;
  7884. int ret;
  7885. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7886. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7887. & ENABLE_LANE_TX_MASK;
  7888. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7889. & TX_POLARITY_INVERSION_MASK;
  7890. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7891. & RX_POLARITY_INVERSION_MASK;
  7892. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7893. return ret;
  7894. }
  7895. static int write_tx_settings(struct hfi1_devdata *dd,
  7896. u8 enable_lane_tx,
  7897. u8 tx_polarity_inversion,
  7898. u8 rx_polarity_inversion,
  7899. u8 max_rate)
  7900. {
  7901. u32 frame;
  7902. /* no need to mask, all variable sizes match field widths */
  7903. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7904. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7905. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7906. | max_rate << MAX_RATE_SHIFT;
  7907. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7908. }
  7909. /*
  7910. * Read an idle LCB message.
  7911. *
  7912. * Returns 0 on success, -EINVAL on error
  7913. */
  7914. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7915. {
  7916. int ret;
  7917. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7918. if (ret != HCMD_SUCCESS) {
  7919. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7920. (u32)type, ret);
  7921. return -EINVAL;
  7922. }
  7923. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7924. /* return only the payload as we already know the type */
  7925. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7926. return 0;
  7927. }
  7928. /*
  7929. * Read an idle SMA message. To be done in response to a notification from
  7930. * the 8051.
  7931. *
  7932. * Returns 0 on success, -EINVAL on error
  7933. */
  7934. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7935. {
  7936. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7937. data);
  7938. }
  7939. /*
  7940. * Send an idle LCB message.
  7941. *
  7942. * Returns 0 on success, -EINVAL on error
  7943. */
  7944. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7945. {
  7946. int ret;
  7947. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7948. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7949. if (ret != HCMD_SUCCESS) {
  7950. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7951. data, ret);
  7952. return -EINVAL;
  7953. }
  7954. return 0;
  7955. }
  7956. /*
  7957. * Send an idle SMA message.
  7958. *
  7959. * Returns 0 on success, -EINVAL on error
  7960. */
  7961. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7962. {
  7963. u64 data;
  7964. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7965. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7966. return send_idle_message(dd, data);
  7967. }
  7968. /*
  7969. * Initialize the LCB then do a quick link up. This may or may not be
  7970. * in loopback.
  7971. *
  7972. * return 0 on success, -errno on error
  7973. */
  7974. static int do_quick_linkup(struct hfi1_devdata *dd)
  7975. {
  7976. int ret;
  7977. lcb_shutdown(dd, 0);
  7978. if (loopback) {
  7979. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7980. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7981. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  7982. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  7983. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  7984. }
  7985. /* start the LCBs */
  7986. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  7987. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  7988. /* simulator only loopback steps */
  7989. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7990. /* LCB_CFG_RUN.EN = 1 */
  7991. write_csr(dd, DC_LCB_CFG_RUN,
  7992. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  7993. ret = wait_link_transfer_active(dd, 10);
  7994. if (ret)
  7995. return ret;
  7996. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  7997. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  7998. }
  7999. if (!loopback) {
  8000. /*
  8001. * When doing quick linkup and not in loopback, both
  8002. * sides must be done with LCB set-up before either
  8003. * starts the quick linkup. Put a delay here so that
  8004. * both sides can be started and have a chance to be
  8005. * done with LCB set up before resuming.
  8006. */
  8007. dd_dev_err(dd,
  8008. "Pausing for peer to be finished with LCB set up\n");
  8009. msleep(5000);
  8010. dd_dev_err(dd, "Continuing with quick linkup\n");
  8011. }
  8012. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  8013. set_8051_lcb_access(dd);
  8014. /*
  8015. * State "quick" LinkUp request sets the physical link state to
  8016. * LinkUp without a verify capability sequence.
  8017. * This state is in simulator v37 and later.
  8018. */
  8019. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  8020. if (ret != HCMD_SUCCESS) {
  8021. dd_dev_err(dd,
  8022. "%s: set physical link state to quick LinkUp failed with return %d\n",
  8023. __func__, ret);
  8024. set_host_lcb_access(dd);
  8025. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8026. if (ret >= 0)
  8027. ret = -EINVAL;
  8028. return ret;
  8029. }
  8030. return 0; /* success */
  8031. }
  8032. /*
  8033. * Do all special steps to set up loopback.
  8034. */
  8035. static int init_loopback(struct hfi1_devdata *dd)
  8036. {
  8037. dd_dev_info(dd, "Entering loopback mode\n");
  8038. /* all loopbacks should disable self GUID check */
  8039. write_csr(dd, DC_DC8051_CFG_MODE,
  8040. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  8041. /*
  8042. * The simulator has only one loopback option - LCB. Switch
  8043. * to that option, which includes quick link up.
  8044. *
  8045. * Accept all valid loopback values.
  8046. */
  8047. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  8048. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  8049. loopback == LOOPBACK_CABLE)) {
  8050. loopback = LOOPBACK_LCB;
  8051. quick_linkup = 1;
  8052. return 0;
  8053. }
  8054. /*
  8055. * SerDes loopback init sequence is handled in set_local_link_attributes
  8056. */
  8057. if (loopback == LOOPBACK_SERDES)
  8058. return 0;
  8059. /* LCB loopback - handled at poll time */
  8060. if (loopback == LOOPBACK_LCB) {
  8061. quick_linkup = 1; /* LCB is always quick linkup */
  8062. /* not supported in emulation due to emulation RTL changes */
  8063. if (dd->icode == ICODE_FPGA_EMULATION) {
  8064. dd_dev_err(dd,
  8065. "LCB loopback not supported in emulation\n");
  8066. return -EINVAL;
  8067. }
  8068. return 0;
  8069. }
  8070. /* external cable loopback requires no extra steps */
  8071. if (loopback == LOOPBACK_CABLE)
  8072. return 0;
  8073. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  8074. return -EINVAL;
  8075. }
  8076. /*
  8077. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  8078. * used in the Verify Capability link width attribute.
  8079. */
  8080. static u16 opa_to_vc_link_widths(u16 opa_widths)
  8081. {
  8082. int i;
  8083. u16 result = 0;
  8084. static const struct link_bits {
  8085. u16 from;
  8086. u16 to;
  8087. } opa_link_xlate[] = {
  8088. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  8089. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  8090. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  8091. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  8092. };
  8093. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  8094. if (opa_widths & opa_link_xlate[i].from)
  8095. result |= opa_link_xlate[i].to;
  8096. }
  8097. return result;
  8098. }
  8099. /*
  8100. * Set link attributes before moving to polling.
  8101. */
  8102. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  8103. {
  8104. struct hfi1_devdata *dd = ppd->dd;
  8105. u8 enable_lane_tx;
  8106. u8 tx_polarity_inversion;
  8107. u8 rx_polarity_inversion;
  8108. int ret;
  8109. u32 misc_bits = 0;
  8110. /* reset our fabric serdes to clear any lingering problems */
  8111. fabric_serdes_reset(dd);
  8112. /* set the local tx rate - need to read-modify-write */
  8113. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  8114. &rx_polarity_inversion, &ppd->local_tx_rate);
  8115. if (ret)
  8116. goto set_local_link_attributes_fail;
  8117. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  8118. /* set the tx rate to the fastest enabled */
  8119. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8120. ppd->local_tx_rate = 1;
  8121. else
  8122. ppd->local_tx_rate = 0;
  8123. } else {
  8124. /* set the tx rate to all enabled */
  8125. ppd->local_tx_rate = 0;
  8126. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8127. ppd->local_tx_rate |= 2;
  8128. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  8129. ppd->local_tx_rate |= 1;
  8130. }
  8131. enable_lane_tx = 0xF; /* enable all four lanes */
  8132. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  8133. rx_polarity_inversion, ppd->local_tx_rate);
  8134. if (ret != HCMD_SUCCESS)
  8135. goto set_local_link_attributes_fail;
  8136. ret = write_host_interface_version(dd, HOST_INTERFACE_VERSION);
  8137. if (ret != HCMD_SUCCESS) {
  8138. dd_dev_err(dd,
  8139. "Failed to set host interface version, return 0x%x\n",
  8140. ret);
  8141. goto set_local_link_attributes_fail;
  8142. }
  8143. /*
  8144. * DC supports continuous updates.
  8145. */
  8146. ret = write_vc_local_phy(dd,
  8147. 0 /* no power management */,
  8148. 1 /* continuous updates */);
  8149. if (ret != HCMD_SUCCESS)
  8150. goto set_local_link_attributes_fail;
  8151. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  8152. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  8153. ppd->port_crc_mode_enabled);
  8154. if (ret != HCMD_SUCCESS)
  8155. goto set_local_link_attributes_fail;
  8156. /*
  8157. * SerDes loopback init sequence requires
  8158. * setting bit 0 of MISC_CONFIG_BITS
  8159. */
  8160. if (loopback == LOOPBACK_SERDES)
  8161. misc_bits |= 1 << LOOPBACK_SERDES_CONFIG_BIT_MASK_SHIFT;
  8162. /*
  8163. * An external device configuration request is used to reset the LCB
  8164. * to retry to obtain operational lanes when the first attempt is
  8165. * unsuccesful.
  8166. */
  8167. if (dd->dc8051_ver >= dc8051_ver(1, 25, 0))
  8168. misc_bits |= 1 << EXT_CFG_LCB_RESET_SUPPORTED_SHIFT;
  8169. ret = write_vc_local_link_mode(dd, misc_bits, 0,
  8170. opa_to_vc_link_widths(
  8171. ppd->link_width_enabled));
  8172. if (ret != HCMD_SUCCESS)
  8173. goto set_local_link_attributes_fail;
  8174. /* let peer know who we are */
  8175. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  8176. if (ret == HCMD_SUCCESS)
  8177. return 0;
  8178. set_local_link_attributes_fail:
  8179. dd_dev_err(dd,
  8180. "Failed to set local link attributes, return 0x%x\n",
  8181. ret);
  8182. return ret;
  8183. }
  8184. /*
  8185. * Call this to start the link.
  8186. * Do not do anything if the link is disabled.
  8187. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8188. */
  8189. int start_link(struct hfi1_pportdata *ppd)
  8190. {
  8191. /*
  8192. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8193. * error rate. Needs to be done before starting the link.
  8194. */
  8195. tune_serdes(ppd);
  8196. if (!ppd->driver_link_ready) {
  8197. dd_dev_info(ppd->dd,
  8198. "%s: stopping link start because driver is not ready\n",
  8199. __func__);
  8200. return 0;
  8201. }
  8202. /*
  8203. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8204. * pkey table can be configured properly if the HFI unit is connected
  8205. * to switch port with MgmtAllowed=NO
  8206. */
  8207. clear_full_mgmt_pkey(ppd);
  8208. return set_link_state(ppd, HLS_DN_POLL);
  8209. }
  8210. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8211. {
  8212. struct hfi1_devdata *dd = ppd->dd;
  8213. u64 mask;
  8214. unsigned long timeout;
  8215. /*
  8216. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8217. * effect of power up on plug-in. We ignore this false positive
  8218. * interrupt until the module has finished powering up by waiting for
  8219. * a minimum timeout of the module inrush initialization time of
  8220. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8221. * module have stabilized.
  8222. */
  8223. msleep(500);
  8224. /*
  8225. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8226. */
  8227. timeout = jiffies + msecs_to_jiffies(2000);
  8228. while (1) {
  8229. mask = read_csr(dd, dd->hfi1_id ?
  8230. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8231. if (!(mask & QSFP_HFI0_INT_N))
  8232. break;
  8233. if (time_after(jiffies, timeout)) {
  8234. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8235. __func__);
  8236. break;
  8237. }
  8238. udelay(2);
  8239. }
  8240. }
  8241. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8242. {
  8243. struct hfi1_devdata *dd = ppd->dd;
  8244. u64 mask;
  8245. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8246. if (enable) {
  8247. /*
  8248. * Clear the status register to avoid an immediate interrupt
  8249. * when we re-enable the IntN pin
  8250. */
  8251. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8252. QSFP_HFI0_INT_N);
  8253. mask |= (u64)QSFP_HFI0_INT_N;
  8254. } else {
  8255. mask &= ~(u64)QSFP_HFI0_INT_N;
  8256. }
  8257. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8258. }
  8259. int reset_qsfp(struct hfi1_pportdata *ppd)
  8260. {
  8261. struct hfi1_devdata *dd = ppd->dd;
  8262. u64 mask, qsfp_mask;
  8263. /* Disable INT_N from triggering QSFP interrupts */
  8264. set_qsfp_int_n(ppd, 0);
  8265. /* Reset the QSFP */
  8266. mask = (u64)QSFP_HFI0_RESET_N;
  8267. qsfp_mask = read_csr(dd,
  8268. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8269. qsfp_mask &= ~mask;
  8270. write_csr(dd,
  8271. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8272. udelay(10);
  8273. qsfp_mask |= mask;
  8274. write_csr(dd,
  8275. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8276. wait_for_qsfp_init(ppd);
  8277. /*
  8278. * Allow INT_N to trigger the QSFP interrupt to watch
  8279. * for alarms and warnings
  8280. */
  8281. set_qsfp_int_n(ppd, 1);
  8282. /*
  8283. * After the reset, AOC transmitters are enabled by default. They need
  8284. * to be turned off to complete the QSFP setup before they can be
  8285. * enabled again.
  8286. */
  8287. return set_qsfp_tx(ppd, 0);
  8288. }
  8289. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8290. u8 *qsfp_interrupt_status)
  8291. {
  8292. struct hfi1_devdata *dd = ppd->dd;
  8293. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8294. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8295. dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
  8296. __func__);
  8297. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8298. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8299. dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
  8300. __func__);
  8301. /*
  8302. * The remaining alarms/warnings don't matter if the link is down.
  8303. */
  8304. if (ppd->host_link_state & HLS_DOWN)
  8305. return 0;
  8306. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8307. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8308. dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
  8309. __func__);
  8310. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8311. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8312. dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
  8313. __func__);
  8314. /* Byte 2 is vendor specific */
  8315. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8316. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8317. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
  8318. __func__);
  8319. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8320. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8321. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
  8322. __func__);
  8323. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8324. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8325. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
  8326. __func__);
  8327. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8328. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8329. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
  8330. __func__);
  8331. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8332. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8333. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8334. __func__);
  8335. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8336. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8337. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8338. __func__);
  8339. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8340. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8341. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8342. __func__);
  8343. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8344. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8345. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8346. __func__);
  8347. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8348. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8349. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
  8350. __func__);
  8351. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8352. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8353. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
  8354. __func__);
  8355. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8356. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8357. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
  8358. __func__);
  8359. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8360. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8361. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
  8362. __func__);
  8363. /* Bytes 9-10 and 11-12 are reserved */
  8364. /* Bytes 13-15 are vendor specific */
  8365. return 0;
  8366. }
  8367. /* This routine will only be scheduled if the QSFP module present is asserted */
  8368. void qsfp_event(struct work_struct *work)
  8369. {
  8370. struct qsfp_data *qd;
  8371. struct hfi1_pportdata *ppd;
  8372. struct hfi1_devdata *dd;
  8373. qd = container_of(work, struct qsfp_data, qsfp_work);
  8374. ppd = qd->ppd;
  8375. dd = ppd->dd;
  8376. /* Sanity check */
  8377. if (!qsfp_mod_present(ppd))
  8378. return;
  8379. if (ppd->host_link_state == HLS_DN_DISABLE) {
  8380. dd_dev_info(ppd->dd,
  8381. "%s: stopping link start because link is disabled\n",
  8382. __func__);
  8383. return;
  8384. }
  8385. /*
  8386. * Turn DC back on after cable has been re-inserted. Up until
  8387. * now, the DC has been in reset to save power.
  8388. */
  8389. dc_start(dd);
  8390. if (qd->cache_refresh_required) {
  8391. set_qsfp_int_n(ppd, 0);
  8392. wait_for_qsfp_init(ppd);
  8393. /*
  8394. * Allow INT_N to trigger the QSFP interrupt to watch
  8395. * for alarms and warnings
  8396. */
  8397. set_qsfp_int_n(ppd, 1);
  8398. start_link(ppd);
  8399. }
  8400. if (qd->check_interrupt_flags) {
  8401. u8 qsfp_interrupt_status[16] = {0,};
  8402. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8403. &qsfp_interrupt_status[0], 16) != 16) {
  8404. dd_dev_info(dd,
  8405. "%s: Failed to read status of QSFP module\n",
  8406. __func__);
  8407. } else {
  8408. unsigned long flags;
  8409. handle_qsfp_error_conditions(
  8410. ppd, qsfp_interrupt_status);
  8411. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8412. ppd->qsfp_info.check_interrupt_flags = 0;
  8413. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8414. flags);
  8415. }
  8416. }
  8417. }
  8418. static void init_qsfp_int(struct hfi1_devdata *dd)
  8419. {
  8420. struct hfi1_pportdata *ppd = dd->pport;
  8421. u64 qsfp_mask, cce_int_mask;
  8422. const int qsfp1_int_smask = QSFP1_INT % 64;
  8423. const int qsfp2_int_smask = QSFP2_INT % 64;
  8424. /*
  8425. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8426. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8427. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8428. * the index of the appropriate CSR in the CCEIntMask CSR array
  8429. */
  8430. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8431. (8 * (QSFP1_INT / 64)));
  8432. if (dd->hfi1_id) {
  8433. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8434. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8435. cce_int_mask);
  8436. } else {
  8437. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8438. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8439. cce_int_mask);
  8440. }
  8441. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8442. /* Clear current status to avoid spurious interrupts */
  8443. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8444. qsfp_mask);
  8445. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8446. qsfp_mask);
  8447. set_qsfp_int_n(ppd, 0);
  8448. /* Handle active low nature of INT_N and MODPRST_N pins */
  8449. if (qsfp_mod_present(ppd))
  8450. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8451. write_csr(dd,
  8452. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8453. qsfp_mask);
  8454. }
  8455. /*
  8456. * Do a one-time initialize of the LCB block.
  8457. */
  8458. static void init_lcb(struct hfi1_devdata *dd)
  8459. {
  8460. /* simulator does not correctly handle LCB cclk loopback, skip */
  8461. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8462. return;
  8463. /* the DC has been reset earlier in the driver load */
  8464. /* set LCB for cclk loopback on the port */
  8465. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8466. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8467. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8468. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8469. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8470. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8471. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8472. }
  8473. /*
  8474. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8475. * on error.
  8476. */
  8477. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8478. {
  8479. int ret;
  8480. u8 status;
  8481. /*
  8482. * Report success if not a QSFP or, if it is a QSFP, but the cable is
  8483. * not present
  8484. */
  8485. if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
  8486. return 0;
  8487. /* read byte 2, the status byte */
  8488. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8489. if (ret < 0)
  8490. return ret;
  8491. if (ret != 1)
  8492. return -EIO;
  8493. return 0; /* success */
  8494. }
  8495. /*
  8496. * Values for QSFP retry.
  8497. *
  8498. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8499. * arrived at from experience on a large cluster.
  8500. */
  8501. #define MAX_QSFP_RETRIES 20
  8502. #define QSFP_RETRY_WAIT 500 /* msec */
  8503. /*
  8504. * Try a QSFP read. If it fails, schedule a retry for later.
  8505. * Called on first link activation after driver load.
  8506. */
  8507. static void try_start_link(struct hfi1_pportdata *ppd)
  8508. {
  8509. if (test_qsfp_read(ppd)) {
  8510. /* read failed */
  8511. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8512. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8513. return;
  8514. }
  8515. dd_dev_info(ppd->dd,
  8516. "QSFP not responding, waiting and retrying %d\n",
  8517. (int)ppd->qsfp_retry_count);
  8518. ppd->qsfp_retry_count++;
  8519. queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
  8520. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8521. return;
  8522. }
  8523. ppd->qsfp_retry_count = 0;
  8524. start_link(ppd);
  8525. }
  8526. /*
  8527. * Workqueue function to start the link after a delay.
  8528. */
  8529. void handle_start_link(struct work_struct *work)
  8530. {
  8531. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8532. start_link_work.work);
  8533. try_start_link(ppd);
  8534. }
  8535. int bringup_serdes(struct hfi1_pportdata *ppd)
  8536. {
  8537. struct hfi1_devdata *dd = ppd->dd;
  8538. u64 guid;
  8539. int ret;
  8540. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8541. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8542. guid = ppd->guids[HFI1_PORT_GUID_INDEX];
  8543. if (!guid) {
  8544. if (dd->base_guid)
  8545. guid = dd->base_guid + ppd->port - 1;
  8546. ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
  8547. }
  8548. /* Set linkinit_reason on power up per OPA spec */
  8549. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8550. /* one-time init of the LCB */
  8551. init_lcb(dd);
  8552. if (loopback) {
  8553. ret = init_loopback(dd);
  8554. if (ret < 0)
  8555. return ret;
  8556. }
  8557. get_port_type(ppd);
  8558. if (ppd->port_type == PORT_TYPE_QSFP) {
  8559. set_qsfp_int_n(ppd, 0);
  8560. wait_for_qsfp_init(ppd);
  8561. set_qsfp_int_n(ppd, 1);
  8562. }
  8563. try_start_link(ppd);
  8564. return 0;
  8565. }
  8566. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8567. {
  8568. struct hfi1_devdata *dd = ppd->dd;
  8569. /*
  8570. * Shut down the link and keep it down. First turn off that the
  8571. * driver wants to allow the link to be up (driver_link_ready).
  8572. * Then make sure the link is not automatically restarted
  8573. * (link_enabled). Cancel any pending restart. And finally
  8574. * go offline.
  8575. */
  8576. ppd->driver_link_ready = 0;
  8577. ppd->link_enabled = 0;
  8578. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8579. flush_delayed_work(&ppd->start_link_work);
  8580. cancel_delayed_work_sync(&ppd->start_link_work);
  8581. ppd->offline_disabled_reason =
  8582. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_REBOOT);
  8583. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_REBOOT, 0,
  8584. OPA_LINKDOWN_REASON_REBOOT);
  8585. set_link_state(ppd, HLS_DN_OFFLINE);
  8586. /* disable the port */
  8587. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8588. }
  8589. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8590. {
  8591. struct hfi1_pportdata *ppd;
  8592. int i;
  8593. ppd = (struct hfi1_pportdata *)(dd + 1);
  8594. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8595. ppd->ibport_data.rvp.rc_acks = NULL;
  8596. ppd->ibport_data.rvp.rc_qacks = NULL;
  8597. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8598. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8599. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8600. if (!ppd->ibport_data.rvp.rc_acks ||
  8601. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8602. !ppd->ibport_data.rvp.rc_qacks)
  8603. return -ENOMEM;
  8604. }
  8605. return 0;
  8606. }
  8607. /*
  8608. * index is the index into the receive array
  8609. */
  8610. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8611. u32 type, unsigned long pa, u16 order)
  8612. {
  8613. u64 reg;
  8614. if (!(dd->flags & HFI1_PRESENT))
  8615. goto done;
  8616. if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
  8617. pa = 0;
  8618. order = 0;
  8619. } else if (type > PT_INVALID) {
  8620. dd_dev_err(dd,
  8621. "unexpected receive array type %u for index %u, not handled\n",
  8622. type, index);
  8623. goto done;
  8624. }
  8625. trace_hfi1_put_tid(dd, index, type, pa, order);
  8626. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8627. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8628. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8629. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8630. << RCV_ARRAY_RT_ADDR_SHIFT;
  8631. trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
  8632. writeq(reg, dd->rcvarray_wc + (index * 8));
  8633. if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
  8634. /*
  8635. * Eager entries are written and flushed
  8636. *
  8637. * Expected entries are flushed every 4 writes
  8638. */
  8639. flush_wc();
  8640. done:
  8641. return;
  8642. }
  8643. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8644. {
  8645. struct hfi1_devdata *dd = rcd->dd;
  8646. u32 i;
  8647. /* this could be optimized */
  8648. for (i = rcd->eager_base; i < rcd->eager_base +
  8649. rcd->egrbufs.alloced; i++)
  8650. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8651. for (i = rcd->expected_base;
  8652. i < rcd->expected_base + rcd->expected_count; i++)
  8653. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8654. }
  8655. static const char * const ib_cfg_name_strings[] = {
  8656. "HFI1_IB_CFG_LIDLMC",
  8657. "HFI1_IB_CFG_LWID_DG_ENB",
  8658. "HFI1_IB_CFG_LWID_ENB",
  8659. "HFI1_IB_CFG_LWID",
  8660. "HFI1_IB_CFG_SPD_ENB",
  8661. "HFI1_IB_CFG_SPD",
  8662. "HFI1_IB_CFG_RXPOL_ENB",
  8663. "HFI1_IB_CFG_LREV_ENB",
  8664. "HFI1_IB_CFG_LINKLATENCY",
  8665. "HFI1_IB_CFG_HRTBT",
  8666. "HFI1_IB_CFG_OP_VLS",
  8667. "HFI1_IB_CFG_VL_HIGH_CAP",
  8668. "HFI1_IB_CFG_VL_LOW_CAP",
  8669. "HFI1_IB_CFG_OVERRUN_THRESH",
  8670. "HFI1_IB_CFG_PHYERR_THRESH",
  8671. "HFI1_IB_CFG_LINKDEFAULT",
  8672. "HFI1_IB_CFG_PKEYS",
  8673. "HFI1_IB_CFG_MTU",
  8674. "HFI1_IB_CFG_LSTATE",
  8675. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8676. "HFI1_IB_CFG_PMA_TICKS",
  8677. "HFI1_IB_CFG_PORT"
  8678. };
  8679. static const char *ib_cfg_name(int which)
  8680. {
  8681. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8682. return "invalid";
  8683. return ib_cfg_name_strings[which];
  8684. }
  8685. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8686. {
  8687. struct hfi1_devdata *dd = ppd->dd;
  8688. int val = 0;
  8689. switch (which) {
  8690. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8691. val = ppd->link_width_enabled;
  8692. break;
  8693. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8694. val = ppd->link_width_active;
  8695. break;
  8696. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8697. val = ppd->link_speed_enabled;
  8698. break;
  8699. case HFI1_IB_CFG_SPD: /* current Link speed */
  8700. val = ppd->link_speed_active;
  8701. break;
  8702. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8703. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8704. case HFI1_IB_CFG_LINKLATENCY:
  8705. goto unimplemented;
  8706. case HFI1_IB_CFG_OP_VLS:
  8707. val = ppd->actual_vls_operational;
  8708. break;
  8709. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8710. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8711. break;
  8712. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8713. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8714. break;
  8715. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8716. val = ppd->overrun_threshold;
  8717. break;
  8718. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8719. val = ppd->phy_error_threshold;
  8720. break;
  8721. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8722. val = HLS_DEFAULT;
  8723. break;
  8724. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8725. case HFI1_IB_CFG_PMA_TICKS:
  8726. default:
  8727. unimplemented:
  8728. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8729. dd_dev_info(
  8730. dd,
  8731. "%s: which %s: not implemented\n",
  8732. __func__,
  8733. ib_cfg_name(which));
  8734. break;
  8735. }
  8736. return val;
  8737. }
  8738. /*
  8739. * The largest MAD packet size.
  8740. */
  8741. #define MAX_MAD_PACKET 2048
  8742. /*
  8743. * Return the maximum header bytes that can go on the _wire_
  8744. * for this device. This count includes the ICRC which is
  8745. * not part of the packet held in memory but it is appended
  8746. * by the HW.
  8747. * This is dependent on the device's receive header entry size.
  8748. * HFI allows this to be set per-receive context, but the
  8749. * driver presently enforces a global value.
  8750. */
  8751. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8752. {
  8753. /*
  8754. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8755. * the Receive Header Entry Size minus the PBC (or RHF) size
  8756. * plus one DW for the ICRC appended by HW.
  8757. *
  8758. * dd->rcd[0].rcvhdrqentsize is in DW.
  8759. * We use rcd[0] as all context will have the same value. Also,
  8760. * the first kernel context would have been allocated by now so
  8761. * we are guaranteed a valid value.
  8762. */
  8763. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8764. }
  8765. /*
  8766. * Set Send Length
  8767. * @ppd - per port data
  8768. *
  8769. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8770. * registers compare against LRH.PktLen, so use the max bytes included
  8771. * in the LRH.
  8772. *
  8773. * This routine changes all VL values except VL15, which it maintains at
  8774. * the same value.
  8775. */
  8776. static void set_send_length(struct hfi1_pportdata *ppd)
  8777. {
  8778. struct hfi1_devdata *dd = ppd->dd;
  8779. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8780. u32 maxvlmtu = dd->vld[15].mtu;
  8781. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8782. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8783. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8784. int i, j;
  8785. u32 thres;
  8786. for (i = 0; i < ppd->vls_supported; i++) {
  8787. if (dd->vld[i].mtu > maxvlmtu)
  8788. maxvlmtu = dd->vld[i].mtu;
  8789. if (i <= 3)
  8790. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8791. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8792. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8793. else
  8794. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8795. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8796. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8797. }
  8798. write_csr(dd, SEND_LEN_CHECK0, len1);
  8799. write_csr(dd, SEND_LEN_CHECK1, len2);
  8800. /* adjust kernel credit return thresholds based on new MTUs */
  8801. /* all kernel receive contexts have the same hdrqentsize */
  8802. for (i = 0; i < ppd->vls_supported; i++) {
  8803. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8804. sc_mtu_to_threshold(dd->vld[i].sc,
  8805. dd->vld[i].mtu,
  8806. dd->rcd[0]->rcvhdrqentsize));
  8807. for (j = 0; j < INIT_SC_PER_VL; j++)
  8808. sc_set_cr_threshold(
  8809. pio_select_send_context_vl(dd, j, i),
  8810. thres);
  8811. }
  8812. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8813. sc_mtu_to_threshold(dd->vld[15].sc,
  8814. dd->vld[15].mtu,
  8815. dd->rcd[0]->rcvhdrqentsize));
  8816. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8817. /* Adjust maximum MTU for the port in DC */
  8818. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8819. (ilog2(maxvlmtu >> 8) + 1);
  8820. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8821. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8822. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8823. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8824. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8825. }
  8826. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8827. {
  8828. int i;
  8829. u64 sreg = 0;
  8830. struct hfi1_devdata *dd = ppd->dd;
  8831. u32 mask = ~((1U << ppd->lmc) - 1);
  8832. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8833. u32 lid;
  8834. /*
  8835. * Program 0 in CSR if port lid is extended. This prevents
  8836. * 9B packets being sent out for large lids.
  8837. */
  8838. lid = (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ? 0 : ppd->lid;
  8839. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8840. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8841. c1 |= ((lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8842. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8843. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8844. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8845. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8846. /*
  8847. * Iterate over all the send contexts and set their SLID check
  8848. */
  8849. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8850. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8851. (((lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8852. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8853. for (i = 0; i < dd->chip_send_contexts; i++) {
  8854. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8855. i, (u32)sreg);
  8856. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8857. }
  8858. /* Now we have to do the same thing for the sdma engines */
  8859. sdma_update_lmc(dd, mask, lid);
  8860. }
  8861. static const char *state_completed_string(u32 completed)
  8862. {
  8863. static const char * const state_completed[] = {
  8864. "EstablishComm",
  8865. "OptimizeEQ",
  8866. "VerifyCap"
  8867. };
  8868. if (completed < ARRAY_SIZE(state_completed))
  8869. return state_completed[completed];
  8870. return "unknown";
  8871. }
  8872. static const char all_lanes_dead_timeout_expired[] =
  8873. "All lanes were inactive – was the interconnect media removed?";
  8874. static const char tx_out_of_policy[] =
  8875. "Passing lanes on local port do not meet the local link width policy";
  8876. static const char no_state_complete[] =
  8877. "State timeout occurred before link partner completed the state";
  8878. static const char * const state_complete_reasons[] = {
  8879. [0x00] = "Reason unknown",
  8880. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8881. [0x02] = "Link partner reported failure",
  8882. [0x10] = "Unable to achieve frame sync on any lane",
  8883. [0x11] =
  8884. "Unable to find a common bit rate with the link partner",
  8885. [0x12] =
  8886. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8887. [0x13] =
  8888. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8889. [0x14] = no_state_complete,
  8890. [0x15] =
  8891. "State timeout occurred before link partner identified equalization presets",
  8892. [0x16] =
  8893. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8894. [0x17] = tx_out_of_policy,
  8895. [0x20] = all_lanes_dead_timeout_expired,
  8896. [0x21] =
  8897. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8898. [0x22] = no_state_complete,
  8899. [0x23] =
  8900. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8901. [0x24] = tx_out_of_policy,
  8902. [0x30] = all_lanes_dead_timeout_expired,
  8903. [0x31] =
  8904. "State timeout occurred waiting for host to process received frames",
  8905. [0x32] = no_state_complete,
  8906. [0x33] =
  8907. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8908. [0x34] = tx_out_of_policy,
  8909. [0x35] = "Negotiated link width is mutually exclusive",
  8910. [0x36] =
  8911. "Timed out before receiving verifycap frames in VerifyCap.Exchange",
  8912. [0x37] = "Unable to resolve secure data exchange",
  8913. };
  8914. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8915. u32 code)
  8916. {
  8917. const char *str = NULL;
  8918. if (code < ARRAY_SIZE(state_complete_reasons))
  8919. str = state_complete_reasons[code];
  8920. if (str)
  8921. return str;
  8922. return "Reserved";
  8923. }
  8924. /* describe the given last state complete frame */
  8925. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8926. const char *prefix)
  8927. {
  8928. struct hfi1_devdata *dd = ppd->dd;
  8929. u32 success;
  8930. u32 state;
  8931. u32 reason;
  8932. u32 lanes;
  8933. /*
  8934. * Decode frame:
  8935. * [ 0: 0] - success
  8936. * [ 3: 1] - state
  8937. * [ 7: 4] - next state timeout
  8938. * [15: 8] - reason code
  8939. * [31:16] - lanes
  8940. */
  8941. success = frame & 0x1;
  8942. state = (frame >> 1) & 0x7;
  8943. reason = (frame >> 8) & 0xff;
  8944. lanes = (frame >> 16) & 0xffff;
  8945. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8946. prefix, frame);
  8947. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8948. state_completed_string(state), state);
  8949. dd_dev_err(dd, " state successfully completed: %s\n",
  8950. success ? "yes" : "no");
  8951. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8952. reason, state_complete_reason_code_string(ppd, reason));
  8953. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8954. }
  8955. /*
  8956. * Read the last state complete frames and explain them. This routine
  8957. * expects to be called if the link went down during link negotiation
  8958. * and initialization (LNI). That is, anywhere between polling and link up.
  8959. */
  8960. static void check_lni_states(struct hfi1_pportdata *ppd)
  8961. {
  8962. u32 last_local_state;
  8963. u32 last_remote_state;
  8964. read_last_local_state(ppd->dd, &last_local_state);
  8965. read_last_remote_state(ppd->dd, &last_remote_state);
  8966. /*
  8967. * Don't report anything if there is nothing to report. A value of
  8968. * 0 means the link was taken down while polling and there was no
  8969. * training in-process.
  8970. */
  8971. if (last_local_state == 0 && last_remote_state == 0)
  8972. return;
  8973. decode_state_complete(ppd, last_local_state, "transmitted");
  8974. decode_state_complete(ppd, last_remote_state, "received");
  8975. }
  8976. /* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
  8977. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
  8978. {
  8979. u64 reg;
  8980. unsigned long timeout;
  8981. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  8982. timeout = jiffies + msecs_to_jiffies(wait_ms);
  8983. while (1) {
  8984. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  8985. if (reg)
  8986. break;
  8987. if (time_after(jiffies, timeout)) {
  8988. dd_dev_err(dd,
  8989. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  8990. return -ETIMEDOUT;
  8991. }
  8992. udelay(2);
  8993. }
  8994. return 0;
  8995. }
  8996. /* called when the logical link state is not down as it should be */
  8997. static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
  8998. {
  8999. struct hfi1_devdata *dd = ppd->dd;
  9000. /*
  9001. * Bring link up in LCB loopback
  9002. */
  9003. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  9004. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  9005. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  9006. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  9007. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
  9008. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  9009. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
  9010. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  9011. (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
  9012. udelay(3);
  9013. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
  9014. write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  9015. wait_link_transfer_active(dd, 100);
  9016. /*
  9017. * Bring the link down again.
  9018. */
  9019. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  9020. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
  9021. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
  9022. dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
  9023. }
  9024. /*
  9025. * Helper for set_link_state(). Do not call except from that routine.
  9026. * Expects ppd->hls_mutex to be held.
  9027. *
  9028. * @rem_reason value to be sent to the neighbor
  9029. *
  9030. * LinkDownReasons only set if transition succeeds.
  9031. */
  9032. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  9033. {
  9034. struct hfi1_devdata *dd = ppd->dd;
  9035. u32 previous_state;
  9036. int offline_state_ret;
  9037. int ret;
  9038. update_lcb_cache(dd);
  9039. previous_state = ppd->host_link_state;
  9040. ppd->host_link_state = HLS_GOING_OFFLINE;
  9041. /* start offline transition */
  9042. ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
  9043. if (ret != HCMD_SUCCESS) {
  9044. dd_dev_err(dd,
  9045. "Failed to transition to Offline link state, return %d\n",
  9046. ret);
  9047. return -EINVAL;
  9048. }
  9049. if (ppd->offline_disabled_reason ==
  9050. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  9051. ppd->offline_disabled_reason =
  9052. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  9053. offline_state_ret = wait_phys_link_offline_substates(ppd, 10000);
  9054. if (offline_state_ret < 0)
  9055. return offline_state_ret;
  9056. /* Disabling AOC transmitters */
  9057. if (ppd->port_type == PORT_TYPE_QSFP &&
  9058. ppd->qsfp_info.limiting_active &&
  9059. qsfp_mod_present(ppd)) {
  9060. int ret;
  9061. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  9062. if (ret == 0) {
  9063. set_qsfp_tx(ppd, 0);
  9064. release_chip_resource(dd, qsfp_resource(dd));
  9065. } else {
  9066. /* not fatal, but should warn */
  9067. dd_dev_err(dd,
  9068. "Unable to acquire lock to turn off QSFP TX\n");
  9069. }
  9070. }
  9071. /*
  9072. * Wait for the offline.Quiet transition if it hasn't happened yet. It
  9073. * can take a while for the link to go down.
  9074. */
  9075. if (offline_state_ret != PLS_OFFLINE_QUIET) {
  9076. ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 30000);
  9077. if (ret < 0)
  9078. return ret;
  9079. }
  9080. /*
  9081. * Now in charge of LCB - must be after the physical state is
  9082. * offline.quiet and before host_link_state is changed.
  9083. */
  9084. set_host_lcb_access(dd);
  9085. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  9086. /* make sure the logical state is also down */
  9087. ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  9088. if (ret)
  9089. force_logical_link_state_down(ppd);
  9090. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  9091. update_statusp(ppd, IB_PORT_DOWN);
  9092. /*
  9093. * The LNI has a mandatory wait time after the physical state
  9094. * moves to Offline.Quiet. The wait time may be different
  9095. * depending on how the link went down. The 8051 firmware
  9096. * will observe the needed wait time and only move to ready
  9097. * when that is completed. The largest of the quiet timeouts
  9098. * is 6s, so wait that long and then at least 0.5s more for
  9099. * other transitions, and another 0.5s for a buffer.
  9100. */
  9101. ret = wait_fm_ready(dd, 7000);
  9102. if (ret) {
  9103. dd_dev_err(dd,
  9104. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  9105. /* state is really offline, so make it so */
  9106. ppd->host_link_state = HLS_DN_OFFLINE;
  9107. return ret;
  9108. }
  9109. /*
  9110. * The state is now offline and the 8051 is ready to accept host
  9111. * requests.
  9112. * - change our state
  9113. * - notify others if we were previously in a linkup state
  9114. */
  9115. ppd->host_link_state = HLS_DN_OFFLINE;
  9116. if (previous_state & HLS_UP) {
  9117. /* went down while link was up */
  9118. handle_linkup_change(dd, 0);
  9119. } else if (previous_state
  9120. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  9121. /* went down while attempting link up */
  9122. check_lni_states(ppd);
  9123. /* The QSFP doesn't need to be reset on LNI failure */
  9124. ppd->qsfp_info.reset_needed = 0;
  9125. }
  9126. /* the active link width (downgrade) is 0 on link down */
  9127. ppd->link_width_active = 0;
  9128. ppd->link_width_downgrade_tx_active = 0;
  9129. ppd->link_width_downgrade_rx_active = 0;
  9130. ppd->current_egress_rate = 0;
  9131. return 0;
  9132. }
  9133. /* return the link state name */
  9134. static const char *link_state_name(u32 state)
  9135. {
  9136. const char *name;
  9137. int n = ilog2(state);
  9138. static const char * const names[] = {
  9139. [__HLS_UP_INIT_BP] = "INIT",
  9140. [__HLS_UP_ARMED_BP] = "ARMED",
  9141. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  9142. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  9143. [__HLS_DN_POLL_BP] = "POLL",
  9144. [__HLS_DN_DISABLE_BP] = "DISABLE",
  9145. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  9146. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  9147. [__HLS_GOING_UP_BP] = "GOING_UP",
  9148. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  9149. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  9150. };
  9151. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  9152. return name ? name : "unknown";
  9153. }
  9154. /* return the link state reason name */
  9155. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  9156. {
  9157. if (state == HLS_UP_INIT) {
  9158. switch (ppd->linkinit_reason) {
  9159. case OPA_LINKINIT_REASON_LINKUP:
  9160. return "(LINKUP)";
  9161. case OPA_LINKINIT_REASON_FLAPPING:
  9162. return "(FLAPPING)";
  9163. case OPA_LINKINIT_OUTSIDE_POLICY:
  9164. return "(OUTSIDE_POLICY)";
  9165. case OPA_LINKINIT_QUARANTINED:
  9166. return "(QUARANTINED)";
  9167. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  9168. return "(INSUFIC_CAPABILITY)";
  9169. default:
  9170. break;
  9171. }
  9172. }
  9173. return "";
  9174. }
  9175. /*
  9176. * driver_pstate - convert the driver's notion of a port's
  9177. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  9178. * Return -1 (converted to a u32) to indicate error.
  9179. */
  9180. u32 driver_pstate(struct hfi1_pportdata *ppd)
  9181. {
  9182. switch (ppd->host_link_state) {
  9183. case HLS_UP_INIT:
  9184. case HLS_UP_ARMED:
  9185. case HLS_UP_ACTIVE:
  9186. return IB_PORTPHYSSTATE_LINKUP;
  9187. case HLS_DN_POLL:
  9188. return IB_PORTPHYSSTATE_POLLING;
  9189. case HLS_DN_DISABLE:
  9190. return IB_PORTPHYSSTATE_DISABLED;
  9191. case HLS_DN_OFFLINE:
  9192. return OPA_PORTPHYSSTATE_OFFLINE;
  9193. case HLS_VERIFY_CAP:
  9194. return IB_PORTPHYSSTATE_TRAINING;
  9195. case HLS_GOING_UP:
  9196. return IB_PORTPHYSSTATE_TRAINING;
  9197. case HLS_GOING_OFFLINE:
  9198. return OPA_PORTPHYSSTATE_OFFLINE;
  9199. case HLS_LINK_COOLDOWN:
  9200. return OPA_PORTPHYSSTATE_OFFLINE;
  9201. case HLS_DN_DOWNDEF:
  9202. default:
  9203. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9204. ppd->host_link_state);
  9205. return -1;
  9206. }
  9207. }
  9208. /*
  9209. * driver_lstate - convert the driver's notion of a port's
  9210. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9211. * (converted to a u32) to indicate error.
  9212. */
  9213. u32 driver_lstate(struct hfi1_pportdata *ppd)
  9214. {
  9215. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9216. return IB_PORT_DOWN;
  9217. switch (ppd->host_link_state & HLS_UP) {
  9218. case HLS_UP_INIT:
  9219. return IB_PORT_INIT;
  9220. case HLS_UP_ARMED:
  9221. return IB_PORT_ARMED;
  9222. case HLS_UP_ACTIVE:
  9223. return IB_PORT_ACTIVE;
  9224. default:
  9225. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9226. ppd->host_link_state);
  9227. return -1;
  9228. }
  9229. }
  9230. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9231. u8 neigh_reason, u8 rem_reason)
  9232. {
  9233. if (ppd->local_link_down_reason.latest == 0 &&
  9234. ppd->neigh_link_down_reason.latest == 0) {
  9235. ppd->local_link_down_reason.latest = lcl_reason;
  9236. ppd->neigh_link_down_reason.latest = neigh_reason;
  9237. ppd->remote_link_down_reason = rem_reason;
  9238. }
  9239. }
  9240. /*
  9241. * Verify if BCT for data VLs is non-zero.
  9242. */
  9243. static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
  9244. {
  9245. return !!ppd->actual_vls_operational;
  9246. }
  9247. /*
  9248. * Change the physical and/or logical link state.
  9249. *
  9250. * Do not call this routine while inside an interrupt. It contains
  9251. * calls to routines that can take multiple seconds to finish.
  9252. *
  9253. * Returns 0 on success, -errno on failure.
  9254. */
  9255. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9256. {
  9257. struct hfi1_devdata *dd = ppd->dd;
  9258. struct ib_event event = {.device = NULL};
  9259. int ret1, ret = 0;
  9260. int orig_new_state, poll_bounce;
  9261. mutex_lock(&ppd->hls_lock);
  9262. orig_new_state = state;
  9263. if (state == HLS_DN_DOWNDEF)
  9264. state = HLS_DEFAULT;
  9265. /* interpret poll -> poll as a link bounce */
  9266. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9267. state == HLS_DN_POLL;
  9268. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9269. link_state_name(ppd->host_link_state),
  9270. link_state_name(orig_new_state),
  9271. poll_bounce ? "(bounce) " : "",
  9272. link_state_reason_name(ppd, state));
  9273. /*
  9274. * If we're going to a (HLS_*) link state that implies the logical
  9275. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9276. * reset is_sm_config_started to 0.
  9277. */
  9278. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9279. ppd->is_sm_config_started = 0;
  9280. /*
  9281. * Do nothing if the states match. Let a poll to poll link bounce
  9282. * go through.
  9283. */
  9284. if (ppd->host_link_state == state && !poll_bounce)
  9285. goto done;
  9286. switch (state) {
  9287. case HLS_UP_INIT:
  9288. if (ppd->host_link_state == HLS_DN_POLL &&
  9289. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9290. /*
  9291. * Quick link up jumps from polling to here.
  9292. *
  9293. * Whether in normal or loopback mode, the
  9294. * simulator jumps from polling to link up.
  9295. * Accept that here.
  9296. */
  9297. /* OK */
  9298. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9299. goto unexpected;
  9300. }
  9301. /*
  9302. * Wait for Link_Up physical state.
  9303. * Physical and Logical states should already be
  9304. * be transitioned to LinkUp and LinkInit respectively.
  9305. */
  9306. ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
  9307. if (ret) {
  9308. dd_dev_err(dd,
  9309. "%s: physical state did not change to LINK-UP\n",
  9310. __func__);
  9311. break;
  9312. }
  9313. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9314. if (ret) {
  9315. dd_dev_err(dd,
  9316. "%s: logical state did not change to INIT\n",
  9317. __func__);
  9318. break;
  9319. }
  9320. /* clear old transient LINKINIT_REASON code */
  9321. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9322. ppd->linkinit_reason =
  9323. OPA_LINKINIT_REASON_LINKUP;
  9324. /* enable the port */
  9325. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9326. handle_linkup_change(dd, 1);
  9327. /*
  9328. * After link up, a new link width will have been set.
  9329. * Update the xmit counters with regards to the new
  9330. * link width.
  9331. */
  9332. update_xmit_counters(ppd, ppd->link_width_active);
  9333. ppd->host_link_state = HLS_UP_INIT;
  9334. update_statusp(ppd, IB_PORT_INIT);
  9335. break;
  9336. case HLS_UP_ARMED:
  9337. if (ppd->host_link_state != HLS_UP_INIT)
  9338. goto unexpected;
  9339. if (!data_vls_operational(ppd)) {
  9340. dd_dev_err(dd,
  9341. "%s: data VLs not operational\n", __func__);
  9342. ret = -EINVAL;
  9343. break;
  9344. }
  9345. set_logical_state(dd, LSTATE_ARMED);
  9346. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9347. if (ret) {
  9348. dd_dev_err(dd,
  9349. "%s: logical state did not change to ARMED\n",
  9350. __func__);
  9351. break;
  9352. }
  9353. ppd->host_link_state = HLS_UP_ARMED;
  9354. update_statusp(ppd, IB_PORT_ARMED);
  9355. /*
  9356. * The simulator does not currently implement SMA messages,
  9357. * so neighbor_normal is not set. Set it here when we first
  9358. * move to Armed.
  9359. */
  9360. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9361. ppd->neighbor_normal = 1;
  9362. break;
  9363. case HLS_UP_ACTIVE:
  9364. if (ppd->host_link_state != HLS_UP_ARMED)
  9365. goto unexpected;
  9366. set_logical_state(dd, LSTATE_ACTIVE);
  9367. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9368. if (ret) {
  9369. dd_dev_err(dd,
  9370. "%s: logical state did not change to ACTIVE\n",
  9371. __func__);
  9372. } else {
  9373. /* tell all engines to go running */
  9374. sdma_all_running(dd);
  9375. ppd->host_link_state = HLS_UP_ACTIVE;
  9376. update_statusp(ppd, IB_PORT_ACTIVE);
  9377. /* Signal the IB layer that the port has went active */
  9378. event.device = &dd->verbs_dev.rdi.ibdev;
  9379. event.element.port_num = ppd->port;
  9380. event.event = IB_EVENT_PORT_ACTIVE;
  9381. }
  9382. break;
  9383. case HLS_DN_POLL:
  9384. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9385. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9386. dd->dc_shutdown)
  9387. dc_start(dd);
  9388. /* Hand LED control to the DC */
  9389. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9390. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9391. u8 tmp = ppd->link_enabled;
  9392. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9393. if (ret) {
  9394. ppd->link_enabled = tmp;
  9395. break;
  9396. }
  9397. ppd->remote_link_down_reason = 0;
  9398. if (ppd->driver_link_ready)
  9399. ppd->link_enabled = 1;
  9400. }
  9401. set_all_slowpath(ppd->dd);
  9402. ret = set_local_link_attributes(ppd);
  9403. if (ret)
  9404. break;
  9405. ppd->port_error_action = 0;
  9406. ppd->host_link_state = HLS_DN_POLL;
  9407. if (quick_linkup) {
  9408. /* quick linkup does not go into polling */
  9409. ret = do_quick_linkup(dd);
  9410. } else {
  9411. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9412. if (ret1 != HCMD_SUCCESS) {
  9413. dd_dev_err(dd,
  9414. "Failed to transition to Polling link state, return 0x%x\n",
  9415. ret1);
  9416. ret = -EINVAL;
  9417. }
  9418. }
  9419. ppd->offline_disabled_reason =
  9420. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9421. /*
  9422. * If an error occurred above, go back to offline. The
  9423. * caller may reschedule another attempt.
  9424. */
  9425. if (ret)
  9426. goto_offline(ppd, 0);
  9427. else
  9428. log_physical_state(ppd, PLS_POLLING);
  9429. break;
  9430. case HLS_DN_DISABLE:
  9431. /* link is disabled */
  9432. ppd->link_enabled = 0;
  9433. /* allow any state to transition to disabled */
  9434. /* must transition to offline first */
  9435. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9436. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9437. if (ret)
  9438. break;
  9439. ppd->remote_link_down_reason = 0;
  9440. }
  9441. if (!dd->dc_shutdown) {
  9442. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9443. if (ret1 != HCMD_SUCCESS) {
  9444. dd_dev_err(dd,
  9445. "Failed to transition to Disabled link state, return 0x%x\n",
  9446. ret1);
  9447. ret = -EINVAL;
  9448. break;
  9449. }
  9450. ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
  9451. if (ret) {
  9452. dd_dev_err(dd,
  9453. "%s: physical state did not change to DISABLED\n",
  9454. __func__);
  9455. break;
  9456. }
  9457. dc_shutdown(dd);
  9458. }
  9459. ppd->host_link_state = HLS_DN_DISABLE;
  9460. break;
  9461. case HLS_DN_OFFLINE:
  9462. if (ppd->host_link_state == HLS_DN_DISABLE)
  9463. dc_start(dd);
  9464. /* allow any state to transition to offline */
  9465. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9466. if (!ret)
  9467. ppd->remote_link_down_reason = 0;
  9468. break;
  9469. case HLS_VERIFY_CAP:
  9470. if (ppd->host_link_state != HLS_DN_POLL)
  9471. goto unexpected;
  9472. ppd->host_link_state = HLS_VERIFY_CAP;
  9473. log_physical_state(ppd, PLS_CONFIGPHY_VERIFYCAP);
  9474. break;
  9475. case HLS_GOING_UP:
  9476. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9477. goto unexpected;
  9478. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9479. if (ret1 != HCMD_SUCCESS) {
  9480. dd_dev_err(dd,
  9481. "Failed to transition to link up state, return 0x%x\n",
  9482. ret1);
  9483. ret = -EINVAL;
  9484. break;
  9485. }
  9486. ppd->host_link_state = HLS_GOING_UP;
  9487. break;
  9488. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9489. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9490. default:
  9491. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9492. __func__, state);
  9493. ret = -EINVAL;
  9494. break;
  9495. }
  9496. goto done;
  9497. unexpected:
  9498. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9499. __func__, link_state_name(ppd->host_link_state),
  9500. link_state_name(state));
  9501. ret = -EINVAL;
  9502. done:
  9503. mutex_unlock(&ppd->hls_lock);
  9504. if (event.device)
  9505. ib_dispatch_event(&event);
  9506. return ret;
  9507. }
  9508. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9509. {
  9510. u64 reg;
  9511. int ret = 0;
  9512. switch (which) {
  9513. case HFI1_IB_CFG_LIDLMC:
  9514. set_lidlmc(ppd);
  9515. break;
  9516. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9517. /*
  9518. * The VL Arbitrator high limit is sent in units of 4k
  9519. * bytes, while HFI stores it in units of 64 bytes.
  9520. */
  9521. val *= 4096 / 64;
  9522. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9523. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9524. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9525. break;
  9526. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9527. /* HFI only supports POLL as the default link down state */
  9528. if (val != HLS_DN_POLL)
  9529. ret = -EINVAL;
  9530. break;
  9531. case HFI1_IB_CFG_OP_VLS:
  9532. if (ppd->vls_operational != val) {
  9533. ppd->vls_operational = val;
  9534. if (!ppd->port)
  9535. ret = -EINVAL;
  9536. }
  9537. break;
  9538. /*
  9539. * For link width, link width downgrade, and speed enable, always AND
  9540. * the setting with what is actually supported. This has two benefits.
  9541. * First, enabled can't have unsupported values, no matter what the
  9542. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9543. * "fill in with your supported value" have all the bits in the
  9544. * field set, so simply ANDing with supported has the desired result.
  9545. */
  9546. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9547. ppd->link_width_enabled = val & ppd->link_width_supported;
  9548. break;
  9549. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9550. ppd->link_width_downgrade_enabled =
  9551. val & ppd->link_width_downgrade_supported;
  9552. break;
  9553. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9554. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9555. break;
  9556. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9557. /*
  9558. * HFI does not follow IB specs, save this value
  9559. * so we can report it, if asked.
  9560. */
  9561. ppd->overrun_threshold = val;
  9562. break;
  9563. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9564. /*
  9565. * HFI does not follow IB specs, save this value
  9566. * so we can report it, if asked.
  9567. */
  9568. ppd->phy_error_threshold = val;
  9569. break;
  9570. case HFI1_IB_CFG_MTU:
  9571. set_send_length(ppd);
  9572. break;
  9573. case HFI1_IB_CFG_PKEYS:
  9574. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9575. set_partition_keys(ppd);
  9576. break;
  9577. default:
  9578. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9579. dd_dev_info(ppd->dd,
  9580. "%s: which %s, val 0x%x: not implemented\n",
  9581. __func__, ib_cfg_name(which), val);
  9582. break;
  9583. }
  9584. return ret;
  9585. }
  9586. /* begin functions related to vl arbitration table caching */
  9587. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9588. {
  9589. int i;
  9590. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9591. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9592. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9593. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9594. /*
  9595. * Note that we always return values directly from the
  9596. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9597. * 'Get(VLArbTable)'. This is obviously correct after a
  9598. * 'Set(VLArbTable)', since the cache will then be up to
  9599. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9600. * since then both the cache, and the relevant h/w registers
  9601. * will be zeroed.
  9602. */
  9603. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9604. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9605. }
  9606. /*
  9607. * vl_arb_lock_cache
  9608. *
  9609. * All other vl_arb_* functions should be called only after locking
  9610. * the cache.
  9611. */
  9612. static inline struct vl_arb_cache *
  9613. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9614. {
  9615. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9616. return NULL;
  9617. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9618. return &ppd->vl_arb_cache[idx];
  9619. }
  9620. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9621. {
  9622. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9623. }
  9624. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9625. struct ib_vl_weight_elem *vl)
  9626. {
  9627. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9628. }
  9629. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9630. struct ib_vl_weight_elem *vl)
  9631. {
  9632. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9633. }
  9634. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9635. struct ib_vl_weight_elem *vl)
  9636. {
  9637. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9638. }
  9639. /* end functions related to vl arbitration table caching */
  9640. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9641. u32 size, struct ib_vl_weight_elem *vl)
  9642. {
  9643. struct hfi1_devdata *dd = ppd->dd;
  9644. u64 reg;
  9645. unsigned int i, is_up = 0;
  9646. int drain, ret = 0;
  9647. mutex_lock(&ppd->hls_lock);
  9648. if (ppd->host_link_state & HLS_UP)
  9649. is_up = 1;
  9650. drain = !is_ax(dd) && is_up;
  9651. if (drain)
  9652. /*
  9653. * Before adjusting VL arbitration weights, empty per-VL
  9654. * FIFOs, otherwise a packet whose VL weight is being
  9655. * set to 0 could get stuck in a FIFO with no chance to
  9656. * egress.
  9657. */
  9658. ret = stop_drain_data_vls(dd);
  9659. if (ret) {
  9660. dd_dev_err(
  9661. dd,
  9662. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9663. __func__);
  9664. goto err;
  9665. }
  9666. for (i = 0; i < size; i++, vl++) {
  9667. /*
  9668. * NOTE: The low priority shift and mask are used here, but
  9669. * they are the same for both the low and high registers.
  9670. */
  9671. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9672. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9673. | (((u64)vl->weight
  9674. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9675. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9676. write_csr(dd, target + (i * 8), reg);
  9677. }
  9678. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9679. if (drain)
  9680. open_fill_data_vls(dd); /* reopen all VLs */
  9681. err:
  9682. mutex_unlock(&ppd->hls_lock);
  9683. return ret;
  9684. }
  9685. /*
  9686. * Read one credit merge VL register.
  9687. */
  9688. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9689. struct vl_limit *vll)
  9690. {
  9691. u64 reg = read_csr(dd, csr);
  9692. vll->dedicated = cpu_to_be16(
  9693. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9694. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9695. vll->shared = cpu_to_be16(
  9696. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9697. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9698. }
  9699. /*
  9700. * Read the current credit merge limits.
  9701. */
  9702. static int get_buffer_control(struct hfi1_devdata *dd,
  9703. struct buffer_control *bc, u16 *overall_limit)
  9704. {
  9705. u64 reg;
  9706. int i;
  9707. /* not all entries are filled in */
  9708. memset(bc, 0, sizeof(*bc));
  9709. /* OPA and HFI have a 1-1 mapping */
  9710. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9711. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9712. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9713. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9714. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9715. bc->overall_shared_limit = cpu_to_be16(
  9716. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9717. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9718. if (overall_limit)
  9719. *overall_limit = (reg
  9720. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9721. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9722. return sizeof(struct buffer_control);
  9723. }
  9724. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9725. {
  9726. u64 reg;
  9727. int i;
  9728. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9729. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9730. for (i = 0; i < sizeof(u64); i++) {
  9731. u8 byte = *(((u8 *)&reg) + i);
  9732. dp->vlnt[2 * i] = byte & 0xf;
  9733. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9734. }
  9735. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9736. for (i = 0; i < sizeof(u64); i++) {
  9737. u8 byte = *(((u8 *)&reg) + i);
  9738. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9739. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9740. }
  9741. return sizeof(struct sc2vlnt);
  9742. }
  9743. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9744. struct ib_vl_weight_elem *vl)
  9745. {
  9746. unsigned int i;
  9747. for (i = 0; i < nelems; i++, vl++) {
  9748. vl->vl = 0xf;
  9749. vl->weight = 0;
  9750. }
  9751. }
  9752. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9753. {
  9754. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9755. DC_SC_VL_VAL(15_0,
  9756. 0, dp->vlnt[0] & 0xf,
  9757. 1, dp->vlnt[1] & 0xf,
  9758. 2, dp->vlnt[2] & 0xf,
  9759. 3, dp->vlnt[3] & 0xf,
  9760. 4, dp->vlnt[4] & 0xf,
  9761. 5, dp->vlnt[5] & 0xf,
  9762. 6, dp->vlnt[6] & 0xf,
  9763. 7, dp->vlnt[7] & 0xf,
  9764. 8, dp->vlnt[8] & 0xf,
  9765. 9, dp->vlnt[9] & 0xf,
  9766. 10, dp->vlnt[10] & 0xf,
  9767. 11, dp->vlnt[11] & 0xf,
  9768. 12, dp->vlnt[12] & 0xf,
  9769. 13, dp->vlnt[13] & 0xf,
  9770. 14, dp->vlnt[14] & 0xf,
  9771. 15, dp->vlnt[15] & 0xf));
  9772. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9773. DC_SC_VL_VAL(31_16,
  9774. 16, dp->vlnt[16] & 0xf,
  9775. 17, dp->vlnt[17] & 0xf,
  9776. 18, dp->vlnt[18] & 0xf,
  9777. 19, dp->vlnt[19] & 0xf,
  9778. 20, dp->vlnt[20] & 0xf,
  9779. 21, dp->vlnt[21] & 0xf,
  9780. 22, dp->vlnt[22] & 0xf,
  9781. 23, dp->vlnt[23] & 0xf,
  9782. 24, dp->vlnt[24] & 0xf,
  9783. 25, dp->vlnt[25] & 0xf,
  9784. 26, dp->vlnt[26] & 0xf,
  9785. 27, dp->vlnt[27] & 0xf,
  9786. 28, dp->vlnt[28] & 0xf,
  9787. 29, dp->vlnt[29] & 0xf,
  9788. 30, dp->vlnt[30] & 0xf,
  9789. 31, dp->vlnt[31] & 0xf));
  9790. }
  9791. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9792. u16 limit)
  9793. {
  9794. if (limit != 0)
  9795. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9796. what, (int)limit, idx);
  9797. }
  9798. /* change only the shared limit portion of SendCmGLobalCredit */
  9799. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9800. {
  9801. u64 reg;
  9802. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9803. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9804. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9805. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9806. }
  9807. /* change only the total credit limit portion of SendCmGLobalCredit */
  9808. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9809. {
  9810. u64 reg;
  9811. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9812. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9813. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9814. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9815. }
  9816. /* set the given per-VL shared limit */
  9817. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9818. {
  9819. u64 reg;
  9820. u32 addr;
  9821. if (vl < TXE_NUM_DATA_VL)
  9822. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9823. else
  9824. addr = SEND_CM_CREDIT_VL15;
  9825. reg = read_csr(dd, addr);
  9826. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9827. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9828. write_csr(dd, addr, reg);
  9829. }
  9830. /* set the given per-VL dedicated limit */
  9831. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9832. {
  9833. u64 reg;
  9834. u32 addr;
  9835. if (vl < TXE_NUM_DATA_VL)
  9836. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9837. else
  9838. addr = SEND_CM_CREDIT_VL15;
  9839. reg = read_csr(dd, addr);
  9840. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9841. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9842. write_csr(dd, addr, reg);
  9843. }
  9844. /* spin until the given per-VL status mask bits clear */
  9845. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9846. const char *which)
  9847. {
  9848. unsigned long timeout;
  9849. u64 reg;
  9850. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9851. while (1) {
  9852. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9853. if (reg == 0)
  9854. return; /* success */
  9855. if (time_after(jiffies, timeout))
  9856. break; /* timed out */
  9857. udelay(1);
  9858. }
  9859. dd_dev_err(dd,
  9860. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9861. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9862. /*
  9863. * If this occurs, it is likely there was a credit loss on the link.
  9864. * The only recovery from that is a link bounce.
  9865. */
  9866. dd_dev_err(dd,
  9867. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9868. }
  9869. /*
  9870. * The number of credits on the VLs may be changed while everything
  9871. * is "live", but the following algorithm must be followed due to
  9872. * how the hardware is actually implemented. In particular,
  9873. * Return_Credit_Status[] is the only correct status check.
  9874. *
  9875. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9876. * set Global_Shared_Credit_Limit = 0
  9877. * use_all_vl = 1
  9878. * mask0 = all VLs that are changing either dedicated or shared limits
  9879. * set Shared_Limit[mask0] = 0
  9880. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9881. * if (changing any dedicated limit)
  9882. * mask1 = all VLs that are lowering dedicated limits
  9883. * lower Dedicated_Limit[mask1]
  9884. * spin until Return_Credit_Status[mask1] == 0
  9885. * raise Dedicated_Limits
  9886. * raise Shared_Limits
  9887. * raise Global_Shared_Credit_Limit
  9888. *
  9889. * lower = if the new limit is lower, set the limit to the new value
  9890. * raise = if the new limit is higher than the current value (may be changed
  9891. * earlier in the algorithm), set the new limit to the new value
  9892. */
  9893. int set_buffer_control(struct hfi1_pportdata *ppd,
  9894. struct buffer_control *new_bc)
  9895. {
  9896. struct hfi1_devdata *dd = ppd->dd;
  9897. u64 changing_mask, ld_mask, stat_mask;
  9898. int change_count;
  9899. int i, use_all_mask;
  9900. int this_shared_changing;
  9901. int vl_count = 0, ret;
  9902. /*
  9903. * A0: add the variable any_shared_limit_changing below and in the
  9904. * algorithm above. If removing A0 support, it can be removed.
  9905. */
  9906. int any_shared_limit_changing;
  9907. struct buffer_control cur_bc;
  9908. u8 changing[OPA_MAX_VLS];
  9909. u8 lowering_dedicated[OPA_MAX_VLS];
  9910. u16 cur_total;
  9911. u32 new_total = 0;
  9912. const u64 all_mask =
  9913. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9914. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9915. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9916. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9917. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9918. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9919. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9920. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9921. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9922. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9923. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9924. /* find the new total credits, do sanity check on unused VLs */
  9925. for (i = 0; i < OPA_MAX_VLS; i++) {
  9926. if (valid_vl(i)) {
  9927. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9928. continue;
  9929. }
  9930. nonzero_msg(dd, i, "dedicated",
  9931. be16_to_cpu(new_bc->vl[i].dedicated));
  9932. nonzero_msg(dd, i, "shared",
  9933. be16_to_cpu(new_bc->vl[i].shared));
  9934. new_bc->vl[i].dedicated = 0;
  9935. new_bc->vl[i].shared = 0;
  9936. }
  9937. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9938. /* fetch the current values */
  9939. get_buffer_control(dd, &cur_bc, &cur_total);
  9940. /*
  9941. * Create the masks we will use.
  9942. */
  9943. memset(changing, 0, sizeof(changing));
  9944. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9945. /*
  9946. * NOTE: Assumes that the individual VL bits are adjacent and in
  9947. * increasing order
  9948. */
  9949. stat_mask =
  9950. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9951. changing_mask = 0;
  9952. ld_mask = 0;
  9953. change_count = 0;
  9954. any_shared_limit_changing = 0;
  9955. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9956. if (!valid_vl(i))
  9957. continue;
  9958. this_shared_changing = new_bc->vl[i].shared
  9959. != cur_bc.vl[i].shared;
  9960. if (this_shared_changing)
  9961. any_shared_limit_changing = 1;
  9962. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9963. this_shared_changing) {
  9964. changing[i] = 1;
  9965. changing_mask |= stat_mask;
  9966. change_count++;
  9967. }
  9968. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9969. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9970. lowering_dedicated[i] = 1;
  9971. ld_mask |= stat_mask;
  9972. }
  9973. }
  9974. /* bracket the credit change with a total adjustment */
  9975. if (new_total > cur_total)
  9976. set_global_limit(dd, new_total);
  9977. /*
  9978. * Start the credit change algorithm.
  9979. */
  9980. use_all_mask = 0;
  9981. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  9982. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  9983. (is_ax(dd) && any_shared_limit_changing)) {
  9984. set_global_shared(dd, 0);
  9985. cur_bc.overall_shared_limit = 0;
  9986. use_all_mask = 1;
  9987. }
  9988. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9989. if (!valid_vl(i))
  9990. continue;
  9991. if (changing[i]) {
  9992. set_vl_shared(dd, i, 0);
  9993. cur_bc.vl[i].shared = 0;
  9994. }
  9995. }
  9996. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  9997. "shared");
  9998. if (change_count > 0) {
  9999. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10000. if (!valid_vl(i))
  10001. continue;
  10002. if (lowering_dedicated[i]) {
  10003. set_vl_dedicated(dd, i,
  10004. be16_to_cpu(new_bc->
  10005. vl[i].dedicated));
  10006. cur_bc.vl[i].dedicated =
  10007. new_bc->vl[i].dedicated;
  10008. }
  10009. }
  10010. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  10011. /* now raise all dedicated that are going up */
  10012. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10013. if (!valid_vl(i))
  10014. continue;
  10015. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  10016. be16_to_cpu(cur_bc.vl[i].dedicated))
  10017. set_vl_dedicated(dd, i,
  10018. be16_to_cpu(new_bc->
  10019. vl[i].dedicated));
  10020. }
  10021. }
  10022. /* next raise all shared that are going up */
  10023. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10024. if (!valid_vl(i))
  10025. continue;
  10026. if (be16_to_cpu(new_bc->vl[i].shared) >
  10027. be16_to_cpu(cur_bc.vl[i].shared))
  10028. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  10029. }
  10030. /* finally raise the global shared */
  10031. if (be16_to_cpu(new_bc->overall_shared_limit) >
  10032. be16_to_cpu(cur_bc.overall_shared_limit))
  10033. set_global_shared(dd,
  10034. be16_to_cpu(new_bc->overall_shared_limit));
  10035. /* bracket the credit change with a total adjustment */
  10036. if (new_total < cur_total)
  10037. set_global_limit(dd, new_total);
  10038. /*
  10039. * Determine the actual number of operational VLS using the number of
  10040. * dedicated and shared credits for each VL.
  10041. */
  10042. if (change_count > 0) {
  10043. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  10044. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  10045. be16_to_cpu(new_bc->vl[i].shared) > 0)
  10046. vl_count++;
  10047. ppd->actual_vls_operational = vl_count;
  10048. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  10049. ppd->actual_vls_operational :
  10050. ppd->vls_operational,
  10051. NULL);
  10052. if (ret == 0)
  10053. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  10054. ppd->actual_vls_operational :
  10055. ppd->vls_operational, NULL);
  10056. if (ret)
  10057. return ret;
  10058. }
  10059. return 0;
  10060. }
  10061. /*
  10062. * Read the given fabric manager table. Return the size of the
  10063. * table (in bytes) on success, and a negative error code on
  10064. * failure.
  10065. */
  10066. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  10067. {
  10068. int size;
  10069. struct vl_arb_cache *vlc;
  10070. switch (which) {
  10071. case FM_TBL_VL_HIGH_ARB:
  10072. size = 256;
  10073. /*
  10074. * OPA specifies 128 elements (of 2 bytes each), though
  10075. * HFI supports only 16 elements in h/w.
  10076. */
  10077. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10078. vl_arb_get_cache(vlc, t);
  10079. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10080. break;
  10081. case FM_TBL_VL_LOW_ARB:
  10082. size = 256;
  10083. /*
  10084. * OPA specifies 128 elements (of 2 bytes each), though
  10085. * HFI supports only 16 elements in h/w.
  10086. */
  10087. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10088. vl_arb_get_cache(vlc, t);
  10089. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10090. break;
  10091. case FM_TBL_BUFFER_CONTROL:
  10092. size = get_buffer_control(ppd->dd, t, NULL);
  10093. break;
  10094. case FM_TBL_SC2VLNT:
  10095. size = get_sc2vlnt(ppd->dd, t);
  10096. break;
  10097. case FM_TBL_VL_PREEMPT_ELEMS:
  10098. size = 256;
  10099. /* OPA specifies 128 elements, of 2 bytes each */
  10100. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  10101. break;
  10102. case FM_TBL_VL_PREEMPT_MATRIX:
  10103. size = 256;
  10104. /*
  10105. * OPA specifies that this is the same size as the VL
  10106. * arbitration tables (i.e., 256 bytes).
  10107. */
  10108. break;
  10109. default:
  10110. return -EINVAL;
  10111. }
  10112. return size;
  10113. }
  10114. /*
  10115. * Write the given fabric manager table.
  10116. */
  10117. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  10118. {
  10119. int ret = 0;
  10120. struct vl_arb_cache *vlc;
  10121. switch (which) {
  10122. case FM_TBL_VL_HIGH_ARB:
  10123. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10124. if (vl_arb_match_cache(vlc, t)) {
  10125. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10126. break;
  10127. }
  10128. vl_arb_set_cache(vlc, t);
  10129. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10130. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  10131. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  10132. break;
  10133. case FM_TBL_VL_LOW_ARB:
  10134. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10135. if (vl_arb_match_cache(vlc, t)) {
  10136. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10137. break;
  10138. }
  10139. vl_arb_set_cache(vlc, t);
  10140. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10141. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  10142. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  10143. break;
  10144. case FM_TBL_BUFFER_CONTROL:
  10145. ret = set_buffer_control(ppd, t);
  10146. break;
  10147. case FM_TBL_SC2VLNT:
  10148. set_sc2vlnt(ppd->dd, t);
  10149. break;
  10150. default:
  10151. ret = -EINVAL;
  10152. }
  10153. return ret;
  10154. }
  10155. /*
  10156. * Disable all data VLs.
  10157. *
  10158. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  10159. */
  10160. static int disable_data_vls(struct hfi1_devdata *dd)
  10161. {
  10162. if (is_ax(dd))
  10163. return 1;
  10164. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  10165. return 0;
  10166. }
  10167. /*
  10168. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  10169. * Just re-enables all data VLs (the "fill" part happens
  10170. * automatically - the name was chosen for symmetry with
  10171. * stop_drain_data_vls()).
  10172. *
  10173. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  10174. */
  10175. int open_fill_data_vls(struct hfi1_devdata *dd)
  10176. {
  10177. if (is_ax(dd))
  10178. return 1;
  10179. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  10180. return 0;
  10181. }
  10182. /*
  10183. * drain_data_vls() - assumes that disable_data_vls() has been called,
  10184. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  10185. * engines to drop to 0.
  10186. */
  10187. static void drain_data_vls(struct hfi1_devdata *dd)
  10188. {
  10189. sc_wait(dd);
  10190. sdma_wait(dd);
  10191. pause_for_credit_return(dd);
  10192. }
  10193. /*
  10194. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  10195. *
  10196. * Use open_fill_data_vls() to resume using data VLs. This pair is
  10197. * meant to be used like this:
  10198. *
  10199. * stop_drain_data_vls(dd);
  10200. * // do things with per-VL resources
  10201. * open_fill_data_vls(dd);
  10202. */
  10203. int stop_drain_data_vls(struct hfi1_devdata *dd)
  10204. {
  10205. int ret;
  10206. ret = disable_data_vls(dd);
  10207. if (ret == 0)
  10208. drain_data_vls(dd);
  10209. return ret;
  10210. }
  10211. /*
  10212. * Convert a nanosecond time to a cclock count. No matter how slow
  10213. * the cclock, a non-zero ns will always have a non-zero result.
  10214. */
  10215. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  10216. {
  10217. u32 cclocks;
  10218. if (dd->icode == ICODE_FPGA_EMULATION)
  10219. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  10220. else /* simulation pretends to be ASIC */
  10221. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  10222. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  10223. cclocks = 1;
  10224. return cclocks;
  10225. }
  10226. /*
  10227. * Convert a cclock count to nanoseconds. Not matter how slow
  10228. * the cclock, a non-zero cclocks will always have a non-zero result.
  10229. */
  10230. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  10231. {
  10232. u32 ns;
  10233. if (dd->icode == ICODE_FPGA_EMULATION)
  10234. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  10235. else /* simulation pretends to be ASIC */
  10236. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  10237. if (cclocks && !ns)
  10238. ns = 1;
  10239. return ns;
  10240. }
  10241. /*
  10242. * Dynamically adjust the receive interrupt timeout for a context based on
  10243. * incoming packet rate.
  10244. *
  10245. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  10246. */
  10247. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  10248. {
  10249. struct hfi1_devdata *dd = rcd->dd;
  10250. u32 timeout = rcd->rcvavail_timeout;
  10251. /*
  10252. * This algorithm doubles or halves the timeout depending on whether
  10253. * the number of packets received in this interrupt were less than or
  10254. * greater equal the interrupt count.
  10255. *
  10256. * The calculations below do not allow a steady state to be achieved.
  10257. * Only at the endpoints it is possible to have an unchanging
  10258. * timeout.
  10259. */
  10260. if (npkts < rcv_intr_count) {
  10261. /*
  10262. * Not enough packets arrived before the timeout, adjust
  10263. * timeout downward.
  10264. */
  10265. if (timeout < 2) /* already at minimum? */
  10266. return;
  10267. timeout >>= 1;
  10268. } else {
  10269. /*
  10270. * More than enough packets arrived before the timeout, adjust
  10271. * timeout upward.
  10272. */
  10273. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10274. return;
  10275. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10276. }
  10277. rcd->rcvavail_timeout = timeout;
  10278. /*
  10279. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10280. * been verified to be in range
  10281. */
  10282. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10283. (u64)timeout <<
  10284. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10285. }
  10286. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10287. u32 intr_adjust, u32 npkts)
  10288. {
  10289. struct hfi1_devdata *dd = rcd->dd;
  10290. u64 reg;
  10291. u32 ctxt = rcd->ctxt;
  10292. /*
  10293. * Need to write timeout register before updating RcvHdrHead to ensure
  10294. * that a new value is used when the HW decides to restart counting.
  10295. */
  10296. if (intr_adjust)
  10297. adjust_rcv_timeout(rcd, npkts);
  10298. if (updegr) {
  10299. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10300. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10301. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10302. }
  10303. mmiowb();
  10304. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10305. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10306. << RCV_HDR_HEAD_HEAD_SHIFT);
  10307. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10308. mmiowb();
  10309. }
  10310. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10311. {
  10312. u32 head, tail;
  10313. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10314. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10315. if (rcd->rcvhdrtail_kvaddr)
  10316. tail = get_rcvhdrtail(rcd);
  10317. else
  10318. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10319. return head == tail;
  10320. }
  10321. /*
  10322. * Context Control and Receive Array encoding for buffer size:
  10323. * 0x0 invalid
  10324. * 0x1 4 KB
  10325. * 0x2 8 KB
  10326. * 0x3 16 KB
  10327. * 0x4 32 KB
  10328. * 0x5 64 KB
  10329. * 0x6 128 KB
  10330. * 0x7 256 KB
  10331. * 0x8 512 KB (Receive Array only)
  10332. * 0x9 1 MB (Receive Array only)
  10333. * 0xa 2 MB (Receive Array only)
  10334. *
  10335. * 0xB-0xF - reserved (Receive Array only)
  10336. *
  10337. *
  10338. * This routine assumes that the value has already been sanity checked.
  10339. */
  10340. static u32 encoded_size(u32 size)
  10341. {
  10342. switch (size) {
  10343. case 4 * 1024: return 0x1;
  10344. case 8 * 1024: return 0x2;
  10345. case 16 * 1024: return 0x3;
  10346. case 32 * 1024: return 0x4;
  10347. case 64 * 1024: return 0x5;
  10348. case 128 * 1024: return 0x6;
  10349. case 256 * 1024: return 0x7;
  10350. case 512 * 1024: return 0x8;
  10351. case 1 * 1024 * 1024: return 0x9;
  10352. case 2 * 1024 * 1024: return 0xa;
  10353. }
  10354. return 0x1; /* if invalid, go with the minimum size */
  10355. }
  10356. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
  10357. struct hfi1_ctxtdata *rcd)
  10358. {
  10359. u64 rcvctrl, reg;
  10360. int did_enable = 0;
  10361. u16 ctxt;
  10362. if (!rcd)
  10363. return;
  10364. ctxt = rcd->ctxt;
  10365. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10366. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10367. /* if the context already enabled, don't do the extra steps */
  10368. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10369. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10370. /* reset the tail and hdr addresses, and sequence count */
  10371. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10372. rcd->rcvhdrq_dma);
  10373. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  10374. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10375. rcd->rcvhdrqtailaddr_dma);
  10376. rcd->seq_cnt = 1;
  10377. /* reset the cached receive header queue head value */
  10378. rcd->head = 0;
  10379. /*
  10380. * Zero the receive header queue so we don't get false
  10381. * positives when checking the sequence number. The
  10382. * sequence numbers could land exactly on the same spot.
  10383. * E.g. a rcd restart before the receive header wrapped.
  10384. */
  10385. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  10386. /* starting timeout */
  10387. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10388. /* enable the context */
  10389. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10390. /* clean the egr buffer size first */
  10391. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10392. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10393. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10394. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10395. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10396. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10397. did_enable = 1;
  10398. /* zero RcvEgrIndexHead */
  10399. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10400. /* set eager count and base index */
  10401. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10402. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10403. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10404. (((rcd->eager_base >> RCV_SHIFT)
  10405. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10406. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10407. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10408. /*
  10409. * Set TID (expected) count and base index.
  10410. * rcd->expected_count is set to individual RcvArray entries,
  10411. * not pairs, and the CSR takes a pair-count in groups of
  10412. * four, so divide by 8.
  10413. */
  10414. reg = (((rcd->expected_count >> RCV_SHIFT)
  10415. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10416. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10417. (((rcd->expected_base >> RCV_SHIFT)
  10418. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10419. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10420. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10421. if (ctxt == HFI1_CTRL_CTXT)
  10422. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10423. }
  10424. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10425. write_csr(dd, RCV_VL15, 0);
  10426. /*
  10427. * When receive context is being disabled turn on tail
  10428. * update with a dummy tail address and then disable
  10429. * receive context.
  10430. */
  10431. if (dd->rcvhdrtail_dummy_dma) {
  10432. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10433. dd->rcvhdrtail_dummy_dma);
  10434. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10435. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10436. }
  10437. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10438. }
  10439. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10440. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10441. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10442. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10443. if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
  10444. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10445. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10446. /* See comment on RcvCtxtCtrl.TailUpd above */
  10447. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10448. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10449. }
  10450. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10451. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10452. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10453. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10454. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10455. /*
  10456. * In one-packet-per-eager mode, the size comes from
  10457. * the RcvArray entry.
  10458. */
  10459. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10460. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10461. }
  10462. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10463. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10464. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10465. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10466. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10467. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10468. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10469. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10470. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10471. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10472. rcd->rcvctrl = rcvctrl;
  10473. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10474. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
  10475. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10476. if (did_enable &&
  10477. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10478. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10479. if (reg != 0) {
  10480. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10481. ctxt, reg);
  10482. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10483. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10484. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10485. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10486. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10487. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10488. ctxt, reg, reg == 0 ? "not" : "still");
  10489. }
  10490. }
  10491. if (did_enable) {
  10492. /*
  10493. * The interrupt timeout and count must be set after
  10494. * the context is enabled to take effect.
  10495. */
  10496. /* set interrupt timeout */
  10497. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10498. (u64)rcd->rcvavail_timeout <<
  10499. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10500. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10501. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10502. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10503. }
  10504. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10505. /*
  10506. * If the context has been disabled and the Tail Update has
  10507. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10508. * so it doesn't contain an address that is invalid.
  10509. */
  10510. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10511. dd->rcvhdrtail_dummy_dma);
  10512. }
  10513. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10514. {
  10515. int ret;
  10516. u64 val = 0;
  10517. if (namep) {
  10518. ret = dd->cntrnameslen;
  10519. *namep = dd->cntrnames;
  10520. } else {
  10521. const struct cntr_entry *entry;
  10522. int i, j;
  10523. ret = (dd->ndevcntrs) * sizeof(u64);
  10524. /* Get the start of the block of counters */
  10525. *cntrp = dd->cntrs;
  10526. /*
  10527. * Now go and fill in each counter in the block.
  10528. */
  10529. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10530. entry = &dev_cntrs[i];
  10531. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10532. if (entry->flags & CNTR_DISABLED) {
  10533. /* Nothing */
  10534. hfi1_cdbg(CNTR, "\tDisabled\n");
  10535. } else {
  10536. if (entry->flags & CNTR_VL) {
  10537. hfi1_cdbg(CNTR, "\tPer VL\n");
  10538. for (j = 0; j < C_VL_COUNT; j++) {
  10539. val = entry->rw_cntr(entry,
  10540. dd, j,
  10541. CNTR_MODE_R,
  10542. 0);
  10543. hfi1_cdbg(
  10544. CNTR,
  10545. "\t\tRead 0x%llx for %d\n",
  10546. val, j);
  10547. dd->cntrs[entry->offset + j] =
  10548. val;
  10549. }
  10550. } else if (entry->flags & CNTR_SDMA) {
  10551. hfi1_cdbg(CNTR,
  10552. "\t Per SDMA Engine\n");
  10553. for (j = 0; j < dd->chip_sdma_engines;
  10554. j++) {
  10555. val =
  10556. entry->rw_cntr(entry, dd, j,
  10557. CNTR_MODE_R, 0);
  10558. hfi1_cdbg(CNTR,
  10559. "\t\tRead 0x%llx for %d\n",
  10560. val, j);
  10561. dd->cntrs[entry->offset + j] =
  10562. val;
  10563. }
  10564. } else {
  10565. val = entry->rw_cntr(entry, dd,
  10566. CNTR_INVALID_VL,
  10567. CNTR_MODE_R, 0);
  10568. dd->cntrs[entry->offset] = val;
  10569. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10570. }
  10571. }
  10572. }
  10573. }
  10574. return ret;
  10575. }
  10576. /*
  10577. * Used by sysfs to create files for hfi stats to read
  10578. */
  10579. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10580. {
  10581. int ret;
  10582. u64 val = 0;
  10583. if (namep) {
  10584. ret = ppd->dd->portcntrnameslen;
  10585. *namep = ppd->dd->portcntrnames;
  10586. } else {
  10587. const struct cntr_entry *entry;
  10588. int i, j;
  10589. ret = ppd->dd->nportcntrs * sizeof(u64);
  10590. *cntrp = ppd->cntrs;
  10591. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10592. entry = &port_cntrs[i];
  10593. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10594. if (entry->flags & CNTR_DISABLED) {
  10595. /* Nothing */
  10596. hfi1_cdbg(CNTR, "\tDisabled\n");
  10597. continue;
  10598. }
  10599. if (entry->flags & CNTR_VL) {
  10600. hfi1_cdbg(CNTR, "\tPer VL");
  10601. for (j = 0; j < C_VL_COUNT; j++) {
  10602. val = entry->rw_cntr(entry, ppd, j,
  10603. CNTR_MODE_R,
  10604. 0);
  10605. hfi1_cdbg(
  10606. CNTR,
  10607. "\t\tRead 0x%llx for %d",
  10608. val, j);
  10609. ppd->cntrs[entry->offset + j] = val;
  10610. }
  10611. } else {
  10612. val = entry->rw_cntr(entry, ppd,
  10613. CNTR_INVALID_VL,
  10614. CNTR_MODE_R,
  10615. 0);
  10616. ppd->cntrs[entry->offset] = val;
  10617. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10618. }
  10619. }
  10620. }
  10621. return ret;
  10622. }
  10623. static void free_cntrs(struct hfi1_devdata *dd)
  10624. {
  10625. struct hfi1_pportdata *ppd;
  10626. int i;
  10627. if (dd->synth_stats_timer.function)
  10628. del_timer_sync(&dd->synth_stats_timer);
  10629. ppd = (struct hfi1_pportdata *)(dd + 1);
  10630. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10631. kfree(ppd->cntrs);
  10632. kfree(ppd->scntrs);
  10633. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10634. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10635. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10636. ppd->cntrs = NULL;
  10637. ppd->scntrs = NULL;
  10638. ppd->ibport_data.rvp.rc_acks = NULL;
  10639. ppd->ibport_data.rvp.rc_qacks = NULL;
  10640. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10641. }
  10642. kfree(dd->portcntrnames);
  10643. dd->portcntrnames = NULL;
  10644. kfree(dd->cntrs);
  10645. dd->cntrs = NULL;
  10646. kfree(dd->scntrs);
  10647. dd->scntrs = NULL;
  10648. kfree(dd->cntrnames);
  10649. dd->cntrnames = NULL;
  10650. if (dd->update_cntr_wq) {
  10651. destroy_workqueue(dd->update_cntr_wq);
  10652. dd->update_cntr_wq = NULL;
  10653. }
  10654. }
  10655. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10656. u64 *psval, void *context, int vl)
  10657. {
  10658. u64 val;
  10659. u64 sval = *psval;
  10660. if (entry->flags & CNTR_DISABLED) {
  10661. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10662. return 0;
  10663. }
  10664. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10665. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10666. /* If its a synthetic counter there is more work we need to do */
  10667. if (entry->flags & CNTR_SYNTH) {
  10668. if (sval == CNTR_MAX) {
  10669. /* No need to read already saturated */
  10670. return CNTR_MAX;
  10671. }
  10672. if (entry->flags & CNTR_32BIT) {
  10673. /* 32bit counters can wrap multiple times */
  10674. u64 upper = sval >> 32;
  10675. u64 lower = (sval << 32) >> 32;
  10676. if (lower > val) { /* hw wrapped */
  10677. if (upper == CNTR_32BIT_MAX)
  10678. val = CNTR_MAX;
  10679. else
  10680. upper++;
  10681. }
  10682. if (val != CNTR_MAX)
  10683. val = (upper << 32) | val;
  10684. } else {
  10685. /* If we rolled we are saturated */
  10686. if ((val < sval) || (val > CNTR_MAX))
  10687. val = CNTR_MAX;
  10688. }
  10689. }
  10690. *psval = val;
  10691. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10692. return val;
  10693. }
  10694. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10695. struct cntr_entry *entry,
  10696. u64 *psval, void *context, int vl, u64 data)
  10697. {
  10698. u64 val;
  10699. if (entry->flags & CNTR_DISABLED) {
  10700. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10701. return 0;
  10702. }
  10703. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10704. if (entry->flags & CNTR_SYNTH) {
  10705. *psval = data;
  10706. if (entry->flags & CNTR_32BIT) {
  10707. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10708. (data << 32) >> 32);
  10709. val = data; /* return the full 64bit value */
  10710. } else {
  10711. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10712. data);
  10713. }
  10714. } else {
  10715. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10716. }
  10717. *psval = val;
  10718. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10719. return val;
  10720. }
  10721. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10722. {
  10723. struct cntr_entry *entry;
  10724. u64 *sval;
  10725. entry = &dev_cntrs[index];
  10726. sval = dd->scntrs + entry->offset;
  10727. if (vl != CNTR_INVALID_VL)
  10728. sval += vl;
  10729. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10730. }
  10731. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10732. {
  10733. struct cntr_entry *entry;
  10734. u64 *sval;
  10735. entry = &dev_cntrs[index];
  10736. sval = dd->scntrs + entry->offset;
  10737. if (vl != CNTR_INVALID_VL)
  10738. sval += vl;
  10739. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10740. }
  10741. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10742. {
  10743. struct cntr_entry *entry;
  10744. u64 *sval;
  10745. entry = &port_cntrs[index];
  10746. sval = ppd->scntrs + entry->offset;
  10747. if (vl != CNTR_INVALID_VL)
  10748. sval += vl;
  10749. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10750. (index <= C_RCV_HDR_OVF_LAST)) {
  10751. /* We do not want to bother for disabled contexts */
  10752. return 0;
  10753. }
  10754. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10755. }
  10756. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10757. {
  10758. struct cntr_entry *entry;
  10759. u64 *sval;
  10760. entry = &port_cntrs[index];
  10761. sval = ppd->scntrs + entry->offset;
  10762. if (vl != CNTR_INVALID_VL)
  10763. sval += vl;
  10764. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10765. (index <= C_RCV_HDR_OVF_LAST)) {
  10766. /* We do not want to bother for disabled contexts */
  10767. return 0;
  10768. }
  10769. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10770. }
  10771. static void do_update_synth_timer(struct work_struct *work)
  10772. {
  10773. u64 cur_tx;
  10774. u64 cur_rx;
  10775. u64 total_flits;
  10776. u8 update = 0;
  10777. int i, j, vl;
  10778. struct hfi1_pportdata *ppd;
  10779. struct cntr_entry *entry;
  10780. struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
  10781. update_cntr_work);
  10782. /*
  10783. * Rather than keep beating on the CSRs pick a minimal set that we can
  10784. * check to watch for potential roll over. We can do this by looking at
  10785. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10786. * we have to iterate all the counters and update.
  10787. */
  10788. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10789. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10790. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10791. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10792. hfi1_cdbg(
  10793. CNTR,
  10794. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10795. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10796. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10797. /*
  10798. * May not be strictly necessary to update but it won't hurt and
  10799. * simplifies the logic here.
  10800. */
  10801. update = 1;
  10802. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10803. dd->unit);
  10804. } else {
  10805. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10806. hfi1_cdbg(CNTR,
  10807. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10808. total_flits, (u64)CNTR_32BIT_MAX);
  10809. if (total_flits >= CNTR_32BIT_MAX) {
  10810. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10811. dd->unit);
  10812. update = 1;
  10813. }
  10814. }
  10815. if (update) {
  10816. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10817. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10818. entry = &dev_cntrs[i];
  10819. if (entry->flags & CNTR_VL) {
  10820. for (vl = 0; vl < C_VL_COUNT; vl++)
  10821. read_dev_cntr(dd, i, vl);
  10822. } else {
  10823. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10824. }
  10825. }
  10826. ppd = (struct hfi1_pportdata *)(dd + 1);
  10827. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10828. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10829. entry = &port_cntrs[j];
  10830. if (entry->flags & CNTR_VL) {
  10831. for (vl = 0; vl < C_VL_COUNT; vl++)
  10832. read_port_cntr(ppd, j, vl);
  10833. } else {
  10834. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10835. }
  10836. }
  10837. }
  10838. /*
  10839. * We want the value in the register. The goal is to keep track
  10840. * of the number of "ticks" not the counter value. In other
  10841. * words if the register rolls we want to notice it and go ahead
  10842. * and force an update.
  10843. */
  10844. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10845. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10846. CNTR_MODE_R, 0);
  10847. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10848. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10849. CNTR_MODE_R, 0);
  10850. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10851. dd->unit, dd->last_tx, dd->last_rx);
  10852. } else {
  10853. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10854. }
  10855. }
  10856. static void update_synth_timer(struct timer_list *t)
  10857. {
  10858. struct hfi1_devdata *dd = from_timer(dd, t, synth_stats_timer);
  10859. queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
  10860. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10861. }
  10862. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10863. static int init_cntrs(struct hfi1_devdata *dd)
  10864. {
  10865. int i, rcv_ctxts, j;
  10866. size_t sz;
  10867. char *p;
  10868. char name[C_MAX_NAME];
  10869. struct hfi1_pportdata *ppd;
  10870. const char *bit_type_32 = ",32";
  10871. const int bit_type_32_sz = strlen(bit_type_32);
  10872. /* set up the stats timer; the add_timer is done at the end */
  10873. timer_setup(&dd->synth_stats_timer, update_synth_timer, 0);
  10874. /***********************/
  10875. /* per device counters */
  10876. /***********************/
  10877. /* size names and determine how many we have*/
  10878. dd->ndevcntrs = 0;
  10879. sz = 0;
  10880. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10881. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10882. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10883. continue;
  10884. }
  10885. if (dev_cntrs[i].flags & CNTR_VL) {
  10886. dev_cntrs[i].offset = dd->ndevcntrs;
  10887. for (j = 0; j < C_VL_COUNT; j++) {
  10888. snprintf(name, C_MAX_NAME, "%s%d",
  10889. dev_cntrs[i].name, vl_from_idx(j));
  10890. sz += strlen(name);
  10891. /* Add ",32" for 32-bit counters */
  10892. if (dev_cntrs[i].flags & CNTR_32BIT)
  10893. sz += bit_type_32_sz;
  10894. sz++;
  10895. dd->ndevcntrs++;
  10896. }
  10897. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10898. dev_cntrs[i].offset = dd->ndevcntrs;
  10899. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10900. snprintf(name, C_MAX_NAME, "%s%d",
  10901. dev_cntrs[i].name, j);
  10902. sz += strlen(name);
  10903. /* Add ",32" for 32-bit counters */
  10904. if (dev_cntrs[i].flags & CNTR_32BIT)
  10905. sz += bit_type_32_sz;
  10906. sz++;
  10907. dd->ndevcntrs++;
  10908. }
  10909. } else {
  10910. /* +1 for newline. */
  10911. sz += strlen(dev_cntrs[i].name) + 1;
  10912. /* Add ",32" for 32-bit counters */
  10913. if (dev_cntrs[i].flags & CNTR_32BIT)
  10914. sz += bit_type_32_sz;
  10915. dev_cntrs[i].offset = dd->ndevcntrs;
  10916. dd->ndevcntrs++;
  10917. }
  10918. }
  10919. /* allocate space for the counter values */
  10920. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10921. if (!dd->cntrs)
  10922. goto bail;
  10923. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10924. if (!dd->scntrs)
  10925. goto bail;
  10926. /* allocate space for the counter names */
  10927. dd->cntrnameslen = sz;
  10928. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10929. if (!dd->cntrnames)
  10930. goto bail;
  10931. /* fill in the names */
  10932. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10933. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10934. /* Nothing */
  10935. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10936. for (j = 0; j < C_VL_COUNT; j++) {
  10937. snprintf(name, C_MAX_NAME, "%s%d",
  10938. dev_cntrs[i].name,
  10939. vl_from_idx(j));
  10940. memcpy(p, name, strlen(name));
  10941. p += strlen(name);
  10942. /* Counter is 32 bits */
  10943. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10944. memcpy(p, bit_type_32, bit_type_32_sz);
  10945. p += bit_type_32_sz;
  10946. }
  10947. *p++ = '\n';
  10948. }
  10949. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10950. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10951. snprintf(name, C_MAX_NAME, "%s%d",
  10952. dev_cntrs[i].name, j);
  10953. memcpy(p, name, strlen(name));
  10954. p += strlen(name);
  10955. /* Counter is 32 bits */
  10956. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10957. memcpy(p, bit_type_32, bit_type_32_sz);
  10958. p += bit_type_32_sz;
  10959. }
  10960. *p++ = '\n';
  10961. }
  10962. } else {
  10963. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10964. p += strlen(dev_cntrs[i].name);
  10965. /* Counter is 32 bits */
  10966. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10967. memcpy(p, bit_type_32, bit_type_32_sz);
  10968. p += bit_type_32_sz;
  10969. }
  10970. *p++ = '\n';
  10971. }
  10972. }
  10973. /*********************/
  10974. /* per port counters */
  10975. /*********************/
  10976. /*
  10977. * Go through the counters for the overflows and disable the ones we
  10978. * don't need. This varies based on platform so we need to do it
  10979. * dynamically here.
  10980. */
  10981. rcv_ctxts = dd->num_rcv_contexts;
  10982. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  10983. i <= C_RCV_HDR_OVF_LAST; i++) {
  10984. port_cntrs[i].flags |= CNTR_DISABLED;
  10985. }
  10986. /* size port counter names and determine how many we have*/
  10987. sz = 0;
  10988. dd->nportcntrs = 0;
  10989. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10990. if (port_cntrs[i].flags & CNTR_DISABLED) {
  10991. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  10992. continue;
  10993. }
  10994. if (port_cntrs[i].flags & CNTR_VL) {
  10995. port_cntrs[i].offset = dd->nportcntrs;
  10996. for (j = 0; j < C_VL_COUNT; j++) {
  10997. snprintf(name, C_MAX_NAME, "%s%d",
  10998. port_cntrs[i].name, vl_from_idx(j));
  10999. sz += strlen(name);
  11000. /* Add ",32" for 32-bit counters */
  11001. if (port_cntrs[i].flags & CNTR_32BIT)
  11002. sz += bit_type_32_sz;
  11003. sz++;
  11004. dd->nportcntrs++;
  11005. }
  11006. } else {
  11007. /* +1 for newline */
  11008. sz += strlen(port_cntrs[i].name) + 1;
  11009. /* Add ",32" for 32-bit counters */
  11010. if (port_cntrs[i].flags & CNTR_32BIT)
  11011. sz += bit_type_32_sz;
  11012. port_cntrs[i].offset = dd->nportcntrs;
  11013. dd->nportcntrs++;
  11014. }
  11015. }
  11016. /* allocate space for the counter names */
  11017. dd->portcntrnameslen = sz;
  11018. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  11019. if (!dd->portcntrnames)
  11020. goto bail;
  11021. /* fill in port cntr names */
  11022. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  11023. if (port_cntrs[i].flags & CNTR_DISABLED)
  11024. continue;
  11025. if (port_cntrs[i].flags & CNTR_VL) {
  11026. for (j = 0; j < C_VL_COUNT; j++) {
  11027. snprintf(name, C_MAX_NAME, "%s%d",
  11028. port_cntrs[i].name, vl_from_idx(j));
  11029. memcpy(p, name, strlen(name));
  11030. p += strlen(name);
  11031. /* Counter is 32 bits */
  11032. if (port_cntrs[i].flags & CNTR_32BIT) {
  11033. memcpy(p, bit_type_32, bit_type_32_sz);
  11034. p += bit_type_32_sz;
  11035. }
  11036. *p++ = '\n';
  11037. }
  11038. } else {
  11039. memcpy(p, port_cntrs[i].name,
  11040. strlen(port_cntrs[i].name));
  11041. p += strlen(port_cntrs[i].name);
  11042. /* Counter is 32 bits */
  11043. if (port_cntrs[i].flags & CNTR_32BIT) {
  11044. memcpy(p, bit_type_32, bit_type_32_sz);
  11045. p += bit_type_32_sz;
  11046. }
  11047. *p++ = '\n';
  11048. }
  11049. }
  11050. /* allocate per port storage for counter values */
  11051. ppd = (struct hfi1_pportdata *)(dd + 1);
  11052. for (i = 0; i < dd->num_pports; i++, ppd++) {
  11053. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11054. if (!ppd->cntrs)
  11055. goto bail;
  11056. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11057. if (!ppd->scntrs)
  11058. goto bail;
  11059. }
  11060. /* CPU counters need to be allocated and zeroed */
  11061. if (init_cpu_counters(dd))
  11062. goto bail;
  11063. dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
  11064. WQ_MEM_RECLAIM, dd->unit);
  11065. if (!dd->update_cntr_wq)
  11066. goto bail;
  11067. INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
  11068. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  11069. return 0;
  11070. bail:
  11071. free_cntrs(dd);
  11072. return -ENOMEM;
  11073. }
  11074. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  11075. {
  11076. switch (chip_lstate) {
  11077. default:
  11078. dd_dev_err(dd,
  11079. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  11080. chip_lstate);
  11081. /* fall through */
  11082. case LSTATE_DOWN:
  11083. return IB_PORT_DOWN;
  11084. case LSTATE_INIT:
  11085. return IB_PORT_INIT;
  11086. case LSTATE_ARMED:
  11087. return IB_PORT_ARMED;
  11088. case LSTATE_ACTIVE:
  11089. return IB_PORT_ACTIVE;
  11090. }
  11091. }
  11092. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  11093. {
  11094. /* look at the HFI meta-states only */
  11095. switch (chip_pstate & 0xf0) {
  11096. default:
  11097. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  11098. chip_pstate);
  11099. /* fall through */
  11100. case PLS_DISABLED:
  11101. return IB_PORTPHYSSTATE_DISABLED;
  11102. case PLS_OFFLINE:
  11103. return OPA_PORTPHYSSTATE_OFFLINE;
  11104. case PLS_POLLING:
  11105. return IB_PORTPHYSSTATE_POLLING;
  11106. case PLS_CONFIGPHY:
  11107. return IB_PORTPHYSSTATE_TRAINING;
  11108. case PLS_LINKUP:
  11109. return IB_PORTPHYSSTATE_LINKUP;
  11110. case PLS_PHYTEST:
  11111. return IB_PORTPHYSSTATE_PHY_TEST;
  11112. }
  11113. }
  11114. /* return the OPA port logical state name */
  11115. const char *opa_lstate_name(u32 lstate)
  11116. {
  11117. static const char * const port_logical_names[] = {
  11118. "PORT_NOP",
  11119. "PORT_DOWN",
  11120. "PORT_INIT",
  11121. "PORT_ARMED",
  11122. "PORT_ACTIVE",
  11123. "PORT_ACTIVE_DEFER",
  11124. };
  11125. if (lstate < ARRAY_SIZE(port_logical_names))
  11126. return port_logical_names[lstate];
  11127. return "unknown";
  11128. }
  11129. /* return the OPA port physical state name */
  11130. const char *opa_pstate_name(u32 pstate)
  11131. {
  11132. static const char * const port_physical_names[] = {
  11133. "PHYS_NOP",
  11134. "reserved1",
  11135. "PHYS_POLL",
  11136. "PHYS_DISABLED",
  11137. "PHYS_TRAINING",
  11138. "PHYS_LINKUP",
  11139. "PHYS_LINK_ERR_RECOVER",
  11140. "PHYS_PHY_TEST",
  11141. "reserved8",
  11142. "PHYS_OFFLINE",
  11143. "PHYS_GANGED",
  11144. "PHYS_TEST",
  11145. };
  11146. if (pstate < ARRAY_SIZE(port_physical_names))
  11147. return port_physical_names[pstate];
  11148. return "unknown";
  11149. }
  11150. /**
  11151. * update_statusp - Update userspace status flag
  11152. * @ppd: Port data structure
  11153. * @state: port state information
  11154. *
  11155. * Actual port status is determined by the host_link_state value
  11156. * in the ppd.
  11157. *
  11158. * host_link_state MUST be updated before updating the user space
  11159. * statusp.
  11160. */
  11161. static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
  11162. {
  11163. /*
  11164. * Set port status flags in the page mapped into userspace
  11165. * memory. Do it here to ensure a reliable state - this is
  11166. * the only function called by all state handling code.
  11167. * Always set the flags due to the fact that the cache value
  11168. * might have been changed explicitly outside of this
  11169. * function.
  11170. */
  11171. if (ppd->statusp) {
  11172. switch (state) {
  11173. case IB_PORT_DOWN:
  11174. case IB_PORT_INIT:
  11175. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  11176. HFI1_STATUS_IB_READY);
  11177. break;
  11178. case IB_PORT_ARMED:
  11179. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  11180. break;
  11181. case IB_PORT_ACTIVE:
  11182. *ppd->statusp |= HFI1_STATUS_IB_READY;
  11183. break;
  11184. }
  11185. }
  11186. dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
  11187. opa_lstate_name(state), state);
  11188. }
  11189. /**
  11190. * wait_logical_linkstate - wait for an IB link state change to occur
  11191. * @ppd: port device
  11192. * @state: the state to wait for
  11193. * @msecs: the number of milliseconds to wait
  11194. *
  11195. * Wait up to msecs milliseconds for IB link state change to occur.
  11196. * For now, take the easy polling route.
  11197. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11198. */
  11199. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11200. int msecs)
  11201. {
  11202. unsigned long timeout;
  11203. u32 new_state;
  11204. timeout = jiffies + msecs_to_jiffies(msecs);
  11205. while (1) {
  11206. new_state = chip_to_opa_lstate(ppd->dd,
  11207. read_logical_state(ppd->dd));
  11208. if (new_state == state)
  11209. break;
  11210. if (time_after(jiffies, timeout)) {
  11211. dd_dev_err(ppd->dd,
  11212. "timeout waiting for link state 0x%x\n",
  11213. state);
  11214. return -ETIMEDOUT;
  11215. }
  11216. msleep(20);
  11217. }
  11218. return 0;
  11219. }
  11220. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state)
  11221. {
  11222. u32 ib_pstate = chip_to_opa_pstate(ppd->dd, state);
  11223. dd_dev_info(ppd->dd,
  11224. "physical state changed to %s (0x%x), phy 0x%x\n",
  11225. opa_pstate_name(ib_pstate), ib_pstate, state);
  11226. }
  11227. /*
  11228. * Read the physical hardware link state and check if it matches host
  11229. * drivers anticipated state.
  11230. */
  11231. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state)
  11232. {
  11233. u32 read_state = read_physical_state(ppd->dd);
  11234. if (read_state == state) {
  11235. log_state_transition(ppd, state);
  11236. } else {
  11237. dd_dev_err(ppd->dd,
  11238. "anticipated phy link state 0x%x, read 0x%x\n",
  11239. state, read_state);
  11240. }
  11241. }
  11242. /*
  11243. * wait_physical_linkstate - wait for an physical link state change to occur
  11244. * @ppd: port device
  11245. * @state: the state to wait for
  11246. * @msecs: the number of milliseconds to wait
  11247. *
  11248. * Wait up to msecs milliseconds for physical link state change to occur.
  11249. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11250. */
  11251. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11252. int msecs)
  11253. {
  11254. u32 read_state;
  11255. unsigned long timeout;
  11256. timeout = jiffies + msecs_to_jiffies(msecs);
  11257. while (1) {
  11258. read_state = read_physical_state(ppd->dd);
  11259. if (read_state == state)
  11260. break;
  11261. if (time_after(jiffies, timeout)) {
  11262. dd_dev_err(ppd->dd,
  11263. "timeout waiting for phy link state 0x%x\n",
  11264. state);
  11265. return -ETIMEDOUT;
  11266. }
  11267. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11268. }
  11269. log_state_transition(ppd, state);
  11270. return 0;
  11271. }
  11272. /*
  11273. * wait_phys_link_offline_quiet_substates - wait for any offline substate
  11274. * @ppd: port device
  11275. * @msecs: the number of milliseconds to wait
  11276. *
  11277. * Wait up to msecs milliseconds for any offline physical link
  11278. * state change to occur.
  11279. * Returns 0 if at least one state is reached, otherwise -ETIMEDOUT.
  11280. */
  11281. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  11282. int msecs)
  11283. {
  11284. u32 read_state;
  11285. unsigned long timeout;
  11286. timeout = jiffies + msecs_to_jiffies(msecs);
  11287. while (1) {
  11288. read_state = read_physical_state(ppd->dd);
  11289. if ((read_state & 0xF0) == PLS_OFFLINE)
  11290. break;
  11291. if (time_after(jiffies, timeout)) {
  11292. dd_dev_err(ppd->dd,
  11293. "timeout waiting for phy link offline.quiet substates. Read state 0x%x, %dms\n",
  11294. read_state, msecs);
  11295. return -ETIMEDOUT;
  11296. }
  11297. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11298. }
  11299. log_state_transition(ppd, read_state);
  11300. return read_state;
  11301. }
  11302. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  11303. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11304. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  11305. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11306. void hfi1_init_ctxt(struct send_context *sc)
  11307. {
  11308. if (sc) {
  11309. struct hfi1_devdata *dd = sc->dd;
  11310. u64 reg;
  11311. u8 set = (sc->type == SC_USER ?
  11312. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  11313. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  11314. reg = read_kctxt_csr(dd, sc->hw_context,
  11315. SEND_CTXT_CHECK_ENABLE);
  11316. if (set)
  11317. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  11318. else
  11319. SET_STATIC_RATE_CONTROL_SMASK(reg);
  11320. write_kctxt_csr(dd, sc->hw_context,
  11321. SEND_CTXT_CHECK_ENABLE, reg);
  11322. }
  11323. }
  11324. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  11325. {
  11326. int ret = 0;
  11327. u64 reg;
  11328. if (dd->icode != ICODE_RTL_SILICON) {
  11329. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  11330. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  11331. __func__);
  11332. return -EINVAL;
  11333. }
  11334. reg = read_csr(dd, ASIC_STS_THERM);
  11335. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  11336. ASIC_STS_THERM_CURR_TEMP_MASK);
  11337. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  11338. ASIC_STS_THERM_LO_TEMP_MASK);
  11339. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11340. ASIC_STS_THERM_HI_TEMP_MASK);
  11341. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11342. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11343. /* triggers is a 3-bit value - 1 bit per trigger. */
  11344. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11345. return ret;
  11346. }
  11347. /**
  11348. * get_int_mask - get 64 bit int mask
  11349. * @dd - the devdata
  11350. * @i - the csr (relative to CCE_INT_MASK)
  11351. *
  11352. * Returns the mask with the urgent interrupt mask
  11353. * bit clear for kernel receive contexts.
  11354. */
  11355. static u64 get_int_mask(struct hfi1_devdata *dd, u32 i)
  11356. {
  11357. u64 mask = U64_MAX; /* default to no change */
  11358. if (i >= (IS_RCVURGENT_START / 64) && i < (IS_RCVURGENT_END / 64)) {
  11359. int j = (i - (IS_RCVURGENT_START / 64)) * 64;
  11360. int k = !j ? IS_RCVURGENT_START % 64 : 0;
  11361. if (j)
  11362. j -= IS_RCVURGENT_START % 64;
  11363. /* j = 0..dd->first_dyn_alloc_ctxt - 1,k = 0..63 */
  11364. for (; j < dd->first_dyn_alloc_ctxt && k < 64; j++, k++)
  11365. /* convert to bit in mask and clear */
  11366. mask &= ~BIT_ULL(k);
  11367. }
  11368. return mask;
  11369. }
  11370. /* ========================================================================= */
  11371. /*
  11372. * Enable/disable chip from delivering interrupts.
  11373. */
  11374. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11375. {
  11376. int i;
  11377. /*
  11378. * In HFI, the mask needs to be 1 to allow interrupts.
  11379. */
  11380. if (enable) {
  11381. /* enable all interrupts but urgent on kernel contexts */
  11382. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11383. u64 mask = get_int_mask(dd, i);
  11384. write_csr(dd, CCE_INT_MASK + (8 * i), mask);
  11385. }
  11386. init_qsfp_int(dd);
  11387. } else {
  11388. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11389. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11390. }
  11391. }
  11392. /*
  11393. * Clear all interrupt sources on the chip.
  11394. */
  11395. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11396. {
  11397. int i;
  11398. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11399. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11400. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11401. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11402. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11403. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11404. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11405. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11406. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11407. for (i = 0; i < dd->chip_send_contexts; i++)
  11408. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11409. for (i = 0; i < dd->chip_sdma_engines; i++)
  11410. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11411. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11412. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11413. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11414. }
  11415. /* Move to pcie.c? */
  11416. static void disable_intx(struct pci_dev *pdev)
  11417. {
  11418. pci_intx(pdev, 0);
  11419. }
  11420. /**
  11421. * hfi1_clean_up_interrupts() - Free all IRQ resources
  11422. * @dd: valid device data data structure
  11423. *
  11424. * Free the MSI or INTx IRQs and assoicated PCI resources,
  11425. * if they have been allocated.
  11426. */
  11427. void hfi1_clean_up_interrupts(struct hfi1_devdata *dd)
  11428. {
  11429. int i;
  11430. /* remove irqs - must happen before disabling/turning off */
  11431. if (dd->num_msix_entries) {
  11432. /* MSI-X */
  11433. struct hfi1_msix_entry *me = dd->msix_entries;
  11434. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11435. if (!me->arg) /* => no irq, no affinity */
  11436. continue;
  11437. hfi1_put_irq_affinity(dd, me);
  11438. pci_free_irq(dd->pcidev, i, me->arg);
  11439. }
  11440. /* clean structures */
  11441. kfree(dd->msix_entries);
  11442. dd->msix_entries = NULL;
  11443. dd->num_msix_entries = 0;
  11444. } else {
  11445. /* INTx */
  11446. if (dd->requested_intx_irq) {
  11447. pci_free_irq(dd->pcidev, 0, dd);
  11448. dd->requested_intx_irq = 0;
  11449. }
  11450. disable_intx(dd->pcidev);
  11451. }
  11452. pci_free_irq_vectors(dd->pcidev);
  11453. }
  11454. /*
  11455. * Remap the interrupt source from the general handler to the given MSI-X
  11456. * interrupt.
  11457. */
  11458. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11459. {
  11460. u64 reg;
  11461. int m, n;
  11462. /* clear from the handled mask of the general interrupt */
  11463. m = isrc / 64;
  11464. n = isrc % 64;
  11465. if (likely(m < CCE_NUM_INT_CSRS)) {
  11466. dd->gi_mask[m] &= ~((u64)1 << n);
  11467. } else {
  11468. dd_dev_err(dd, "remap interrupt err\n");
  11469. return;
  11470. }
  11471. /* direct the chip source to the given MSI-X interrupt */
  11472. m = isrc / 8;
  11473. n = isrc % 8;
  11474. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11475. reg &= ~((u64)0xff << (8 * n));
  11476. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11477. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11478. }
  11479. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11480. int engine, int msix_intr)
  11481. {
  11482. /*
  11483. * SDMA engine interrupt sources grouped by type, rather than
  11484. * engine. Per-engine interrupts are as follows:
  11485. * SDMA
  11486. * SDMAProgress
  11487. * SDMAIdle
  11488. */
  11489. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11490. msix_intr);
  11491. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11492. msix_intr);
  11493. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11494. msix_intr);
  11495. }
  11496. static int request_intx_irq(struct hfi1_devdata *dd)
  11497. {
  11498. int ret;
  11499. ret = pci_request_irq(dd->pcidev, 0, general_interrupt, NULL, dd,
  11500. DRIVER_NAME "_%d", dd->unit);
  11501. if (ret)
  11502. dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
  11503. ret);
  11504. else
  11505. dd->requested_intx_irq = 1;
  11506. return ret;
  11507. }
  11508. static int request_msix_irqs(struct hfi1_devdata *dd)
  11509. {
  11510. int first_general, last_general;
  11511. int first_sdma, last_sdma;
  11512. int first_rx, last_rx;
  11513. int i, ret = 0;
  11514. /* calculate the ranges we are going to use */
  11515. first_general = 0;
  11516. last_general = first_general + 1;
  11517. first_sdma = last_general;
  11518. last_sdma = first_sdma + dd->num_sdma;
  11519. first_rx = last_sdma;
  11520. last_rx = first_rx + dd->n_krcv_queues + dd->num_vnic_contexts;
  11521. /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
  11522. dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
  11523. /*
  11524. * Sanity check - the code expects all SDMA chip source
  11525. * interrupts to be in the same CSR, starting at bit 0. Verify
  11526. * that this is true by checking the bit location of the start.
  11527. */
  11528. BUILD_BUG_ON(IS_SDMA_START % 64);
  11529. for (i = 0; i < dd->num_msix_entries; i++) {
  11530. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11531. const char *err_info;
  11532. irq_handler_t handler;
  11533. irq_handler_t thread = NULL;
  11534. void *arg = NULL;
  11535. int idx;
  11536. struct hfi1_ctxtdata *rcd = NULL;
  11537. struct sdma_engine *sde = NULL;
  11538. char name[MAX_NAME_SIZE];
  11539. /* obtain the arguments to pci_request_irq */
  11540. if (first_general <= i && i < last_general) {
  11541. idx = i - first_general;
  11542. handler = general_interrupt;
  11543. arg = dd;
  11544. snprintf(name, sizeof(name),
  11545. DRIVER_NAME "_%d", dd->unit);
  11546. err_info = "general";
  11547. me->type = IRQ_GENERAL;
  11548. } else if (first_sdma <= i && i < last_sdma) {
  11549. idx = i - first_sdma;
  11550. sde = &dd->per_sdma[idx];
  11551. handler = sdma_interrupt;
  11552. arg = sde;
  11553. snprintf(name, sizeof(name),
  11554. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11555. err_info = "sdma";
  11556. remap_sdma_interrupts(dd, idx, i);
  11557. me->type = IRQ_SDMA;
  11558. } else if (first_rx <= i && i < last_rx) {
  11559. idx = i - first_rx;
  11560. rcd = hfi1_rcd_get_by_index_safe(dd, idx);
  11561. if (rcd) {
  11562. /*
  11563. * Set the interrupt register and mask for this
  11564. * context's interrupt.
  11565. */
  11566. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11567. rcd->imask = ((u64)1) <<
  11568. ((IS_RCVAVAIL_START + idx) % 64);
  11569. handler = receive_context_interrupt;
  11570. thread = receive_context_thread;
  11571. arg = rcd;
  11572. snprintf(name, sizeof(name),
  11573. DRIVER_NAME "_%d kctxt%d",
  11574. dd->unit, idx);
  11575. err_info = "receive context";
  11576. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11577. me->type = IRQ_RCVCTXT;
  11578. rcd->msix_intr = i;
  11579. hfi1_rcd_put(rcd);
  11580. }
  11581. } else {
  11582. /* not in our expected range - complain, then
  11583. * ignore it
  11584. */
  11585. dd_dev_err(dd,
  11586. "Unexpected extra MSI-X interrupt %d\n", i);
  11587. continue;
  11588. }
  11589. /* no argument, no interrupt */
  11590. if (!arg)
  11591. continue;
  11592. /* make sure the name is terminated */
  11593. name[sizeof(name) - 1] = 0;
  11594. me->irq = pci_irq_vector(dd->pcidev, i);
  11595. ret = pci_request_irq(dd->pcidev, i, handler, thread, arg,
  11596. name);
  11597. if (ret) {
  11598. dd_dev_err(dd,
  11599. "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
  11600. err_info, me->irq, idx, ret);
  11601. return ret;
  11602. }
  11603. /*
  11604. * assign arg after pci_request_irq call, so it will be
  11605. * cleaned up
  11606. */
  11607. me->arg = arg;
  11608. ret = hfi1_get_irq_affinity(dd, me);
  11609. if (ret)
  11610. dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
  11611. }
  11612. return ret;
  11613. }
  11614. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
  11615. {
  11616. int i;
  11617. if (!dd->num_msix_entries) {
  11618. synchronize_irq(pci_irq_vector(dd->pcidev, 0));
  11619. return;
  11620. }
  11621. for (i = 0; i < dd->vnic.num_ctxt; i++) {
  11622. struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
  11623. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11624. synchronize_irq(me->irq);
  11625. }
  11626. }
  11627. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11628. {
  11629. struct hfi1_devdata *dd = rcd->dd;
  11630. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11631. if (!me->arg) /* => no irq, no affinity */
  11632. return;
  11633. hfi1_put_irq_affinity(dd, me);
  11634. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11635. me->arg = NULL;
  11636. }
  11637. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11638. {
  11639. struct hfi1_devdata *dd = rcd->dd;
  11640. struct hfi1_msix_entry *me;
  11641. int idx = rcd->ctxt;
  11642. void *arg = rcd;
  11643. int ret;
  11644. rcd->msix_intr = dd->vnic.msix_idx++;
  11645. me = &dd->msix_entries[rcd->msix_intr];
  11646. /*
  11647. * Set the interrupt register and mask for this
  11648. * context's interrupt.
  11649. */
  11650. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11651. rcd->imask = ((u64)1) <<
  11652. ((IS_RCVAVAIL_START + idx) % 64);
  11653. me->type = IRQ_RCVCTXT;
  11654. me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
  11655. remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
  11656. ret = pci_request_irq(dd->pcidev, rcd->msix_intr,
  11657. receive_context_interrupt,
  11658. receive_context_thread, arg,
  11659. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11660. if (ret) {
  11661. dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
  11662. me->irq, idx, ret);
  11663. return;
  11664. }
  11665. /*
  11666. * assign arg after pci_request_irq call, so it will be
  11667. * cleaned up
  11668. */
  11669. me->arg = arg;
  11670. ret = hfi1_get_irq_affinity(dd, me);
  11671. if (ret) {
  11672. dd_dev_err(dd,
  11673. "unable to pin IRQ %d\n", ret);
  11674. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11675. }
  11676. }
  11677. /*
  11678. * Set the general handler to accept all interrupts, remap all
  11679. * chip interrupts back to MSI-X 0.
  11680. */
  11681. static void reset_interrupts(struct hfi1_devdata *dd)
  11682. {
  11683. int i;
  11684. /* all interrupts handled by the general handler */
  11685. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11686. dd->gi_mask[i] = ~(u64)0;
  11687. /* all chip interrupts map to MSI-X 0 */
  11688. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11689. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11690. }
  11691. static int set_up_interrupts(struct hfi1_devdata *dd)
  11692. {
  11693. u32 total;
  11694. int ret, request;
  11695. int single_interrupt = 0; /* we expect to have all the interrupts */
  11696. /*
  11697. * Interrupt count:
  11698. * 1 general, "slow path" interrupt (includes the SDMA engines
  11699. * slow source, SDMACleanupDone)
  11700. * N interrupts - one per used SDMA engine
  11701. * M interrupt - one per kernel receive context
  11702. * V interrupt - one for each VNIC context
  11703. */
  11704. total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
  11705. /* ask for MSI-X interrupts */
  11706. request = request_msix(dd, total);
  11707. if (request < 0) {
  11708. ret = request;
  11709. goto fail;
  11710. } else if (request == 0) {
  11711. /* using INTx */
  11712. /* dd->num_msix_entries already zero */
  11713. single_interrupt = 1;
  11714. dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
  11715. } else if (request < total) {
  11716. /* using MSI-X, with reduced interrupts */
  11717. dd_dev_err(dd, "reduced interrupt found, wanted %u, got %u\n",
  11718. total, request);
  11719. ret = -EINVAL;
  11720. goto fail;
  11721. } else {
  11722. dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
  11723. GFP_KERNEL);
  11724. if (!dd->msix_entries) {
  11725. ret = -ENOMEM;
  11726. goto fail;
  11727. }
  11728. /* using MSI-X */
  11729. dd->num_msix_entries = total;
  11730. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11731. }
  11732. /* mask all interrupts */
  11733. set_intr_state(dd, 0);
  11734. /* clear all pending interrupts */
  11735. clear_all_interrupts(dd);
  11736. /* reset general handler mask, chip MSI-X mappings */
  11737. reset_interrupts(dd);
  11738. if (single_interrupt)
  11739. ret = request_intx_irq(dd);
  11740. else
  11741. ret = request_msix_irqs(dd);
  11742. if (ret)
  11743. goto fail;
  11744. return 0;
  11745. fail:
  11746. hfi1_clean_up_interrupts(dd);
  11747. return ret;
  11748. }
  11749. /*
  11750. * Set up context values in dd. Sets:
  11751. *
  11752. * num_rcv_contexts - number of contexts being used
  11753. * n_krcv_queues - number of kernel contexts
  11754. * first_dyn_alloc_ctxt - first dynamically allocated context
  11755. * in array of contexts
  11756. * freectxts - number of free user contexts
  11757. * num_send_contexts - number of PIO send contexts being used
  11758. * num_vnic_contexts - number of contexts reserved for VNIC
  11759. */
  11760. static int set_up_context_variables(struct hfi1_devdata *dd)
  11761. {
  11762. unsigned long num_kernel_contexts;
  11763. u16 num_vnic_contexts = HFI1_NUM_VNIC_CTXT;
  11764. int total_contexts;
  11765. int ret;
  11766. unsigned ngroups;
  11767. int qos_rmt_count;
  11768. int user_rmt_reduced;
  11769. u32 n_usr_ctxts;
  11770. /*
  11771. * Kernel receive contexts:
  11772. * - Context 0 - control context (VL15/multicast/error)
  11773. * - Context 1 - first kernel context
  11774. * - Context 2 - second kernel context
  11775. * ...
  11776. */
  11777. if (n_krcvqs)
  11778. /*
  11779. * n_krcvqs is the sum of module parameter kernel receive
  11780. * contexts, krcvqs[]. It does not include the control
  11781. * context, so add that.
  11782. */
  11783. num_kernel_contexts = n_krcvqs + 1;
  11784. else
  11785. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11786. /*
  11787. * Every kernel receive context needs an ACK send context.
  11788. * one send context is allocated for each VL{0-7} and VL15
  11789. */
  11790. if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
  11791. dd_dev_err(dd,
  11792. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11793. (int)(dd->chip_send_contexts - num_vls - 1),
  11794. num_kernel_contexts);
  11795. num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
  11796. }
  11797. /* Accommodate VNIC contexts if possible */
  11798. if ((num_kernel_contexts + num_vnic_contexts) > dd->chip_rcv_contexts) {
  11799. dd_dev_err(dd, "No receive contexts available for VNIC\n");
  11800. num_vnic_contexts = 0;
  11801. }
  11802. total_contexts = num_kernel_contexts + num_vnic_contexts;
  11803. /*
  11804. * User contexts:
  11805. * - default to 1 user context per real (non-HT) CPU core if
  11806. * num_user_contexts is negative
  11807. */
  11808. if (num_user_contexts < 0)
  11809. n_usr_ctxts = cpumask_weight(&node_affinity.real_cpu_mask);
  11810. else
  11811. n_usr_ctxts = num_user_contexts;
  11812. /*
  11813. * Adjust the counts given a global max.
  11814. */
  11815. if (total_contexts + n_usr_ctxts > dd->chip_rcv_contexts) {
  11816. dd_dev_err(dd,
  11817. "Reducing # user receive contexts to: %d, from %u\n",
  11818. (int)(dd->chip_rcv_contexts - total_contexts),
  11819. n_usr_ctxts);
  11820. /* recalculate */
  11821. n_usr_ctxts = dd->chip_rcv_contexts - total_contexts;
  11822. }
  11823. /* each user context requires an entry in the RMT */
  11824. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11825. if (qos_rmt_count + n_usr_ctxts > NUM_MAP_ENTRIES) {
  11826. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11827. dd_dev_err(dd,
  11828. "RMT size is reducing the number of user receive contexts from %u to %d\n",
  11829. n_usr_ctxts,
  11830. user_rmt_reduced);
  11831. /* recalculate */
  11832. n_usr_ctxts = user_rmt_reduced;
  11833. }
  11834. total_contexts += n_usr_ctxts;
  11835. /* the first N are kernel contexts, the rest are user/vnic contexts */
  11836. dd->num_rcv_contexts = total_contexts;
  11837. dd->n_krcv_queues = num_kernel_contexts;
  11838. dd->first_dyn_alloc_ctxt = num_kernel_contexts;
  11839. dd->num_vnic_contexts = num_vnic_contexts;
  11840. dd->num_user_contexts = n_usr_ctxts;
  11841. dd->freectxts = n_usr_ctxts;
  11842. dd_dev_info(dd,
  11843. "rcv contexts: chip %d, used %d (kernel %d, vnic %u, user %u)\n",
  11844. (int)dd->chip_rcv_contexts,
  11845. (int)dd->num_rcv_contexts,
  11846. (int)dd->n_krcv_queues,
  11847. dd->num_vnic_contexts,
  11848. dd->num_user_contexts);
  11849. /*
  11850. * Receive array allocation:
  11851. * All RcvArray entries are divided into groups of 8. This
  11852. * is required by the hardware and will speed up writes to
  11853. * consecutive entries by using write-combining of the entire
  11854. * cacheline.
  11855. *
  11856. * The number of groups are evenly divided among all contexts.
  11857. * any left over groups will be given to the first N user
  11858. * contexts.
  11859. */
  11860. dd->rcv_entries.group_size = RCV_INCREMENT;
  11861. ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
  11862. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11863. dd->rcv_entries.nctxt_extra = ngroups -
  11864. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11865. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11866. dd->rcv_entries.ngroups,
  11867. dd->rcv_entries.nctxt_extra);
  11868. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11869. MAX_EAGER_ENTRIES * 2) {
  11870. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11871. dd->rcv_entries.group_size;
  11872. dd_dev_info(dd,
  11873. "RcvArray group count too high, change to %u\n",
  11874. dd->rcv_entries.ngroups);
  11875. dd->rcv_entries.nctxt_extra = 0;
  11876. }
  11877. /*
  11878. * PIO send contexts
  11879. */
  11880. ret = init_sc_pools_and_sizes(dd);
  11881. if (ret >= 0) { /* success */
  11882. dd->num_send_contexts = ret;
  11883. dd_dev_info(
  11884. dd,
  11885. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11886. dd->chip_send_contexts,
  11887. dd->num_send_contexts,
  11888. dd->sc_sizes[SC_KERNEL].count,
  11889. dd->sc_sizes[SC_ACK].count,
  11890. dd->sc_sizes[SC_USER].count,
  11891. dd->sc_sizes[SC_VL15].count);
  11892. ret = 0; /* success */
  11893. }
  11894. return ret;
  11895. }
  11896. /*
  11897. * Set the device/port partition key table. The MAD code
  11898. * will ensure that, at least, the partial management
  11899. * partition key is present in the table.
  11900. */
  11901. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11902. {
  11903. struct hfi1_devdata *dd = ppd->dd;
  11904. u64 reg = 0;
  11905. int i;
  11906. dd_dev_info(dd, "Setting partition keys\n");
  11907. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11908. reg |= (ppd->pkeys[i] &
  11909. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11910. ((i % 4) *
  11911. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11912. /* Each register holds 4 PKey values. */
  11913. if ((i % 4) == 3) {
  11914. write_csr(dd, RCV_PARTITION_KEY +
  11915. ((i - 3) * 2), reg);
  11916. reg = 0;
  11917. }
  11918. }
  11919. /* Always enable HW pkeys check when pkeys table is set */
  11920. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11921. }
  11922. /*
  11923. * These CSRs and memories are uninitialized on reset and must be
  11924. * written before reading to set the ECC/parity bits.
  11925. *
  11926. * NOTE: All user context CSRs that are not mmaped write-only
  11927. * (e.g. the TID flows) must be initialized even if the driver never
  11928. * reads them.
  11929. */
  11930. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11931. {
  11932. int i, j;
  11933. /* CceIntMap */
  11934. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11935. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11936. /* SendCtxtCreditReturnAddr */
  11937. for (i = 0; i < dd->chip_send_contexts; i++)
  11938. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11939. /* PIO Send buffers */
  11940. /* SDMA Send buffers */
  11941. /*
  11942. * These are not normally read, and (presently) have no method
  11943. * to be read, so are not pre-initialized
  11944. */
  11945. /* RcvHdrAddr */
  11946. /* RcvHdrTailAddr */
  11947. /* RcvTidFlowTable */
  11948. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11949. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11950. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11951. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11952. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11953. }
  11954. /* RcvArray */
  11955. for (i = 0; i < dd->chip_rcv_array_count; i++)
  11956. hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
  11957. /* RcvQPMapTable */
  11958. for (i = 0; i < 32; i++)
  11959. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11960. }
  11961. /*
  11962. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11963. */
  11964. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11965. u64 ctrl_bits)
  11966. {
  11967. unsigned long timeout;
  11968. u64 reg;
  11969. /* is the condition present? */
  11970. reg = read_csr(dd, CCE_STATUS);
  11971. if ((reg & status_bits) == 0)
  11972. return;
  11973. /* clear the condition */
  11974. write_csr(dd, CCE_CTRL, ctrl_bits);
  11975. /* wait for the condition to clear */
  11976. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11977. while (1) {
  11978. reg = read_csr(dd, CCE_STATUS);
  11979. if ((reg & status_bits) == 0)
  11980. return;
  11981. if (time_after(jiffies, timeout)) {
  11982. dd_dev_err(dd,
  11983. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11984. status_bits, reg & status_bits);
  11985. return;
  11986. }
  11987. udelay(1);
  11988. }
  11989. }
  11990. /* set CCE CSRs to chip reset defaults */
  11991. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11992. {
  11993. int i;
  11994. /* CCE_REVISION read-only */
  11995. /* CCE_REVISION2 read-only */
  11996. /* CCE_CTRL - bits clear automatically */
  11997. /* CCE_STATUS read-only, use CceCtrl to clear */
  11998. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11999. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  12000. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  12001. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  12002. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  12003. /* CCE_ERR_STATUS read-only */
  12004. write_csr(dd, CCE_ERR_MASK, 0);
  12005. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  12006. /* CCE_ERR_FORCE leave alone */
  12007. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  12008. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  12009. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  12010. /* CCE_PCIE_CTRL leave alone */
  12011. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  12012. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  12013. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  12014. CCE_MSIX_TABLE_UPPER_RESETCSR);
  12015. }
  12016. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  12017. /* CCE_MSIX_PBA read-only */
  12018. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  12019. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  12020. }
  12021. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  12022. write_csr(dd, CCE_INT_MAP, 0);
  12023. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  12024. /* CCE_INT_STATUS read-only */
  12025. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  12026. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  12027. /* CCE_INT_FORCE leave alone */
  12028. /* CCE_INT_BLOCKED read-only */
  12029. }
  12030. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  12031. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  12032. }
  12033. /* set MISC CSRs to chip reset defaults */
  12034. static void reset_misc_csrs(struct hfi1_devdata *dd)
  12035. {
  12036. int i;
  12037. for (i = 0; i < 32; i++) {
  12038. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  12039. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  12040. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  12041. }
  12042. /*
  12043. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  12044. * only be written 128-byte chunks
  12045. */
  12046. /* init RSA engine to clear lingering errors */
  12047. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  12048. write_csr(dd, MISC_CFG_RSA_MU, 0);
  12049. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  12050. /* MISC_STS_8051_DIGEST read-only */
  12051. /* MISC_STS_SBM_DIGEST read-only */
  12052. /* MISC_STS_PCIE_DIGEST read-only */
  12053. /* MISC_STS_FAB_DIGEST read-only */
  12054. /* MISC_ERR_STATUS read-only */
  12055. write_csr(dd, MISC_ERR_MASK, 0);
  12056. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  12057. /* MISC_ERR_FORCE leave alone */
  12058. }
  12059. /* set TXE CSRs to chip reset defaults */
  12060. static void reset_txe_csrs(struct hfi1_devdata *dd)
  12061. {
  12062. int i;
  12063. /*
  12064. * TXE Kernel CSRs
  12065. */
  12066. write_csr(dd, SEND_CTRL, 0);
  12067. __cm_reset(dd, 0); /* reset CM internal state */
  12068. /* SEND_CONTEXTS read-only */
  12069. /* SEND_DMA_ENGINES read-only */
  12070. /* SEND_PIO_MEM_SIZE read-only */
  12071. /* SEND_DMA_MEM_SIZE read-only */
  12072. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  12073. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  12074. /* SEND_PIO_ERR_STATUS read-only */
  12075. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  12076. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  12077. /* SEND_PIO_ERR_FORCE leave alone */
  12078. /* SEND_DMA_ERR_STATUS read-only */
  12079. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  12080. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  12081. /* SEND_DMA_ERR_FORCE leave alone */
  12082. /* SEND_EGRESS_ERR_STATUS read-only */
  12083. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  12084. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  12085. /* SEND_EGRESS_ERR_FORCE leave alone */
  12086. write_csr(dd, SEND_BTH_QP, 0);
  12087. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  12088. write_csr(dd, SEND_SC2VLT0, 0);
  12089. write_csr(dd, SEND_SC2VLT1, 0);
  12090. write_csr(dd, SEND_SC2VLT2, 0);
  12091. write_csr(dd, SEND_SC2VLT3, 0);
  12092. write_csr(dd, SEND_LEN_CHECK0, 0);
  12093. write_csr(dd, SEND_LEN_CHECK1, 0);
  12094. /* SEND_ERR_STATUS read-only */
  12095. write_csr(dd, SEND_ERR_MASK, 0);
  12096. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  12097. /* SEND_ERR_FORCE read-only */
  12098. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  12099. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  12100. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  12101. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  12102. for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
  12103. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  12104. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  12105. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  12106. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  12107. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  12108. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  12109. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  12110. /* SEND_CM_CREDIT_USED_STATUS read-only */
  12111. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  12112. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  12113. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  12114. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  12115. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  12116. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  12117. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  12118. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  12119. /* SEND_CM_CREDIT_USED_VL read-only */
  12120. /* SEND_CM_CREDIT_USED_VL15 read-only */
  12121. /* SEND_EGRESS_CTXT_STATUS read-only */
  12122. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  12123. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  12124. /* SEND_EGRESS_ERR_INFO read-only */
  12125. /* SEND_EGRESS_ERR_SOURCE read-only */
  12126. /*
  12127. * TXE Per-Context CSRs
  12128. */
  12129. for (i = 0; i < dd->chip_send_contexts; i++) {
  12130. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12131. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  12132. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  12133. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  12134. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  12135. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  12136. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  12137. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  12138. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  12139. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12140. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  12141. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  12142. }
  12143. /*
  12144. * TXE Per-SDMA CSRs
  12145. */
  12146. for (i = 0; i < dd->chip_sdma_engines; i++) {
  12147. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12148. /* SEND_DMA_STATUS read-only */
  12149. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  12150. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  12151. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  12152. /* SEND_DMA_HEAD read-only */
  12153. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  12154. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  12155. /* SEND_DMA_IDLE_CNT read-only */
  12156. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  12157. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  12158. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  12159. /* SEND_DMA_ENG_ERR_STATUS read-only */
  12160. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  12161. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  12162. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  12163. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  12164. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  12165. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  12166. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  12167. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  12168. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  12169. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  12170. }
  12171. }
  12172. /*
  12173. * Expect on entry:
  12174. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  12175. */
  12176. static void init_rbufs(struct hfi1_devdata *dd)
  12177. {
  12178. u64 reg;
  12179. int count;
  12180. /*
  12181. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  12182. * clear.
  12183. */
  12184. count = 0;
  12185. while (1) {
  12186. reg = read_csr(dd, RCV_STATUS);
  12187. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  12188. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  12189. break;
  12190. /*
  12191. * Give up after 1ms - maximum wait time.
  12192. *
  12193. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  12194. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  12195. * 136 KB / (66% * 250MB/s) = 844us
  12196. */
  12197. if (count++ > 500) {
  12198. dd_dev_err(dd,
  12199. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  12200. __func__, reg);
  12201. break;
  12202. }
  12203. udelay(2); /* do not busy-wait the CSR */
  12204. }
  12205. /* start the init - expect RcvCtrl to be 0 */
  12206. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  12207. /*
  12208. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  12209. * period after the write before RcvStatus.RxRbufInitDone is valid.
  12210. * The delay in the first run through the loop below is sufficient and
  12211. * required before the first read of RcvStatus.RxRbufInintDone.
  12212. */
  12213. read_csr(dd, RCV_CTRL);
  12214. /* wait for the init to finish */
  12215. count = 0;
  12216. while (1) {
  12217. /* delay is required first time through - see above */
  12218. udelay(2); /* do not busy-wait the CSR */
  12219. reg = read_csr(dd, RCV_STATUS);
  12220. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  12221. break;
  12222. /* give up after 100us - slowest possible at 33MHz is 73us */
  12223. if (count++ > 50) {
  12224. dd_dev_err(dd,
  12225. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  12226. __func__);
  12227. break;
  12228. }
  12229. }
  12230. }
  12231. /* set RXE CSRs to chip reset defaults */
  12232. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  12233. {
  12234. int i, j;
  12235. /*
  12236. * RXE Kernel CSRs
  12237. */
  12238. write_csr(dd, RCV_CTRL, 0);
  12239. init_rbufs(dd);
  12240. /* RCV_STATUS read-only */
  12241. /* RCV_CONTEXTS read-only */
  12242. /* RCV_ARRAY_CNT read-only */
  12243. /* RCV_BUF_SIZE read-only */
  12244. write_csr(dd, RCV_BTH_QP, 0);
  12245. write_csr(dd, RCV_MULTICAST, 0);
  12246. write_csr(dd, RCV_BYPASS, 0);
  12247. write_csr(dd, RCV_VL15, 0);
  12248. /* this is a clear-down */
  12249. write_csr(dd, RCV_ERR_INFO,
  12250. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  12251. /* RCV_ERR_STATUS read-only */
  12252. write_csr(dd, RCV_ERR_MASK, 0);
  12253. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  12254. /* RCV_ERR_FORCE leave alone */
  12255. for (i = 0; i < 32; i++)
  12256. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  12257. for (i = 0; i < 4; i++)
  12258. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  12259. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  12260. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  12261. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  12262. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  12263. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
  12264. clear_rsm_rule(dd, i);
  12265. for (i = 0; i < 32; i++)
  12266. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  12267. /*
  12268. * RXE Kernel and User Per-Context CSRs
  12269. */
  12270. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  12271. /* kernel */
  12272. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  12273. /* RCV_CTXT_STATUS read-only */
  12274. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  12275. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  12276. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  12277. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  12278. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  12279. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  12280. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  12281. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  12282. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  12283. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  12284. /* user */
  12285. /* RCV_HDR_TAIL read-only */
  12286. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  12287. /* RCV_EGR_INDEX_TAIL read-only */
  12288. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  12289. /* RCV_EGR_OFFSET_TAIL read-only */
  12290. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  12291. write_uctxt_csr(dd, i,
  12292. RCV_TID_FLOW_TABLE + (8 * j), 0);
  12293. }
  12294. }
  12295. }
  12296. /*
  12297. * Set sc2vl tables.
  12298. *
  12299. * They power on to zeros, so to avoid send context errors
  12300. * they need to be set:
  12301. *
  12302. * SC 0-7 -> VL 0-7 (respectively)
  12303. * SC 15 -> VL 15
  12304. * otherwise
  12305. * -> VL 0
  12306. */
  12307. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  12308. {
  12309. int i;
  12310. /* init per architecture spec, constrained by hardware capability */
  12311. /* HFI maps sent packets */
  12312. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  12313. 0,
  12314. 0, 0, 1, 1,
  12315. 2, 2, 3, 3,
  12316. 4, 4, 5, 5,
  12317. 6, 6, 7, 7));
  12318. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  12319. 1,
  12320. 8, 0, 9, 0,
  12321. 10, 0, 11, 0,
  12322. 12, 0, 13, 0,
  12323. 14, 0, 15, 15));
  12324. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  12325. 2,
  12326. 16, 0, 17, 0,
  12327. 18, 0, 19, 0,
  12328. 20, 0, 21, 0,
  12329. 22, 0, 23, 0));
  12330. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  12331. 3,
  12332. 24, 0, 25, 0,
  12333. 26, 0, 27, 0,
  12334. 28, 0, 29, 0,
  12335. 30, 0, 31, 0));
  12336. /* DC maps received packets */
  12337. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  12338. 15_0,
  12339. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  12340. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  12341. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  12342. 31_16,
  12343. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  12344. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  12345. /* initialize the cached sc2vl values consistently with h/w */
  12346. for (i = 0; i < 32; i++) {
  12347. if (i < 8 || i == 15)
  12348. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  12349. else
  12350. *((u8 *)(dd->sc2vl) + i) = 0;
  12351. }
  12352. }
  12353. /*
  12354. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  12355. * depend on the chip going through a power-on reset - a driver may be loaded
  12356. * and unloaded many times.
  12357. *
  12358. * Do not write any CSR values to the chip in this routine - there may be
  12359. * a reset following the (possible) FLR in this routine.
  12360. *
  12361. */
  12362. static int init_chip(struct hfi1_devdata *dd)
  12363. {
  12364. int i;
  12365. int ret = 0;
  12366. /*
  12367. * Put the HFI CSRs in a known state.
  12368. * Combine this with a DC reset.
  12369. *
  12370. * Stop the device from doing anything while we do a
  12371. * reset. We know there are no other active users of
  12372. * the device since we are now in charge. Turn off
  12373. * off all outbound and inbound traffic and make sure
  12374. * the device does not generate any interrupts.
  12375. */
  12376. /* disable send contexts and SDMA engines */
  12377. write_csr(dd, SEND_CTRL, 0);
  12378. for (i = 0; i < dd->chip_send_contexts; i++)
  12379. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12380. for (i = 0; i < dd->chip_sdma_engines; i++)
  12381. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12382. /* disable port (turn off RXE inbound traffic) and contexts */
  12383. write_csr(dd, RCV_CTRL, 0);
  12384. for (i = 0; i < dd->chip_rcv_contexts; i++)
  12385. write_csr(dd, RCV_CTXT_CTRL, 0);
  12386. /* mask all interrupt sources */
  12387. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  12388. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  12389. /*
  12390. * DC Reset: do a full DC reset before the register clear.
  12391. * A recommended length of time to hold is one CSR read,
  12392. * so reread the CceDcCtrl. Then, hold the DC in reset
  12393. * across the clear.
  12394. */
  12395. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  12396. (void)read_csr(dd, CCE_DC_CTRL);
  12397. if (use_flr) {
  12398. /*
  12399. * A FLR will reset the SPC core and part of the PCIe.
  12400. * The parts that need to be restored have already been
  12401. * saved.
  12402. */
  12403. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12404. /* do the FLR, the DC reset will remain */
  12405. pcie_flr(dd->pcidev);
  12406. /* restore command and BARs */
  12407. ret = restore_pci_variables(dd);
  12408. if (ret) {
  12409. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12410. __func__);
  12411. return ret;
  12412. }
  12413. if (is_ax(dd)) {
  12414. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12415. pcie_flr(dd->pcidev);
  12416. ret = restore_pci_variables(dd);
  12417. if (ret) {
  12418. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12419. __func__);
  12420. return ret;
  12421. }
  12422. }
  12423. } else {
  12424. dd_dev_info(dd, "Resetting CSRs with writes\n");
  12425. reset_cce_csrs(dd);
  12426. reset_txe_csrs(dd);
  12427. reset_rxe_csrs(dd);
  12428. reset_misc_csrs(dd);
  12429. }
  12430. /* clear the DC reset */
  12431. write_csr(dd, CCE_DC_CTRL, 0);
  12432. /* Set the LED off */
  12433. setextled(dd, 0);
  12434. /*
  12435. * Clear the QSFP reset.
  12436. * An FLR enforces a 0 on all out pins. The driver does not touch
  12437. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  12438. * anything plugged constantly in reset, if it pays attention
  12439. * to RESET_N.
  12440. * Prime examples of this are optical cables. Set all pins high.
  12441. * I2CCLK and I2CDAT will change per direction, and INT_N and
  12442. * MODPRS_N are input only and their value is ignored.
  12443. */
  12444. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  12445. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  12446. init_chip_resources(dd);
  12447. return ret;
  12448. }
  12449. static void init_early_variables(struct hfi1_devdata *dd)
  12450. {
  12451. int i;
  12452. /* assign link credit variables */
  12453. dd->vau = CM_VAU;
  12454. dd->link_credits = CM_GLOBAL_CREDITS;
  12455. if (is_ax(dd))
  12456. dd->link_credits--;
  12457. dd->vcu = cu_to_vcu(hfi1_cu);
  12458. /* enough room for 8 MAD packets plus header - 17K */
  12459. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12460. if (dd->vl15_init > dd->link_credits)
  12461. dd->vl15_init = dd->link_credits;
  12462. write_uninitialized_csrs_and_memories(dd);
  12463. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12464. for (i = 0; i < dd->num_pports; i++) {
  12465. struct hfi1_pportdata *ppd = &dd->pport[i];
  12466. set_partition_keys(ppd);
  12467. }
  12468. init_sc2vl_tables(dd);
  12469. }
  12470. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12471. {
  12472. /* user changed the KDETH_QP */
  12473. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12474. /* out of range or illegal value */
  12475. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12476. kdeth_qp = 0;
  12477. }
  12478. if (kdeth_qp == 0) /* not set, or failed range check */
  12479. kdeth_qp = DEFAULT_KDETH_QP;
  12480. write_csr(dd, SEND_BTH_QP,
  12481. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12482. SEND_BTH_QP_KDETH_QP_SHIFT);
  12483. write_csr(dd, RCV_BTH_QP,
  12484. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12485. RCV_BTH_QP_KDETH_QP_SHIFT);
  12486. }
  12487. /**
  12488. * init_qpmap_table
  12489. * @dd - device data
  12490. * @first_ctxt - first context
  12491. * @last_ctxt - first context
  12492. *
  12493. * This return sets the qpn mapping table that
  12494. * is indexed by qpn[8:1].
  12495. *
  12496. * The routine will round robin the 256 settings
  12497. * from first_ctxt to last_ctxt.
  12498. *
  12499. * The first/last looks ahead to having specialized
  12500. * receive contexts for mgmt and bypass. Normal
  12501. * verbs traffic will assumed to be on a range
  12502. * of receive contexts.
  12503. */
  12504. static void init_qpmap_table(struct hfi1_devdata *dd,
  12505. u32 first_ctxt,
  12506. u32 last_ctxt)
  12507. {
  12508. u64 reg = 0;
  12509. u64 regno = RCV_QP_MAP_TABLE;
  12510. int i;
  12511. u64 ctxt = first_ctxt;
  12512. for (i = 0; i < 256; i++) {
  12513. reg |= ctxt << (8 * (i % 8));
  12514. ctxt++;
  12515. if (ctxt > last_ctxt)
  12516. ctxt = first_ctxt;
  12517. if (i % 8 == 7) {
  12518. write_csr(dd, regno, reg);
  12519. reg = 0;
  12520. regno += 8;
  12521. }
  12522. }
  12523. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12524. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12525. }
  12526. struct rsm_map_table {
  12527. u64 map[NUM_MAP_REGS];
  12528. unsigned int used;
  12529. };
  12530. struct rsm_rule_data {
  12531. u8 offset;
  12532. u8 pkt_type;
  12533. u32 field1_off;
  12534. u32 field2_off;
  12535. u32 index1_off;
  12536. u32 index1_width;
  12537. u32 index2_off;
  12538. u32 index2_width;
  12539. u32 mask1;
  12540. u32 value1;
  12541. u32 mask2;
  12542. u32 value2;
  12543. };
  12544. /*
  12545. * Return an initialized RMT map table for users to fill in. OK if it
  12546. * returns NULL, indicating no table.
  12547. */
  12548. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12549. {
  12550. struct rsm_map_table *rmt;
  12551. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12552. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12553. if (rmt) {
  12554. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12555. rmt->used = 0;
  12556. }
  12557. return rmt;
  12558. }
  12559. /*
  12560. * Write the final RMT map table to the chip and free the table. OK if
  12561. * table is NULL.
  12562. */
  12563. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12564. struct rsm_map_table *rmt)
  12565. {
  12566. int i;
  12567. if (rmt) {
  12568. /* write table to chip */
  12569. for (i = 0; i < NUM_MAP_REGS; i++)
  12570. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12571. /* enable RSM */
  12572. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12573. }
  12574. }
  12575. /*
  12576. * Add a receive side mapping rule.
  12577. */
  12578. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12579. struct rsm_rule_data *rrd)
  12580. {
  12581. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12582. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12583. 1ull << rule_index | /* enable bit */
  12584. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12585. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12586. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12587. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12588. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12589. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12590. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12591. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12592. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12593. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12594. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12595. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12596. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12597. }
  12598. /*
  12599. * Clear a receive side mapping rule.
  12600. */
  12601. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
  12602. {
  12603. write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
  12604. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
  12605. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
  12606. }
  12607. /* return the number of RSM map table entries that will be used for QOS */
  12608. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12609. unsigned int *np)
  12610. {
  12611. int i;
  12612. unsigned int m, n;
  12613. u8 max_by_vl = 0;
  12614. /* is QOS active at all? */
  12615. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12616. num_vls == 1 ||
  12617. krcvqsset <= 1)
  12618. goto no_qos;
  12619. /* determine bits for qpn */
  12620. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12621. if (krcvqs[i] > max_by_vl)
  12622. max_by_vl = krcvqs[i];
  12623. if (max_by_vl > 32)
  12624. goto no_qos;
  12625. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12626. /* determine bits for vl */
  12627. n = ilog2(__roundup_pow_of_two(num_vls));
  12628. /* reject if too much is used */
  12629. if ((m + n) > 7)
  12630. goto no_qos;
  12631. if (mp)
  12632. *mp = m;
  12633. if (np)
  12634. *np = n;
  12635. return 1 << (m + n);
  12636. no_qos:
  12637. if (mp)
  12638. *mp = 0;
  12639. if (np)
  12640. *np = 0;
  12641. return 0;
  12642. }
  12643. /**
  12644. * init_qos - init RX qos
  12645. * @dd - device data
  12646. * @rmt - RSM map table
  12647. *
  12648. * This routine initializes Rule 0 and the RSM map table to implement
  12649. * quality of service (qos).
  12650. *
  12651. * If all of the limit tests succeed, qos is applied based on the array
  12652. * interpretation of krcvqs where entry 0 is VL0.
  12653. *
  12654. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12655. * feed both the RSM map table and the single rule.
  12656. */
  12657. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12658. {
  12659. struct rsm_rule_data rrd;
  12660. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12661. unsigned int rmt_entries;
  12662. u64 reg;
  12663. if (!rmt)
  12664. goto bail;
  12665. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12666. if (rmt_entries == 0)
  12667. goto bail;
  12668. qpns_per_vl = 1 << m;
  12669. /* enough room in the map table? */
  12670. rmt_entries = 1 << (m + n);
  12671. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12672. goto bail;
  12673. /* add qos entries to the the RSM map table */
  12674. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12675. unsigned tctxt;
  12676. for (qpn = 0, tctxt = ctxt;
  12677. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12678. unsigned idx, regoff, regidx;
  12679. /* generate the index the hardware will produce */
  12680. idx = rmt->used + ((qpn << n) ^ i);
  12681. regoff = (idx % 8) * 8;
  12682. regidx = idx / 8;
  12683. /* replace default with context number */
  12684. reg = rmt->map[regidx];
  12685. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12686. << regoff);
  12687. reg |= (u64)(tctxt++) << regoff;
  12688. rmt->map[regidx] = reg;
  12689. if (tctxt == ctxt + krcvqs[i])
  12690. tctxt = ctxt;
  12691. }
  12692. ctxt += krcvqs[i];
  12693. }
  12694. rrd.offset = rmt->used;
  12695. rrd.pkt_type = 2;
  12696. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12697. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12698. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12699. rrd.index1_width = n;
  12700. rrd.index2_off = QPN_SELECT_OFFSET;
  12701. rrd.index2_width = m + n;
  12702. rrd.mask1 = LRH_BTH_MASK;
  12703. rrd.value1 = LRH_BTH_VALUE;
  12704. rrd.mask2 = LRH_SC_MASK;
  12705. rrd.value2 = LRH_SC_VALUE;
  12706. /* add rule 0 */
  12707. add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
  12708. /* mark RSM map entries as used */
  12709. rmt->used += rmt_entries;
  12710. /* map everything else to the mcast/err/vl15 context */
  12711. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12712. dd->qos_shift = n + 1;
  12713. return;
  12714. bail:
  12715. dd->qos_shift = 1;
  12716. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12717. }
  12718. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12719. struct rsm_map_table *rmt)
  12720. {
  12721. struct rsm_rule_data rrd;
  12722. u64 reg;
  12723. int i, idx, regoff, regidx;
  12724. u8 offset;
  12725. /* there needs to be enough room in the map table */
  12726. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12727. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12728. return;
  12729. }
  12730. /*
  12731. * RSM will extract the destination context as an index into the
  12732. * map table. The destination contexts are a sequential block
  12733. * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
  12734. * Map entries are accessed as offset + extracted value. Adjust
  12735. * the added offset so this sequence can be placed anywhere in
  12736. * the table - as long as the entries themselves do not wrap.
  12737. * There are only enough bits in offset for the table size, so
  12738. * start with that to allow for a "negative" offset.
  12739. */
  12740. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12741. (int)dd->first_dyn_alloc_ctxt);
  12742. for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
  12743. i < dd->num_rcv_contexts; i++, idx++) {
  12744. /* replace with identity mapping */
  12745. regoff = (idx % 8) * 8;
  12746. regidx = idx / 8;
  12747. reg = rmt->map[regidx];
  12748. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12749. reg |= (u64)i << regoff;
  12750. rmt->map[regidx] = reg;
  12751. }
  12752. /*
  12753. * For RSM intercept of Expected FECN packets:
  12754. * o packet type 0 - expected
  12755. * o match on F (bit 95), using select/match 1, and
  12756. * o match on SH (bit 133), using select/match 2.
  12757. *
  12758. * Use index 1 to extract the 8-bit receive context from DestQP
  12759. * (start at bit 64). Use that as the RSM map table index.
  12760. */
  12761. rrd.offset = offset;
  12762. rrd.pkt_type = 0;
  12763. rrd.field1_off = 95;
  12764. rrd.field2_off = 133;
  12765. rrd.index1_off = 64;
  12766. rrd.index1_width = 8;
  12767. rrd.index2_off = 0;
  12768. rrd.index2_width = 0;
  12769. rrd.mask1 = 1;
  12770. rrd.value1 = 1;
  12771. rrd.mask2 = 1;
  12772. rrd.value2 = 1;
  12773. /* add rule 1 */
  12774. add_rsm_rule(dd, RSM_INS_FECN, &rrd);
  12775. rmt->used += dd->num_user_contexts;
  12776. }
  12777. /* Initialize RSM for VNIC */
  12778. void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
  12779. {
  12780. u8 i, j;
  12781. u8 ctx_id = 0;
  12782. u64 reg;
  12783. u32 regoff;
  12784. struct rsm_rule_data rrd;
  12785. if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
  12786. dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
  12787. dd->vnic.rmt_start);
  12788. return;
  12789. }
  12790. dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
  12791. dd->vnic.rmt_start,
  12792. dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
  12793. /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
  12794. regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
  12795. reg = read_csr(dd, regoff);
  12796. for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
  12797. /* Update map register with vnic context */
  12798. j = (dd->vnic.rmt_start + i) % 8;
  12799. reg &= ~(0xffllu << (j * 8));
  12800. reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
  12801. /* Wrap up vnic ctx index */
  12802. ctx_id %= dd->vnic.num_ctxt;
  12803. /* Write back map register */
  12804. if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
  12805. dev_dbg(&(dd)->pcidev->dev,
  12806. "Vnic rsm map reg[%d] =0x%llx\n",
  12807. regoff - RCV_RSM_MAP_TABLE, reg);
  12808. write_csr(dd, regoff, reg);
  12809. regoff += 8;
  12810. if (i < (NUM_VNIC_MAP_ENTRIES - 1))
  12811. reg = read_csr(dd, regoff);
  12812. }
  12813. }
  12814. /* Add rule for vnic */
  12815. rrd.offset = dd->vnic.rmt_start;
  12816. rrd.pkt_type = 4;
  12817. /* Match 16B packets */
  12818. rrd.field1_off = L2_TYPE_MATCH_OFFSET;
  12819. rrd.mask1 = L2_TYPE_MASK;
  12820. rrd.value1 = L2_16B_VALUE;
  12821. /* Match ETH L4 packets */
  12822. rrd.field2_off = L4_TYPE_MATCH_OFFSET;
  12823. rrd.mask2 = L4_16B_TYPE_MASK;
  12824. rrd.value2 = L4_16B_ETH_VALUE;
  12825. /* Calc context from veswid and entropy */
  12826. rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
  12827. rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12828. rrd.index2_off = L2_16B_ENTROPY_OFFSET;
  12829. rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12830. add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
  12831. /* Enable RSM if not already enabled */
  12832. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12833. }
  12834. void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
  12835. {
  12836. clear_rsm_rule(dd, RSM_INS_VNIC);
  12837. /* Disable RSM if used only by vnic */
  12838. if (dd->vnic.rmt_start == 0)
  12839. clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12840. }
  12841. static void init_rxe(struct hfi1_devdata *dd)
  12842. {
  12843. struct rsm_map_table *rmt;
  12844. u64 val;
  12845. /* enable all receive errors */
  12846. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12847. rmt = alloc_rsm_map_table(dd);
  12848. /* set up QOS, including the QPN map table */
  12849. init_qos(dd, rmt);
  12850. init_user_fecn_handling(dd, rmt);
  12851. complete_rsm_map_table(dd, rmt);
  12852. /* record number of used rsm map entries for vnic */
  12853. dd->vnic.rmt_start = rmt->used;
  12854. kfree(rmt);
  12855. /*
  12856. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12857. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12858. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12859. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12860. * Max_PayLoad_Size set to its minimum of 128.
  12861. *
  12862. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12863. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12864. * tune_pcie_caps() which is called after this routine.
  12865. */
  12866. /* Have 16 bytes (4DW) of bypass header available in header queue */
  12867. val = read_csr(dd, RCV_BYPASS);
  12868. val |= (4ull << 16);
  12869. write_csr(dd, RCV_BYPASS, val);
  12870. }
  12871. static void init_other(struct hfi1_devdata *dd)
  12872. {
  12873. /* enable all CCE errors */
  12874. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12875. /* enable *some* Misc errors */
  12876. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12877. /* enable all DC errors, except LCB */
  12878. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12879. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12880. }
  12881. /*
  12882. * Fill out the given AU table using the given CU. A CU is defined in terms
  12883. * AUs. The table is a an encoding: given the index, how many AUs does that
  12884. * represent?
  12885. *
  12886. * NOTE: Assumes that the register layout is the same for the
  12887. * local and remote tables.
  12888. */
  12889. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12890. u32 csr0to3, u32 csr4to7)
  12891. {
  12892. write_csr(dd, csr0to3,
  12893. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12894. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12895. 2ull * cu <<
  12896. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12897. 4ull * cu <<
  12898. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12899. write_csr(dd, csr4to7,
  12900. 8ull * cu <<
  12901. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12902. 16ull * cu <<
  12903. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12904. 32ull * cu <<
  12905. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12906. 64ull * cu <<
  12907. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12908. }
  12909. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12910. {
  12911. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12912. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12913. }
  12914. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12915. {
  12916. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12917. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12918. }
  12919. static void init_txe(struct hfi1_devdata *dd)
  12920. {
  12921. int i;
  12922. /* enable all PIO, SDMA, general, and Egress errors */
  12923. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12924. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12925. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12926. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12927. /* enable all per-context and per-SDMA engine errors */
  12928. for (i = 0; i < dd->chip_send_contexts; i++)
  12929. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12930. for (i = 0; i < dd->chip_sdma_engines; i++)
  12931. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12932. /* set the local CU to AU mapping */
  12933. assign_local_cm_au_table(dd, dd->vcu);
  12934. /*
  12935. * Set reasonable default for Credit Return Timer
  12936. * Don't set on Simulator - causes it to choke.
  12937. */
  12938. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12939. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12940. }
  12941. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12942. u16 jkey)
  12943. {
  12944. u8 hw_ctxt;
  12945. u64 reg;
  12946. if (!rcd || !rcd->sc)
  12947. return -EINVAL;
  12948. hw_ctxt = rcd->sc->hw_context;
  12949. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12950. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12951. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12952. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12953. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12954. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12955. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12956. /*
  12957. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12958. */
  12959. if (!is_ax(dd)) {
  12960. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12961. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12962. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12963. }
  12964. /* Enable J_KEY check on receive context. */
  12965. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12966. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12967. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12968. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
  12969. return 0;
  12970. }
  12971. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
  12972. {
  12973. u8 hw_ctxt;
  12974. u64 reg;
  12975. if (!rcd || !rcd->sc)
  12976. return -EINVAL;
  12977. hw_ctxt = rcd->sc->hw_context;
  12978. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12979. /*
  12980. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12981. * This check would not have been enabled for A0 h/w, see
  12982. * set_ctxt_jkey().
  12983. */
  12984. if (!is_ax(dd)) {
  12985. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12986. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12987. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12988. }
  12989. /* Turn off the J_KEY on the receive side */
  12990. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
  12991. return 0;
  12992. }
  12993. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12994. u16 pkey)
  12995. {
  12996. u8 hw_ctxt;
  12997. u64 reg;
  12998. if (!rcd || !rcd->sc)
  12999. return -EINVAL;
  13000. hw_ctxt = rcd->sc->hw_context;
  13001. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  13002. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  13003. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  13004. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  13005. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  13006. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  13007. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  13008. return 0;
  13009. }
  13010. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
  13011. {
  13012. u8 hw_ctxt;
  13013. u64 reg;
  13014. if (!ctxt || !ctxt->sc)
  13015. return -EINVAL;
  13016. hw_ctxt = ctxt->sc->hw_context;
  13017. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  13018. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  13019. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  13020. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  13021. return 0;
  13022. }
  13023. /*
  13024. * Start doing the clean up the the chip. Our clean up happens in multiple
  13025. * stages and this is just the first.
  13026. */
  13027. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  13028. {
  13029. aspm_exit(dd);
  13030. free_cntrs(dd);
  13031. free_rcverr(dd);
  13032. finish_chip_resources(dd);
  13033. }
  13034. #define HFI_BASE_GUID(dev) \
  13035. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  13036. /*
  13037. * Information can be shared between the two HFIs on the same ASIC
  13038. * in the same OS. This function finds the peer device and sets
  13039. * up a shared structure.
  13040. */
  13041. static int init_asic_data(struct hfi1_devdata *dd)
  13042. {
  13043. unsigned long flags;
  13044. struct hfi1_devdata *tmp, *peer = NULL;
  13045. struct hfi1_asic_data *asic_data;
  13046. int ret = 0;
  13047. /* pre-allocate the asic structure in case we are the first device */
  13048. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  13049. if (!asic_data)
  13050. return -ENOMEM;
  13051. spin_lock_irqsave(&hfi1_devs_lock, flags);
  13052. /* Find our peer device */
  13053. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  13054. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  13055. dd->unit != tmp->unit) {
  13056. peer = tmp;
  13057. break;
  13058. }
  13059. }
  13060. if (peer) {
  13061. /* use already allocated structure */
  13062. dd->asic_data = peer->asic_data;
  13063. kfree(asic_data);
  13064. } else {
  13065. dd->asic_data = asic_data;
  13066. mutex_init(&dd->asic_data->asic_resource_mutex);
  13067. }
  13068. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  13069. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  13070. /* first one through - set up i2c devices */
  13071. if (!peer)
  13072. ret = set_up_i2c(dd, dd->asic_data);
  13073. return ret;
  13074. }
  13075. /*
  13076. * Set dd->boardname. Use a generic name if a name is not returned from
  13077. * EFI variable space.
  13078. *
  13079. * Return 0 on success, -ENOMEM if space could not be allocated.
  13080. */
  13081. static int obtain_boardname(struct hfi1_devdata *dd)
  13082. {
  13083. /* generic board description */
  13084. const char generic[] =
  13085. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  13086. unsigned long size;
  13087. int ret;
  13088. ret = read_hfi1_efi_var(dd, "description", &size,
  13089. (void **)&dd->boardname);
  13090. if (ret) {
  13091. dd_dev_info(dd, "Board description not found\n");
  13092. /* use generic description */
  13093. dd->boardname = kstrdup(generic, GFP_KERNEL);
  13094. if (!dd->boardname)
  13095. return -ENOMEM;
  13096. }
  13097. return 0;
  13098. }
  13099. /*
  13100. * Check the interrupt registers to make sure that they are mapped correctly.
  13101. * It is intended to help user identify any mismapping by VMM when the driver
  13102. * is running in a VM. This function should only be called before interrupt
  13103. * is set up properly.
  13104. *
  13105. * Return 0 on success, -EINVAL on failure.
  13106. */
  13107. static int check_int_registers(struct hfi1_devdata *dd)
  13108. {
  13109. u64 reg;
  13110. u64 all_bits = ~(u64)0;
  13111. u64 mask;
  13112. /* Clear CceIntMask[0] to avoid raising any interrupts */
  13113. mask = read_csr(dd, CCE_INT_MASK);
  13114. write_csr(dd, CCE_INT_MASK, 0ull);
  13115. reg = read_csr(dd, CCE_INT_MASK);
  13116. if (reg)
  13117. goto err_exit;
  13118. /* Clear all interrupt status bits */
  13119. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13120. reg = read_csr(dd, CCE_INT_STATUS);
  13121. if (reg)
  13122. goto err_exit;
  13123. /* Set all interrupt status bits */
  13124. write_csr(dd, CCE_INT_FORCE, all_bits);
  13125. reg = read_csr(dd, CCE_INT_STATUS);
  13126. if (reg != all_bits)
  13127. goto err_exit;
  13128. /* Restore the interrupt mask */
  13129. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13130. write_csr(dd, CCE_INT_MASK, mask);
  13131. return 0;
  13132. err_exit:
  13133. write_csr(dd, CCE_INT_MASK, mask);
  13134. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  13135. return -EINVAL;
  13136. }
  13137. /**
  13138. * Allocate and initialize the device structure for the hfi.
  13139. * @dev: the pci_dev for hfi1_ib device
  13140. * @ent: pci_device_id struct for this dev
  13141. *
  13142. * Also allocates, initializes, and returns the devdata struct for this
  13143. * device instance
  13144. *
  13145. * This is global, and is called directly at init to set up the
  13146. * chip-specific function pointers for later use.
  13147. */
  13148. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  13149. const struct pci_device_id *ent)
  13150. {
  13151. struct hfi1_devdata *dd;
  13152. struct hfi1_pportdata *ppd;
  13153. u64 reg;
  13154. int i, ret;
  13155. static const char * const inames[] = { /* implementation names */
  13156. "RTL silicon",
  13157. "RTL VCS simulation",
  13158. "RTL FPGA emulation",
  13159. "Functional simulator"
  13160. };
  13161. struct pci_dev *parent = pdev->bus->self;
  13162. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  13163. sizeof(struct hfi1_pportdata));
  13164. if (IS_ERR(dd))
  13165. goto bail;
  13166. ppd = dd->pport;
  13167. for (i = 0; i < dd->num_pports; i++, ppd++) {
  13168. int vl;
  13169. /* init common fields */
  13170. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  13171. /* DC supports 4 link widths */
  13172. ppd->link_width_supported =
  13173. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  13174. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  13175. ppd->link_width_downgrade_supported =
  13176. ppd->link_width_supported;
  13177. /* start out enabling only 4X */
  13178. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  13179. ppd->link_width_downgrade_enabled =
  13180. ppd->link_width_downgrade_supported;
  13181. /* link width active is 0 when link is down */
  13182. /* link width downgrade active is 0 when link is down */
  13183. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  13184. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  13185. dd_dev_err(dd, "Invalid num_vls %u, using %u VLs\n",
  13186. num_vls, HFI1_MAX_VLS_SUPPORTED);
  13187. num_vls = HFI1_MAX_VLS_SUPPORTED;
  13188. }
  13189. ppd->vls_supported = num_vls;
  13190. ppd->vls_operational = ppd->vls_supported;
  13191. /* Set the default MTU. */
  13192. for (vl = 0; vl < num_vls; vl++)
  13193. dd->vld[vl].mtu = hfi1_max_mtu;
  13194. dd->vld[15].mtu = MAX_MAD_PACKET;
  13195. /*
  13196. * Set the initial values to reasonable default, will be set
  13197. * for real when link is up.
  13198. */
  13199. ppd->overrun_threshold = 0x4;
  13200. ppd->phy_error_threshold = 0xf;
  13201. ppd->port_crc_mode_enabled = link_crc_mask;
  13202. /* initialize supported LTP CRC mode */
  13203. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  13204. /* initialize enabled LTP CRC mode */
  13205. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  13206. /* start in offline */
  13207. ppd->host_link_state = HLS_DN_OFFLINE;
  13208. init_vl_arb_caches(ppd);
  13209. }
  13210. /*
  13211. * Do remaining PCIe setup and save PCIe values in dd.
  13212. * Any error printing is already done by the init code.
  13213. * On return, we have the chip mapped.
  13214. */
  13215. ret = hfi1_pcie_ddinit(dd, pdev);
  13216. if (ret < 0)
  13217. goto bail_free;
  13218. /* Save PCI space registers to rewrite after device reset */
  13219. ret = save_pci_variables(dd);
  13220. if (ret < 0)
  13221. goto bail_cleanup;
  13222. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  13223. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  13224. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  13225. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  13226. /*
  13227. * Check interrupt registers mapping if the driver has no access to
  13228. * the upstream component. In this case, it is likely that the driver
  13229. * is running in a VM.
  13230. */
  13231. if (!parent) {
  13232. ret = check_int_registers(dd);
  13233. if (ret)
  13234. goto bail_cleanup;
  13235. }
  13236. /*
  13237. * obtain the hardware ID - NOT related to unit, which is a
  13238. * software enumeration
  13239. */
  13240. reg = read_csr(dd, CCE_REVISION2);
  13241. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  13242. & CCE_REVISION2_HFI_ID_MASK;
  13243. /* the variable size will remove unwanted bits */
  13244. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  13245. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  13246. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  13247. dd->icode < ARRAY_SIZE(inames) ?
  13248. inames[dd->icode] : "unknown", (int)dd->irev);
  13249. /* speeds the hardware can support */
  13250. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  13251. /* speeds allowed to run at */
  13252. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  13253. /* give a reasonable active value, will be set on link up */
  13254. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  13255. dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
  13256. dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
  13257. dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
  13258. dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
  13259. dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
  13260. /* fix up link widths for emulation _p */
  13261. ppd = dd->pport;
  13262. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  13263. ppd->link_width_supported =
  13264. ppd->link_width_enabled =
  13265. ppd->link_width_downgrade_supported =
  13266. ppd->link_width_downgrade_enabled =
  13267. OPA_LINK_WIDTH_1X;
  13268. }
  13269. /* insure num_vls isn't larger than number of sdma engines */
  13270. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
  13271. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  13272. num_vls, dd->chip_sdma_engines);
  13273. num_vls = dd->chip_sdma_engines;
  13274. ppd->vls_supported = dd->chip_sdma_engines;
  13275. ppd->vls_operational = ppd->vls_supported;
  13276. }
  13277. /*
  13278. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  13279. * Limit the max if larger than the field holds. If timeout is
  13280. * non-zero, then the calculated field will be at least 1.
  13281. *
  13282. * Must be after icode is set up - the cclock rate depends
  13283. * on knowing the hardware being used.
  13284. */
  13285. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  13286. if (dd->rcv_intr_timeout_csr >
  13287. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  13288. dd->rcv_intr_timeout_csr =
  13289. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  13290. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  13291. dd->rcv_intr_timeout_csr = 1;
  13292. /* needs to be done before we look for the peer device */
  13293. read_guid(dd);
  13294. /* set up shared ASIC data with peer device */
  13295. ret = init_asic_data(dd);
  13296. if (ret)
  13297. goto bail_cleanup;
  13298. /* obtain chip sizes, reset chip CSRs */
  13299. ret = init_chip(dd);
  13300. if (ret)
  13301. goto bail_cleanup;
  13302. /* read in the PCIe link speed information */
  13303. ret = pcie_speeds(dd);
  13304. if (ret)
  13305. goto bail_cleanup;
  13306. /* call before get_platform_config(), after init_chip_resources() */
  13307. ret = eprom_init(dd);
  13308. if (ret)
  13309. goto bail_free_rcverr;
  13310. /* Needs to be called before hfi1_firmware_init */
  13311. get_platform_config(dd);
  13312. /* read in firmware */
  13313. ret = hfi1_firmware_init(dd);
  13314. if (ret)
  13315. goto bail_cleanup;
  13316. /*
  13317. * In general, the PCIe Gen3 transition must occur after the
  13318. * chip has been idled (so it won't initiate any PCIe transactions
  13319. * e.g. an interrupt) and before the driver changes any registers
  13320. * (the transition will reset the registers).
  13321. *
  13322. * In particular, place this call after:
  13323. * - init_chip() - the chip will not initiate any PCIe transactions
  13324. * - pcie_speeds() - reads the current link speed
  13325. * - hfi1_firmware_init() - the needed firmware is ready to be
  13326. * downloaded
  13327. */
  13328. ret = do_pcie_gen3_transition(dd);
  13329. if (ret)
  13330. goto bail_cleanup;
  13331. /* start setting dd values and adjusting CSRs */
  13332. init_early_variables(dd);
  13333. parse_platform_config(dd);
  13334. ret = obtain_boardname(dd);
  13335. if (ret)
  13336. goto bail_cleanup;
  13337. snprintf(dd->boardversion, BOARD_VERS_MAX,
  13338. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  13339. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  13340. (u32)dd->majrev,
  13341. (u32)dd->minrev,
  13342. (dd->revision >> CCE_REVISION_SW_SHIFT)
  13343. & CCE_REVISION_SW_MASK);
  13344. ret = set_up_context_variables(dd);
  13345. if (ret)
  13346. goto bail_cleanup;
  13347. /* set initial RXE CSRs */
  13348. init_rxe(dd);
  13349. /* set initial TXE CSRs */
  13350. init_txe(dd);
  13351. /* set initial non-RXE, non-TXE CSRs */
  13352. init_other(dd);
  13353. /* set up KDETH QP prefix in both RX and TX CSRs */
  13354. init_kdeth_qp(dd);
  13355. ret = hfi1_dev_affinity_init(dd);
  13356. if (ret)
  13357. goto bail_cleanup;
  13358. /* send contexts must be set up before receive contexts */
  13359. ret = init_send_contexts(dd);
  13360. if (ret)
  13361. goto bail_cleanup;
  13362. ret = hfi1_create_kctxts(dd);
  13363. if (ret)
  13364. goto bail_cleanup;
  13365. /*
  13366. * Initialize aspm, to be done after gen3 transition and setting up
  13367. * contexts and before enabling interrupts
  13368. */
  13369. aspm_init(dd);
  13370. dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
  13371. /*
  13372. * rcd[0] is guaranteed to be valid by this point. Also, all
  13373. * context are using the same value, as per the module parameter.
  13374. */
  13375. dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
  13376. ret = init_pervl_scs(dd);
  13377. if (ret)
  13378. goto bail_cleanup;
  13379. /* sdma init */
  13380. for (i = 0; i < dd->num_pports; ++i) {
  13381. ret = sdma_init(dd, i);
  13382. if (ret)
  13383. goto bail_cleanup;
  13384. }
  13385. /* use contexts created by hfi1_create_kctxts */
  13386. ret = set_up_interrupts(dd);
  13387. if (ret)
  13388. goto bail_cleanup;
  13389. ret = hfi1_comp_vectors_set_up(dd);
  13390. if (ret)
  13391. goto bail_clear_intr;
  13392. /* set up LCB access - must be after set_up_interrupts() */
  13393. init_lcb_access(dd);
  13394. /*
  13395. * Serial number is created from the base guid:
  13396. * [27:24] = base guid [38:35]
  13397. * [23: 0] = base guid [23: 0]
  13398. */
  13399. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  13400. (dd->base_guid & 0xFFFFFF) |
  13401. ((dd->base_guid >> 11) & 0xF000000));
  13402. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  13403. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  13404. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  13405. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  13406. if (ret)
  13407. goto bail_clear_intr;
  13408. thermal_init(dd);
  13409. ret = init_cntrs(dd);
  13410. if (ret)
  13411. goto bail_clear_intr;
  13412. ret = init_rcverr(dd);
  13413. if (ret)
  13414. goto bail_free_cntrs;
  13415. init_completion(&dd->user_comp);
  13416. /* The user refcount starts with one to inidicate an active device */
  13417. atomic_set(&dd->user_refcount, 1);
  13418. goto bail;
  13419. bail_free_rcverr:
  13420. free_rcverr(dd);
  13421. bail_free_cntrs:
  13422. free_cntrs(dd);
  13423. bail_clear_intr:
  13424. hfi1_comp_vectors_clean_up(dd);
  13425. hfi1_clean_up_interrupts(dd);
  13426. bail_cleanup:
  13427. hfi1_pcie_ddcleanup(dd);
  13428. bail_free:
  13429. hfi1_free_devdata(dd);
  13430. dd = ERR_PTR(ret);
  13431. bail:
  13432. return dd;
  13433. }
  13434. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  13435. u32 dw_len)
  13436. {
  13437. u32 delta_cycles;
  13438. u32 current_egress_rate = ppd->current_egress_rate;
  13439. /* rates here are in units of 10^6 bits/sec */
  13440. if (desired_egress_rate == -1)
  13441. return 0; /* shouldn't happen */
  13442. if (desired_egress_rate >= current_egress_rate)
  13443. return 0; /* we can't help go faster, only slower */
  13444. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  13445. egress_cycles(dw_len * 4, current_egress_rate);
  13446. return (u16)delta_cycles;
  13447. }
  13448. /**
  13449. * create_pbc - build a pbc for transmission
  13450. * @flags: special case flags or-ed in built pbc
  13451. * @srate: static rate
  13452. * @vl: vl
  13453. * @dwlen: dword length (header words + data words + pbc words)
  13454. *
  13455. * Create a PBC with the given flags, rate, VL, and length.
  13456. *
  13457. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  13458. * for verbs, which does not use this PSM feature. The lone other caller
  13459. * is for the diagnostic interface which calls this if the user does not
  13460. * supply their own PBC.
  13461. */
  13462. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  13463. u32 dw_len)
  13464. {
  13465. u64 pbc, delay = 0;
  13466. if (unlikely(srate_mbs))
  13467. delay = delay_cycles(ppd, srate_mbs, dw_len);
  13468. pbc = flags
  13469. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  13470. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  13471. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  13472. | (dw_len & PBC_LENGTH_DWS_MASK)
  13473. << PBC_LENGTH_DWS_SHIFT;
  13474. return pbc;
  13475. }
  13476. #define SBUS_THERMAL 0x4f
  13477. #define SBUS_THERM_MONITOR_MODE 0x1
  13478. #define THERM_FAILURE(dev, ret, reason) \
  13479. dd_dev_err((dd), \
  13480. "Thermal sensor initialization failed: %s (%d)\n", \
  13481. (reason), (ret))
  13482. /*
  13483. * Initialize the thermal sensor.
  13484. *
  13485. * After initialization, enable polling of thermal sensor through
  13486. * SBus interface. In order for this to work, the SBus Master
  13487. * firmware has to be loaded due to the fact that the HW polling
  13488. * logic uses SBus interrupts, which are not supported with
  13489. * default firmware. Otherwise, no data will be returned through
  13490. * the ASIC_STS_THERM CSR.
  13491. */
  13492. static int thermal_init(struct hfi1_devdata *dd)
  13493. {
  13494. int ret = 0;
  13495. if (dd->icode != ICODE_RTL_SILICON ||
  13496. check_chip_resource(dd, CR_THERM_INIT, NULL))
  13497. return ret;
  13498. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  13499. if (ret) {
  13500. THERM_FAILURE(dd, ret, "Acquire SBus");
  13501. return ret;
  13502. }
  13503. dd_dev_info(dd, "Initializing thermal sensor\n");
  13504. /* Disable polling of thermal readings */
  13505. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13506. msleep(100);
  13507. /* Thermal Sensor Initialization */
  13508. /* Step 1: Reset the Thermal SBus Receiver */
  13509. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13510. RESET_SBUS_RECEIVER, 0);
  13511. if (ret) {
  13512. THERM_FAILURE(dd, ret, "Bus Reset");
  13513. goto done;
  13514. }
  13515. /* Step 2: Set Reset bit in Thermal block */
  13516. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13517. WRITE_SBUS_RECEIVER, 0x1);
  13518. if (ret) {
  13519. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13520. goto done;
  13521. }
  13522. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13523. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13524. WRITE_SBUS_RECEIVER, 0x32);
  13525. if (ret) {
  13526. THERM_FAILURE(dd, ret, "Write Clock Div");
  13527. goto done;
  13528. }
  13529. /* Step 4: Select temperature mode */
  13530. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13531. WRITE_SBUS_RECEIVER,
  13532. SBUS_THERM_MONITOR_MODE);
  13533. if (ret) {
  13534. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13535. goto done;
  13536. }
  13537. /* Step 5: De-assert block reset and start conversion */
  13538. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13539. WRITE_SBUS_RECEIVER, 0x2);
  13540. if (ret) {
  13541. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13542. goto done;
  13543. }
  13544. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13545. msleep(22);
  13546. /* Enable polling of thermal readings */
  13547. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13548. /* Set initialized flag */
  13549. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13550. if (ret)
  13551. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13552. done:
  13553. release_chip_resource(dd, CR_SBUS);
  13554. return ret;
  13555. }
  13556. static void handle_temp_err(struct hfi1_devdata *dd)
  13557. {
  13558. struct hfi1_pportdata *ppd = &dd->pport[0];
  13559. /*
  13560. * Thermal Critical Interrupt
  13561. * Put the device into forced freeze mode, take link down to
  13562. * offline, and put DC into reset.
  13563. */
  13564. dd_dev_emerg(dd,
  13565. "Critical temperature reached! Forcing device into freeze mode!\n");
  13566. dd->flags |= HFI1_FORCED_FREEZE;
  13567. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13568. /*
  13569. * Shut DC down as much and as quickly as possible.
  13570. *
  13571. * Step 1: Take the link down to OFFLINE. This will cause the
  13572. * 8051 to put the Serdes in reset. However, we don't want to
  13573. * go through the entire link state machine since we want to
  13574. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13575. * but rather an attempt to save the chip.
  13576. * Code below is almost the same as quiet_serdes() but avoids
  13577. * all the extra work and the sleeps.
  13578. */
  13579. ppd->driver_link_ready = 0;
  13580. ppd->link_enabled = 0;
  13581. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13582. PLS_OFFLINE);
  13583. /*
  13584. * Step 2: Shutdown LCB and 8051
  13585. * After shutdown, do not restore DC_CFG_RESET value.
  13586. */
  13587. dc_shutdown(dd);
  13588. }