chip.c 450 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424
  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. unsigned long irq_flags;
  5178. sw_index = dd->hw_to_sw[hw_context];
  5179. if (sw_index >= dd->num_send_contexts) {
  5180. dd_dev_err(dd,
  5181. "out of range sw index %u for send context %u\n",
  5182. sw_index, hw_context);
  5183. return;
  5184. }
  5185. sci = &dd->send_contexts[sw_index];
  5186. spin_lock_irqsave(&dd->sc_lock, irq_flags);
  5187. sc = sci->sc;
  5188. if (!sc) {
  5189. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5190. sw_index, hw_context);
  5191. spin_unlock_irqrestore(&dd->sc_lock, irq_flags);
  5192. return;
  5193. }
  5194. /* tell the software that a halt has begun */
  5195. sc_stop(sc, SCF_HALTED);
  5196. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5197. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5198. send_context_err_status_string(flags, sizeof(flags),
  5199. status));
  5200. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5201. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5202. /*
  5203. * Automatically restart halted kernel contexts out of interrupt
  5204. * context. User contexts must ask the driver to restart the context.
  5205. */
  5206. if (sc->type != SC_USER)
  5207. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5208. spin_unlock_irqrestore(&dd->sc_lock, irq_flags);
  5209. /*
  5210. * Update the counters for the corresponding status bits.
  5211. * Note that these particular counters are aggregated over all
  5212. * 160 contexts.
  5213. */
  5214. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5215. if (status & (1ull << i))
  5216. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5217. }
  5218. }
  5219. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5220. unsigned int source, u64 status)
  5221. {
  5222. struct sdma_engine *sde;
  5223. int i = 0;
  5224. sde = &dd->per_sdma[source];
  5225. #ifdef CONFIG_SDMA_VERBOSITY
  5226. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5227. slashstrip(__FILE__), __LINE__, __func__);
  5228. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5229. sde->this_idx, source, (unsigned long long)status);
  5230. #endif
  5231. sde->err_cnt++;
  5232. sdma_engine_error(sde, status);
  5233. /*
  5234. * Update the counters for the corresponding status bits.
  5235. * Note that these particular counters are aggregated over
  5236. * all 16 DMA engines.
  5237. */
  5238. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5239. if (status & (1ull << i))
  5240. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5241. }
  5242. }
  5243. /*
  5244. * CCE block SDMA error interrupt. Source is < 16.
  5245. */
  5246. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5247. {
  5248. #ifdef CONFIG_SDMA_VERBOSITY
  5249. struct sdma_engine *sde = &dd->per_sdma[source];
  5250. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5251. slashstrip(__FILE__), __LINE__, __func__);
  5252. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5253. source);
  5254. sdma_dumpstate(sde);
  5255. #endif
  5256. interrupt_clear_down(dd, source, &sdma_eng_err);
  5257. }
  5258. /*
  5259. * CCE block "various" interrupt. Source is < 8.
  5260. */
  5261. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5262. {
  5263. const struct err_reg_info *eri = &various_err[source];
  5264. /*
  5265. * TCritInt cannot go through interrupt_clear_down()
  5266. * because it is not a second tier interrupt. The handler
  5267. * should be called directly.
  5268. */
  5269. if (source == TCRIT_INT_SOURCE)
  5270. handle_temp_err(dd);
  5271. else if (eri->handler)
  5272. interrupt_clear_down(dd, 0, eri);
  5273. else
  5274. dd_dev_info(dd,
  5275. "%s: Unimplemented/reserved interrupt %d\n",
  5276. __func__, source);
  5277. }
  5278. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5279. {
  5280. /* src_ctx is always zero */
  5281. struct hfi1_pportdata *ppd = dd->pport;
  5282. unsigned long flags;
  5283. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5284. if (reg & QSFP_HFI0_MODPRST_N) {
  5285. if (!qsfp_mod_present(ppd)) {
  5286. dd_dev_info(dd, "%s: QSFP module removed\n",
  5287. __func__);
  5288. ppd->driver_link_ready = 0;
  5289. /*
  5290. * Cable removed, reset all our information about the
  5291. * cache and cable capabilities
  5292. */
  5293. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5294. /*
  5295. * We don't set cache_refresh_required here as we expect
  5296. * an interrupt when a cable is inserted
  5297. */
  5298. ppd->qsfp_info.cache_valid = 0;
  5299. ppd->qsfp_info.reset_needed = 0;
  5300. ppd->qsfp_info.limiting_active = 0;
  5301. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5302. flags);
  5303. /* Invert the ModPresent pin now to detect plug-in */
  5304. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5305. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5306. if ((ppd->offline_disabled_reason >
  5307. HFI1_ODR_MASK(
  5308. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5309. (ppd->offline_disabled_reason ==
  5310. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5311. ppd->offline_disabled_reason =
  5312. HFI1_ODR_MASK(
  5313. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5314. if (ppd->host_link_state == HLS_DN_POLL) {
  5315. /*
  5316. * The link is still in POLL. This means
  5317. * that the normal link down processing
  5318. * will not happen. We have to do it here
  5319. * before turning the DC off.
  5320. */
  5321. queue_work(ppd->link_wq, &ppd->link_down_work);
  5322. }
  5323. } else {
  5324. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5325. __func__);
  5326. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5327. ppd->qsfp_info.cache_valid = 0;
  5328. ppd->qsfp_info.cache_refresh_required = 1;
  5329. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5330. flags);
  5331. /*
  5332. * Stop inversion of ModPresent pin to detect
  5333. * removal of the cable
  5334. */
  5335. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5336. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5337. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5338. ppd->offline_disabled_reason =
  5339. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5340. }
  5341. }
  5342. if (reg & QSFP_HFI0_INT_N) {
  5343. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5344. __func__);
  5345. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5346. ppd->qsfp_info.check_interrupt_flags = 1;
  5347. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5348. }
  5349. /* Schedule the QSFP work only if there is a cable attached. */
  5350. if (qsfp_mod_present(ppd))
  5351. queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
  5352. }
  5353. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5354. {
  5355. int ret;
  5356. ret = do_8051_command(dd, HCMD_MISC,
  5357. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5358. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5359. if (ret != HCMD_SUCCESS) {
  5360. dd_dev_err(dd, "%s: command failed with error %d\n",
  5361. __func__, ret);
  5362. }
  5363. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5364. }
  5365. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5366. {
  5367. int ret;
  5368. ret = do_8051_command(dd, HCMD_MISC,
  5369. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5370. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5371. if (ret != HCMD_SUCCESS) {
  5372. dd_dev_err(dd, "%s: command failed with error %d\n",
  5373. __func__, ret);
  5374. }
  5375. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5376. }
  5377. /*
  5378. * Set the LCB selector - allow host access. The DCC selector always
  5379. * points to the host.
  5380. */
  5381. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5382. {
  5383. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5384. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5385. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5386. }
  5387. /*
  5388. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5389. * points to the host.
  5390. */
  5391. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5392. {
  5393. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5394. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5395. }
  5396. /*
  5397. * Acquire LCB access from the 8051. If the host already has access,
  5398. * just increment a counter. Otherwise, inform the 8051 that the
  5399. * host is taking access.
  5400. *
  5401. * Returns:
  5402. * 0 on success
  5403. * -EBUSY if the 8051 has control and cannot be disturbed
  5404. * -errno if unable to acquire access from the 8051
  5405. */
  5406. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5407. {
  5408. struct hfi1_pportdata *ppd = dd->pport;
  5409. int ret = 0;
  5410. /*
  5411. * Use the host link state lock so the operation of this routine
  5412. * { link state check, selector change, count increment } can occur
  5413. * as a unit against a link state change. Otherwise there is a
  5414. * race between the state change and the count increment.
  5415. */
  5416. if (sleep_ok) {
  5417. mutex_lock(&ppd->hls_lock);
  5418. } else {
  5419. while (!mutex_trylock(&ppd->hls_lock))
  5420. udelay(1);
  5421. }
  5422. /* this access is valid only when the link is up */
  5423. if (ppd->host_link_state & HLS_DOWN) {
  5424. dd_dev_info(dd, "%s: link state %s not up\n",
  5425. __func__, link_state_name(ppd->host_link_state));
  5426. ret = -EBUSY;
  5427. goto done;
  5428. }
  5429. if (dd->lcb_access_count == 0) {
  5430. ret = request_host_lcb_access(dd);
  5431. if (ret) {
  5432. dd_dev_err(dd,
  5433. "%s: unable to acquire LCB access, err %d\n",
  5434. __func__, ret);
  5435. goto done;
  5436. }
  5437. set_host_lcb_access(dd);
  5438. }
  5439. dd->lcb_access_count++;
  5440. done:
  5441. mutex_unlock(&ppd->hls_lock);
  5442. return ret;
  5443. }
  5444. /*
  5445. * Release LCB access by decrementing the use count. If the count is moving
  5446. * from 1 to 0, inform 8051 that it has control back.
  5447. *
  5448. * Returns:
  5449. * 0 on success
  5450. * -errno if unable to release access to the 8051
  5451. */
  5452. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5453. {
  5454. int ret = 0;
  5455. /*
  5456. * Use the host link state lock because the acquire needed it.
  5457. * Here, we only need to keep { selector change, count decrement }
  5458. * as a unit.
  5459. */
  5460. if (sleep_ok) {
  5461. mutex_lock(&dd->pport->hls_lock);
  5462. } else {
  5463. while (!mutex_trylock(&dd->pport->hls_lock))
  5464. udelay(1);
  5465. }
  5466. if (dd->lcb_access_count == 0) {
  5467. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5468. __func__);
  5469. goto done;
  5470. }
  5471. if (dd->lcb_access_count == 1) {
  5472. set_8051_lcb_access(dd);
  5473. ret = request_8051_lcb_access(dd);
  5474. if (ret) {
  5475. dd_dev_err(dd,
  5476. "%s: unable to release LCB access, err %d\n",
  5477. __func__, ret);
  5478. /* restore host access if the grant didn't work */
  5479. set_host_lcb_access(dd);
  5480. goto done;
  5481. }
  5482. }
  5483. dd->lcb_access_count--;
  5484. done:
  5485. mutex_unlock(&dd->pport->hls_lock);
  5486. return ret;
  5487. }
  5488. /*
  5489. * Initialize LCB access variables and state. Called during driver load,
  5490. * after most of the initialization is finished.
  5491. *
  5492. * The DC default is LCB access on for the host. The driver defaults to
  5493. * leaving access to the 8051. Assign access now - this constrains the call
  5494. * to this routine to be after all LCB set-up is done. In particular, after
  5495. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5496. */
  5497. static void init_lcb_access(struct hfi1_devdata *dd)
  5498. {
  5499. dd->lcb_access_count = 0;
  5500. }
  5501. /*
  5502. * Write a response back to a 8051 request.
  5503. */
  5504. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5505. {
  5506. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5507. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5508. (u64)return_code <<
  5509. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5510. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5511. }
  5512. /*
  5513. * Handle host requests from the 8051.
  5514. */
  5515. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5516. {
  5517. struct hfi1_devdata *dd = ppd->dd;
  5518. u64 reg;
  5519. u16 data = 0;
  5520. u8 type;
  5521. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5522. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5523. return; /* no request */
  5524. /* zero out COMPLETED so the response is seen */
  5525. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5526. /* extract request details */
  5527. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5528. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5529. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5530. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5531. switch (type) {
  5532. case HREQ_LOAD_CONFIG:
  5533. case HREQ_SAVE_CONFIG:
  5534. case HREQ_READ_CONFIG:
  5535. case HREQ_SET_TX_EQ_ABS:
  5536. case HREQ_SET_TX_EQ_REL:
  5537. case HREQ_ENABLE:
  5538. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5539. type);
  5540. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5541. break;
  5542. case HREQ_LCB_RESET:
  5543. /* Put the LCB, RX FPE and TX FPE into reset */
  5544. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_INTO_RESET);
  5545. /* Make sure the write completed */
  5546. (void)read_csr(dd, DCC_CFG_RESET);
  5547. /* Hold the reset long enough to take effect */
  5548. udelay(1);
  5549. /* Take the LCB, RX FPE and TX FPE out of reset */
  5550. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_OUT_OF_RESET);
  5551. hreq_response(dd, HREQ_SUCCESS, 0);
  5552. break;
  5553. case HREQ_CONFIG_DONE:
  5554. hreq_response(dd, HREQ_SUCCESS, 0);
  5555. break;
  5556. case HREQ_INTERFACE_TEST:
  5557. hreq_response(dd, HREQ_SUCCESS, data);
  5558. break;
  5559. default:
  5560. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5561. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5562. break;
  5563. }
  5564. }
  5565. /*
  5566. * Set up allocation unit vaulue.
  5567. */
  5568. void set_up_vau(struct hfi1_devdata *dd, u8 vau)
  5569. {
  5570. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5571. /* do not modify other values in the register */
  5572. reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
  5573. reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
  5574. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5575. }
  5576. /*
  5577. * Set up initial VL15 credits of the remote. Assumes the rest of
  5578. * the CM credit registers are zero from a previous global or credit reset.
  5579. * Shared limit for VL15 will always be 0.
  5580. */
  5581. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
  5582. {
  5583. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5584. /* set initial values for total and shared credit limit */
  5585. reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
  5586. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
  5587. /*
  5588. * Set total limit to be equal to VL15 credits.
  5589. * Leave shared limit at 0.
  5590. */
  5591. reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  5592. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5593. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5594. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5595. }
  5596. /*
  5597. * Zero all credit details from the previous connection and
  5598. * reset the CM manager's internal counters.
  5599. */
  5600. void reset_link_credits(struct hfi1_devdata *dd)
  5601. {
  5602. int i;
  5603. /* remove all previous VL credit limits */
  5604. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5605. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5606. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5607. write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
  5608. /* reset the CM block */
  5609. pio_send_control(dd, PSC_CM_RESET);
  5610. /* reset cached value */
  5611. dd->vl15buf_cached = 0;
  5612. }
  5613. /* convert a vCU to a CU */
  5614. static u32 vcu_to_cu(u8 vcu)
  5615. {
  5616. return 1 << vcu;
  5617. }
  5618. /* convert a CU to a vCU */
  5619. static u8 cu_to_vcu(u32 cu)
  5620. {
  5621. return ilog2(cu);
  5622. }
  5623. /* convert a vAU to an AU */
  5624. static u32 vau_to_au(u8 vau)
  5625. {
  5626. return 8 * (1 << vau);
  5627. }
  5628. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5629. {
  5630. ppd->sm_trap_qp = 0x0;
  5631. ppd->sa_qp = 0x1;
  5632. }
  5633. /*
  5634. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5635. */
  5636. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5637. {
  5638. u64 reg;
  5639. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5640. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5641. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5642. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5643. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5644. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5645. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5646. reg = read_csr(dd, DCC_CFG_RESET);
  5647. write_csr(dd, DCC_CFG_RESET, reg |
  5648. DCC_CFG_RESET_RESET_LCB | DCC_CFG_RESET_RESET_RX_FPE);
  5649. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5650. if (!abort) {
  5651. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5652. write_csr(dd, DCC_CFG_RESET, reg);
  5653. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5654. }
  5655. }
  5656. /*
  5657. * This routine should be called after the link has been transitioned to
  5658. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5659. * reset).
  5660. *
  5661. * The expectation is that the caller of this routine would have taken
  5662. * care of properly transitioning the link into the correct state.
  5663. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5664. * before calling this function.
  5665. */
  5666. static void _dc_shutdown(struct hfi1_devdata *dd)
  5667. {
  5668. lockdep_assert_held(&dd->dc8051_lock);
  5669. if (dd->dc_shutdown)
  5670. return;
  5671. dd->dc_shutdown = 1;
  5672. /* Shutdown the LCB */
  5673. lcb_shutdown(dd, 1);
  5674. /*
  5675. * Going to OFFLINE would have causes the 8051 to put the
  5676. * SerDes into reset already. Just need to shut down the 8051,
  5677. * itself.
  5678. */
  5679. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5680. }
  5681. static void dc_shutdown(struct hfi1_devdata *dd)
  5682. {
  5683. mutex_lock(&dd->dc8051_lock);
  5684. _dc_shutdown(dd);
  5685. mutex_unlock(&dd->dc8051_lock);
  5686. }
  5687. /*
  5688. * Calling this after the DC has been brought out of reset should not
  5689. * do any damage.
  5690. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5691. * before calling this function.
  5692. */
  5693. static void _dc_start(struct hfi1_devdata *dd)
  5694. {
  5695. lockdep_assert_held(&dd->dc8051_lock);
  5696. if (!dd->dc_shutdown)
  5697. return;
  5698. /* Take the 8051 out of reset */
  5699. write_csr(dd, DC_DC8051_CFG_RST, 0ull);
  5700. /* Wait until 8051 is ready */
  5701. if (wait_fm_ready(dd, TIMEOUT_8051_START))
  5702. dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
  5703. __func__);
  5704. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5705. write_csr(dd, DCC_CFG_RESET, LCB_RX_FPE_TX_FPE_OUT_OF_RESET);
  5706. /* lcb_shutdown() with abort=1 does not restore these */
  5707. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5708. dd->dc_shutdown = 0;
  5709. }
  5710. static void dc_start(struct hfi1_devdata *dd)
  5711. {
  5712. mutex_lock(&dd->dc8051_lock);
  5713. _dc_start(dd);
  5714. mutex_unlock(&dd->dc8051_lock);
  5715. }
  5716. /*
  5717. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5718. */
  5719. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5720. {
  5721. u64 rx_radr, tx_radr;
  5722. u32 version;
  5723. if (dd->icode != ICODE_FPGA_EMULATION)
  5724. return;
  5725. /*
  5726. * These LCB defaults on emulator _s are good, nothing to do here:
  5727. * LCB_CFG_TX_FIFOS_RADR
  5728. * LCB_CFG_RX_FIFOS_RADR
  5729. * LCB_CFG_LN_DCLK
  5730. * LCB_CFG_IGNORE_LOST_RCLK
  5731. */
  5732. if (is_emulator_s(dd))
  5733. return;
  5734. /* else this is _p */
  5735. version = emulator_rev(dd);
  5736. if (!is_ax(dd))
  5737. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5738. if (version <= 0x12) {
  5739. /* release 0x12 and below */
  5740. /*
  5741. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5742. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5743. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5744. */
  5745. rx_radr =
  5746. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5747. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5748. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5749. /*
  5750. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5751. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5752. */
  5753. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5754. } else if (version <= 0x18) {
  5755. /* release 0x13 up to 0x18 */
  5756. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5757. rx_radr =
  5758. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5759. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5760. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5761. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5762. } else if (version == 0x19) {
  5763. /* release 0x19 */
  5764. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5765. rx_radr =
  5766. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5767. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5768. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5769. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5770. } else if (version == 0x1a) {
  5771. /* release 0x1a */
  5772. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5773. rx_radr =
  5774. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5775. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5776. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5777. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5778. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5779. } else {
  5780. /* release 0x1b and higher */
  5781. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5782. rx_radr =
  5783. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5784. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5785. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5786. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5787. }
  5788. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5789. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5790. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5791. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5792. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5793. }
  5794. /*
  5795. * Handle a SMA idle message
  5796. *
  5797. * This is a work-queue function outside of the interrupt.
  5798. */
  5799. void handle_sma_message(struct work_struct *work)
  5800. {
  5801. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5802. sma_message_work);
  5803. struct hfi1_devdata *dd = ppd->dd;
  5804. u64 msg;
  5805. int ret;
  5806. /*
  5807. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5808. * is stripped off
  5809. */
  5810. ret = read_idle_sma(dd, &msg);
  5811. if (ret)
  5812. return;
  5813. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5814. /*
  5815. * React to the SMA message. Byte[1] (0 for us) is the command.
  5816. */
  5817. switch (msg & 0xff) {
  5818. case SMA_IDLE_ARM:
  5819. /*
  5820. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5821. * State Transitions
  5822. *
  5823. * Only expected in INIT or ARMED, discard otherwise.
  5824. */
  5825. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5826. ppd->neighbor_normal = 1;
  5827. break;
  5828. case SMA_IDLE_ACTIVE:
  5829. /*
  5830. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5831. * State Transitions
  5832. *
  5833. * Can activate the node. Discard otherwise.
  5834. */
  5835. if (ppd->host_link_state == HLS_UP_ARMED &&
  5836. ppd->is_active_optimize_enabled) {
  5837. ppd->neighbor_normal = 1;
  5838. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5839. if (ret)
  5840. dd_dev_err(
  5841. dd,
  5842. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5843. __func__);
  5844. }
  5845. break;
  5846. default:
  5847. dd_dev_err(dd,
  5848. "%s: received unexpected SMA idle message 0x%llx\n",
  5849. __func__, msg);
  5850. break;
  5851. }
  5852. }
  5853. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5854. {
  5855. u64 rcvctrl;
  5856. unsigned long flags;
  5857. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5858. rcvctrl = read_csr(dd, RCV_CTRL);
  5859. rcvctrl |= add;
  5860. rcvctrl &= ~clear;
  5861. write_csr(dd, RCV_CTRL, rcvctrl);
  5862. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5863. }
  5864. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5865. {
  5866. adjust_rcvctrl(dd, add, 0);
  5867. }
  5868. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5869. {
  5870. adjust_rcvctrl(dd, 0, clear);
  5871. }
  5872. /*
  5873. * Called from all interrupt handlers to start handling an SPC freeze.
  5874. */
  5875. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5876. {
  5877. struct hfi1_devdata *dd = ppd->dd;
  5878. struct send_context *sc;
  5879. int i;
  5880. int sc_flags;
  5881. if (flags & FREEZE_SELF)
  5882. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5883. /* enter frozen mode */
  5884. dd->flags |= HFI1_FROZEN;
  5885. /* notify all SDMA engines that they are going into a freeze */
  5886. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5887. sc_flags = SCF_FROZEN | SCF_HALTED | (flags & FREEZE_LINK_DOWN ?
  5888. SCF_LINK_DOWN : 0);
  5889. /* do halt pre-handling on all enabled send contexts */
  5890. for (i = 0; i < dd->num_send_contexts; i++) {
  5891. sc = dd->send_contexts[i].sc;
  5892. if (sc && (sc->flags & SCF_ENABLED))
  5893. sc_stop(sc, sc_flags);
  5894. }
  5895. /* Send context are frozen. Notify user space */
  5896. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5897. if (flags & FREEZE_ABORT) {
  5898. dd_dev_err(dd,
  5899. "Aborted freeze recovery. Please REBOOT system\n");
  5900. return;
  5901. }
  5902. /* queue non-interrupt handler */
  5903. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5904. }
  5905. /*
  5906. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5907. * depending on the "freeze" parameter.
  5908. *
  5909. * No need to return an error if it times out, our only option
  5910. * is to proceed anyway.
  5911. */
  5912. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5913. {
  5914. unsigned long timeout;
  5915. u64 reg;
  5916. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5917. while (1) {
  5918. reg = read_csr(dd, CCE_STATUS);
  5919. if (freeze) {
  5920. /* waiting until all indicators are set */
  5921. if ((reg & ALL_FROZE) == ALL_FROZE)
  5922. return; /* all done */
  5923. } else {
  5924. /* waiting until all indicators are clear */
  5925. if ((reg & ALL_FROZE) == 0)
  5926. return; /* all done */
  5927. }
  5928. if (time_after(jiffies, timeout)) {
  5929. dd_dev_err(dd,
  5930. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5931. freeze ? "" : "un", reg & ALL_FROZE,
  5932. freeze ? ALL_FROZE : 0ull);
  5933. return;
  5934. }
  5935. usleep_range(80, 120);
  5936. }
  5937. }
  5938. /*
  5939. * Do all freeze handling for the RXE block.
  5940. */
  5941. static void rxe_freeze(struct hfi1_devdata *dd)
  5942. {
  5943. int i;
  5944. struct hfi1_ctxtdata *rcd;
  5945. /* disable port */
  5946. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5947. /* disable all receive contexts */
  5948. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5949. rcd = hfi1_rcd_get_by_index(dd, i);
  5950. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
  5951. hfi1_rcd_put(rcd);
  5952. }
  5953. }
  5954. /*
  5955. * Unfreeze handling for the RXE block - kernel contexts only.
  5956. * This will also enable the port. User contexts will do unfreeze
  5957. * handling on a per-context basis as they call into the driver.
  5958. *
  5959. */
  5960. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5961. {
  5962. u32 rcvmask;
  5963. u16 i;
  5964. struct hfi1_ctxtdata *rcd;
  5965. /* enable all kernel contexts */
  5966. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5967. rcd = hfi1_rcd_get_by_index(dd, i);
  5968. /* Ensure all non-user contexts(including vnic) are enabled */
  5969. if (!rcd ||
  5970. (i >= dd->first_dyn_alloc_ctxt && !rcd->is_vnic)) {
  5971. hfi1_rcd_put(rcd);
  5972. continue;
  5973. }
  5974. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5975. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5976. rcvmask |= rcd->rcvhdrtail_kvaddr ?
  5977. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5978. hfi1_rcvctrl(dd, rcvmask, rcd);
  5979. hfi1_rcd_put(rcd);
  5980. }
  5981. /* enable port */
  5982. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5983. }
  5984. /*
  5985. * Non-interrupt SPC freeze handling.
  5986. *
  5987. * This is a work-queue function outside of the triggering interrupt.
  5988. */
  5989. void handle_freeze(struct work_struct *work)
  5990. {
  5991. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5992. freeze_work);
  5993. struct hfi1_devdata *dd = ppd->dd;
  5994. /* wait for freeze indicators on all affected blocks */
  5995. wait_for_freeze_status(dd, 1);
  5996. /* SPC is now frozen */
  5997. /* do send PIO freeze steps */
  5998. pio_freeze(dd);
  5999. /* do send DMA freeze steps */
  6000. sdma_freeze(dd);
  6001. /* do send egress freeze steps - nothing to do */
  6002. /* do receive freeze steps */
  6003. rxe_freeze(dd);
  6004. /*
  6005. * Unfreeze the hardware - clear the freeze, wait for each
  6006. * block's frozen bit to clear, then clear the frozen flag.
  6007. */
  6008. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  6009. wait_for_freeze_status(dd, 0);
  6010. if (is_ax(dd)) {
  6011. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  6012. wait_for_freeze_status(dd, 1);
  6013. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  6014. wait_for_freeze_status(dd, 0);
  6015. }
  6016. /* do send PIO unfreeze steps for kernel contexts */
  6017. pio_kernel_unfreeze(dd);
  6018. /* do send DMA unfreeze steps */
  6019. sdma_unfreeze(dd);
  6020. /* do send egress unfreeze steps - nothing to do */
  6021. /* do receive unfreeze steps for kernel contexts */
  6022. rxe_kernel_unfreeze(dd);
  6023. /*
  6024. * The unfreeze procedure touches global device registers when
  6025. * it disables and re-enables RXE. Mark the device unfrozen
  6026. * after all that is done so other parts of the driver waiting
  6027. * for the device to unfreeze don't do things out of order.
  6028. *
  6029. * The above implies that the meaning of HFI1_FROZEN flag is
  6030. * "Device has gone into freeze mode and freeze mode handling
  6031. * is still in progress."
  6032. *
  6033. * The flag will be removed when freeze mode processing has
  6034. * completed.
  6035. */
  6036. dd->flags &= ~HFI1_FROZEN;
  6037. wake_up(&dd->event_queue);
  6038. /* no longer frozen */
  6039. }
  6040. /**
  6041. * update_xmit_counters - update PortXmitWait/PortVlXmitWait
  6042. * counters.
  6043. * @ppd: info of physical Hfi port
  6044. * @link_width: new link width after link up or downgrade
  6045. *
  6046. * Update the PortXmitWait and PortVlXmitWait counters after
  6047. * a link up or downgrade event to reflect a link width change.
  6048. */
  6049. static void update_xmit_counters(struct hfi1_pportdata *ppd, u16 link_width)
  6050. {
  6051. int i;
  6052. u16 tx_width;
  6053. u16 link_speed;
  6054. tx_width = tx_link_width(link_width);
  6055. link_speed = get_link_speed(ppd->link_speed_active);
  6056. /*
  6057. * There are C_VL_COUNT number of PortVLXmitWait counters.
  6058. * Adding 1 to C_VL_COUNT to include the PortXmitWait counter.
  6059. */
  6060. for (i = 0; i < C_VL_COUNT + 1; i++)
  6061. get_xmit_wait_counters(ppd, tx_width, link_speed, i);
  6062. }
  6063. /*
  6064. * Handle a link up interrupt from the 8051.
  6065. *
  6066. * This is a work-queue function outside of the interrupt.
  6067. */
  6068. void handle_link_up(struct work_struct *work)
  6069. {
  6070. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6071. link_up_work);
  6072. struct hfi1_devdata *dd = ppd->dd;
  6073. set_link_state(ppd, HLS_UP_INIT);
  6074. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  6075. read_ltp_rtt(dd);
  6076. /*
  6077. * OPA specifies that certain counters are cleared on a transition
  6078. * to link up, so do that.
  6079. */
  6080. clear_linkup_counters(dd);
  6081. /*
  6082. * And (re)set link up default values.
  6083. */
  6084. set_linkup_defaults(ppd);
  6085. /*
  6086. * Set VL15 credits. Use cached value from verify cap interrupt.
  6087. * In case of quick linkup or simulator, vl15 value will be set by
  6088. * handle_linkup_change. VerifyCap interrupt handler will not be
  6089. * called in those scenarios.
  6090. */
  6091. if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
  6092. set_up_vl15(dd, dd->vl15buf_cached);
  6093. /* enforce link speed enabled */
  6094. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  6095. /* oops - current speed is not enabled, bounce */
  6096. dd_dev_err(dd,
  6097. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  6098. ppd->link_speed_active, ppd->link_speed_enabled);
  6099. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  6100. OPA_LINKDOWN_REASON_SPEED_POLICY);
  6101. set_link_state(ppd, HLS_DN_OFFLINE);
  6102. start_link(ppd);
  6103. }
  6104. }
  6105. /*
  6106. * Several pieces of LNI information were cached for SMA in ppd.
  6107. * Reset these on link down
  6108. */
  6109. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  6110. {
  6111. ppd->neighbor_guid = 0;
  6112. ppd->neighbor_port_number = 0;
  6113. ppd->neighbor_type = 0;
  6114. ppd->neighbor_fm_security = 0;
  6115. }
  6116. static const char * const link_down_reason_strs[] = {
  6117. [OPA_LINKDOWN_REASON_NONE] = "None",
  6118. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
  6119. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  6120. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  6121. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  6122. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  6123. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  6124. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  6125. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  6126. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  6127. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  6128. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  6129. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  6130. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  6131. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  6132. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  6133. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  6134. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  6135. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  6136. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  6137. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  6138. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  6139. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  6140. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  6141. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  6142. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  6143. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  6144. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  6145. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  6146. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  6147. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  6148. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  6149. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  6150. "Excessive buffer overrun",
  6151. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  6152. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  6153. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  6154. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  6155. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  6156. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  6157. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6158. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6159. "Local media not installed",
  6160. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6161. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6162. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6163. "End to end not installed",
  6164. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6165. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6166. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6167. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6168. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6169. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6170. };
  6171. /* return the neighbor link down reason string */
  6172. static const char *link_down_reason_str(u8 reason)
  6173. {
  6174. const char *str = NULL;
  6175. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6176. str = link_down_reason_strs[reason];
  6177. if (!str)
  6178. str = "(invalid)";
  6179. return str;
  6180. }
  6181. /*
  6182. * Handle a link down interrupt from the 8051.
  6183. *
  6184. * This is a work-queue function outside of the interrupt.
  6185. */
  6186. void handle_link_down(struct work_struct *work)
  6187. {
  6188. u8 lcl_reason, neigh_reason = 0;
  6189. u8 link_down_reason;
  6190. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6191. link_down_work);
  6192. int was_up;
  6193. static const char ldr_str[] = "Link down reason: ";
  6194. if ((ppd->host_link_state &
  6195. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6196. ppd->port_type == PORT_TYPE_FIXED)
  6197. ppd->offline_disabled_reason =
  6198. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6199. /* Go offline first, then deal with reading/writing through 8051 */
  6200. was_up = !!(ppd->host_link_state & HLS_UP);
  6201. set_link_state(ppd, HLS_DN_OFFLINE);
  6202. xchg(&ppd->is_link_down_queued, 0);
  6203. if (was_up) {
  6204. lcl_reason = 0;
  6205. /* link down reason is only valid if the link was up */
  6206. read_link_down_reason(ppd->dd, &link_down_reason);
  6207. switch (link_down_reason) {
  6208. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6209. /* the link went down, no idle message reason */
  6210. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6211. ldr_str);
  6212. break;
  6213. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6214. /*
  6215. * The neighbor reason is only valid if an idle message
  6216. * was received for it.
  6217. */
  6218. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6219. dd_dev_info(ppd->dd,
  6220. "%sNeighbor link down message %d, %s\n",
  6221. ldr_str, neigh_reason,
  6222. link_down_reason_str(neigh_reason));
  6223. break;
  6224. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6225. dd_dev_info(ppd->dd,
  6226. "%sHost requested link to go offline\n",
  6227. ldr_str);
  6228. break;
  6229. default:
  6230. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6231. ldr_str, link_down_reason);
  6232. break;
  6233. }
  6234. /*
  6235. * If no reason, assume peer-initiated but missed
  6236. * LinkGoingDown idle flits.
  6237. */
  6238. if (neigh_reason == 0)
  6239. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6240. } else {
  6241. /* went down while polling or going up */
  6242. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6243. }
  6244. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6245. /* inform the SMA when the link transitions from up to down */
  6246. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6247. ppd->neigh_link_down_reason.sma == 0) {
  6248. ppd->local_link_down_reason.sma =
  6249. ppd->local_link_down_reason.latest;
  6250. ppd->neigh_link_down_reason.sma =
  6251. ppd->neigh_link_down_reason.latest;
  6252. }
  6253. reset_neighbor_info(ppd);
  6254. /* disable the port */
  6255. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6256. /*
  6257. * If there is no cable attached, turn the DC off. Otherwise,
  6258. * start the link bring up.
  6259. */
  6260. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6261. dc_shutdown(ppd->dd);
  6262. else
  6263. start_link(ppd);
  6264. }
  6265. void handle_link_bounce(struct work_struct *work)
  6266. {
  6267. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6268. link_bounce_work);
  6269. /*
  6270. * Only do something if the link is currently up.
  6271. */
  6272. if (ppd->host_link_state & HLS_UP) {
  6273. set_link_state(ppd, HLS_DN_OFFLINE);
  6274. start_link(ppd);
  6275. } else {
  6276. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6277. __func__, link_state_name(ppd->host_link_state));
  6278. }
  6279. }
  6280. /*
  6281. * Mask conversion: Capability exchange to Port LTP. The capability
  6282. * exchange has an implicit 16b CRC that is mandatory.
  6283. */
  6284. static int cap_to_port_ltp(int cap)
  6285. {
  6286. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6287. if (cap & CAP_CRC_14B)
  6288. port_ltp |= PORT_LTP_CRC_MODE_14;
  6289. if (cap & CAP_CRC_48B)
  6290. port_ltp |= PORT_LTP_CRC_MODE_48;
  6291. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6292. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6293. return port_ltp;
  6294. }
  6295. /*
  6296. * Convert an OPA Port LTP mask to capability mask
  6297. */
  6298. int port_ltp_to_cap(int port_ltp)
  6299. {
  6300. int cap_mask = 0;
  6301. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6302. cap_mask |= CAP_CRC_14B;
  6303. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6304. cap_mask |= CAP_CRC_48B;
  6305. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6306. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6307. return cap_mask;
  6308. }
  6309. /*
  6310. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6311. */
  6312. static int lcb_to_port_ltp(int lcb_crc)
  6313. {
  6314. int port_ltp = 0;
  6315. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6316. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6317. else if (lcb_crc == LCB_CRC_48B)
  6318. port_ltp = PORT_LTP_CRC_MODE_48;
  6319. else if (lcb_crc == LCB_CRC_14B)
  6320. port_ltp = PORT_LTP_CRC_MODE_14;
  6321. else
  6322. port_ltp = PORT_LTP_CRC_MODE_16;
  6323. return port_ltp;
  6324. }
  6325. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6326. {
  6327. if (ppd->pkeys[2] != 0) {
  6328. ppd->pkeys[2] = 0;
  6329. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6330. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6331. }
  6332. }
  6333. /*
  6334. * Convert the given link width to the OPA link width bitmask.
  6335. */
  6336. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6337. {
  6338. switch (width) {
  6339. case 0:
  6340. /*
  6341. * Simulator and quick linkup do not set the width.
  6342. * Just set it to 4x without complaint.
  6343. */
  6344. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6345. return OPA_LINK_WIDTH_4X;
  6346. return 0; /* no lanes up */
  6347. case 1: return OPA_LINK_WIDTH_1X;
  6348. case 2: return OPA_LINK_WIDTH_2X;
  6349. case 3: return OPA_LINK_WIDTH_3X;
  6350. default:
  6351. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6352. __func__, width);
  6353. /* fall through */
  6354. case 4: return OPA_LINK_WIDTH_4X;
  6355. }
  6356. }
  6357. /*
  6358. * Do a population count on the bottom nibble.
  6359. */
  6360. static const u8 bit_counts[16] = {
  6361. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6362. };
  6363. static inline u8 nibble_to_count(u8 nibble)
  6364. {
  6365. return bit_counts[nibble & 0xf];
  6366. }
  6367. /*
  6368. * Read the active lane information from the 8051 registers and return
  6369. * their widths.
  6370. *
  6371. * Active lane information is found in these 8051 registers:
  6372. * enable_lane_tx
  6373. * enable_lane_rx
  6374. */
  6375. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6376. u16 *rx_width)
  6377. {
  6378. u16 tx, rx;
  6379. u8 enable_lane_rx;
  6380. u8 enable_lane_tx;
  6381. u8 tx_polarity_inversion;
  6382. u8 rx_polarity_inversion;
  6383. u8 max_rate;
  6384. /* read the active lanes */
  6385. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6386. &rx_polarity_inversion, &max_rate);
  6387. read_local_lni(dd, &enable_lane_rx);
  6388. /* convert to counts */
  6389. tx = nibble_to_count(enable_lane_tx);
  6390. rx = nibble_to_count(enable_lane_rx);
  6391. /*
  6392. * Set link_speed_active here, overriding what was set in
  6393. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6394. * set the max_rate field in handle_verify_cap until v0.19.
  6395. */
  6396. if ((dd->icode == ICODE_RTL_SILICON) &&
  6397. (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
  6398. /* max_rate: 0 = 12.5G, 1 = 25G */
  6399. switch (max_rate) {
  6400. case 0:
  6401. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6402. break;
  6403. default:
  6404. dd_dev_err(dd,
  6405. "%s: unexpected max rate %d, using 25Gb\n",
  6406. __func__, (int)max_rate);
  6407. /* fall through */
  6408. case 1:
  6409. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6410. break;
  6411. }
  6412. }
  6413. dd_dev_info(dd,
  6414. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6415. enable_lane_tx, tx, enable_lane_rx, rx);
  6416. *tx_width = link_width_to_bits(dd, tx);
  6417. *rx_width = link_width_to_bits(dd, rx);
  6418. }
  6419. /*
  6420. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6421. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6422. * after link up. I.e. look elsewhere for downgrade information.
  6423. *
  6424. * Bits are:
  6425. * + bits [7:4] contain the number of active transmitters
  6426. * + bits [3:0] contain the number of active receivers
  6427. * These are numbers 1 through 4 and can be different values if the
  6428. * link is asymmetric.
  6429. *
  6430. * verify_cap_local_fm_link_width[0] retains its original value.
  6431. */
  6432. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6433. u16 *rx_width)
  6434. {
  6435. u16 widths, tx, rx;
  6436. u8 misc_bits, local_flags;
  6437. u16 active_tx, active_rx;
  6438. read_vc_local_link_mode(dd, &misc_bits, &local_flags, &widths);
  6439. tx = widths >> 12;
  6440. rx = (widths >> 8) & 0xf;
  6441. *tx_width = link_width_to_bits(dd, tx);
  6442. *rx_width = link_width_to_bits(dd, rx);
  6443. /* print the active widths */
  6444. get_link_widths(dd, &active_tx, &active_rx);
  6445. }
  6446. /*
  6447. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6448. * hardware information when the link first comes up.
  6449. *
  6450. * The link width is not available until after VerifyCap.AllFramesReceived
  6451. * (the trigger for handle_verify_cap), so this is outside that routine
  6452. * and should be called when the 8051 signals linkup.
  6453. */
  6454. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6455. {
  6456. u16 tx_width, rx_width;
  6457. /* get end-of-LNI link widths */
  6458. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6459. /* use tx_width as the link is supposed to be symmetric on link up */
  6460. ppd->link_width_active = tx_width;
  6461. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6462. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6463. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6464. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6465. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6466. /* cache the active egress rate (units {10^6 bits/sec]) */
  6467. ppd->current_egress_rate = active_egress_rate(ppd);
  6468. }
  6469. /*
  6470. * Handle a verify capabilities interrupt from the 8051.
  6471. *
  6472. * This is a work-queue function outside of the interrupt.
  6473. */
  6474. void handle_verify_cap(struct work_struct *work)
  6475. {
  6476. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6477. link_vc_work);
  6478. struct hfi1_devdata *dd = ppd->dd;
  6479. u64 reg;
  6480. u8 power_management;
  6481. u8 continuous;
  6482. u8 vcu;
  6483. u8 vau;
  6484. u8 z;
  6485. u16 vl15buf;
  6486. u16 link_widths;
  6487. u16 crc_mask;
  6488. u16 crc_val;
  6489. u16 device_id;
  6490. u16 active_tx, active_rx;
  6491. u8 partner_supported_crc;
  6492. u8 remote_tx_rate;
  6493. u8 device_rev;
  6494. set_link_state(ppd, HLS_VERIFY_CAP);
  6495. lcb_shutdown(dd, 0);
  6496. adjust_lcb_for_fpga_serdes(dd);
  6497. read_vc_remote_phy(dd, &power_management, &continuous);
  6498. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6499. &partner_supported_crc);
  6500. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6501. read_remote_device_id(dd, &device_id, &device_rev);
  6502. /* print the active widths */
  6503. get_link_widths(dd, &active_tx, &active_rx);
  6504. dd_dev_info(dd,
  6505. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6506. (int)power_management, (int)continuous);
  6507. dd_dev_info(dd,
  6508. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6509. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6510. (int)partner_supported_crc);
  6511. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6512. (u32)remote_tx_rate, (u32)link_widths);
  6513. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6514. (u32)device_id, (u32)device_rev);
  6515. /*
  6516. * The peer vAU value just read is the peer receiver value. HFI does
  6517. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6518. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6519. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6520. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6521. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6522. * subject to the Z value exception.
  6523. */
  6524. if (vau == 0)
  6525. vau = 1;
  6526. set_up_vau(dd, vau);
  6527. /*
  6528. * Set VL15 credits to 0 in global credit register. Cache remote VL15
  6529. * credits value and wait for link-up interrupt ot set it.
  6530. */
  6531. set_up_vl15(dd, 0);
  6532. dd->vl15buf_cached = vl15buf;
  6533. /* set up the LCB CRC mode */
  6534. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6535. /* order is important: use the lowest bit in common */
  6536. if (crc_mask & CAP_CRC_14B)
  6537. crc_val = LCB_CRC_14B;
  6538. else if (crc_mask & CAP_CRC_48B)
  6539. crc_val = LCB_CRC_48B;
  6540. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6541. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6542. else
  6543. crc_val = LCB_CRC_16B;
  6544. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6545. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6546. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6547. /* set (14b only) or clear sideband credit */
  6548. reg = read_csr(dd, SEND_CM_CTRL);
  6549. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6550. write_csr(dd, SEND_CM_CTRL,
  6551. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6552. } else {
  6553. write_csr(dd, SEND_CM_CTRL,
  6554. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6555. }
  6556. ppd->link_speed_active = 0; /* invalid value */
  6557. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  6558. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6559. switch (remote_tx_rate) {
  6560. case 0:
  6561. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6562. break;
  6563. case 1:
  6564. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6565. break;
  6566. }
  6567. } else {
  6568. /* actual rate is highest bit of the ANDed rates */
  6569. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6570. if (rate & 2)
  6571. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6572. else if (rate & 1)
  6573. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6574. }
  6575. if (ppd->link_speed_active == 0) {
  6576. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6577. __func__, (int)remote_tx_rate);
  6578. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6579. }
  6580. /*
  6581. * Cache the values of the supported, enabled, and active
  6582. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6583. * flags that are returned in the portinfo query differ from
  6584. * what's in the link_crc_mask, crc_sizes, and crc_val
  6585. * variables. Convert these here.
  6586. */
  6587. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6588. /* supported crc modes */
  6589. ppd->port_ltp_crc_mode |=
  6590. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6591. /* enabled crc modes */
  6592. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6593. /* active crc mode */
  6594. /* set up the remote credit return table */
  6595. assign_remote_cm_au_table(dd, vcu);
  6596. /*
  6597. * The LCB is reset on entry to handle_verify_cap(), so this must
  6598. * be applied on every link up.
  6599. *
  6600. * Adjust LCB error kill enable to kill the link if
  6601. * these RBUF errors are seen:
  6602. * REPLAY_BUF_MBE_SMASK
  6603. * FLIT_INPUT_BUF_MBE_SMASK
  6604. */
  6605. if (is_ax(dd)) { /* fixed in B0 */
  6606. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6607. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6608. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6609. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6610. }
  6611. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6612. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6613. /* give 8051 access to the LCB CSRs */
  6614. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6615. set_8051_lcb_access(dd);
  6616. /* tell the 8051 to go to LinkUp */
  6617. set_link_state(ppd, HLS_GOING_UP);
  6618. }
  6619. /**
  6620. * apply_link_downgrade_policy - Apply the link width downgrade enabled
  6621. * policy against the current active link widths.
  6622. * @ppd: info of physical Hfi port
  6623. * @refresh_widths: True indicates link downgrade event
  6624. * @return: True indicates a successful link downgrade. False indicates
  6625. * link downgrade event failed and the link will bounce back to
  6626. * default link width.
  6627. *
  6628. * Called when the enabled policy changes or the active link widths
  6629. * change.
  6630. * Refresh_widths indicates that a link downgrade occurred. The
  6631. * link_downgraded variable is set by refresh_widths and
  6632. * determines the success/failure of the policy application.
  6633. */
  6634. bool apply_link_downgrade_policy(struct hfi1_pportdata *ppd,
  6635. bool refresh_widths)
  6636. {
  6637. int do_bounce = 0;
  6638. int tries;
  6639. u16 lwde;
  6640. u16 tx, rx;
  6641. bool link_downgraded = refresh_widths;
  6642. /* use the hls lock to avoid a race with actual link up */
  6643. tries = 0;
  6644. retry:
  6645. mutex_lock(&ppd->hls_lock);
  6646. /* only apply if the link is up */
  6647. if (ppd->host_link_state & HLS_DOWN) {
  6648. /* still going up..wait and retry */
  6649. if (ppd->host_link_state & HLS_GOING_UP) {
  6650. if (++tries < 1000) {
  6651. mutex_unlock(&ppd->hls_lock);
  6652. usleep_range(100, 120); /* arbitrary */
  6653. goto retry;
  6654. }
  6655. dd_dev_err(ppd->dd,
  6656. "%s: giving up waiting for link state change\n",
  6657. __func__);
  6658. }
  6659. goto done;
  6660. }
  6661. lwde = ppd->link_width_downgrade_enabled;
  6662. if (refresh_widths) {
  6663. get_link_widths(ppd->dd, &tx, &rx);
  6664. ppd->link_width_downgrade_tx_active = tx;
  6665. ppd->link_width_downgrade_rx_active = rx;
  6666. }
  6667. if (ppd->link_width_downgrade_tx_active == 0 ||
  6668. ppd->link_width_downgrade_rx_active == 0) {
  6669. /* the 8051 reported a dead link as a downgrade */
  6670. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6671. link_downgraded = false;
  6672. } else if (lwde == 0) {
  6673. /* downgrade is disabled */
  6674. /* bounce if not at starting active width */
  6675. if ((ppd->link_width_active !=
  6676. ppd->link_width_downgrade_tx_active) ||
  6677. (ppd->link_width_active !=
  6678. ppd->link_width_downgrade_rx_active)) {
  6679. dd_dev_err(ppd->dd,
  6680. "Link downgrade is disabled and link has downgraded, downing link\n");
  6681. dd_dev_err(ppd->dd,
  6682. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6683. ppd->link_width_active,
  6684. ppd->link_width_downgrade_tx_active,
  6685. ppd->link_width_downgrade_rx_active);
  6686. do_bounce = 1;
  6687. link_downgraded = false;
  6688. }
  6689. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6690. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6691. /* Tx or Rx is outside the enabled policy */
  6692. dd_dev_err(ppd->dd,
  6693. "Link is outside of downgrade allowed, downing link\n");
  6694. dd_dev_err(ppd->dd,
  6695. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6696. lwde, ppd->link_width_downgrade_tx_active,
  6697. ppd->link_width_downgrade_rx_active);
  6698. do_bounce = 1;
  6699. link_downgraded = false;
  6700. }
  6701. done:
  6702. mutex_unlock(&ppd->hls_lock);
  6703. if (do_bounce) {
  6704. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6705. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6706. set_link_state(ppd, HLS_DN_OFFLINE);
  6707. start_link(ppd);
  6708. }
  6709. return link_downgraded;
  6710. }
  6711. /*
  6712. * Handle a link downgrade interrupt from the 8051.
  6713. *
  6714. * This is a work-queue function outside of the interrupt.
  6715. */
  6716. void handle_link_downgrade(struct work_struct *work)
  6717. {
  6718. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6719. link_downgrade_work);
  6720. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6721. if (apply_link_downgrade_policy(ppd, true))
  6722. update_xmit_counters(ppd, ppd->link_width_downgrade_tx_active);
  6723. }
  6724. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6725. {
  6726. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6727. ARRAY_SIZE(dcc_err_flags));
  6728. }
  6729. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6730. {
  6731. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6732. ARRAY_SIZE(lcb_err_flags));
  6733. }
  6734. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6735. {
  6736. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6737. ARRAY_SIZE(dc8051_err_flags));
  6738. }
  6739. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6740. {
  6741. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6742. ARRAY_SIZE(dc8051_info_err_flags));
  6743. }
  6744. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6745. {
  6746. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6747. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6748. }
  6749. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6750. {
  6751. struct hfi1_pportdata *ppd = dd->pport;
  6752. u64 info, err, host_msg;
  6753. int queue_link_down = 0;
  6754. char buf[96];
  6755. /* look at the flags */
  6756. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6757. /* 8051 information set by firmware */
  6758. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6759. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6760. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6761. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6762. host_msg = (info >>
  6763. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6764. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6765. /*
  6766. * Handle error flags.
  6767. */
  6768. if (err & FAILED_LNI) {
  6769. /*
  6770. * LNI error indications are cleared by the 8051
  6771. * only when starting polling. Only pay attention
  6772. * to them when in the states that occur during
  6773. * LNI.
  6774. */
  6775. if (ppd->host_link_state
  6776. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6777. queue_link_down = 1;
  6778. dd_dev_info(dd, "Link error: %s\n",
  6779. dc8051_info_err_string(buf,
  6780. sizeof(buf),
  6781. err &
  6782. FAILED_LNI));
  6783. }
  6784. err &= ~(u64)FAILED_LNI;
  6785. }
  6786. /* unknown frames can happen durning LNI, just count */
  6787. if (err & UNKNOWN_FRAME) {
  6788. ppd->unknown_frame_count++;
  6789. err &= ~(u64)UNKNOWN_FRAME;
  6790. }
  6791. if (err) {
  6792. /* report remaining errors, but do not do anything */
  6793. dd_dev_err(dd, "8051 info error: %s\n",
  6794. dc8051_info_err_string(buf, sizeof(buf),
  6795. err));
  6796. }
  6797. /*
  6798. * Handle host message flags.
  6799. */
  6800. if (host_msg & HOST_REQ_DONE) {
  6801. /*
  6802. * Presently, the driver does a busy wait for
  6803. * host requests to complete. This is only an
  6804. * informational message.
  6805. * NOTE: The 8051 clears the host message
  6806. * information *on the next 8051 command*.
  6807. * Therefore, when linkup is achieved,
  6808. * this flag will still be set.
  6809. */
  6810. host_msg &= ~(u64)HOST_REQ_DONE;
  6811. }
  6812. if (host_msg & BC_SMA_MSG) {
  6813. queue_work(ppd->link_wq, &ppd->sma_message_work);
  6814. host_msg &= ~(u64)BC_SMA_MSG;
  6815. }
  6816. if (host_msg & LINKUP_ACHIEVED) {
  6817. dd_dev_info(dd, "8051: Link up\n");
  6818. queue_work(ppd->link_wq, &ppd->link_up_work);
  6819. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6820. }
  6821. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6822. handle_8051_request(ppd);
  6823. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6824. }
  6825. if (host_msg & VERIFY_CAP_FRAME) {
  6826. queue_work(ppd->link_wq, &ppd->link_vc_work);
  6827. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6828. }
  6829. if (host_msg & LINK_GOING_DOWN) {
  6830. const char *extra = "";
  6831. /* no downgrade action needed if going down */
  6832. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6833. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6834. extra = " (ignoring downgrade)";
  6835. }
  6836. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6837. queue_link_down = 1;
  6838. host_msg &= ~(u64)LINK_GOING_DOWN;
  6839. }
  6840. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6841. queue_work(ppd->link_wq, &ppd->link_downgrade_work);
  6842. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6843. }
  6844. if (host_msg) {
  6845. /* report remaining messages, but do not do anything */
  6846. dd_dev_info(dd, "8051 info host message: %s\n",
  6847. dc8051_info_host_msg_string(buf,
  6848. sizeof(buf),
  6849. host_msg));
  6850. }
  6851. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6852. }
  6853. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6854. /*
  6855. * Lost the 8051 heartbeat. If this happens, we
  6856. * receive constant interrupts about it. Disable
  6857. * the interrupt after the first.
  6858. */
  6859. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6860. write_csr(dd, DC_DC8051_ERR_EN,
  6861. read_csr(dd, DC_DC8051_ERR_EN) &
  6862. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6863. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6864. }
  6865. if (reg) {
  6866. /* report the error, but do not do anything */
  6867. dd_dev_err(dd, "8051 error: %s\n",
  6868. dc8051_err_string(buf, sizeof(buf), reg));
  6869. }
  6870. if (queue_link_down) {
  6871. /*
  6872. * if the link is already going down or disabled, do not
  6873. * queue another. If there's a link down entry already
  6874. * queued, don't queue another one.
  6875. */
  6876. if ((ppd->host_link_state &
  6877. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6878. ppd->link_enabled == 0) {
  6879. dd_dev_info(dd, "%s: not queuing link down. host_link_state %x, link_enabled %x\n",
  6880. __func__, ppd->host_link_state,
  6881. ppd->link_enabled);
  6882. } else {
  6883. if (xchg(&ppd->is_link_down_queued, 1) == 1)
  6884. dd_dev_info(dd,
  6885. "%s: link down request already queued\n",
  6886. __func__);
  6887. else
  6888. queue_work(ppd->link_wq, &ppd->link_down_work);
  6889. }
  6890. }
  6891. }
  6892. static const char * const fm_config_txt[] = {
  6893. [0] =
  6894. "BadHeadDist: Distance violation between two head flits",
  6895. [1] =
  6896. "BadTailDist: Distance violation between two tail flits",
  6897. [2] =
  6898. "BadCtrlDist: Distance violation between two credit control flits",
  6899. [3] =
  6900. "BadCrdAck: Credits return for unsupported VL",
  6901. [4] =
  6902. "UnsupportedVLMarker: Received VL Marker",
  6903. [5] =
  6904. "BadPreempt: Exceeded the preemption nesting level",
  6905. [6] =
  6906. "BadControlFlit: Received unsupported control flit",
  6907. /* no 7 */
  6908. [8] =
  6909. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6910. };
  6911. static const char * const port_rcv_txt[] = {
  6912. [1] =
  6913. "BadPktLen: Illegal PktLen",
  6914. [2] =
  6915. "PktLenTooLong: Packet longer than PktLen",
  6916. [3] =
  6917. "PktLenTooShort: Packet shorter than PktLen",
  6918. [4] =
  6919. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6920. [5] =
  6921. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6922. [6] =
  6923. "BadL2: Illegal L2 opcode",
  6924. [7] =
  6925. "BadSC: Unsupported SC",
  6926. [9] =
  6927. "BadRC: Illegal RC",
  6928. [11] =
  6929. "PreemptError: Preempting with same VL",
  6930. [12] =
  6931. "PreemptVL15: Preempting a VL15 packet",
  6932. };
  6933. #define OPA_LDR_FMCONFIG_OFFSET 16
  6934. #define OPA_LDR_PORTRCV_OFFSET 0
  6935. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6936. {
  6937. u64 info, hdr0, hdr1;
  6938. const char *extra;
  6939. char buf[96];
  6940. struct hfi1_pportdata *ppd = dd->pport;
  6941. u8 lcl_reason = 0;
  6942. int do_bounce = 0;
  6943. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6944. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6945. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6946. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6947. /* set status bit */
  6948. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6949. }
  6950. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6951. }
  6952. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6953. struct hfi1_pportdata *ppd = dd->pport;
  6954. /* this counter saturates at (2^32) - 1 */
  6955. if (ppd->link_downed < (u32)UINT_MAX)
  6956. ppd->link_downed++;
  6957. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6958. }
  6959. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6960. u8 reason_valid = 1;
  6961. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6962. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6963. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6964. /* set status bit */
  6965. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6966. }
  6967. switch (info) {
  6968. case 0:
  6969. case 1:
  6970. case 2:
  6971. case 3:
  6972. case 4:
  6973. case 5:
  6974. case 6:
  6975. extra = fm_config_txt[info];
  6976. break;
  6977. case 8:
  6978. extra = fm_config_txt[info];
  6979. if (ppd->port_error_action &
  6980. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6981. do_bounce = 1;
  6982. /*
  6983. * lcl_reason cannot be derived from info
  6984. * for this error
  6985. */
  6986. lcl_reason =
  6987. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6988. }
  6989. break;
  6990. default:
  6991. reason_valid = 0;
  6992. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6993. extra = buf;
  6994. break;
  6995. }
  6996. if (reason_valid && !do_bounce) {
  6997. do_bounce = ppd->port_error_action &
  6998. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6999. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  7000. }
  7001. /* just report this */
  7002. dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
  7003. extra);
  7004. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  7005. }
  7006. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  7007. u8 reason_valid = 1;
  7008. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  7009. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  7010. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  7011. if (!(dd->err_info_rcvport.status_and_code &
  7012. OPA_EI_STATUS_SMASK)) {
  7013. dd->err_info_rcvport.status_and_code =
  7014. info & OPA_EI_CODE_SMASK;
  7015. /* set status bit */
  7016. dd->err_info_rcvport.status_and_code |=
  7017. OPA_EI_STATUS_SMASK;
  7018. /*
  7019. * save first 2 flits in the packet that caused
  7020. * the error
  7021. */
  7022. dd->err_info_rcvport.packet_flit1 = hdr0;
  7023. dd->err_info_rcvport.packet_flit2 = hdr1;
  7024. }
  7025. switch (info) {
  7026. case 1:
  7027. case 2:
  7028. case 3:
  7029. case 4:
  7030. case 5:
  7031. case 6:
  7032. case 7:
  7033. case 9:
  7034. case 11:
  7035. case 12:
  7036. extra = port_rcv_txt[info];
  7037. break;
  7038. default:
  7039. reason_valid = 0;
  7040. snprintf(buf, sizeof(buf), "reserved%lld", info);
  7041. extra = buf;
  7042. break;
  7043. }
  7044. if (reason_valid && !do_bounce) {
  7045. do_bounce = ppd->port_error_action &
  7046. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  7047. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  7048. }
  7049. /* just report this */
  7050. dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
  7051. " hdr0 0x%llx, hdr1 0x%llx\n",
  7052. extra, hdr0, hdr1);
  7053. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  7054. }
  7055. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  7056. /* informative only */
  7057. dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
  7058. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  7059. }
  7060. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  7061. /* informative only */
  7062. dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
  7063. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  7064. }
  7065. if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
  7066. reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
  7067. /* report any remaining errors */
  7068. if (reg)
  7069. dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
  7070. dcc_err_string(buf, sizeof(buf), reg));
  7071. if (lcl_reason == 0)
  7072. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  7073. if (do_bounce) {
  7074. dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
  7075. __func__);
  7076. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  7077. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  7078. }
  7079. }
  7080. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  7081. {
  7082. char buf[96];
  7083. dd_dev_info(dd, "LCB Error: %s\n",
  7084. lcb_err_string(buf, sizeof(buf), reg));
  7085. }
  7086. /*
  7087. * CCE block DC interrupt. Source is < 8.
  7088. */
  7089. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  7090. {
  7091. const struct err_reg_info *eri = &dc_errs[source];
  7092. if (eri->handler) {
  7093. interrupt_clear_down(dd, 0, eri);
  7094. } else if (source == 3 /* dc_lbm_int */) {
  7095. /*
  7096. * This indicates that a parity error has occurred on the
  7097. * address/control lines presented to the LBM. The error
  7098. * is a single pulse, there is no associated error flag,
  7099. * and it is non-maskable. This is because if a parity
  7100. * error occurs on the request the request is dropped.
  7101. * This should never occur, but it is nice to know if it
  7102. * ever does.
  7103. */
  7104. dd_dev_err(dd, "Parity error in DC LBM block\n");
  7105. } else {
  7106. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  7107. }
  7108. }
  7109. /*
  7110. * TX block send credit interrupt. Source is < 160.
  7111. */
  7112. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  7113. {
  7114. sc_group_release_update(dd, source);
  7115. }
  7116. /*
  7117. * TX block SDMA interrupt. Source is < 48.
  7118. *
  7119. * SDMA interrupts are grouped by type:
  7120. *
  7121. * 0 - N-1 = SDma
  7122. * N - 2N-1 = SDmaProgress
  7123. * 2N - 3N-1 = SDmaIdle
  7124. */
  7125. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  7126. {
  7127. /* what interrupt */
  7128. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  7129. /* which engine */
  7130. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  7131. #ifdef CONFIG_SDMA_VERBOSITY
  7132. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  7133. slashstrip(__FILE__), __LINE__, __func__);
  7134. sdma_dumpstate(&dd->per_sdma[which]);
  7135. #endif
  7136. if (likely(what < 3 && which < dd->num_sdma)) {
  7137. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  7138. } else {
  7139. /* should not happen */
  7140. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  7141. }
  7142. }
  7143. /**
  7144. * is_rcv_avail_int() - User receive context available IRQ handler
  7145. * @dd: valid dd
  7146. * @source: logical IRQ source (offset from IS_RCVAVAIL_START)
  7147. *
  7148. * RX block receive available interrupt. Source is < 160.
  7149. *
  7150. * This is the general interrupt handler for user (PSM) receive contexts,
  7151. * and can only be used for non-threaded IRQs.
  7152. */
  7153. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7154. {
  7155. struct hfi1_ctxtdata *rcd;
  7156. char *err_detail;
  7157. if (likely(source < dd->num_rcv_contexts)) {
  7158. rcd = hfi1_rcd_get_by_index(dd, source);
  7159. if (rcd) {
  7160. handle_user_interrupt(rcd);
  7161. hfi1_rcd_put(rcd);
  7162. return; /* OK */
  7163. }
  7164. /* received an interrupt, but no rcd */
  7165. err_detail = "dataless";
  7166. } else {
  7167. /* received an interrupt, but are not using that context */
  7168. err_detail = "out of range";
  7169. }
  7170. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7171. err_detail, source);
  7172. }
  7173. /**
  7174. * is_rcv_urgent_int() - User receive context urgent IRQ handler
  7175. * @dd: valid dd
  7176. * @source: logical IRQ source (ofse from IS_RCVURGENT_START)
  7177. *
  7178. * RX block receive urgent interrupt. Source is < 160.
  7179. *
  7180. * NOTE: kernel receive contexts specifically do NOT enable this IRQ.
  7181. */
  7182. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7183. {
  7184. struct hfi1_ctxtdata *rcd;
  7185. char *err_detail;
  7186. if (likely(source < dd->num_rcv_contexts)) {
  7187. rcd = hfi1_rcd_get_by_index(dd, source);
  7188. if (rcd) {
  7189. handle_user_interrupt(rcd);
  7190. hfi1_rcd_put(rcd);
  7191. return; /* OK */
  7192. }
  7193. /* received an interrupt, but no rcd */
  7194. err_detail = "dataless";
  7195. } else {
  7196. /* received an interrupt, but are not using that context */
  7197. err_detail = "out of range";
  7198. }
  7199. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7200. err_detail, source);
  7201. }
  7202. /*
  7203. * Reserved range interrupt. Should not be called in normal operation.
  7204. */
  7205. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7206. {
  7207. char name[64];
  7208. dd_dev_err(dd, "unexpected %s interrupt\n",
  7209. is_reserved_name(name, sizeof(name), source));
  7210. }
  7211. static const struct is_table is_table[] = {
  7212. /*
  7213. * start end
  7214. * name func interrupt func
  7215. */
  7216. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7217. is_misc_err_name, is_misc_err_int },
  7218. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7219. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7220. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7221. is_sendctxt_err_name, is_sendctxt_err_int },
  7222. { IS_SDMA_START, IS_SDMA_END,
  7223. is_sdma_eng_name, is_sdma_eng_int },
  7224. { IS_VARIOUS_START, IS_VARIOUS_END,
  7225. is_various_name, is_various_int },
  7226. { IS_DC_START, IS_DC_END,
  7227. is_dc_name, is_dc_int },
  7228. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7229. is_rcv_avail_name, is_rcv_avail_int },
  7230. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7231. is_rcv_urgent_name, is_rcv_urgent_int },
  7232. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7233. is_send_credit_name, is_send_credit_int},
  7234. { IS_RESERVED_START, IS_RESERVED_END,
  7235. is_reserved_name, is_reserved_int},
  7236. };
  7237. /*
  7238. * Interrupt source interrupt - called when the given source has an interrupt.
  7239. * Source is a bit index into an array of 64-bit integers.
  7240. */
  7241. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7242. {
  7243. const struct is_table *entry;
  7244. /* avoids a double compare by walking the table in-order */
  7245. for (entry = &is_table[0]; entry->is_name; entry++) {
  7246. if (source < entry->end) {
  7247. trace_hfi1_interrupt(dd, entry, source);
  7248. entry->is_int(dd, source - entry->start);
  7249. return;
  7250. }
  7251. }
  7252. /* fell off the end */
  7253. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7254. }
  7255. /**
  7256. * gerneral_interrupt() - General interrupt handler
  7257. * @irq: MSIx IRQ vector
  7258. * @data: hfi1 devdata
  7259. *
  7260. * This is able to correctly handle all non-threaded interrupts. Receive
  7261. * context DATA IRQs are threaded and are not supported by this handler.
  7262. *
  7263. */
  7264. static irqreturn_t general_interrupt(int irq, void *data)
  7265. {
  7266. struct hfi1_devdata *dd = data;
  7267. u64 regs[CCE_NUM_INT_CSRS];
  7268. u32 bit;
  7269. int i;
  7270. irqreturn_t handled = IRQ_NONE;
  7271. this_cpu_inc(*dd->int_counter);
  7272. /* phase 1: scan and clear all handled interrupts */
  7273. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7274. if (dd->gi_mask[i] == 0) {
  7275. regs[i] = 0; /* used later */
  7276. continue;
  7277. }
  7278. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7279. dd->gi_mask[i];
  7280. /* only clear if anything is set */
  7281. if (regs[i])
  7282. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7283. }
  7284. /* phase 2: call the appropriate handler */
  7285. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7286. CCE_NUM_INT_CSRS * 64) {
  7287. is_interrupt(dd, bit);
  7288. handled = IRQ_HANDLED;
  7289. }
  7290. return handled;
  7291. }
  7292. static irqreturn_t sdma_interrupt(int irq, void *data)
  7293. {
  7294. struct sdma_engine *sde = data;
  7295. struct hfi1_devdata *dd = sde->dd;
  7296. u64 status;
  7297. #ifdef CONFIG_SDMA_VERBOSITY
  7298. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7299. slashstrip(__FILE__), __LINE__, __func__);
  7300. sdma_dumpstate(sde);
  7301. #endif
  7302. this_cpu_inc(*dd->int_counter);
  7303. /* This read_csr is really bad in the hot path */
  7304. status = read_csr(dd,
  7305. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7306. & sde->imask;
  7307. if (likely(status)) {
  7308. /* clear the interrupt(s) */
  7309. write_csr(dd,
  7310. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7311. status);
  7312. /* handle the interrupt(s) */
  7313. sdma_engine_interrupt(sde, status);
  7314. } else {
  7315. dd_dev_info_ratelimited(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7316. sde->this_idx);
  7317. }
  7318. return IRQ_HANDLED;
  7319. }
  7320. /*
  7321. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7322. * to insure that the write completed. This does NOT guarantee that
  7323. * queued DMA writes to memory from the chip are pushed.
  7324. */
  7325. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7326. {
  7327. struct hfi1_devdata *dd = rcd->dd;
  7328. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7329. mmiowb(); /* make sure everything before is written */
  7330. write_csr(dd, addr, rcd->imask);
  7331. /* force the above write on the chip and get a value back */
  7332. (void)read_csr(dd, addr);
  7333. }
  7334. /* force the receive interrupt */
  7335. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7336. {
  7337. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7338. }
  7339. /*
  7340. * Return non-zero if a packet is present.
  7341. *
  7342. * This routine is called when rechecking for packets after the RcvAvail
  7343. * interrupt has been cleared down. First, do a quick check of memory for
  7344. * a packet present. If not found, use an expensive CSR read of the context
  7345. * tail to determine the actual tail. The CSR read is necessary because there
  7346. * is no method to push pending DMAs to memory other than an interrupt and we
  7347. * are trying to determine if we need to force an interrupt.
  7348. */
  7349. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7350. {
  7351. u32 tail;
  7352. int present;
  7353. if (!rcd->rcvhdrtail_kvaddr)
  7354. present = (rcd->seq_cnt ==
  7355. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7356. else /* is RDMA rtail */
  7357. present = (rcd->head != get_rcvhdrtail(rcd));
  7358. if (present)
  7359. return 1;
  7360. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7361. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7362. return rcd->head != tail;
  7363. }
  7364. /*
  7365. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7366. * This routine will try to handle packets immediately (latency), but if
  7367. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7368. * chip receive interrupt is *not* cleared down until this or the thread (if
  7369. * invoked) is finished. The intent is to avoid extra interrupts while we
  7370. * are processing packets anyway.
  7371. */
  7372. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7373. {
  7374. struct hfi1_ctxtdata *rcd = data;
  7375. struct hfi1_devdata *dd = rcd->dd;
  7376. int disposition;
  7377. int present;
  7378. trace_hfi1_receive_interrupt(dd, rcd);
  7379. this_cpu_inc(*dd->int_counter);
  7380. aspm_ctx_disable(rcd);
  7381. /* receive interrupt remains blocked while processing packets */
  7382. disposition = rcd->do_interrupt(rcd, 0);
  7383. /*
  7384. * Too many packets were seen while processing packets in this
  7385. * IRQ handler. Invoke the handler thread. The receive interrupt
  7386. * remains blocked.
  7387. */
  7388. if (disposition == RCV_PKT_LIMIT)
  7389. return IRQ_WAKE_THREAD;
  7390. /*
  7391. * The packet processor detected no more packets. Clear the receive
  7392. * interrupt and recheck for a packet packet that may have arrived
  7393. * after the previous check and interrupt clear. If a packet arrived,
  7394. * force another interrupt.
  7395. */
  7396. clear_recv_intr(rcd);
  7397. present = check_packet_present(rcd);
  7398. if (present)
  7399. force_recv_intr(rcd);
  7400. return IRQ_HANDLED;
  7401. }
  7402. /*
  7403. * Receive packet thread handler. This expects to be invoked with the
  7404. * receive interrupt still blocked.
  7405. */
  7406. static irqreturn_t receive_context_thread(int irq, void *data)
  7407. {
  7408. struct hfi1_ctxtdata *rcd = data;
  7409. int present;
  7410. /* receive interrupt is still blocked from the IRQ handler */
  7411. (void)rcd->do_interrupt(rcd, 1);
  7412. /*
  7413. * The packet processor will only return if it detected no more
  7414. * packets. Hold IRQs here so we can safely clear the interrupt and
  7415. * recheck for a packet that may have arrived after the previous
  7416. * check and the interrupt clear. If a packet arrived, force another
  7417. * interrupt.
  7418. */
  7419. local_irq_disable();
  7420. clear_recv_intr(rcd);
  7421. present = check_packet_present(rcd);
  7422. if (present)
  7423. force_recv_intr(rcd);
  7424. local_irq_enable();
  7425. return IRQ_HANDLED;
  7426. }
  7427. /* ========================================================================= */
  7428. u32 read_physical_state(struct hfi1_devdata *dd)
  7429. {
  7430. u64 reg;
  7431. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7432. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7433. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7434. }
  7435. u32 read_logical_state(struct hfi1_devdata *dd)
  7436. {
  7437. u64 reg;
  7438. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7439. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7440. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7441. }
  7442. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7443. {
  7444. u64 reg;
  7445. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7446. /* clear current state, set new state */
  7447. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7448. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7449. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7450. }
  7451. /*
  7452. * Use the 8051 to read a LCB CSR.
  7453. */
  7454. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7455. {
  7456. u32 regno;
  7457. int ret;
  7458. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7459. if (acquire_lcb_access(dd, 0) == 0) {
  7460. *data = read_csr(dd, addr);
  7461. release_lcb_access(dd, 0);
  7462. return 0;
  7463. }
  7464. return -EBUSY;
  7465. }
  7466. /* register is an index of LCB registers: (offset - base) / 8 */
  7467. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7468. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7469. if (ret != HCMD_SUCCESS)
  7470. return -EBUSY;
  7471. return 0;
  7472. }
  7473. /*
  7474. * Provide a cache for some of the LCB registers in case the LCB is
  7475. * unavailable.
  7476. * (The LCB is unavailable in certain link states, for example.)
  7477. */
  7478. struct lcb_datum {
  7479. u32 off;
  7480. u64 val;
  7481. };
  7482. static struct lcb_datum lcb_cache[] = {
  7483. { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
  7484. { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
  7485. { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
  7486. };
  7487. static void update_lcb_cache(struct hfi1_devdata *dd)
  7488. {
  7489. int i;
  7490. int ret;
  7491. u64 val;
  7492. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7493. ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
  7494. /* Update if we get good data */
  7495. if (likely(ret != -EBUSY))
  7496. lcb_cache[i].val = val;
  7497. }
  7498. }
  7499. static int read_lcb_cache(u32 off, u64 *val)
  7500. {
  7501. int i;
  7502. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7503. if (lcb_cache[i].off == off) {
  7504. *val = lcb_cache[i].val;
  7505. return 0;
  7506. }
  7507. }
  7508. pr_warn("%s bad offset 0x%x\n", __func__, off);
  7509. return -1;
  7510. }
  7511. /*
  7512. * Read an LCB CSR. Access may not be in host control, so check.
  7513. * Return 0 on success, -EBUSY on failure.
  7514. */
  7515. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7516. {
  7517. struct hfi1_pportdata *ppd = dd->pport;
  7518. /* if up, go through the 8051 for the value */
  7519. if (ppd->host_link_state & HLS_UP)
  7520. return read_lcb_via_8051(dd, addr, data);
  7521. /* if going up or down, check the cache, otherwise, no access */
  7522. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
  7523. if (read_lcb_cache(addr, data))
  7524. return -EBUSY;
  7525. return 0;
  7526. }
  7527. /* otherwise, host has access */
  7528. *data = read_csr(dd, addr);
  7529. return 0;
  7530. }
  7531. /*
  7532. * Use the 8051 to write a LCB CSR.
  7533. */
  7534. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7535. {
  7536. u32 regno;
  7537. int ret;
  7538. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7539. (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
  7540. if (acquire_lcb_access(dd, 0) == 0) {
  7541. write_csr(dd, addr, data);
  7542. release_lcb_access(dd, 0);
  7543. return 0;
  7544. }
  7545. return -EBUSY;
  7546. }
  7547. /* register is an index of LCB registers: (offset - base) / 8 */
  7548. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7549. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7550. if (ret != HCMD_SUCCESS)
  7551. return -EBUSY;
  7552. return 0;
  7553. }
  7554. /*
  7555. * Write an LCB CSR. Access may not be in host control, so check.
  7556. * Return 0 on success, -EBUSY on failure.
  7557. */
  7558. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7559. {
  7560. struct hfi1_pportdata *ppd = dd->pport;
  7561. /* if up, go through the 8051 for the value */
  7562. if (ppd->host_link_state & HLS_UP)
  7563. return write_lcb_via_8051(dd, addr, data);
  7564. /* if going up or down, no access */
  7565. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7566. return -EBUSY;
  7567. /* otherwise, host has access */
  7568. write_csr(dd, addr, data);
  7569. return 0;
  7570. }
  7571. /*
  7572. * Returns:
  7573. * < 0 = Linux error, not able to get access
  7574. * > 0 = 8051 command RETURN_CODE
  7575. */
  7576. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  7577. u64 *out_data)
  7578. {
  7579. u64 reg, completed;
  7580. int return_code;
  7581. unsigned long timeout;
  7582. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7583. mutex_lock(&dd->dc8051_lock);
  7584. /* We can't send any commands to the 8051 if it's in reset */
  7585. if (dd->dc_shutdown) {
  7586. return_code = -ENODEV;
  7587. goto fail;
  7588. }
  7589. /*
  7590. * If an 8051 host command timed out previously, then the 8051 is
  7591. * stuck.
  7592. *
  7593. * On first timeout, attempt to reset and restart the entire DC
  7594. * block (including 8051). (Is this too big of a hammer?)
  7595. *
  7596. * If the 8051 times out a second time, the reset did not bring it
  7597. * back to healthy life. In that case, fail any subsequent commands.
  7598. */
  7599. if (dd->dc8051_timed_out) {
  7600. if (dd->dc8051_timed_out > 1) {
  7601. dd_dev_err(dd,
  7602. "Previous 8051 host command timed out, skipping command %u\n",
  7603. type);
  7604. return_code = -ENXIO;
  7605. goto fail;
  7606. }
  7607. _dc_shutdown(dd);
  7608. _dc_start(dd);
  7609. }
  7610. /*
  7611. * If there is no timeout, then the 8051 command interface is
  7612. * waiting for a command.
  7613. */
  7614. /*
  7615. * When writing a LCB CSR, out_data contains the full value to
  7616. * to be written, while in_data contains the relative LCB
  7617. * address in 7:0. Do the work here, rather than the caller,
  7618. * of distrubting the write data to where it needs to go:
  7619. *
  7620. * Write data
  7621. * 39:00 -> in_data[47:8]
  7622. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7623. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7624. */
  7625. if (type == HCMD_WRITE_LCB_CSR) {
  7626. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7627. /* must preserve COMPLETED - it is tied to hardware */
  7628. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
  7629. reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
  7630. reg |= ((((*out_data) >> 40) & 0xff) <<
  7631. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7632. | ((((*out_data) >> 48) & 0xffff) <<
  7633. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7634. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7635. }
  7636. /*
  7637. * Do two writes: the first to stabilize the type and req_data, the
  7638. * second to activate.
  7639. */
  7640. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7641. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7642. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7643. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7644. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7645. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7646. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7647. /* wait for completion, alternate: interrupt */
  7648. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7649. while (1) {
  7650. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7651. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7652. if (completed)
  7653. break;
  7654. if (time_after(jiffies, timeout)) {
  7655. dd->dc8051_timed_out++;
  7656. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7657. if (out_data)
  7658. *out_data = 0;
  7659. return_code = -ETIMEDOUT;
  7660. goto fail;
  7661. }
  7662. udelay(2);
  7663. }
  7664. if (out_data) {
  7665. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7666. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7667. if (type == HCMD_READ_LCB_CSR) {
  7668. /* top 16 bits are in a different register */
  7669. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7670. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7671. << (48
  7672. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7673. }
  7674. }
  7675. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7676. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7677. dd->dc8051_timed_out = 0;
  7678. /*
  7679. * Clear command for next user.
  7680. */
  7681. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7682. fail:
  7683. mutex_unlock(&dd->dc8051_lock);
  7684. return return_code;
  7685. }
  7686. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7687. {
  7688. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7689. }
  7690. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7691. u8 lane_id, u32 config_data)
  7692. {
  7693. u64 data;
  7694. int ret;
  7695. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7696. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7697. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7698. ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7699. if (ret != HCMD_SUCCESS) {
  7700. dd_dev_err(dd,
  7701. "load 8051 config: field id %d, lane %d, err %d\n",
  7702. (int)field_id, (int)lane_id, ret);
  7703. }
  7704. return ret;
  7705. }
  7706. /*
  7707. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7708. * set the result, even on error.
  7709. * Return 0 on success, -errno on failure
  7710. */
  7711. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7712. u32 *result)
  7713. {
  7714. u64 big_data;
  7715. u32 addr;
  7716. int ret;
  7717. /* address start depends on the lane_id */
  7718. if (lane_id < 4)
  7719. addr = (4 * NUM_GENERAL_FIELDS)
  7720. + (lane_id * 4 * NUM_LANE_FIELDS);
  7721. else
  7722. addr = 0;
  7723. addr += field_id * 4;
  7724. /* read is in 8-byte chunks, hardware will truncate the address down */
  7725. ret = read_8051_data(dd, addr, 8, &big_data);
  7726. if (ret == 0) {
  7727. /* extract the 4 bytes we want */
  7728. if (addr & 0x4)
  7729. *result = (u32)(big_data >> 32);
  7730. else
  7731. *result = (u32)big_data;
  7732. } else {
  7733. *result = 0;
  7734. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7735. __func__, lane_id, field_id);
  7736. }
  7737. return ret;
  7738. }
  7739. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7740. u8 continuous)
  7741. {
  7742. u32 frame;
  7743. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7744. | power_management << POWER_MANAGEMENT_SHIFT;
  7745. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7746. GENERAL_CONFIG, frame);
  7747. }
  7748. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7749. u16 vl15buf, u8 crc_sizes)
  7750. {
  7751. u32 frame;
  7752. frame = (u32)vau << VAU_SHIFT
  7753. | (u32)z << Z_SHIFT
  7754. | (u32)vcu << VCU_SHIFT
  7755. | (u32)vl15buf << VL15BUF_SHIFT
  7756. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7757. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7758. GENERAL_CONFIG, frame);
  7759. }
  7760. static void read_vc_local_link_mode(struct hfi1_devdata *dd, u8 *misc_bits,
  7761. u8 *flag_bits, u16 *link_widths)
  7762. {
  7763. u32 frame;
  7764. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_MODE, GENERAL_CONFIG,
  7765. &frame);
  7766. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7767. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7768. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7769. }
  7770. static int write_vc_local_link_mode(struct hfi1_devdata *dd,
  7771. u8 misc_bits,
  7772. u8 flag_bits,
  7773. u16 link_widths)
  7774. {
  7775. u32 frame;
  7776. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7777. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7778. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7779. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_MODE, GENERAL_CONFIG,
  7780. frame);
  7781. }
  7782. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7783. u8 device_rev)
  7784. {
  7785. u32 frame;
  7786. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7787. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7788. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7789. }
  7790. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7791. u8 *device_rev)
  7792. {
  7793. u32 frame;
  7794. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7795. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7796. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7797. & REMOTE_DEVICE_REV_MASK;
  7798. }
  7799. int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
  7800. {
  7801. u32 frame;
  7802. u32 mask;
  7803. mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
  7804. read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
  7805. /* Clear, then set field */
  7806. frame &= ~mask;
  7807. frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
  7808. return load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
  7809. frame);
  7810. }
  7811. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
  7812. u8 *ver_patch)
  7813. {
  7814. u32 frame;
  7815. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7816. *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
  7817. STS_FM_VERSION_MAJOR_MASK;
  7818. *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
  7819. STS_FM_VERSION_MINOR_MASK;
  7820. read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
  7821. *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
  7822. STS_FM_VERSION_PATCH_MASK;
  7823. }
  7824. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7825. u8 *continuous)
  7826. {
  7827. u32 frame;
  7828. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7829. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7830. & POWER_MANAGEMENT_MASK;
  7831. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7832. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7833. }
  7834. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7835. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7836. {
  7837. u32 frame;
  7838. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7839. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7840. *z = (frame >> Z_SHIFT) & Z_MASK;
  7841. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7842. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7843. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7844. }
  7845. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7846. u8 *remote_tx_rate,
  7847. u16 *link_widths)
  7848. {
  7849. u32 frame;
  7850. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7851. &frame);
  7852. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7853. & REMOTE_TX_RATE_MASK;
  7854. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7855. }
  7856. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7857. {
  7858. u32 frame;
  7859. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7860. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7861. }
  7862. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7863. {
  7864. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7865. }
  7866. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7867. {
  7868. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7869. }
  7870. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7871. {
  7872. u32 frame;
  7873. int ret;
  7874. *link_quality = 0;
  7875. if (dd->pport->host_link_state & HLS_UP) {
  7876. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7877. &frame);
  7878. if (ret == 0)
  7879. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7880. & LINK_QUALITY_MASK;
  7881. }
  7882. }
  7883. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7884. {
  7885. u32 frame;
  7886. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7887. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7888. }
  7889. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7890. {
  7891. u32 frame;
  7892. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7893. *ldr = (frame & 0xff);
  7894. }
  7895. static int read_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. int ret;
  7903. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7904. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7905. & ENABLE_LANE_TX_MASK;
  7906. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7907. & TX_POLARITY_INVERSION_MASK;
  7908. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7909. & RX_POLARITY_INVERSION_MASK;
  7910. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7911. return ret;
  7912. }
  7913. static int write_tx_settings(struct hfi1_devdata *dd,
  7914. u8 enable_lane_tx,
  7915. u8 tx_polarity_inversion,
  7916. u8 rx_polarity_inversion,
  7917. u8 max_rate)
  7918. {
  7919. u32 frame;
  7920. /* no need to mask, all variable sizes match field widths */
  7921. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7922. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7923. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7924. | max_rate << MAX_RATE_SHIFT;
  7925. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7926. }
  7927. /*
  7928. * Read an idle LCB message.
  7929. *
  7930. * Returns 0 on success, -EINVAL on error
  7931. */
  7932. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7933. {
  7934. int ret;
  7935. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7936. if (ret != HCMD_SUCCESS) {
  7937. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7938. (u32)type, ret);
  7939. return -EINVAL;
  7940. }
  7941. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7942. /* return only the payload as we already know the type */
  7943. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7944. return 0;
  7945. }
  7946. /*
  7947. * Read an idle SMA message. To be done in response to a notification from
  7948. * the 8051.
  7949. *
  7950. * Returns 0 on success, -EINVAL on error
  7951. */
  7952. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7953. {
  7954. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7955. data);
  7956. }
  7957. /*
  7958. * Send an idle LCB message.
  7959. *
  7960. * Returns 0 on success, -EINVAL on error
  7961. */
  7962. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7963. {
  7964. int ret;
  7965. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7966. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7967. if (ret != HCMD_SUCCESS) {
  7968. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7969. data, ret);
  7970. return -EINVAL;
  7971. }
  7972. return 0;
  7973. }
  7974. /*
  7975. * Send an idle SMA message.
  7976. *
  7977. * Returns 0 on success, -EINVAL on error
  7978. */
  7979. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7980. {
  7981. u64 data;
  7982. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7983. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7984. return send_idle_message(dd, data);
  7985. }
  7986. /*
  7987. * Initialize the LCB then do a quick link up. This may or may not be
  7988. * in loopback.
  7989. *
  7990. * return 0 on success, -errno on error
  7991. */
  7992. static int do_quick_linkup(struct hfi1_devdata *dd)
  7993. {
  7994. int ret;
  7995. lcb_shutdown(dd, 0);
  7996. if (loopback) {
  7997. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7998. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7999. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  8000. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  8001. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  8002. }
  8003. /* start the LCBs */
  8004. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  8005. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  8006. /* simulator only loopback steps */
  8007. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  8008. /* LCB_CFG_RUN.EN = 1 */
  8009. write_csr(dd, DC_LCB_CFG_RUN,
  8010. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  8011. ret = wait_link_transfer_active(dd, 10);
  8012. if (ret)
  8013. return ret;
  8014. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  8015. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  8016. }
  8017. if (!loopback) {
  8018. /*
  8019. * When doing quick linkup and not in loopback, both
  8020. * sides must be done with LCB set-up before either
  8021. * starts the quick linkup. Put a delay here so that
  8022. * both sides can be started and have a chance to be
  8023. * done with LCB set up before resuming.
  8024. */
  8025. dd_dev_err(dd,
  8026. "Pausing for peer to be finished with LCB set up\n");
  8027. msleep(5000);
  8028. dd_dev_err(dd, "Continuing with quick linkup\n");
  8029. }
  8030. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  8031. set_8051_lcb_access(dd);
  8032. /*
  8033. * State "quick" LinkUp request sets the physical link state to
  8034. * LinkUp without a verify capability sequence.
  8035. * This state is in simulator v37 and later.
  8036. */
  8037. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  8038. if (ret != HCMD_SUCCESS) {
  8039. dd_dev_err(dd,
  8040. "%s: set physical link state to quick LinkUp failed with return %d\n",
  8041. __func__, ret);
  8042. set_host_lcb_access(dd);
  8043. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8044. if (ret >= 0)
  8045. ret = -EINVAL;
  8046. return ret;
  8047. }
  8048. return 0; /* success */
  8049. }
  8050. /*
  8051. * Do all special steps to set up loopback.
  8052. */
  8053. static int init_loopback(struct hfi1_devdata *dd)
  8054. {
  8055. dd_dev_info(dd, "Entering loopback mode\n");
  8056. /* all loopbacks should disable self GUID check */
  8057. write_csr(dd, DC_DC8051_CFG_MODE,
  8058. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  8059. /*
  8060. * The simulator has only one loopback option - LCB. Switch
  8061. * to that option, which includes quick link up.
  8062. *
  8063. * Accept all valid loopback values.
  8064. */
  8065. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  8066. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  8067. loopback == LOOPBACK_CABLE)) {
  8068. loopback = LOOPBACK_LCB;
  8069. quick_linkup = 1;
  8070. return 0;
  8071. }
  8072. /*
  8073. * SerDes loopback init sequence is handled in set_local_link_attributes
  8074. */
  8075. if (loopback == LOOPBACK_SERDES)
  8076. return 0;
  8077. /* LCB loopback - handled at poll time */
  8078. if (loopback == LOOPBACK_LCB) {
  8079. quick_linkup = 1; /* LCB is always quick linkup */
  8080. /* not supported in emulation due to emulation RTL changes */
  8081. if (dd->icode == ICODE_FPGA_EMULATION) {
  8082. dd_dev_err(dd,
  8083. "LCB loopback not supported in emulation\n");
  8084. return -EINVAL;
  8085. }
  8086. return 0;
  8087. }
  8088. /* external cable loopback requires no extra steps */
  8089. if (loopback == LOOPBACK_CABLE)
  8090. return 0;
  8091. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  8092. return -EINVAL;
  8093. }
  8094. /*
  8095. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  8096. * used in the Verify Capability link width attribute.
  8097. */
  8098. static u16 opa_to_vc_link_widths(u16 opa_widths)
  8099. {
  8100. int i;
  8101. u16 result = 0;
  8102. static const struct link_bits {
  8103. u16 from;
  8104. u16 to;
  8105. } opa_link_xlate[] = {
  8106. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  8107. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  8108. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  8109. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  8110. };
  8111. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  8112. if (opa_widths & opa_link_xlate[i].from)
  8113. result |= opa_link_xlate[i].to;
  8114. }
  8115. return result;
  8116. }
  8117. /*
  8118. * Set link attributes before moving to polling.
  8119. */
  8120. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  8121. {
  8122. struct hfi1_devdata *dd = ppd->dd;
  8123. u8 enable_lane_tx;
  8124. u8 tx_polarity_inversion;
  8125. u8 rx_polarity_inversion;
  8126. int ret;
  8127. u32 misc_bits = 0;
  8128. /* reset our fabric serdes to clear any lingering problems */
  8129. fabric_serdes_reset(dd);
  8130. /* set the local tx rate - need to read-modify-write */
  8131. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  8132. &rx_polarity_inversion, &ppd->local_tx_rate);
  8133. if (ret)
  8134. goto set_local_link_attributes_fail;
  8135. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  8136. /* set the tx rate to the fastest enabled */
  8137. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8138. ppd->local_tx_rate = 1;
  8139. else
  8140. ppd->local_tx_rate = 0;
  8141. } else {
  8142. /* set the tx rate to all enabled */
  8143. ppd->local_tx_rate = 0;
  8144. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8145. ppd->local_tx_rate |= 2;
  8146. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  8147. ppd->local_tx_rate |= 1;
  8148. }
  8149. enable_lane_tx = 0xF; /* enable all four lanes */
  8150. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  8151. rx_polarity_inversion, ppd->local_tx_rate);
  8152. if (ret != HCMD_SUCCESS)
  8153. goto set_local_link_attributes_fail;
  8154. ret = write_host_interface_version(dd, HOST_INTERFACE_VERSION);
  8155. if (ret != HCMD_SUCCESS) {
  8156. dd_dev_err(dd,
  8157. "Failed to set host interface version, return 0x%x\n",
  8158. ret);
  8159. goto set_local_link_attributes_fail;
  8160. }
  8161. /*
  8162. * DC supports continuous updates.
  8163. */
  8164. ret = write_vc_local_phy(dd,
  8165. 0 /* no power management */,
  8166. 1 /* continuous updates */);
  8167. if (ret != HCMD_SUCCESS)
  8168. goto set_local_link_attributes_fail;
  8169. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  8170. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  8171. ppd->port_crc_mode_enabled);
  8172. if (ret != HCMD_SUCCESS)
  8173. goto set_local_link_attributes_fail;
  8174. /*
  8175. * SerDes loopback init sequence requires
  8176. * setting bit 0 of MISC_CONFIG_BITS
  8177. */
  8178. if (loopback == LOOPBACK_SERDES)
  8179. misc_bits |= 1 << LOOPBACK_SERDES_CONFIG_BIT_MASK_SHIFT;
  8180. /*
  8181. * An external device configuration request is used to reset the LCB
  8182. * to retry to obtain operational lanes when the first attempt is
  8183. * unsuccesful.
  8184. */
  8185. if (dd->dc8051_ver >= dc8051_ver(1, 25, 0))
  8186. misc_bits |= 1 << EXT_CFG_LCB_RESET_SUPPORTED_SHIFT;
  8187. ret = write_vc_local_link_mode(dd, misc_bits, 0,
  8188. opa_to_vc_link_widths(
  8189. ppd->link_width_enabled));
  8190. if (ret != HCMD_SUCCESS)
  8191. goto set_local_link_attributes_fail;
  8192. /* let peer know who we are */
  8193. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  8194. if (ret == HCMD_SUCCESS)
  8195. return 0;
  8196. set_local_link_attributes_fail:
  8197. dd_dev_err(dd,
  8198. "Failed to set local link attributes, return 0x%x\n",
  8199. ret);
  8200. return ret;
  8201. }
  8202. /*
  8203. * Call this to start the link.
  8204. * Do not do anything if the link is disabled.
  8205. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8206. */
  8207. int start_link(struct hfi1_pportdata *ppd)
  8208. {
  8209. /*
  8210. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8211. * error rate. Needs to be done before starting the link.
  8212. */
  8213. tune_serdes(ppd);
  8214. if (!ppd->driver_link_ready) {
  8215. dd_dev_info(ppd->dd,
  8216. "%s: stopping link start because driver is not ready\n",
  8217. __func__);
  8218. return 0;
  8219. }
  8220. /*
  8221. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8222. * pkey table can be configured properly if the HFI unit is connected
  8223. * to switch port with MgmtAllowed=NO
  8224. */
  8225. clear_full_mgmt_pkey(ppd);
  8226. return set_link_state(ppd, HLS_DN_POLL);
  8227. }
  8228. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8229. {
  8230. struct hfi1_devdata *dd = ppd->dd;
  8231. u64 mask;
  8232. unsigned long timeout;
  8233. /*
  8234. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8235. * effect of power up on plug-in. We ignore this false positive
  8236. * interrupt until the module has finished powering up by waiting for
  8237. * a minimum timeout of the module inrush initialization time of
  8238. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8239. * module have stabilized.
  8240. */
  8241. msleep(500);
  8242. /*
  8243. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8244. */
  8245. timeout = jiffies + msecs_to_jiffies(2000);
  8246. while (1) {
  8247. mask = read_csr(dd, dd->hfi1_id ?
  8248. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8249. if (!(mask & QSFP_HFI0_INT_N))
  8250. break;
  8251. if (time_after(jiffies, timeout)) {
  8252. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8253. __func__);
  8254. break;
  8255. }
  8256. udelay(2);
  8257. }
  8258. }
  8259. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8260. {
  8261. struct hfi1_devdata *dd = ppd->dd;
  8262. u64 mask;
  8263. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8264. if (enable) {
  8265. /*
  8266. * Clear the status register to avoid an immediate interrupt
  8267. * when we re-enable the IntN pin
  8268. */
  8269. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8270. QSFP_HFI0_INT_N);
  8271. mask |= (u64)QSFP_HFI0_INT_N;
  8272. } else {
  8273. mask &= ~(u64)QSFP_HFI0_INT_N;
  8274. }
  8275. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8276. }
  8277. int reset_qsfp(struct hfi1_pportdata *ppd)
  8278. {
  8279. struct hfi1_devdata *dd = ppd->dd;
  8280. u64 mask, qsfp_mask;
  8281. /* Disable INT_N from triggering QSFP interrupts */
  8282. set_qsfp_int_n(ppd, 0);
  8283. /* Reset the QSFP */
  8284. mask = (u64)QSFP_HFI0_RESET_N;
  8285. qsfp_mask = read_csr(dd,
  8286. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8287. qsfp_mask &= ~mask;
  8288. write_csr(dd,
  8289. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8290. udelay(10);
  8291. qsfp_mask |= mask;
  8292. write_csr(dd,
  8293. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8294. wait_for_qsfp_init(ppd);
  8295. /*
  8296. * Allow INT_N to trigger the QSFP interrupt to watch
  8297. * for alarms and warnings
  8298. */
  8299. set_qsfp_int_n(ppd, 1);
  8300. /*
  8301. * After the reset, AOC transmitters are enabled by default. They need
  8302. * to be turned off to complete the QSFP setup before they can be
  8303. * enabled again.
  8304. */
  8305. return set_qsfp_tx(ppd, 0);
  8306. }
  8307. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8308. u8 *qsfp_interrupt_status)
  8309. {
  8310. struct hfi1_devdata *dd = ppd->dd;
  8311. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8312. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8313. dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
  8314. __func__);
  8315. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8316. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8317. dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
  8318. __func__);
  8319. /*
  8320. * The remaining alarms/warnings don't matter if the link is down.
  8321. */
  8322. if (ppd->host_link_state & HLS_DOWN)
  8323. return 0;
  8324. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8325. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8326. dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
  8327. __func__);
  8328. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8329. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8330. dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
  8331. __func__);
  8332. /* Byte 2 is vendor specific */
  8333. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8334. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8335. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
  8336. __func__);
  8337. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8338. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8339. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
  8340. __func__);
  8341. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8342. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8343. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
  8344. __func__);
  8345. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8346. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8347. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
  8348. __func__);
  8349. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8350. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8351. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8352. __func__);
  8353. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8354. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8355. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8356. __func__);
  8357. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8358. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8359. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8360. __func__);
  8361. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8362. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8363. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8364. __func__);
  8365. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8366. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8367. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
  8368. __func__);
  8369. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8370. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8371. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
  8372. __func__);
  8373. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8374. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8375. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
  8376. __func__);
  8377. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8378. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8379. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
  8380. __func__);
  8381. /* Bytes 9-10 and 11-12 are reserved */
  8382. /* Bytes 13-15 are vendor specific */
  8383. return 0;
  8384. }
  8385. /* This routine will only be scheduled if the QSFP module present is asserted */
  8386. void qsfp_event(struct work_struct *work)
  8387. {
  8388. struct qsfp_data *qd;
  8389. struct hfi1_pportdata *ppd;
  8390. struct hfi1_devdata *dd;
  8391. qd = container_of(work, struct qsfp_data, qsfp_work);
  8392. ppd = qd->ppd;
  8393. dd = ppd->dd;
  8394. /* Sanity check */
  8395. if (!qsfp_mod_present(ppd))
  8396. return;
  8397. if (ppd->host_link_state == HLS_DN_DISABLE) {
  8398. dd_dev_info(ppd->dd,
  8399. "%s: stopping link start because link is disabled\n",
  8400. __func__);
  8401. return;
  8402. }
  8403. /*
  8404. * Turn DC back on after cable has been re-inserted. Up until
  8405. * now, the DC has been in reset to save power.
  8406. */
  8407. dc_start(dd);
  8408. if (qd->cache_refresh_required) {
  8409. set_qsfp_int_n(ppd, 0);
  8410. wait_for_qsfp_init(ppd);
  8411. /*
  8412. * Allow INT_N to trigger the QSFP interrupt to watch
  8413. * for alarms and warnings
  8414. */
  8415. set_qsfp_int_n(ppd, 1);
  8416. start_link(ppd);
  8417. }
  8418. if (qd->check_interrupt_flags) {
  8419. u8 qsfp_interrupt_status[16] = {0,};
  8420. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8421. &qsfp_interrupt_status[0], 16) != 16) {
  8422. dd_dev_info(dd,
  8423. "%s: Failed to read status of QSFP module\n",
  8424. __func__);
  8425. } else {
  8426. unsigned long flags;
  8427. handle_qsfp_error_conditions(
  8428. ppd, qsfp_interrupt_status);
  8429. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8430. ppd->qsfp_info.check_interrupt_flags = 0;
  8431. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8432. flags);
  8433. }
  8434. }
  8435. }
  8436. static void init_qsfp_int(struct hfi1_devdata *dd)
  8437. {
  8438. struct hfi1_pportdata *ppd = dd->pport;
  8439. u64 qsfp_mask, cce_int_mask;
  8440. const int qsfp1_int_smask = QSFP1_INT % 64;
  8441. const int qsfp2_int_smask = QSFP2_INT % 64;
  8442. /*
  8443. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8444. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8445. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8446. * the index of the appropriate CSR in the CCEIntMask CSR array
  8447. */
  8448. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8449. (8 * (QSFP1_INT / 64)));
  8450. if (dd->hfi1_id) {
  8451. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8452. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8453. cce_int_mask);
  8454. } else {
  8455. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8456. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8457. cce_int_mask);
  8458. }
  8459. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8460. /* Clear current status to avoid spurious interrupts */
  8461. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8462. qsfp_mask);
  8463. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8464. qsfp_mask);
  8465. set_qsfp_int_n(ppd, 0);
  8466. /* Handle active low nature of INT_N and MODPRST_N pins */
  8467. if (qsfp_mod_present(ppd))
  8468. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8469. write_csr(dd,
  8470. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8471. qsfp_mask);
  8472. }
  8473. /*
  8474. * Do a one-time initialize of the LCB block.
  8475. */
  8476. static void init_lcb(struct hfi1_devdata *dd)
  8477. {
  8478. /* simulator does not correctly handle LCB cclk loopback, skip */
  8479. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8480. return;
  8481. /* the DC has been reset earlier in the driver load */
  8482. /* set LCB for cclk loopback on the port */
  8483. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8484. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8485. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8486. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8487. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8488. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8489. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8490. }
  8491. /*
  8492. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8493. * on error.
  8494. */
  8495. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8496. {
  8497. int ret;
  8498. u8 status;
  8499. /*
  8500. * Report success if not a QSFP or, if it is a QSFP, but the cable is
  8501. * not present
  8502. */
  8503. if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
  8504. return 0;
  8505. /* read byte 2, the status byte */
  8506. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8507. if (ret < 0)
  8508. return ret;
  8509. if (ret != 1)
  8510. return -EIO;
  8511. return 0; /* success */
  8512. }
  8513. /*
  8514. * Values for QSFP retry.
  8515. *
  8516. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8517. * arrived at from experience on a large cluster.
  8518. */
  8519. #define MAX_QSFP_RETRIES 20
  8520. #define QSFP_RETRY_WAIT 500 /* msec */
  8521. /*
  8522. * Try a QSFP read. If it fails, schedule a retry for later.
  8523. * Called on first link activation after driver load.
  8524. */
  8525. static void try_start_link(struct hfi1_pportdata *ppd)
  8526. {
  8527. if (test_qsfp_read(ppd)) {
  8528. /* read failed */
  8529. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8530. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8531. return;
  8532. }
  8533. dd_dev_info(ppd->dd,
  8534. "QSFP not responding, waiting and retrying %d\n",
  8535. (int)ppd->qsfp_retry_count);
  8536. ppd->qsfp_retry_count++;
  8537. queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
  8538. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8539. return;
  8540. }
  8541. ppd->qsfp_retry_count = 0;
  8542. start_link(ppd);
  8543. }
  8544. /*
  8545. * Workqueue function to start the link after a delay.
  8546. */
  8547. void handle_start_link(struct work_struct *work)
  8548. {
  8549. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8550. start_link_work.work);
  8551. try_start_link(ppd);
  8552. }
  8553. int bringup_serdes(struct hfi1_pportdata *ppd)
  8554. {
  8555. struct hfi1_devdata *dd = ppd->dd;
  8556. u64 guid;
  8557. int ret;
  8558. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8559. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8560. guid = ppd->guids[HFI1_PORT_GUID_INDEX];
  8561. if (!guid) {
  8562. if (dd->base_guid)
  8563. guid = dd->base_guid + ppd->port - 1;
  8564. ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
  8565. }
  8566. /* Set linkinit_reason on power up per OPA spec */
  8567. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8568. /* one-time init of the LCB */
  8569. init_lcb(dd);
  8570. if (loopback) {
  8571. ret = init_loopback(dd);
  8572. if (ret < 0)
  8573. return ret;
  8574. }
  8575. get_port_type(ppd);
  8576. if (ppd->port_type == PORT_TYPE_QSFP) {
  8577. set_qsfp_int_n(ppd, 0);
  8578. wait_for_qsfp_init(ppd);
  8579. set_qsfp_int_n(ppd, 1);
  8580. }
  8581. try_start_link(ppd);
  8582. return 0;
  8583. }
  8584. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8585. {
  8586. struct hfi1_devdata *dd = ppd->dd;
  8587. /*
  8588. * Shut down the link and keep it down. First turn off that the
  8589. * driver wants to allow the link to be up (driver_link_ready).
  8590. * Then make sure the link is not automatically restarted
  8591. * (link_enabled). Cancel any pending restart. And finally
  8592. * go offline.
  8593. */
  8594. ppd->driver_link_ready = 0;
  8595. ppd->link_enabled = 0;
  8596. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8597. flush_delayed_work(&ppd->start_link_work);
  8598. cancel_delayed_work_sync(&ppd->start_link_work);
  8599. ppd->offline_disabled_reason =
  8600. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_REBOOT);
  8601. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_REBOOT, 0,
  8602. OPA_LINKDOWN_REASON_REBOOT);
  8603. set_link_state(ppd, HLS_DN_OFFLINE);
  8604. /* disable the port */
  8605. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8606. }
  8607. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8608. {
  8609. struct hfi1_pportdata *ppd;
  8610. int i;
  8611. ppd = (struct hfi1_pportdata *)(dd + 1);
  8612. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8613. ppd->ibport_data.rvp.rc_acks = NULL;
  8614. ppd->ibport_data.rvp.rc_qacks = NULL;
  8615. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8616. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8617. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8618. if (!ppd->ibport_data.rvp.rc_acks ||
  8619. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8620. !ppd->ibport_data.rvp.rc_qacks)
  8621. return -ENOMEM;
  8622. }
  8623. return 0;
  8624. }
  8625. /*
  8626. * index is the index into the receive array
  8627. */
  8628. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8629. u32 type, unsigned long pa, u16 order)
  8630. {
  8631. u64 reg;
  8632. if (!(dd->flags & HFI1_PRESENT))
  8633. goto done;
  8634. if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
  8635. pa = 0;
  8636. order = 0;
  8637. } else if (type > PT_INVALID) {
  8638. dd_dev_err(dd,
  8639. "unexpected receive array type %u for index %u, not handled\n",
  8640. type, index);
  8641. goto done;
  8642. }
  8643. trace_hfi1_put_tid(dd, index, type, pa, order);
  8644. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8645. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8646. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8647. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8648. << RCV_ARRAY_RT_ADDR_SHIFT;
  8649. trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
  8650. writeq(reg, dd->rcvarray_wc + (index * 8));
  8651. if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
  8652. /*
  8653. * Eager entries are written and flushed
  8654. *
  8655. * Expected entries are flushed every 4 writes
  8656. */
  8657. flush_wc();
  8658. done:
  8659. return;
  8660. }
  8661. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8662. {
  8663. struct hfi1_devdata *dd = rcd->dd;
  8664. u32 i;
  8665. /* this could be optimized */
  8666. for (i = rcd->eager_base; i < rcd->eager_base +
  8667. rcd->egrbufs.alloced; i++)
  8668. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8669. for (i = rcd->expected_base;
  8670. i < rcd->expected_base + rcd->expected_count; i++)
  8671. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8672. }
  8673. static const char * const ib_cfg_name_strings[] = {
  8674. "HFI1_IB_CFG_LIDLMC",
  8675. "HFI1_IB_CFG_LWID_DG_ENB",
  8676. "HFI1_IB_CFG_LWID_ENB",
  8677. "HFI1_IB_CFG_LWID",
  8678. "HFI1_IB_CFG_SPD_ENB",
  8679. "HFI1_IB_CFG_SPD",
  8680. "HFI1_IB_CFG_RXPOL_ENB",
  8681. "HFI1_IB_CFG_LREV_ENB",
  8682. "HFI1_IB_CFG_LINKLATENCY",
  8683. "HFI1_IB_CFG_HRTBT",
  8684. "HFI1_IB_CFG_OP_VLS",
  8685. "HFI1_IB_CFG_VL_HIGH_CAP",
  8686. "HFI1_IB_CFG_VL_LOW_CAP",
  8687. "HFI1_IB_CFG_OVERRUN_THRESH",
  8688. "HFI1_IB_CFG_PHYERR_THRESH",
  8689. "HFI1_IB_CFG_LINKDEFAULT",
  8690. "HFI1_IB_CFG_PKEYS",
  8691. "HFI1_IB_CFG_MTU",
  8692. "HFI1_IB_CFG_LSTATE",
  8693. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8694. "HFI1_IB_CFG_PMA_TICKS",
  8695. "HFI1_IB_CFG_PORT"
  8696. };
  8697. static const char *ib_cfg_name(int which)
  8698. {
  8699. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8700. return "invalid";
  8701. return ib_cfg_name_strings[which];
  8702. }
  8703. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8704. {
  8705. struct hfi1_devdata *dd = ppd->dd;
  8706. int val = 0;
  8707. switch (which) {
  8708. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8709. val = ppd->link_width_enabled;
  8710. break;
  8711. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8712. val = ppd->link_width_active;
  8713. break;
  8714. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8715. val = ppd->link_speed_enabled;
  8716. break;
  8717. case HFI1_IB_CFG_SPD: /* current Link speed */
  8718. val = ppd->link_speed_active;
  8719. break;
  8720. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8721. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8722. case HFI1_IB_CFG_LINKLATENCY:
  8723. goto unimplemented;
  8724. case HFI1_IB_CFG_OP_VLS:
  8725. val = ppd->actual_vls_operational;
  8726. break;
  8727. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8728. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8729. break;
  8730. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8731. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8732. break;
  8733. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8734. val = ppd->overrun_threshold;
  8735. break;
  8736. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8737. val = ppd->phy_error_threshold;
  8738. break;
  8739. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8740. val = HLS_DEFAULT;
  8741. break;
  8742. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8743. case HFI1_IB_CFG_PMA_TICKS:
  8744. default:
  8745. unimplemented:
  8746. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8747. dd_dev_info(
  8748. dd,
  8749. "%s: which %s: not implemented\n",
  8750. __func__,
  8751. ib_cfg_name(which));
  8752. break;
  8753. }
  8754. return val;
  8755. }
  8756. /*
  8757. * The largest MAD packet size.
  8758. */
  8759. #define MAX_MAD_PACKET 2048
  8760. /*
  8761. * Return the maximum header bytes that can go on the _wire_
  8762. * for this device. This count includes the ICRC which is
  8763. * not part of the packet held in memory but it is appended
  8764. * by the HW.
  8765. * This is dependent on the device's receive header entry size.
  8766. * HFI allows this to be set per-receive context, but the
  8767. * driver presently enforces a global value.
  8768. */
  8769. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8770. {
  8771. /*
  8772. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8773. * the Receive Header Entry Size minus the PBC (or RHF) size
  8774. * plus one DW for the ICRC appended by HW.
  8775. *
  8776. * dd->rcd[0].rcvhdrqentsize is in DW.
  8777. * We use rcd[0] as all context will have the same value. Also,
  8778. * the first kernel context would have been allocated by now so
  8779. * we are guaranteed a valid value.
  8780. */
  8781. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8782. }
  8783. /*
  8784. * Set Send Length
  8785. * @ppd - per port data
  8786. *
  8787. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8788. * registers compare against LRH.PktLen, so use the max bytes included
  8789. * in the LRH.
  8790. *
  8791. * This routine changes all VL values except VL15, which it maintains at
  8792. * the same value.
  8793. */
  8794. static void set_send_length(struct hfi1_pportdata *ppd)
  8795. {
  8796. struct hfi1_devdata *dd = ppd->dd;
  8797. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8798. u32 maxvlmtu = dd->vld[15].mtu;
  8799. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8800. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8801. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8802. int i, j;
  8803. u32 thres;
  8804. for (i = 0; i < ppd->vls_supported; i++) {
  8805. if (dd->vld[i].mtu > maxvlmtu)
  8806. maxvlmtu = dd->vld[i].mtu;
  8807. if (i <= 3)
  8808. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8809. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8810. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8811. else
  8812. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8813. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8814. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8815. }
  8816. write_csr(dd, SEND_LEN_CHECK0, len1);
  8817. write_csr(dd, SEND_LEN_CHECK1, len2);
  8818. /* adjust kernel credit return thresholds based on new MTUs */
  8819. /* all kernel receive contexts have the same hdrqentsize */
  8820. for (i = 0; i < ppd->vls_supported; i++) {
  8821. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8822. sc_mtu_to_threshold(dd->vld[i].sc,
  8823. dd->vld[i].mtu,
  8824. dd->rcd[0]->rcvhdrqentsize));
  8825. for (j = 0; j < INIT_SC_PER_VL; j++)
  8826. sc_set_cr_threshold(
  8827. pio_select_send_context_vl(dd, j, i),
  8828. thres);
  8829. }
  8830. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8831. sc_mtu_to_threshold(dd->vld[15].sc,
  8832. dd->vld[15].mtu,
  8833. dd->rcd[0]->rcvhdrqentsize));
  8834. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8835. /* Adjust maximum MTU for the port in DC */
  8836. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8837. (ilog2(maxvlmtu >> 8) + 1);
  8838. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8839. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8840. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8841. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8842. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8843. }
  8844. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8845. {
  8846. int i;
  8847. u64 sreg = 0;
  8848. struct hfi1_devdata *dd = ppd->dd;
  8849. u32 mask = ~((1U << ppd->lmc) - 1);
  8850. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8851. u32 lid;
  8852. /*
  8853. * Program 0 in CSR if port lid is extended. This prevents
  8854. * 9B packets being sent out for large lids.
  8855. */
  8856. lid = (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ? 0 : ppd->lid;
  8857. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8858. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8859. c1 |= ((lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8860. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8861. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8862. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8863. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8864. /*
  8865. * Iterate over all the send contexts and set their SLID check
  8866. */
  8867. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8868. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8869. (((lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8870. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8871. for (i = 0; i < chip_send_contexts(dd); i++) {
  8872. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8873. i, (u32)sreg);
  8874. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8875. }
  8876. /* Now we have to do the same thing for the sdma engines */
  8877. sdma_update_lmc(dd, mask, lid);
  8878. }
  8879. static const char *state_completed_string(u32 completed)
  8880. {
  8881. static const char * const state_completed[] = {
  8882. "EstablishComm",
  8883. "OptimizeEQ",
  8884. "VerifyCap"
  8885. };
  8886. if (completed < ARRAY_SIZE(state_completed))
  8887. return state_completed[completed];
  8888. return "unknown";
  8889. }
  8890. static const char all_lanes_dead_timeout_expired[] =
  8891. "All lanes were inactive – was the interconnect media removed?";
  8892. static const char tx_out_of_policy[] =
  8893. "Passing lanes on local port do not meet the local link width policy";
  8894. static const char no_state_complete[] =
  8895. "State timeout occurred before link partner completed the state";
  8896. static const char * const state_complete_reasons[] = {
  8897. [0x00] = "Reason unknown",
  8898. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8899. [0x02] = "Link partner reported failure",
  8900. [0x10] = "Unable to achieve frame sync on any lane",
  8901. [0x11] =
  8902. "Unable to find a common bit rate with the link partner",
  8903. [0x12] =
  8904. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8905. [0x13] =
  8906. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8907. [0x14] = no_state_complete,
  8908. [0x15] =
  8909. "State timeout occurred before link partner identified equalization presets",
  8910. [0x16] =
  8911. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8912. [0x17] = tx_out_of_policy,
  8913. [0x20] = all_lanes_dead_timeout_expired,
  8914. [0x21] =
  8915. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8916. [0x22] = no_state_complete,
  8917. [0x23] =
  8918. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8919. [0x24] = tx_out_of_policy,
  8920. [0x30] = all_lanes_dead_timeout_expired,
  8921. [0x31] =
  8922. "State timeout occurred waiting for host to process received frames",
  8923. [0x32] = no_state_complete,
  8924. [0x33] =
  8925. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8926. [0x34] = tx_out_of_policy,
  8927. [0x35] = "Negotiated link width is mutually exclusive",
  8928. [0x36] =
  8929. "Timed out before receiving verifycap frames in VerifyCap.Exchange",
  8930. [0x37] = "Unable to resolve secure data exchange",
  8931. };
  8932. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8933. u32 code)
  8934. {
  8935. const char *str = NULL;
  8936. if (code < ARRAY_SIZE(state_complete_reasons))
  8937. str = state_complete_reasons[code];
  8938. if (str)
  8939. return str;
  8940. return "Reserved";
  8941. }
  8942. /* describe the given last state complete frame */
  8943. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8944. const char *prefix)
  8945. {
  8946. struct hfi1_devdata *dd = ppd->dd;
  8947. u32 success;
  8948. u32 state;
  8949. u32 reason;
  8950. u32 lanes;
  8951. /*
  8952. * Decode frame:
  8953. * [ 0: 0] - success
  8954. * [ 3: 1] - state
  8955. * [ 7: 4] - next state timeout
  8956. * [15: 8] - reason code
  8957. * [31:16] - lanes
  8958. */
  8959. success = frame & 0x1;
  8960. state = (frame >> 1) & 0x7;
  8961. reason = (frame >> 8) & 0xff;
  8962. lanes = (frame >> 16) & 0xffff;
  8963. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8964. prefix, frame);
  8965. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8966. state_completed_string(state), state);
  8967. dd_dev_err(dd, " state successfully completed: %s\n",
  8968. success ? "yes" : "no");
  8969. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8970. reason, state_complete_reason_code_string(ppd, reason));
  8971. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8972. }
  8973. /*
  8974. * Read the last state complete frames and explain them. This routine
  8975. * expects to be called if the link went down during link negotiation
  8976. * and initialization (LNI). That is, anywhere between polling and link up.
  8977. */
  8978. static void check_lni_states(struct hfi1_pportdata *ppd)
  8979. {
  8980. u32 last_local_state;
  8981. u32 last_remote_state;
  8982. read_last_local_state(ppd->dd, &last_local_state);
  8983. read_last_remote_state(ppd->dd, &last_remote_state);
  8984. /*
  8985. * Don't report anything if there is nothing to report. A value of
  8986. * 0 means the link was taken down while polling and there was no
  8987. * training in-process.
  8988. */
  8989. if (last_local_state == 0 && last_remote_state == 0)
  8990. return;
  8991. decode_state_complete(ppd, last_local_state, "transmitted");
  8992. decode_state_complete(ppd, last_remote_state, "received");
  8993. }
  8994. /* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
  8995. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
  8996. {
  8997. u64 reg;
  8998. unsigned long timeout;
  8999. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  9000. timeout = jiffies + msecs_to_jiffies(wait_ms);
  9001. while (1) {
  9002. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  9003. if (reg)
  9004. break;
  9005. if (time_after(jiffies, timeout)) {
  9006. dd_dev_err(dd,
  9007. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  9008. return -ETIMEDOUT;
  9009. }
  9010. udelay(2);
  9011. }
  9012. return 0;
  9013. }
  9014. /* called when the logical link state is not down as it should be */
  9015. static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
  9016. {
  9017. struct hfi1_devdata *dd = ppd->dd;
  9018. /*
  9019. * Bring link up in LCB loopback
  9020. */
  9021. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  9022. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  9023. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  9024. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  9025. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
  9026. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  9027. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
  9028. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  9029. (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
  9030. udelay(3);
  9031. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
  9032. write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  9033. wait_link_transfer_active(dd, 100);
  9034. /*
  9035. * Bring the link down again.
  9036. */
  9037. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  9038. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
  9039. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
  9040. dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
  9041. }
  9042. /*
  9043. * Helper for set_link_state(). Do not call except from that routine.
  9044. * Expects ppd->hls_mutex to be held.
  9045. *
  9046. * @rem_reason value to be sent to the neighbor
  9047. *
  9048. * LinkDownReasons only set if transition succeeds.
  9049. */
  9050. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  9051. {
  9052. struct hfi1_devdata *dd = ppd->dd;
  9053. u32 previous_state;
  9054. int offline_state_ret;
  9055. int ret;
  9056. update_lcb_cache(dd);
  9057. previous_state = ppd->host_link_state;
  9058. ppd->host_link_state = HLS_GOING_OFFLINE;
  9059. /* start offline transition */
  9060. ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
  9061. if (ret != HCMD_SUCCESS) {
  9062. dd_dev_err(dd,
  9063. "Failed to transition to Offline link state, return %d\n",
  9064. ret);
  9065. return -EINVAL;
  9066. }
  9067. if (ppd->offline_disabled_reason ==
  9068. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  9069. ppd->offline_disabled_reason =
  9070. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  9071. offline_state_ret = wait_phys_link_offline_substates(ppd, 10000);
  9072. if (offline_state_ret < 0)
  9073. return offline_state_ret;
  9074. /* Disabling AOC transmitters */
  9075. if (ppd->port_type == PORT_TYPE_QSFP &&
  9076. ppd->qsfp_info.limiting_active &&
  9077. qsfp_mod_present(ppd)) {
  9078. int ret;
  9079. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  9080. if (ret == 0) {
  9081. set_qsfp_tx(ppd, 0);
  9082. release_chip_resource(dd, qsfp_resource(dd));
  9083. } else {
  9084. /* not fatal, but should warn */
  9085. dd_dev_err(dd,
  9086. "Unable to acquire lock to turn off QSFP TX\n");
  9087. }
  9088. }
  9089. /*
  9090. * Wait for the offline.Quiet transition if it hasn't happened yet. It
  9091. * can take a while for the link to go down.
  9092. */
  9093. if (offline_state_ret != PLS_OFFLINE_QUIET) {
  9094. ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 30000);
  9095. if (ret < 0)
  9096. return ret;
  9097. }
  9098. /*
  9099. * Now in charge of LCB - must be after the physical state is
  9100. * offline.quiet and before host_link_state is changed.
  9101. */
  9102. set_host_lcb_access(dd);
  9103. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  9104. /* make sure the logical state is also down */
  9105. ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  9106. if (ret)
  9107. force_logical_link_state_down(ppd);
  9108. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  9109. update_statusp(ppd, IB_PORT_DOWN);
  9110. /*
  9111. * The LNI has a mandatory wait time after the physical state
  9112. * moves to Offline.Quiet. The wait time may be different
  9113. * depending on how the link went down. The 8051 firmware
  9114. * will observe the needed wait time and only move to ready
  9115. * when that is completed. The largest of the quiet timeouts
  9116. * is 6s, so wait that long and then at least 0.5s more for
  9117. * other transitions, and another 0.5s for a buffer.
  9118. */
  9119. ret = wait_fm_ready(dd, 7000);
  9120. if (ret) {
  9121. dd_dev_err(dd,
  9122. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  9123. /* state is really offline, so make it so */
  9124. ppd->host_link_state = HLS_DN_OFFLINE;
  9125. return ret;
  9126. }
  9127. /*
  9128. * The state is now offline and the 8051 is ready to accept host
  9129. * requests.
  9130. * - change our state
  9131. * - notify others if we were previously in a linkup state
  9132. */
  9133. ppd->host_link_state = HLS_DN_OFFLINE;
  9134. if (previous_state & HLS_UP) {
  9135. /* went down while link was up */
  9136. handle_linkup_change(dd, 0);
  9137. } else if (previous_state
  9138. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  9139. /* went down while attempting link up */
  9140. check_lni_states(ppd);
  9141. /* The QSFP doesn't need to be reset on LNI failure */
  9142. ppd->qsfp_info.reset_needed = 0;
  9143. }
  9144. /* the active link width (downgrade) is 0 on link down */
  9145. ppd->link_width_active = 0;
  9146. ppd->link_width_downgrade_tx_active = 0;
  9147. ppd->link_width_downgrade_rx_active = 0;
  9148. ppd->current_egress_rate = 0;
  9149. return 0;
  9150. }
  9151. /* return the link state name */
  9152. static const char *link_state_name(u32 state)
  9153. {
  9154. const char *name;
  9155. int n = ilog2(state);
  9156. static const char * const names[] = {
  9157. [__HLS_UP_INIT_BP] = "INIT",
  9158. [__HLS_UP_ARMED_BP] = "ARMED",
  9159. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  9160. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  9161. [__HLS_DN_POLL_BP] = "POLL",
  9162. [__HLS_DN_DISABLE_BP] = "DISABLE",
  9163. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  9164. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  9165. [__HLS_GOING_UP_BP] = "GOING_UP",
  9166. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  9167. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  9168. };
  9169. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  9170. return name ? name : "unknown";
  9171. }
  9172. /* return the link state reason name */
  9173. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  9174. {
  9175. if (state == HLS_UP_INIT) {
  9176. switch (ppd->linkinit_reason) {
  9177. case OPA_LINKINIT_REASON_LINKUP:
  9178. return "(LINKUP)";
  9179. case OPA_LINKINIT_REASON_FLAPPING:
  9180. return "(FLAPPING)";
  9181. case OPA_LINKINIT_OUTSIDE_POLICY:
  9182. return "(OUTSIDE_POLICY)";
  9183. case OPA_LINKINIT_QUARANTINED:
  9184. return "(QUARANTINED)";
  9185. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  9186. return "(INSUFIC_CAPABILITY)";
  9187. default:
  9188. break;
  9189. }
  9190. }
  9191. return "";
  9192. }
  9193. /*
  9194. * driver_pstate - convert the driver's notion of a port's
  9195. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  9196. * Return -1 (converted to a u32) to indicate error.
  9197. */
  9198. u32 driver_pstate(struct hfi1_pportdata *ppd)
  9199. {
  9200. switch (ppd->host_link_state) {
  9201. case HLS_UP_INIT:
  9202. case HLS_UP_ARMED:
  9203. case HLS_UP_ACTIVE:
  9204. return IB_PORTPHYSSTATE_LINKUP;
  9205. case HLS_DN_POLL:
  9206. return IB_PORTPHYSSTATE_POLLING;
  9207. case HLS_DN_DISABLE:
  9208. return IB_PORTPHYSSTATE_DISABLED;
  9209. case HLS_DN_OFFLINE:
  9210. return OPA_PORTPHYSSTATE_OFFLINE;
  9211. case HLS_VERIFY_CAP:
  9212. return IB_PORTPHYSSTATE_TRAINING;
  9213. case HLS_GOING_UP:
  9214. return IB_PORTPHYSSTATE_TRAINING;
  9215. case HLS_GOING_OFFLINE:
  9216. return OPA_PORTPHYSSTATE_OFFLINE;
  9217. case HLS_LINK_COOLDOWN:
  9218. return OPA_PORTPHYSSTATE_OFFLINE;
  9219. case HLS_DN_DOWNDEF:
  9220. default:
  9221. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9222. ppd->host_link_state);
  9223. return -1;
  9224. }
  9225. }
  9226. /*
  9227. * driver_lstate - convert the driver's notion of a port's
  9228. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9229. * (converted to a u32) to indicate error.
  9230. */
  9231. u32 driver_lstate(struct hfi1_pportdata *ppd)
  9232. {
  9233. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9234. return IB_PORT_DOWN;
  9235. switch (ppd->host_link_state & HLS_UP) {
  9236. case HLS_UP_INIT:
  9237. return IB_PORT_INIT;
  9238. case HLS_UP_ARMED:
  9239. return IB_PORT_ARMED;
  9240. case HLS_UP_ACTIVE:
  9241. return IB_PORT_ACTIVE;
  9242. default:
  9243. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9244. ppd->host_link_state);
  9245. return -1;
  9246. }
  9247. }
  9248. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9249. u8 neigh_reason, u8 rem_reason)
  9250. {
  9251. if (ppd->local_link_down_reason.latest == 0 &&
  9252. ppd->neigh_link_down_reason.latest == 0) {
  9253. ppd->local_link_down_reason.latest = lcl_reason;
  9254. ppd->neigh_link_down_reason.latest = neigh_reason;
  9255. ppd->remote_link_down_reason = rem_reason;
  9256. }
  9257. }
  9258. /*
  9259. * Verify if BCT for data VLs is non-zero.
  9260. */
  9261. static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
  9262. {
  9263. return !!ppd->actual_vls_operational;
  9264. }
  9265. /*
  9266. * Change the physical and/or logical link state.
  9267. *
  9268. * Do not call this routine while inside an interrupt. It contains
  9269. * calls to routines that can take multiple seconds to finish.
  9270. *
  9271. * Returns 0 on success, -errno on failure.
  9272. */
  9273. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9274. {
  9275. struct hfi1_devdata *dd = ppd->dd;
  9276. struct ib_event event = {.device = NULL};
  9277. int ret1, ret = 0;
  9278. int orig_new_state, poll_bounce;
  9279. mutex_lock(&ppd->hls_lock);
  9280. orig_new_state = state;
  9281. if (state == HLS_DN_DOWNDEF)
  9282. state = HLS_DEFAULT;
  9283. /* interpret poll -> poll as a link bounce */
  9284. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9285. state == HLS_DN_POLL;
  9286. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9287. link_state_name(ppd->host_link_state),
  9288. link_state_name(orig_new_state),
  9289. poll_bounce ? "(bounce) " : "",
  9290. link_state_reason_name(ppd, state));
  9291. /*
  9292. * If we're going to a (HLS_*) link state that implies the logical
  9293. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9294. * reset is_sm_config_started to 0.
  9295. */
  9296. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9297. ppd->is_sm_config_started = 0;
  9298. /*
  9299. * Do nothing if the states match. Let a poll to poll link bounce
  9300. * go through.
  9301. */
  9302. if (ppd->host_link_state == state && !poll_bounce)
  9303. goto done;
  9304. switch (state) {
  9305. case HLS_UP_INIT:
  9306. if (ppd->host_link_state == HLS_DN_POLL &&
  9307. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9308. /*
  9309. * Quick link up jumps from polling to here.
  9310. *
  9311. * Whether in normal or loopback mode, the
  9312. * simulator jumps from polling to link up.
  9313. * Accept that here.
  9314. */
  9315. /* OK */
  9316. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9317. goto unexpected;
  9318. }
  9319. /*
  9320. * Wait for Link_Up physical state.
  9321. * Physical and Logical states should already be
  9322. * be transitioned to LinkUp and LinkInit respectively.
  9323. */
  9324. ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
  9325. if (ret) {
  9326. dd_dev_err(dd,
  9327. "%s: physical state did not change to LINK-UP\n",
  9328. __func__);
  9329. break;
  9330. }
  9331. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9332. if (ret) {
  9333. dd_dev_err(dd,
  9334. "%s: logical state did not change to INIT\n",
  9335. __func__);
  9336. break;
  9337. }
  9338. /* clear old transient LINKINIT_REASON code */
  9339. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9340. ppd->linkinit_reason =
  9341. OPA_LINKINIT_REASON_LINKUP;
  9342. /* enable the port */
  9343. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9344. handle_linkup_change(dd, 1);
  9345. pio_kernel_linkup(dd);
  9346. /*
  9347. * After link up, a new link width will have been set.
  9348. * Update the xmit counters with regards to the new
  9349. * link width.
  9350. */
  9351. update_xmit_counters(ppd, ppd->link_width_active);
  9352. ppd->host_link_state = HLS_UP_INIT;
  9353. update_statusp(ppd, IB_PORT_INIT);
  9354. break;
  9355. case HLS_UP_ARMED:
  9356. if (ppd->host_link_state != HLS_UP_INIT)
  9357. goto unexpected;
  9358. if (!data_vls_operational(ppd)) {
  9359. dd_dev_err(dd,
  9360. "%s: data VLs not operational\n", __func__);
  9361. ret = -EINVAL;
  9362. break;
  9363. }
  9364. set_logical_state(dd, LSTATE_ARMED);
  9365. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9366. if (ret) {
  9367. dd_dev_err(dd,
  9368. "%s: logical state did not change to ARMED\n",
  9369. __func__);
  9370. break;
  9371. }
  9372. ppd->host_link_state = HLS_UP_ARMED;
  9373. update_statusp(ppd, IB_PORT_ARMED);
  9374. /*
  9375. * The simulator does not currently implement SMA messages,
  9376. * so neighbor_normal is not set. Set it here when we first
  9377. * move to Armed.
  9378. */
  9379. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9380. ppd->neighbor_normal = 1;
  9381. break;
  9382. case HLS_UP_ACTIVE:
  9383. if (ppd->host_link_state != HLS_UP_ARMED)
  9384. goto unexpected;
  9385. set_logical_state(dd, LSTATE_ACTIVE);
  9386. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9387. if (ret) {
  9388. dd_dev_err(dd,
  9389. "%s: logical state did not change to ACTIVE\n",
  9390. __func__);
  9391. } else {
  9392. /* tell all engines to go running */
  9393. sdma_all_running(dd);
  9394. ppd->host_link_state = HLS_UP_ACTIVE;
  9395. update_statusp(ppd, IB_PORT_ACTIVE);
  9396. /* Signal the IB layer that the port has went active */
  9397. event.device = &dd->verbs_dev.rdi.ibdev;
  9398. event.element.port_num = ppd->port;
  9399. event.event = IB_EVENT_PORT_ACTIVE;
  9400. }
  9401. break;
  9402. case HLS_DN_POLL:
  9403. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9404. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9405. dd->dc_shutdown)
  9406. dc_start(dd);
  9407. /* Hand LED control to the DC */
  9408. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9409. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9410. u8 tmp = ppd->link_enabled;
  9411. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9412. if (ret) {
  9413. ppd->link_enabled = tmp;
  9414. break;
  9415. }
  9416. ppd->remote_link_down_reason = 0;
  9417. if (ppd->driver_link_ready)
  9418. ppd->link_enabled = 1;
  9419. }
  9420. set_all_slowpath(ppd->dd);
  9421. ret = set_local_link_attributes(ppd);
  9422. if (ret)
  9423. break;
  9424. ppd->port_error_action = 0;
  9425. ppd->host_link_state = HLS_DN_POLL;
  9426. if (quick_linkup) {
  9427. /* quick linkup does not go into polling */
  9428. ret = do_quick_linkup(dd);
  9429. } else {
  9430. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9431. if (ret1 != HCMD_SUCCESS) {
  9432. dd_dev_err(dd,
  9433. "Failed to transition to Polling link state, return 0x%x\n",
  9434. ret1);
  9435. ret = -EINVAL;
  9436. }
  9437. }
  9438. ppd->offline_disabled_reason =
  9439. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9440. /*
  9441. * If an error occurred above, go back to offline. The
  9442. * caller may reschedule another attempt.
  9443. */
  9444. if (ret)
  9445. goto_offline(ppd, 0);
  9446. else
  9447. log_physical_state(ppd, PLS_POLLING);
  9448. break;
  9449. case HLS_DN_DISABLE:
  9450. /* link is disabled */
  9451. ppd->link_enabled = 0;
  9452. /* allow any state to transition to disabled */
  9453. /* must transition to offline first */
  9454. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9455. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9456. if (ret)
  9457. break;
  9458. ppd->remote_link_down_reason = 0;
  9459. }
  9460. if (!dd->dc_shutdown) {
  9461. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9462. if (ret1 != HCMD_SUCCESS) {
  9463. dd_dev_err(dd,
  9464. "Failed to transition to Disabled link state, return 0x%x\n",
  9465. ret1);
  9466. ret = -EINVAL;
  9467. break;
  9468. }
  9469. ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
  9470. if (ret) {
  9471. dd_dev_err(dd,
  9472. "%s: physical state did not change to DISABLED\n",
  9473. __func__);
  9474. break;
  9475. }
  9476. dc_shutdown(dd);
  9477. }
  9478. ppd->host_link_state = HLS_DN_DISABLE;
  9479. break;
  9480. case HLS_DN_OFFLINE:
  9481. if (ppd->host_link_state == HLS_DN_DISABLE)
  9482. dc_start(dd);
  9483. /* allow any state to transition to offline */
  9484. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9485. if (!ret)
  9486. ppd->remote_link_down_reason = 0;
  9487. break;
  9488. case HLS_VERIFY_CAP:
  9489. if (ppd->host_link_state != HLS_DN_POLL)
  9490. goto unexpected;
  9491. ppd->host_link_state = HLS_VERIFY_CAP;
  9492. log_physical_state(ppd, PLS_CONFIGPHY_VERIFYCAP);
  9493. break;
  9494. case HLS_GOING_UP:
  9495. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9496. goto unexpected;
  9497. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9498. if (ret1 != HCMD_SUCCESS) {
  9499. dd_dev_err(dd,
  9500. "Failed to transition to link up state, return 0x%x\n",
  9501. ret1);
  9502. ret = -EINVAL;
  9503. break;
  9504. }
  9505. ppd->host_link_state = HLS_GOING_UP;
  9506. break;
  9507. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9508. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9509. default:
  9510. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9511. __func__, state);
  9512. ret = -EINVAL;
  9513. break;
  9514. }
  9515. goto done;
  9516. unexpected:
  9517. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9518. __func__, link_state_name(ppd->host_link_state),
  9519. link_state_name(state));
  9520. ret = -EINVAL;
  9521. done:
  9522. mutex_unlock(&ppd->hls_lock);
  9523. if (event.device)
  9524. ib_dispatch_event(&event);
  9525. return ret;
  9526. }
  9527. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9528. {
  9529. u64 reg;
  9530. int ret = 0;
  9531. switch (which) {
  9532. case HFI1_IB_CFG_LIDLMC:
  9533. set_lidlmc(ppd);
  9534. break;
  9535. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9536. /*
  9537. * The VL Arbitrator high limit is sent in units of 4k
  9538. * bytes, while HFI stores it in units of 64 bytes.
  9539. */
  9540. val *= 4096 / 64;
  9541. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9542. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9543. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9544. break;
  9545. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9546. /* HFI only supports POLL as the default link down state */
  9547. if (val != HLS_DN_POLL)
  9548. ret = -EINVAL;
  9549. break;
  9550. case HFI1_IB_CFG_OP_VLS:
  9551. if (ppd->vls_operational != val) {
  9552. ppd->vls_operational = val;
  9553. if (!ppd->port)
  9554. ret = -EINVAL;
  9555. }
  9556. break;
  9557. /*
  9558. * For link width, link width downgrade, and speed enable, always AND
  9559. * the setting with what is actually supported. This has two benefits.
  9560. * First, enabled can't have unsupported values, no matter what the
  9561. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9562. * "fill in with your supported value" have all the bits in the
  9563. * field set, so simply ANDing with supported has the desired result.
  9564. */
  9565. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9566. ppd->link_width_enabled = val & ppd->link_width_supported;
  9567. break;
  9568. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9569. ppd->link_width_downgrade_enabled =
  9570. val & ppd->link_width_downgrade_supported;
  9571. break;
  9572. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9573. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9574. break;
  9575. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9576. /*
  9577. * HFI does not follow IB specs, save this value
  9578. * so we can report it, if asked.
  9579. */
  9580. ppd->overrun_threshold = val;
  9581. break;
  9582. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9583. /*
  9584. * HFI does not follow IB specs, save this value
  9585. * so we can report it, if asked.
  9586. */
  9587. ppd->phy_error_threshold = val;
  9588. break;
  9589. case HFI1_IB_CFG_MTU:
  9590. set_send_length(ppd);
  9591. break;
  9592. case HFI1_IB_CFG_PKEYS:
  9593. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9594. set_partition_keys(ppd);
  9595. break;
  9596. default:
  9597. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9598. dd_dev_info(ppd->dd,
  9599. "%s: which %s, val 0x%x: not implemented\n",
  9600. __func__, ib_cfg_name(which), val);
  9601. break;
  9602. }
  9603. return ret;
  9604. }
  9605. /* begin functions related to vl arbitration table caching */
  9606. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9607. {
  9608. int i;
  9609. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9610. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9611. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9612. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9613. /*
  9614. * Note that we always return values directly from the
  9615. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9616. * 'Get(VLArbTable)'. This is obviously correct after a
  9617. * 'Set(VLArbTable)', since the cache will then be up to
  9618. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9619. * since then both the cache, and the relevant h/w registers
  9620. * will be zeroed.
  9621. */
  9622. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9623. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9624. }
  9625. /*
  9626. * vl_arb_lock_cache
  9627. *
  9628. * All other vl_arb_* functions should be called only after locking
  9629. * the cache.
  9630. */
  9631. static inline struct vl_arb_cache *
  9632. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9633. {
  9634. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9635. return NULL;
  9636. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9637. return &ppd->vl_arb_cache[idx];
  9638. }
  9639. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9640. {
  9641. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9642. }
  9643. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9644. struct ib_vl_weight_elem *vl)
  9645. {
  9646. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9647. }
  9648. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9649. struct ib_vl_weight_elem *vl)
  9650. {
  9651. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9652. }
  9653. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9654. struct ib_vl_weight_elem *vl)
  9655. {
  9656. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9657. }
  9658. /* end functions related to vl arbitration table caching */
  9659. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9660. u32 size, struct ib_vl_weight_elem *vl)
  9661. {
  9662. struct hfi1_devdata *dd = ppd->dd;
  9663. u64 reg;
  9664. unsigned int i, is_up = 0;
  9665. int drain, ret = 0;
  9666. mutex_lock(&ppd->hls_lock);
  9667. if (ppd->host_link_state & HLS_UP)
  9668. is_up = 1;
  9669. drain = !is_ax(dd) && is_up;
  9670. if (drain)
  9671. /*
  9672. * Before adjusting VL arbitration weights, empty per-VL
  9673. * FIFOs, otherwise a packet whose VL weight is being
  9674. * set to 0 could get stuck in a FIFO with no chance to
  9675. * egress.
  9676. */
  9677. ret = stop_drain_data_vls(dd);
  9678. if (ret) {
  9679. dd_dev_err(
  9680. dd,
  9681. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9682. __func__);
  9683. goto err;
  9684. }
  9685. for (i = 0; i < size; i++, vl++) {
  9686. /*
  9687. * NOTE: The low priority shift and mask are used here, but
  9688. * they are the same for both the low and high registers.
  9689. */
  9690. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9691. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9692. | (((u64)vl->weight
  9693. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9694. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9695. write_csr(dd, target + (i * 8), reg);
  9696. }
  9697. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9698. if (drain)
  9699. open_fill_data_vls(dd); /* reopen all VLs */
  9700. err:
  9701. mutex_unlock(&ppd->hls_lock);
  9702. return ret;
  9703. }
  9704. /*
  9705. * Read one credit merge VL register.
  9706. */
  9707. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9708. struct vl_limit *vll)
  9709. {
  9710. u64 reg = read_csr(dd, csr);
  9711. vll->dedicated = cpu_to_be16(
  9712. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9713. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9714. vll->shared = cpu_to_be16(
  9715. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9716. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9717. }
  9718. /*
  9719. * Read the current credit merge limits.
  9720. */
  9721. static int get_buffer_control(struct hfi1_devdata *dd,
  9722. struct buffer_control *bc, u16 *overall_limit)
  9723. {
  9724. u64 reg;
  9725. int i;
  9726. /* not all entries are filled in */
  9727. memset(bc, 0, sizeof(*bc));
  9728. /* OPA and HFI have a 1-1 mapping */
  9729. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9730. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9731. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9732. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9733. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9734. bc->overall_shared_limit = cpu_to_be16(
  9735. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9736. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9737. if (overall_limit)
  9738. *overall_limit = (reg
  9739. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9740. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9741. return sizeof(struct buffer_control);
  9742. }
  9743. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9744. {
  9745. u64 reg;
  9746. int i;
  9747. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9748. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9749. for (i = 0; i < sizeof(u64); i++) {
  9750. u8 byte = *(((u8 *)&reg) + i);
  9751. dp->vlnt[2 * i] = byte & 0xf;
  9752. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9753. }
  9754. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9755. for (i = 0; i < sizeof(u64); i++) {
  9756. u8 byte = *(((u8 *)&reg) + i);
  9757. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9758. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9759. }
  9760. return sizeof(struct sc2vlnt);
  9761. }
  9762. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9763. struct ib_vl_weight_elem *vl)
  9764. {
  9765. unsigned int i;
  9766. for (i = 0; i < nelems; i++, vl++) {
  9767. vl->vl = 0xf;
  9768. vl->weight = 0;
  9769. }
  9770. }
  9771. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9772. {
  9773. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9774. DC_SC_VL_VAL(15_0,
  9775. 0, dp->vlnt[0] & 0xf,
  9776. 1, dp->vlnt[1] & 0xf,
  9777. 2, dp->vlnt[2] & 0xf,
  9778. 3, dp->vlnt[3] & 0xf,
  9779. 4, dp->vlnt[4] & 0xf,
  9780. 5, dp->vlnt[5] & 0xf,
  9781. 6, dp->vlnt[6] & 0xf,
  9782. 7, dp->vlnt[7] & 0xf,
  9783. 8, dp->vlnt[8] & 0xf,
  9784. 9, dp->vlnt[9] & 0xf,
  9785. 10, dp->vlnt[10] & 0xf,
  9786. 11, dp->vlnt[11] & 0xf,
  9787. 12, dp->vlnt[12] & 0xf,
  9788. 13, dp->vlnt[13] & 0xf,
  9789. 14, dp->vlnt[14] & 0xf,
  9790. 15, dp->vlnt[15] & 0xf));
  9791. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9792. DC_SC_VL_VAL(31_16,
  9793. 16, dp->vlnt[16] & 0xf,
  9794. 17, dp->vlnt[17] & 0xf,
  9795. 18, dp->vlnt[18] & 0xf,
  9796. 19, dp->vlnt[19] & 0xf,
  9797. 20, dp->vlnt[20] & 0xf,
  9798. 21, dp->vlnt[21] & 0xf,
  9799. 22, dp->vlnt[22] & 0xf,
  9800. 23, dp->vlnt[23] & 0xf,
  9801. 24, dp->vlnt[24] & 0xf,
  9802. 25, dp->vlnt[25] & 0xf,
  9803. 26, dp->vlnt[26] & 0xf,
  9804. 27, dp->vlnt[27] & 0xf,
  9805. 28, dp->vlnt[28] & 0xf,
  9806. 29, dp->vlnt[29] & 0xf,
  9807. 30, dp->vlnt[30] & 0xf,
  9808. 31, dp->vlnt[31] & 0xf));
  9809. }
  9810. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9811. u16 limit)
  9812. {
  9813. if (limit != 0)
  9814. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9815. what, (int)limit, idx);
  9816. }
  9817. /* change only the shared limit portion of SendCmGLobalCredit */
  9818. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9819. {
  9820. u64 reg;
  9821. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9822. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9823. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9824. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9825. }
  9826. /* change only the total credit limit portion of SendCmGLobalCredit */
  9827. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9828. {
  9829. u64 reg;
  9830. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9831. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9832. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9833. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9834. }
  9835. /* set the given per-VL shared limit */
  9836. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9837. {
  9838. u64 reg;
  9839. u32 addr;
  9840. if (vl < TXE_NUM_DATA_VL)
  9841. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9842. else
  9843. addr = SEND_CM_CREDIT_VL15;
  9844. reg = read_csr(dd, addr);
  9845. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9846. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9847. write_csr(dd, addr, reg);
  9848. }
  9849. /* set the given per-VL dedicated limit */
  9850. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9851. {
  9852. u64 reg;
  9853. u32 addr;
  9854. if (vl < TXE_NUM_DATA_VL)
  9855. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9856. else
  9857. addr = SEND_CM_CREDIT_VL15;
  9858. reg = read_csr(dd, addr);
  9859. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9860. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9861. write_csr(dd, addr, reg);
  9862. }
  9863. /* spin until the given per-VL status mask bits clear */
  9864. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9865. const char *which)
  9866. {
  9867. unsigned long timeout;
  9868. u64 reg;
  9869. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9870. while (1) {
  9871. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9872. if (reg == 0)
  9873. return; /* success */
  9874. if (time_after(jiffies, timeout))
  9875. break; /* timed out */
  9876. udelay(1);
  9877. }
  9878. dd_dev_err(dd,
  9879. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9880. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9881. /*
  9882. * If this occurs, it is likely there was a credit loss on the link.
  9883. * The only recovery from that is a link bounce.
  9884. */
  9885. dd_dev_err(dd,
  9886. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9887. }
  9888. /*
  9889. * The number of credits on the VLs may be changed while everything
  9890. * is "live", but the following algorithm must be followed due to
  9891. * how the hardware is actually implemented. In particular,
  9892. * Return_Credit_Status[] is the only correct status check.
  9893. *
  9894. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9895. * set Global_Shared_Credit_Limit = 0
  9896. * use_all_vl = 1
  9897. * mask0 = all VLs that are changing either dedicated or shared limits
  9898. * set Shared_Limit[mask0] = 0
  9899. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9900. * if (changing any dedicated limit)
  9901. * mask1 = all VLs that are lowering dedicated limits
  9902. * lower Dedicated_Limit[mask1]
  9903. * spin until Return_Credit_Status[mask1] == 0
  9904. * raise Dedicated_Limits
  9905. * raise Shared_Limits
  9906. * raise Global_Shared_Credit_Limit
  9907. *
  9908. * lower = if the new limit is lower, set the limit to the new value
  9909. * raise = if the new limit is higher than the current value (may be changed
  9910. * earlier in the algorithm), set the new limit to the new value
  9911. */
  9912. int set_buffer_control(struct hfi1_pportdata *ppd,
  9913. struct buffer_control *new_bc)
  9914. {
  9915. struct hfi1_devdata *dd = ppd->dd;
  9916. u64 changing_mask, ld_mask, stat_mask;
  9917. int change_count;
  9918. int i, use_all_mask;
  9919. int this_shared_changing;
  9920. int vl_count = 0, ret;
  9921. /*
  9922. * A0: add the variable any_shared_limit_changing below and in the
  9923. * algorithm above. If removing A0 support, it can be removed.
  9924. */
  9925. int any_shared_limit_changing;
  9926. struct buffer_control cur_bc;
  9927. u8 changing[OPA_MAX_VLS];
  9928. u8 lowering_dedicated[OPA_MAX_VLS];
  9929. u16 cur_total;
  9930. u32 new_total = 0;
  9931. const u64 all_mask =
  9932. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9933. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9934. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9935. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9936. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9937. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9938. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9939. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9940. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9941. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9942. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9943. /* find the new total credits, do sanity check on unused VLs */
  9944. for (i = 0; i < OPA_MAX_VLS; i++) {
  9945. if (valid_vl(i)) {
  9946. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9947. continue;
  9948. }
  9949. nonzero_msg(dd, i, "dedicated",
  9950. be16_to_cpu(new_bc->vl[i].dedicated));
  9951. nonzero_msg(dd, i, "shared",
  9952. be16_to_cpu(new_bc->vl[i].shared));
  9953. new_bc->vl[i].dedicated = 0;
  9954. new_bc->vl[i].shared = 0;
  9955. }
  9956. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9957. /* fetch the current values */
  9958. get_buffer_control(dd, &cur_bc, &cur_total);
  9959. /*
  9960. * Create the masks we will use.
  9961. */
  9962. memset(changing, 0, sizeof(changing));
  9963. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9964. /*
  9965. * NOTE: Assumes that the individual VL bits are adjacent and in
  9966. * increasing order
  9967. */
  9968. stat_mask =
  9969. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9970. changing_mask = 0;
  9971. ld_mask = 0;
  9972. change_count = 0;
  9973. any_shared_limit_changing = 0;
  9974. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9975. if (!valid_vl(i))
  9976. continue;
  9977. this_shared_changing = new_bc->vl[i].shared
  9978. != cur_bc.vl[i].shared;
  9979. if (this_shared_changing)
  9980. any_shared_limit_changing = 1;
  9981. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9982. this_shared_changing) {
  9983. changing[i] = 1;
  9984. changing_mask |= stat_mask;
  9985. change_count++;
  9986. }
  9987. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9988. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9989. lowering_dedicated[i] = 1;
  9990. ld_mask |= stat_mask;
  9991. }
  9992. }
  9993. /* bracket the credit change with a total adjustment */
  9994. if (new_total > cur_total)
  9995. set_global_limit(dd, new_total);
  9996. /*
  9997. * Start the credit change algorithm.
  9998. */
  9999. use_all_mask = 0;
  10000. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  10001. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  10002. (is_ax(dd) && any_shared_limit_changing)) {
  10003. set_global_shared(dd, 0);
  10004. cur_bc.overall_shared_limit = 0;
  10005. use_all_mask = 1;
  10006. }
  10007. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10008. if (!valid_vl(i))
  10009. continue;
  10010. if (changing[i]) {
  10011. set_vl_shared(dd, i, 0);
  10012. cur_bc.vl[i].shared = 0;
  10013. }
  10014. }
  10015. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  10016. "shared");
  10017. if (change_count > 0) {
  10018. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10019. if (!valid_vl(i))
  10020. continue;
  10021. if (lowering_dedicated[i]) {
  10022. set_vl_dedicated(dd, i,
  10023. be16_to_cpu(new_bc->
  10024. vl[i].dedicated));
  10025. cur_bc.vl[i].dedicated =
  10026. new_bc->vl[i].dedicated;
  10027. }
  10028. }
  10029. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  10030. /* now raise all dedicated that are going up */
  10031. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10032. if (!valid_vl(i))
  10033. continue;
  10034. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  10035. be16_to_cpu(cur_bc.vl[i].dedicated))
  10036. set_vl_dedicated(dd, i,
  10037. be16_to_cpu(new_bc->
  10038. vl[i].dedicated));
  10039. }
  10040. }
  10041. /* next raise all shared that are going up */
  10042. for (i = 0; i < NUM_USABLE_VLS; i++) {
  10043. if (!valid_vl(i))
  10044. continue;
  10045. if (be16_to_cpu(new_bc->vl[i].shared) >
  10046. be16_to_cpu(cur_bc.vl[i].shared))
  10047. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  10048. }
  10049. /* finally raise the global shared */
  10050. if (be16_to_cpu(new_bc->overall_shared_limit) >
  10051. be16_to_cpu(cur_bc.overall_shared_limit))
  10052. set_global_shared(dd,
  10053. be16_to_cpu(new_bc->overall_shared_limit));
  10054. /* bracket the credit change with a total adjustment */
  10055. if (new_total < cur_total)
  10056. set_global_limit(dd, new_total);
  10057. /*
  10058. * Determine the actual number of operational VLS using the number of
  10059. * dedicated and shared credits for each VL.
  10060. */
  10061. if (change_count > 0) {
  10062. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  10063. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  10064. be16_to_cpu(new_bc->vl[i].shared) > 0)
  10065. vl_count++;
  10066. ppd->actual_vls_operational = vl_count;
  10067. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  10068. ppd->actual_vls_operational :
  10069. ppd->vls_operational,
  10070. NULL);
  10071. if (ret == 0)
  10072. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  10073. ppd->actual_vls_operational :
  10074. ppd->vls_operational, NULL);
  10075. if (ret)
  10076. return ret;
  10077. }
  10078. return 0;
  10079. }
  10080. /*
  10081. * Read the given fabric manager table. Return the size of the
  10082. * table (in bytes) on success, and a negative error code on
  10083. * failure.
  10084. */
  10085. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  10086. {
  10087. int size;
  10088. struct vl_arb_cache *vlc;
  10089. switch (which) {
  10090. case FM_TBL_VL_HIGH_ARB:
  10091. size = 256;
  10092. /*
  10093. * OPA specifies 128 elements (of 2 bytes each), though
  10094. * HFI supports only 16 elements in h/w.
  10095. */
  10096. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10097. vl_arb_get_cache(vlc, t);
  10098. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10099. break;
  10100. case FM_TBL_VL_LOW_ARB:
  10101. size = 256;
  10102. /*
  10103. * OPA specifies 128 elements (of 2 bytes each), though
  10104. * HFI supports only 16 elements in h/w.
  10105. */
  10106. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10107. vl_arb_get_cache(vlc, t);
  10108. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10109. break;
  10110. case FM_TBL_BUFFER_CONTROL:
  10111. size = get_buffer_control(ppd->dd, t, NULL);
  10112. break;
  10113. case FM_TBL_SC2VLNT:
  10114. size = get_sc2vlnt(ppd->dd, t);
  10115. break;
  10116. case FM_TBL_VL_PREEMPT_ELEMS:
  10117. size = 256;
  10118. /* OPA specifies 128 elements, of 2 bytes each */
  10119. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  10120. break;
  10121. case FM_TBL_VL_PREEMPT_MATRIX:
  10122. size = 256;
  10123. /*
  10124. * OPA specifies that this is the same size as the VL
  10125. * arbitration tables (i.e., 256 bytes).
  10126. */
  10127. break;
  10128. default:
  10129. return -EINVAL;
  10130. }
  10131. return size;
  10132. }
  10133. /*
  10134. * Write the given fabric manager table.
  10135. */
  10136. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  10137. {
  10138. int ret = 0;
  10139. struct vl_arb_cache *vlc;
  10140. switch (which) {
  10141. case FM_TBL_VL_HIGH_ARB:
  10142. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10143. if (vl_arb_match_cache(vlc, t)) {
  10144. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10145. break;
  10146. }
  10147. vl_arb_set_cache(vlc, t);
  10148. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10149. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  10150. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  10151. break;
  10152. case FM_TBL_VL_LOW_ARB:
  10153. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10154. if (vl_arb_match_cache(vlc, t)) {
  10155. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10156. break;
  10157. }
  10158. vl_arb_set_cache(vlc, t);
  10159. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10160. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  10161. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  10162. break;
  10163. case FM_TBL_BUFFER_CONTROL:
  10164. ret = set_buffer_control(ppd, t);
  10165. break;
  10166. case FM_TBL_SC2VLNT:
  10167. set_sc2vlnt(ppd->dd, t);
  10168. break;
  10169. default:
  10170. ret = -EINVAL;
  10171. }
  10172. return ret;
  10173. }
  10174. /*
  10175. * Disable all data VLs.
  10176. *
  10177. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  10178. */
  10179. static int disable_data_vls(struct hfi1_devdata *dd)
  10180. {
  10181. if (is_ax(dd))
  10182. return 1;
  10183. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  10184. return 0;
  10185. }
  10186. /*
  10187. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  10188. * Just re-enables all data VLs (the "fill" part happens
  10189. * automatically - the name was chosen for symmetry with
  10190. * stop_drain_data_vls()).
  10191. *
  10192. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  10193. */
  10194. int open_fill_data_vls(struct hfi1_devdata *dd)
  10195. {
  10196. if (is_ax(dd))
  10197. return 1;
  10198. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  10199. return 0;
  10200. }
  10201. /*
  10202. * drain_data_vls() - assumes that disable_data_vls() has been called,
  10203. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  10204. * engines to drop to 0.
  10205. */
  10206. static void drain_data_vls(struct hfi1_devdata *dd)
  10207. {
  10208. sc_wait(dd);
  10209. sdma_wait(dd);
  10210. pause_for_credit_return(dd);
  10211. }
  10212. /*
  10213. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  10214. *
  10215. * Use open_fill_data_vls() to resume using data VLs. This pair is
  10216. * meant to be used like this:
  10217. *
  10218. * stop_drain_data_vls(dd);
  10219. * // do things with per-VL resources
  10220. * open_fill_data_vls(dd);
  10221. */
  10222. int stop_drain_data_vls(struct hfi1_devdata *dd)
  10223. {
  10224. int ret;
  10225. ret = disable_data_vls(dd);
  10226. if (ret == 0)
  10227. drain_data_vls(dd);
  10228. return ret;
  10229. }
  10230. /*
  10231. * Convert a nanosecond time to a cclock count. No matter how slow
  10232. * the cclock, a non-zero ns will always have a non-zero result.
  10233. */
  10234. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  10235. {
  10236. u32 cclocks;
  10237. if (dd->icode == ICODE_FPGA_EMULATION)
  10238. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  10239. else /* simulation pretends to be ASIC */
  10240. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  10241. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  10242. cclocks = 1;
  10243. return cclocks;
  10244. }
  10245. /*
  10246. * Convert a cclock count to nanoseconds. Not matter how slow
  10247. * the cclock, a non-zero cclocks will always have a non-zero result.
  10248. */
  10249. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  10250. {
  10251. u32 ns;
  10252. if (dd->icode == ICODE_FPGA_EMULATION)
  10253. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  10254. else /* simulation pretends to be ASIC */
  10255. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  10256. if (cclocks && !ns)
  10257. ns = 1;
  10258. return ns;
  10259. }
  10260. /*
  10261. * Dynamically adjust the receive interrupt timeout for a context based on
  10262. * incoming packet rate.
  10263. *
  10264. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  10265. */
  10266. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  10267. {
  10268. struct hfi1_devdata *dd = rcd->dd;
  10269. u32 timeout = rcd->rcvavail_timeout;
  10270. /*
  10271. * This algorithm doubles or halves the timeout depending on whether
  10272. * the number of packets received in this interrupt were less than or
  10273. * greater equal the interrupt count.
  10274. *
  10275. * The calculations below do not allow a steady state to be achieved.
  10276. * Only at the endpoints it is possible to have an unchanging
  10277. * timeout.
  10278. */
  10279. if (npkts < rcv_intr_count) {
  10280. /*
  10281. * Not enough packets arrived before the timeout, adjust
  10282. * timeout downward.
  10283. */
  10284. if (timeout < 2) /* already at minimum? */
  10285. return;
  10286. timeout >>= 1;
  10287. } else {
  10288. /*
  10289. * More than enough packets arrived before the timeout, adjust
  10290. * timeout upward.
  10291. */
  10292. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10293. return;
  10294. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10295. }
  10296. rcd->rcvavail_timeout = timeout;
  10297. /*
  10298. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10299. * been verified to be in range
  10300. */
  10301. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10302. (u64)timeout <<
  10303. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10304. }
  10305. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10306. u32 intr_adjust, u32 npkts)
  10307. {
  10308. struct hfi1_devdata *dd = rcd->dd;
  10309. u64 reg;
  10310. u32 ctxt = rcd->ctxt;
  10311. /*
  10312. * Need to write timeout register before updating RcvHdrHead to ensure
  10313. * that a new value is used when the HW decides to restart counting.
  10314. */
  10315. if (intr_adjust)
  10316. adjust_rcv_timeout(rcd, npkts);
  10317. if (updegr) {
  10318. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10319. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10320. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10321. }
  10322. mmiowb();
  10323. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10324. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10325. << RCV_HDR_HEAD_HEAD_SHIFT);
  10326. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10327. mmiowb();
  10328. }
  10329. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10330. {
  10331. u32 head, tail;
  10332. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10333. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10334. if (rcd->rcvhdrtail_kvaddr)
  10335. tail = get_rcvhdrtail(rcd);
  10336. else
  10337. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10338. return head == tail;
  10339. }
  10340. /*
  10341. * Context Control and Receive Array encoding for buffer size:
  10342. * 0x0 invalid
  10343. * 0x1 4 KB
  10344. * 0x2 8 KB
  10345. * 0x3 16 KB
  10346. * 0x4 32 KB
  10347. * 0x5 64 KB
  10348. * 0x6 128 KB
  10349. * 0x7 256 KB
  10350. * 0x8 512 KB (Receive Array only)
  10351. * 0x9 1 MB (Receive Array only)
  10352. * 0xa 2 MB (Receive Array only)
  10353. *
  10354. * 0xB-0xF - reserved (Receive Array only)
  10355. *
  10356. *
  10357. * This routine assumes that the value has already been sanity checked.
  10358. */
  10359. static u32 encoded_size(u32 size)
  10360. {
  10361. switch (size) {
  10362. case 4 * 1024: return 0x1;
  10363. case 8 * 1024: return 0x2;
  10364. case 16 * 1024: return 0x3;
  10365. case 32 * 1024: return 0x4;
  10366. case 64 * 1024: return 0x5;
  10367. case 128 * 1024: return 0x6;
  10368. case 256 * 1024: return 0x7;
  10369. case 512 * 1024: return 0x8;
  10370. case 1 * 1024 * 1024: return 0x9;
  10371. case 2 * 1024 * 1024: return 0xa;
  10372. }
  10373. return 0x1; /* if invalid, go with the minimum size */
  10374. }
  10375. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
  10376. struct hfi1_ctxtdata *rcd)
  10377. {
  10378. u64 rcvctrl, reg;
  10379. int did_enable = 0;
  10380. u16 ctxt;
  10381. if (!rcd)
  10382. return;
  10383. ctxt = rcd->ctxt;
  10384. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10385. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10386. /* if the context already enabled, don't do the extra steps */
  10387. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10388. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10389. /* reset the tail and hdr addresses, and sequence count */
  10390. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10391. rcd->rcvhdrq_dma);
  10392. if (rcd->rcvhdrtail_kvaddr)
  10393. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10394. rcd->rcvhdrqtailaddr_dma);
  10395. rcd->seq_cnt = 1;
  10396. /* reset the cached receive header queue head value */
  10397. rcd->head = 0;
  10398. /*
  10399. * Zero the receive header queue so we don't get false
  10400. * positives when checking the sequence number. The
  10401. * sequence numbers could land exactly on the same spot.
  10402. * E.g. a rcd restart before the receive header wrapped.
  10403. */
  10404. memset(rcd->rcvhdrq, 0, rcvhdrq_size(rcd));
  10405. /* starting timeout */
  10406. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10407. /* enable the context */
  10408. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10409. /* clean the egr buffer size first */
  10410. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10411. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10412. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10413. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10414. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10415. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10416. did_enable = 1;
  10417. /* zero RcvEgrIndexHead */
  10418. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10419. /* set eager count and base index */
  10420. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10421. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10422. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10423. (((rcd->eager_base >> RCV_SHIFT)
  10424. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10425. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10426. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10427. /*
  10428. * Set TID (expected) count and base index.
  10429. * rcd->expected_count is set to individual RcvArray entries,
  10430. * not pairs, and the CSR takes a pair-count in groups of
  10431. * four, so divide by 8.
  10432. */
  10433. reg = (((rcd->expected_count >> RCV_SHIFT)
  10434. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10435. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10436. (((rcd->expected_base >> RCV_SHIFT)
  10437. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10438. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10439. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10440. if (ctxt == HFI1_CTRL_CTXT)
  10441. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10442. }
  10443. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10444. write_csr(dd, RCV_VL15, 0);
  10445. /*
  10446. * When receive context is being disabled turn on tail
  10447. * update with a dummy tail address and then disable
  10448. * receive context.
  10449. */
  10450. if (dd->rcvhdrtail_dummy_dma) {
  10451. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10452. dd->rcvhdrtail_dummy_dma);
  10453. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10454. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10455. }
  10456. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10457. }
  10458. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10459. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10460. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10461. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10462. if ((op & HFI1_RCVCTRL_TAILUPD_ENB) && rcd->rcvhdrtail_kvaddr)
  10463. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10464. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10465. /* See comment on RcvCtxtCtrl.TailUpd above */
  10466. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10467. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10468. }
  10469. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10470. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10471. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10472. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10473. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10474. /*
  10475. * In one-packet-per-eager mode, the size comes from
  10476. * the RcvArray entry.
  10477. */
  10478. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10479. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10480. }
  10481. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10482. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10483. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10484. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10485. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10486. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10487. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10488. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10489. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10490. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10491. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10492. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcvctrl);
  10493. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10494. if (did_enable &&
  10495. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10496. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10497. if (reg != 0) {
  10498. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10499. ctxt, reg);
  10500. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10501. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10502. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10503. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10504. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10505. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10506. ctxt, reg, reg == 0 ? "not" : "still");
  10507. }
  10508. }
  10509. if (did_enable) {
  10510. /*
  10511. * The interrupt timeout and count must be set after
  10512. * the context is enabled to take effect.
  10513. */
  10514. /* set interrupt timeout */
  10515. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10516. (u64)rcd->rcvavail_timeout <<
  10517. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10518. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10519. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10520. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10521. }
  10522. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10523. /*
  10524. * If the context has been disabled and the Tail Update has
  10525. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10526. * so it doesn't contain an address that is invalid.
  10527. */
  10528. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10529. dd->rcvhdrtail_dummy_dma);
  10530. }
  10531. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10532. {
  10533. int ret;
  10534. u64 val = 0;
  10535. if (namep) {
  10536. ret = dd->cntrnameslen;
  10537. *namep = dd->cntrnames;
  10538. } else {
  10539. const struct cntr_entry *entry;
  10540. int i, j;
  10541. ret = (dd->ndevcntrs) * sizeof(u64);
  10542. /* Get the start of the block of counters */
  10543. *cntrp = dd->cntrs;
  10544. /*
  10545. * Now go and fill in each counter in the block.
  10546. */
  10547. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10548. entry = &dev_cntrs[i];
  10549. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10550. if (entry->flags & CNTR_DISABLED) {
  10551. /* Nothing */
  10552. hfi1_cdbg(CNTR, "\tDisabled\n");
  10553. } else {
  10554. if (entry->flags & CNTR_VL) {
  10555. hfi1_cdbg(CNTR, "\tPer VL\n");
  10556. for (j = 0; j < C_VL_COUNT; j++) {
  10557. val = entry->rw_cntr(entry,
  10558. dd, j,
  10559. CNTR_MODE_R,
  10560. 0);
  10561. hfi1_cdbg(
  10562. CNTR,
  10563. "\t\tRead 0x%llx for %d\n",
  10564. val, j);
  10565. dd->cntrs[entry->offset + j] =
  10566. val;
  10567. }
  10568. } else if (entry->flags & CNTR_SDMA) {
  10569. hfi1_cdbg(CNTR,
  10570. "\t Per SDMA Engine\n");
  10571. for (j = 0; j < chip_sdma_engines(dd);
  10572. j++) {
  10573. val =
  10574. entry->rw_cntr(entry, dd, j,
  10575. CNTR_MODE_R, 0);
  10576. hfi1_cdbg(CNTR,
  10577. "\t\tRead 0x%llx for %d\n",
  10578. val, j);
  10579. dd->cntrs[entry->offset + j] =
  10580. val;
  10581. }
  10582. } else {
  10583. val = entry->rw_cntr(entry, dd,
  10584. CNTR_INVALID_VL,
  10585. CNTR_MODE_R, 0);
  10586. dd->cntrs[entry->offset] = val;
  10587. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10588. }
  10589. }
  10590. }
  10591. }
  10592. return ret;
  10593. }
  10594. /*
  10595. * Used by sysfs to create files for hfi stats to read
  10596. */
  10597. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10598. {
  10599. int ret;
  10600. u64 val = 0;
  10601. if (namep) {
  10602. ret = ppd->dd->portcntrnameslen;
  10603. *namep = ppd->dd->portcntrnames;
  10604. } else {
  10605. const struct cntr_entry *entry;
  10606. int i, j;
  10607. ret = ppd->dd->nportcntrs * sizeof(u64);
  10608. *cntrp = ppd->cntrs;
  10609. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10610. entry = &port_cntrs[i];
  10611. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10612. if (entry->flags & CNTR_DISABLED) {
  10613. /* Nothing */
  10614. hfi1_cdbg(CNTR, "\tDisabled\n");
  10615. continue;
  10616. }
  10617. if (entry->flags & CNTR_VL) {
  10618. hfi1_cdbg(CNTR, "\tPer VL");
  10619. for (j = 0; j < C_VL_COUNT; j++) {
  10620. val = entry->rw_cntr(entry, ppd, j,
  10621. CNTR_MODE_R,
  10622. 0);
  10623. hfi1_cdbg(
  10624. CNTR,
  10625. "\t\tRead 0x%llx for %d",
  10626. val, j);
  10627. ppd->cntrs[entry->offset + j] = val;
  10628. }
  10629. } else {
  10630. val = entry->rw_cntr(entry, ppd,
  10631. CNTR_INVALID_VL,
  10632. CNTR_MODE_R,
  10633. 0);
  10634. ppd->cntrs[entry->offset] = val;
  10635. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10636. }
  10637. }
  10638. }
  10639. return ret;
  10640. }
  10641. static void free_cntrs(struct hfi1_devdata *dd)
  10642. {
  10643. struct hfi1_pportdata *ppd;
  10644. int i;
  10645. if (dd->synth_stats_timer.function)
  10646. del_timer_sync(&dd->synth_stats_timer);
  10647. ppd = (struct hfi1_pportdata *)(dd + 1);
  10648. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10649. kfree(ppd->cntrs);
  10650. kfree(ppd->scntrs);
  10651. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10652. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10653. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10654. ppd->cntrs = NULL;
  10655. ppd->scntrs = NULL;
  10656. ppd->ibport_data.rvp.rc_acks = NULL;
  10657. ppd->ibport_data.rvp.rc_qacks = NULL;
  10658. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10659. }
  10660. kfree(dd->portcntrnames);
  10661. dd->portcntrnames = NULL;
  10662. kfree(dd->cntrs);
  10663. dd->cntrs = NULL;
  10664. kfree(dd->scntrs);
  10665. dd->scntrs = NULL;
  10666. kfree(dd->cntrnames);
  10667. dd->cntrnames = NULL;
  10668. if (dd->update_cntr_wq) {
  10669. destroy_workqueue(dd->update_cntr_wq);
  10670. dd->update_cntr_wq = NULL;
  10671. }
  10672. }
  10673. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10674. u64 *psval, void *context, int vl)
  10675. {
  10676. u64 val;
  10677. u64 sval = *psval;
  10678. if (entry->flags & CNTR_DISABLED) {
  10679. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10680. return 0;
  10681. }
  10682. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10683. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10684. /* If its a synthetic counter there is more work we need to do */
  10685. if (entry->flags & CNTR_SYNTH) {
  10686. if (sval == CNTR_MAX) {
  10687. /* No need to read already saturated */
  10688. return CNTR_MAX;
  10689. }
  10690. if (entry->flags & CNTR_32BIT) {
  10691. /* 32bit counters can wrap multiple times */
  10692. u64 upper = sval >> 32;
  10693. u64 lower = (sval << 32) >> 32;
  10694. if (lower > val) { /* hw wrapped */
  10695. if (upper == CNTR_32BIT_MAX)
  10696. val = CNTR_MAX;
  10697. else
  10698. upper++;
  10699. }
  10700. if (val != CNTR_MAX)
  10701. val = (upper << 32) | val;
  10702. } else {
  10703. /* If we rolled we are saturated */
  10704. if ((val < sval) || (val > CNTR_MAX))
  10705. val = CNTR_MAX;
  10706. }
  10707. }
  10708. *psval = val;
  10709. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10710. return val;
  10711. }
  10712. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10713. struct cntr_entry *entry,
  10714. u64 *psval, void *context, int vl, u64 data)
  10715. {
  10716. u64 val;
  10717. if (entry->flags & CNTR_DISABLED) {
  10718. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10719. return 0;
  10720. }
  10721. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10722. if (entry->flags & CNTR_SYNTH) {
  10723. *psval = data;
  10724. if (entry->flags & CNTR_32BIT) {
  10725. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10726. (data << 32) >> 32);
  10727. val = data; /* return the full 64bit value */
  10728. } else {
  10729. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10730. data);
  10731. }
  10732. } else {
  10733. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10734. }
  10735. *psval = val;
  10736. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10737. return val;
  10738. }
  10739. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10740. {
  10741. struct cntr_entry *entry;
  10742. u64 *sval;
  10743. entry = &dev_cntrs[index];
  10744. sval = dd->scntrs + entry->offset;
  10745. if (vl != CNTR_INVALID_VL)
  10746. sval += vl;
  10747. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10748. }
  10749. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10750. {
  10751. struct cntr_entry *entry;
  10752. u64 *sval;
  10753. entry = &dev_cntrs[index];
  10754. sval = dd->scntrs + entry->offset;
  10755. if (vl != CNTR_INVALID_VL)
  10756. sval += vl;
  10757. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10758. }
  10759. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10760. {
  10761. struct cntr_entry *entry;
  10762. u64 *sval;
  10763. entry = &port_cntrs[index];
  10764. sval = ppd->scntrs + entry->offset;
  10765. if (vl != CNTR_INVALID_VL)
  10766. sval += vl;
  10767. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10768. (index <= C_RCV_HDR_OVF_LAST)) {
  10769. /* We do not want to bother for disabled contexts */
  10770. return 0;
  10771. }
  10772. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10773. }
  10774. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10775. {
  10776. struct cntr_entry *entry;
  10777. u64 *sval;
  10778. entry = &port_cntrs[index];
  10779. sval = ppd->scntrs + entry->offset;
  10780. if (vl != CNTR_INVALID_VL)
  10781. sval += vl;
  10782. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10783. (index <= C_RCV_HDR_OVF_LAST)) {
  10784. /* We do not want to bother for disabled contexts */
  10785. return 0;
  10786. }
  10787. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10788. }
  10789. static void do_update_synth_timer(struct work_struct *work)
  10790. {
  10791. u64 cur_tx;
  10792. u64 cur_rx;
  10793. u64 total_flits;
  10794. u8 update = 0;
  10795. int i, j, vl;
  10796. struct hfi1_pportdata *ppd;
  10797. struct cntr_entry *entry;
  10798. struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
  10799. update_cntr_work);
  10800. /*
  10801. * Rather than keep beating on the CSRs pick a minimal set that we can
  10802. * check to watch for potential roll over. We can do this by looking at
  10803. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10804. * we have to iterate all the counters and update.
  10805. */
  10806. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10807. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10808. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10809. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10810. hfi1_cdbg(
  10811. CNTR,
  10812. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10813. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10814. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10815. /*
  10816. * May not be strictly necessary to update but it won't hurt and
  10817. * simplifies the logic here.
  10818. */
  10819. update = 1;
  10820. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10821. dd->unit);
  10822. } else {
  10823. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10824. hfi1_cdbg(CNTR,
  10825. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10826. total_flits, (u64)CNTR_32BIT_MAX);
  10827. if (total_flits >= CNTR_32BIT_MAX) {
  10828. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10829. dd->unit);
  10830. update = 1;
  10831. }
  10832. }
  10833. if (update) {
  10834. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10835. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10836. entry = &dev_cntrs[i];
  10837. if (entry->flags & CNTR_VL) {
  10838. for (vl = 0; vl < C_VL_COUNT; vl++)
  10839. read_dev_cntr(dd, i, vl);
  10840. } else {
  10841. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10842. }
  10843. }
  10844. ppd = (struct hfi1_pportdata *)(dd + 1);
  10845. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10846. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10847. entry = &port_cntrs[j];
  10848. if (entry->flags & CNTR_VL) {
  10849. for (vl = 0; vl < C_VL_COUNT; vl++)
  10850. read_port_cntr(ppd, j, vl);
  10851. } else {
  10852. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10853. }
  10854. }
  10855. }
  10856. /*
  10857. * We want the value in the register. The goal is to keep track
  10858. * of the number of "ticks" not the counter value. In other
  10859. * words if the register rolls we want to notice it and go ahead
  10860. * and force an update.
  10861. */
  10862. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10863. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10864. CNTR_MODE_R, 0);
  10865. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10866. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10867. CNTR_MODE_R, 0);
  10868. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10869. dd->unit, dd->last_tx, dd->last_rx);
  10870. } else {
  10871. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10872. }
  10873. }
  10874. static void update_synth_timer(struct timer_list *t)
  10875. {
  10876. struct hfi1_devdata *dd = from_timer(dd, t, synth_stats_timer);
  10877. queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
  10878. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10879. }
  10880. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10881. static int init_cntrs(struct hfi1_devdata *dd)
  10882. {
  10883. int i, rcv_ctxts, j;
  10884. size_t sz;
  10885. char *p;
  10886. char name[C_MAX_NAME];
  10887. struct hfi1_pportdata *ppd;
  10888. const char *bit_type_32 = ",32";
  10889. const int bit_type_32_sz = strlen(bit_type_32);
  10890. u32 sdma_engines = chip_sdma_engines(dd);
  10891. /* set up the stats timer; the add_timer is done at the end */
  10892. timer_setup(&dd->synth_stats_timer, update_synth_timer, 0);
  10893. /***********************/
  10894. /* per device counters */
  10895. /***********************/
  10896. /* size names and determine how many we have*/
  10897. dd->ndevcntrs = 0;
  10898. sz = 0;
  10899. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10900. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10901. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10902. continue;
  10903. }
  10904. if (dev_cntrs[i].flags & CNTR_VL) {
  10905. dev_cntrs[i].offset = dd->ndevcntrs;
  10906. for (j = 0; j < C_VL_COUNT; j++) {
  10907. snprintf(name, C_MAX_NAME, "%s%d",
  10908. dev_cntrs[i].name, vl_from_idx(j));
  10909. sz += strlen(name);
  10910. /* Add ",32" for 32-bit counters */
  10911. if (dev_cntrs[i].flags & CNTR_32BIT)
  10912. sz += bit_type_32_sz;
  10913. sz++;
  10914. dd->ndevcntrs++;
  10915. }
  10916. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10917. dev_cntrs[i].offset = dd->ndevcntrs;
  10918. for (j = 0; j < sdma_engines; j++) {
  10919. snprintf(name, C_MAX_NAME, "%s%d",
  10920. dev_cntrs[i].name, j);
  10921. sz += strlen(name);
  10922. /* Add ",32" for 32-bit counters */
  10923. if (dev_cntrs[i].flags & CNTR_32BIT)
  10924. sz += bit_type_32_sz;
  10925. sz++;
  10926. dd->ndevcntrs++;
  10927. }
  10928. } else {
  10929. /* +1 for newline. */
  10930. sz += strlen(dev_cntrs[i].name) + 1;
  10931. /* Add ",32" for 32-bit counters */
  10932. if (dev_cntrs[i].flags & CNTR_32BIT)
  10933. sz += bit_type_32_sz;
  10934. dev_cntrs[i].offset = dd->ndevcntrs;
  10935. dd->ndevcntrs++;
  10936. }
  10937. }
  10938. /* allocate space for the counter values */
  10939. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10940. if (!dd->cntrs)
  10941. goto bail;
  10942. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10943. if (!dd->scntrs)
  10944. goto bail;
  10945. /* allocate space for the counter names */
  10946. dd->cntrnameslen = sz;
  10947. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10948. if (!dd->cntrnames)
  10949. goto bail;
  10950. /* fill in the names */
  10951. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10952. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10953. /* Nothing */
  10954. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10955. for (j = 0; j < C_VL_COUNT; j++) {
  10956. snprintf(name, C_MAX_NAME, "%s%d",
  10957. dev_cntrs[i].name,
  10958. vl_from_idx(j));
  10959. memcpy(p, name, strlen(name));
  10960. p += strlen(name);
  10961. /* Counter is 32 bits */
  10962. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10963. memcpy(p, bit_type_32, bit_type_32_sz);
  10964. p += bit_type_32_sz;
  10965. }
  10966. *p++ = '\n';
  10967. }
  10968. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10969. for (j = 0; j < sdma_engines; j++) {
  10970. snprintf(name, C_MAX_NAME, "%s%d",
  10971. dev_cntrs[i].name, j);
  10972. memcpy(p, name, strlen(name));
  10973. p += strlen(name);
  10974. /* Counter is 32 bits */
  10975. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10976. memcpy(p, bit_type_32, bit_type_32_sz);
  10977. p += bit_type_32_sz;
  10978. }
  10979. *p++ = '\n';
  10980. }
  10981. } else {
  10982. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10983. p += strlen(dev_cntrs[i].name);
  10984. /* Counter is 32 bits */
  10985. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10986. memcpy(p, bit_type_32, bit_type_32_sz);
  10987. p += bit_type_32_sz;
  10988. }
  10989. *p++ = '\n';
  10990. }
  10991. }
  10992. /*********************/
  10993. /* per port counters */
  10994. /*********************/
  10995. /*
  10996. * Go through the counters for the overflows and disable the ones we
  10997. * don't need. This varies based on platform so we need to do it
  10998. * dynamically here.
  10999. */
  11000. rcv_ctxts = dd->num_rcv_contexts;
  11001. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  11002. i <= C_RCV_HDR_OVF_LAST; i++) {
  11003. port_cntrs[i].flags |= CNTR_DISABLED;
  11004. }
  11005. /* size port counter names and determine how many we have*/
  11006. sz = 0;
  11007. dd->nportcntrs = 0;
  11008. for (i = 0; i < PORT_CNTR_LAST; i++) {
  11009. if (port_cntrs[i].flags & CNTR_DISABLED) {
  11010. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  11011. continue;
  11012. }
  11013. if (port_cntrs[i].flags & CNTR_VL) {
  11014. port_cntrs[i].offset = dd->nportcntrs;
  11015. for (j = 0; j < C_VL_COUNT; j++) {
  11016. snprintf(name, C_MAX_NAME, "%s%d",
  11017. port_cntrs[i].name, vl_from_idx(j));
  11018. sz += strlen(name);
  11019. /* Add ",32" for 32-bit counters */
  11020. if (port_cntrs[i].flags & CNTR_32BIT)
  11021. sz += bit_type_32_sz;
  11022. sz++;
  11023. dd->nportcntrs++;
  11024. }
  11025. } else {
  11026. /* +1 for newline */
  11027. sz += strlen(port_cntrs[i].name) + 1;
  11028. /* Add ",32" for 32-bit counters */
  11029. if (port_cntrs[i].flags & CNTR_32BIT)
  11030. sz += bit_type_32_sz;
  11031. port_cntrs[i].offset = dd->nportcntrs;
  11032. dd->nportcntrs++;
  11033. }
  11034. }
  11035. /* allocate space for the counter names */
  11036. dd->portcntrnameslen = sz;
  11037. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  11038. if (!dd->portcntrnames)
  11039. goto bail;
  11040. /* fill in port cntr names */
  11041. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  11042. if (port_cntrs[i].flags & CNTR_DISABLED)
  11043. continue;
  11044. if (port_cntrs[i].flags & CNTR_VL) {
  11045. for (j = 0; j < C_VL_COUNT; j++) {
  11046. snprintf(name, C_MAX_NAME, "%s%d",
  11047. port_cntrs[i].name, vl_from_idx(j));
  11048. memcpy(p, name, strlen(name));
  11049. p += strlen(name);
  11050. /* Counter is 32 bits */
  11051. if (port_cntrs[i].flags & CNTR_32BIT) {
  11052. memcpy(p, bit_type_32, bit_type_32_sz);
  11053. p += bit_type_32_sz;
  11054. }
  11055. *p++ = '\n';
  11056. }
  11057. } else {
  11058. memcpy(p, port_cntrs[i].name,
  11059. strlen(port_cntrs[i].name));
  11060. p += strlen(port_cntrs[i].name);
  11061. /* Counter is 32 bits */
  11062. if (port_cntrs[i].flags & CNTR_32BIT) {
  11063. memcpy(p, bit_type_32, bit_type_32_sz);
  11064. p += bit_type_32_sz;
  11065. }
  11066. *p++ = '\n';
  11067. }
  11068. }
  11069. /* allocate per port storage for counter values */
  11070. ppd = (struct hfi1_pportdata *)(dd + 1);
  11071. for (i = 0; i < dd->num_pports; i++, ppd++) {
  11072. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11073. if (!ppd->cntrs)
  11074. goto bail;
  11075. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11076. if (!ppd->scntrs)
  11077. goto bail;
  11078. }
  11079. /* CPU counters need to be allocated and zeroed */
  11080. if (init_cpu_counters(dd))
  11081. goto bail;
  11082. dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
  11083. WQ_MEM_RECLAIM, dd->unit);
  11084. if (!dd->update_cntr_wq)
  11085. goto bail;
  11086. INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
  11087. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  11088. return 0;
  11089. bail:
  11090. free_cntrs(dd);
  11091. return -ENOMEM;
  11092. }
  11093. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  11094. {
  11095. switch (chip_lstate) {
  11096. default:
  11097. dd_dev_err(dd,
  11098. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  11099. chip_lstate);
  11100. /* fall through */
  11101. case LSTATE_DOWN:
  11102. return IB_PORT_DOWN;
  11103. case LSTATE_INIT:
  11104. return IB_PORT_INIT;
  11105. case LSTATE_ARMED:
  11106. return IB_PORT_ARMED;
  11107. case LSTATE_ACTIVE:
  11108. return IB_PORT_ACTIVE;
  11109. }
  11110. }
  11111. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  11112. {
  11113. /* look at the HFI meta-states only */
  11114. switch (chip_pstate & 0xf0) {
  11115. default:
  11116. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  11117. chip_pstate);
  11118. /* fall through */
  11119. case PLS_DISABLED:
  11120. return IB_PORTPHYSSTATE_DISABLED;
  11121. case PLS_OFFLINE:
  11122. return OPA_PORTPHYSSTATE_OFFLINE;
  11123. case PLS_POLLING:
  11124. return IB_PORTPHYSSTATE_POLLING;
  11125. case PLS_CONFIGPHY:
  11126. return IB_PORTPHYSSTATE_TRAINING;
  11127. case PLS_LINKUP:
  11128. return IB_PORTPHYSSTATE_LINKUP;
  11129. case PLS_PHYTEST:
  11130. return IB_PORTPHYSSTATE_PHY_TEST;
  11131. }
  11132. }
  11133. /* return the OPA port logical state name */
  11134. const char *opa_lstate_name(u32 lstate)
  11135. {
  11136. static const char * const port_logical_names[] = {
  11137. "PORT_NOP",
  11138. "PORT_DOWN",
  11139. "PORT_INIT",
  11140. "PORT_ARMED",
  11141. "PORT_ACTIVE",
  11142. "PORT_ACTIVE_DEFER",
  11143. };
  11144. if (lstate < ARRAY_SIZE(port_logical_names))
  11145. return port_logical_names[lstate];
  11146. return "unknown";
  11147. }
  11148. /* return the OPA port physical state name */
  11149. const char *opa_pstate_name(u32 pstate)
  11150. {
  11151. static const char * const port_physical_names[] = {
  11152. "PHYS_NOP",
  11153. "reserved1",
  11154. "PHYS_POLL",
  11155. "PHYS_DISABLED",
  11156. "PHYS_TRAINING",
  11157. "PHYS_LINKUP",
  11158. "PHYS_LINK_ERR_RECOVER",
  11159. "PHYS_PHY_TEST",
  11160. "reserved8",
  11161. "PHYS_OFFLINE",
  11162. "PHYS_GANGED",
  11163. "PHYS_TEST",
  11164. };
  11165. if (pstate < ARRAY_SIZE(port_physical_names))
  11166. return port_physical_names[pstate];
  11167. return "unknown";
  11168. }
  11169. /**
  11170. * update_statusp - Update userspace status flag
  11171. * @ppd: Port data structure
  11172. * @state: port state information
  11173. *
  11174. * Actual port status is determined by the host_link_state value
  11175. * in the ppd.
  11176. *
  11177. * host_link_state MUST be updated before updating the user space
  11178. * statusp.
  11179. */
  11180. static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
  11181. {
  11182. /*
  11183. * Set port status flags in the page mapped into userspace
  11184. * memory. Do it here to ensure a reliable state - this is
  11185. * the only function called by all state handling code.
  11186. * Always set the flags due to the fact that the cache value
  11187. * might have been changed explicitly outside of this
  11188. * function.
  11189. */
  11190. if (ppd->statusp) {
  11191. switch (state) {
  11192. case IB_PORT_DOWN:
  11193. case IB_PORT_INIT:
  11194. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  11195. HFI1_STATUS_IB_READY);
  11196. break;
  11197. case IB_PORT_ARMED:
  11198. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  11199. break;
  11200. case IB_PORT_ACTIVE:
  11201. *ppd->statusp |= HFI1_STATUS_IB_READY;
  11202. break;
  11203. }
  11204. }
  11205. dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
  11206. opa_lstate_name(state), state);
  11207. }
  11208. /**
  11209. * wait_logical_linkstate - wait for an IB link state change to occur
  11210. * @ppd: port device
  11211. * @state: the state to wait for
  11212. * @msecs: the number of milliseconds to wait
  11213. *
  11214. * Wait up to msecs milliseconds for IB link state change to occur.
  11215. * For now, take the easy polling route.
  11216. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11217. */
  11218. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11219. int msecs)
  11220. {
  11221. unsigned long timeout;
  11222. u32 new_state;
  11223. timeout = jiffies + msecs_to_jiffies(msecs);
  11224. while (1) {
  11225. new_state = chip_to_opa_lstate(ppd->dd,
  11226. read_logical_state(ppd->dd));
  11227. if (new_state == state)
  11228. break;
  11229. if (time_after(jiffies, timeout)) {
  11230. dd_dev_err(ppd->dd,
  11231. "timeout waiting for link state 0x%x\n",
  11232. state);
  11233. return -ETIMEDOUT;
  11234. }
  11235. msleep(20);
  11236. }
  11237. return 0;
  11238. }
  11239. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state)
  11240. {
  11241. u32 ib_pstate = chip_to_opa_pstate(ppd->dd, state);
  11242. dd_dev_info(ppd->dd,
  11243. "physical state changed to %s (0x%x), phy 0x%x\n",
  11244. opa_pstate_name(ib_pstate), ib_pstate, state);
  11245. }
  11246. /*
  11247. * Read the physical hardware link state and check if it matches host
  11248. * drivers anticipated state.
  11249. */
  11250. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state)
  11251. {
  11252. u32 read_state = read_physical_state(ppd->dd);
  11253. if (read_state == state) {
  11254. log_state_transition(ppd, state);
  11255. } else {
  11256. dd_dev_err(ppd->dd,
  11257. "anticipated phy link state 0x%x, read 0x%x\n",
  11258. state, read_state);
  11259. }
  11260. }
  11261. /*
  11262. * wait_physical_linkstate - wait for an physical link state change to occur
  11263. * @ppd: port device
  11264. * @state: the state to wait for
  11265. * @msecs: the number of milliseconds to wait
  11266. *
  11267. * Wait up to msecs milliseconds for physical link state change to occur.
  11268. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11269. */
  11270. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11271. int msecs)
  11272. {
  11273. u32 read_state;
  11274. unsigned long timeout;
  11275. timeout = jiffies + msecs_to_jiffies(msecs);
  11276. while (1) {
  11277. read_state = read_physical_state(ppd->dd);
  11278. if (read_state == state)
  11279. break;
  11280. if (time_after(jiffies, timeout)) {
  11281. dd_dev_err(ppd->dd,
  11282. "timeout waiting for phy link state 0x%x\n",
  11283. state);
  11284. return -ETIMEDOUT;
  11285. }
  11286. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11287. }
  11288. log_state_transition(ppd, state);
  11289. return 0;
  11290. }
  11291. /*
  11292. * wait_phys_link_offline_quiet_substates - wait for any offline substate
  11293. * @ppd: port device
  11294. * @msecs: the number of milliseconds to wait
  11295. *
  11296. * Wait up to msecs milliseconds for any offline physical link
  11297. * state change to occur.
  11298. * Returns 0 if at least one state is reached, otherwise -ETIMEDOUT.
  11299. */
  11300. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  11301. int msecs)
  11302. {
  11303. u32 read_state;
  11304. unsigned long timeout;
  11305. timeout = jiffies + msecs_to_jiffies(msecs);
  11306. while (1) {
  11307. read_state = read_physical_state(ppd->dd);
  11308. if ((read_state & 0xF0) == PLS_OFFLINE)
  11309. break;
  11310. if (time_after(jiffies, timeout)) {
  11311. dd_dev_err(ppd->dd,
  11312. "timeout waiting for phy link offline.quiet substates. Read state 0x%x, %dms\n",
  11313. read_state, msecs);
  11314. return -ETIMEDOUT;
  11315. }
  11316. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11317. }
  11318. log_state_transition(ppd, read_state);
  11319. return read_state;
  11320. }
  11321. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  11322. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11323. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  11324. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11325. void hfi1_init_ctxt(struct send_context *sc)
  11326. {
  11327. if (sc) {
  11328. struct hfi1_devdata *dd = sc->dd;
  11329. u64 reg;
  11330. u8 set = (sc->type == SC_USER ?
  11331. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  11332. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  11333. reg = read_kctxt_csr(dd, sc->hw_context,
  11334. SEND_CTXT_CHECK_ENABLE);
  11335. if (set)
  11336. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  11337. else
  11338. SET_STATIC_RATE_CONTROL_SMASK(reg);
  11339. write_kctxt_csr(dd, sc->hw_context,
  11340. SEND_CTXT_CHECK_ENABLE, reg);
  11341. }
  11342. }
  11343. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  11344. {
  11345. int ret = 0;
  11346. u64 reg;
  11347. if (dd->icode != ICODE_RTL_SILICON) {
  11348. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  11349. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  11350. __func__);
  11351. return -EINVAL;
  11352. }
  11353. reg = read_csr(dd, ASIC_STS_THERM);
  11354. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  11355. ASIC_STS_THERM_CURR_TEMP_MASK);
  11356. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  11357. ASIC_STS_THERM_LO_TEMP_MASK);
  11358. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11359. ASIC_STS_THERM_HI_TEMP_MASK);
  11360. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11361. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11362. /* triggers is a 3-bit value - 1 bit per trigger. */
  11363. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11364. return ret;
  11365. }
  11366. /**
  11367. * get_int_mask - get 64 bit int mask
  11368. * @dd - the devdata
  11369. * @i - the csr (relative to CCE_INT_MASK)
  11370. *
  11371. * Returns the mask with the urgent interrupt mask
  11372. * bit clear for kernel receive contexts.
  11373. */
  11374. static u64 get_int_mask(struct hfi1_devdata *dd, u32 i)
  11375. {
  11376. u64 mask = U64_MAX; /* default to no change */
  11377. if (i >= (IS_RCVURGENT_START / 64) && i < (IS_RCVURGENT_END / 64)) {
  11378. int j = (i - (IS_RCVURGENT_START / 64)) * 64;
  11379. int k = !j ? IS_RCVURGENT_START % 64 : 0;
  11380. if (j)
  11381. j -= IS_RCVURGENT_START % 64;
  11382. /* j = 0..dd->first_dyn_alloc_ctxt - 1,k = 0..63 */
  11383. for (; j < dd->first_dyn_alloc_ctxt && k < 64; j++, k++)
  11384. /* convert to bit in mask and clear */
  11385. mask &= ~BIT_ULL(k);
  11386. }
  11387. return mask;
  11388. }
  11389. /* ========================================================================= */
  11390. /*
  11391. * Enable/disable chip from delivering interrupts.
  11392. */
  11393. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11394. {
  11395. int i;
  11396. /*
  11397. * In HFI, the mask needs to be 1 to allow interrupts.
  11398. */
  11399. if (enable) {
  11400. /* enable all interrupts but urgent on kernel contexts */
  11401. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11402. u64 mask = get_int_mask(dd, i);
  11403. write_csr(dd, CCE_INT_MASK + (8 * i), mask);
  11404. }
  11405. init_qsfp_int(dd);
  11406. } else {
  11407. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11408. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11409. }
  11410. }
  11411. /*
  11412. * Clear all interrupt sources on the chip.
  11413. */
  11414. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11415. {
  11416. int i;
  11417. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11418. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11419. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11420. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11421. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11422. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11423. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11424. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11425. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11426. for (i = 0; i < chip_send_contexts(dd); i++)
  11427. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11428. for (i = 0; i < chip_sdma_engines(dd); i++)
  11429. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11430. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11431. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11432. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11433. }
  11434. /**
  11435. * hfi1_clean_up_interrupts() - Free all IRQ resources
  11436. * @dd: valid device data data structure
  11437. *
  11438. * Free the MSIx and assoicated PCI resources, if they have been allocated.
  11439. */
  11440. void hfi1_clean_up_interrupts(struct hfi1_devdata *dd)
  11441. {
  11442. int i;
  11443. struct hfi1_msix_entry *me = dd->msix_entries;
  11444. /* remove irqs - must happen before disabling/turning off */
  11445. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11446. if (!me->arg) /* => no irq, no affinity */
  11447. continue;
  11448. hfi1_put_irq_affinity(dd, me);
  11449. pci_free_irq(dd->pcidev, i, me->arg);
  11450. }
  11451. /* clean structures */
  11452. kfree(dd->msix_entries);
  11453. dd->msix_entries = NULL;
  11454. dd->num_msix_entries = 0;
  11455. pci_free_irq_vectors(dd->pcidev);
  11456. }
  11457. /*
  11458. * Remap the interrupt source from the general handler to the given MSI-X
  11459. * interrupt.
  11460. */
  11461. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11462. {
  11463. u64 reg;
  11464. int m, n;
  11465. /* clear from the handled mask of the general interrupt */
  11466. m = isrc / 64;
  11467. n = isrc % 64;
  11468. if (likely(m < CCE_NUM_INT_CSRS)) {
  11469. dd->gi_mask[m] &= ~((u64)1 << n);
  11470. } else {
  11471. dd_dev_err(dd, "remap interrupt err\n");
  11472. return;
  11473. }
  11474. /* direct the chip source to the given MSI-X interrupt */
  11475. m = isrc / 8;
  11476. n = isrc % 8;
  11477. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11478. reg &= ~((u64)0xff << (8 * n));
  11479. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11480. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11481. }
  11482. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11483. int engine, int msix_intr)
  11484. {
  11485. /*
  11486. * SDMA engine interrupt sources grouped by type, rather than
  11487. * engine. Per-engine interrupts are as follows:
  11488. * SDMA
  11489. * SDMAProgress
  11490. * SDMAIdle
  11491. */
  11492. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11493. msix_intr);
  11494. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11495. msix_intr);
  11496. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11497. msix_intr);
  11498. }
  11499. static int request_msix_irqs(struct hfi1_devdata *dd)
  11500. {
  11501. int first_general, last_general;
  11502. int first_sdma, last_sdma;
  11503. int first_rx, last_rx;
  11504. int i, ret = 0;
  11505. /* calculate the ranges we are going to use */
  11506. first_general = 0;
  11507. last_general = first_general + 1;
  11508. first_sdma = last_general;
  11509. last_sdma = first_sdma + dd->num_sdma;
  11510. first_rx = last_sdma;
  11511. last_rx = first_rx + dd->n_krcv_queues + dd->num_vnic_contexts;
  11512. /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
  11513. dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
  11514. /*
  11515. * Sanity check - the code expects all SDMA chip source
  11516. * interrupts to be in the same CSR, starting at bit 0. Verify
  11517. * that this is true by checking the bit location of the start.
  11518. */
  11519. BUILD_BUG_ON(IS_SDMA_START % 64);
  11520. for (i = 0; i < dd->num_msix_entries; i++) {
  11521. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11522. const char *err_info;
  11523. irq_handler_t handler;
  11524. irq_handler_t thread = NULL;
  11525. void *arg = NULL;
  11526. int idx;
  11527. struct hfi1_ctxtdata *rcd = NULL;
  11528. struct sdma_engine *sde = NULL;
  11529. char name[MAX_NAME_SIZE];
  11530. /* obtain the arguments to pci_request_irq */
  11531. if (first_general <= i && i < last_general) {
  11532. idx = i - first_general;
  11533. handler = general_interrupt;
  11534. arg = dd;
  11535. snprintf(name, sizeof(name),
  11536. DRIVER_NAME "_%d", dd->unit);
  11537. err_info = "general";
  11538. me->type = IRQ_GENERAL;
  11539. } else if (first_sdma <= i && i < last_sdma) {
  11540. idx = i - first_sdma;
  11541. sde = &dd->per_sdma[idx];
  11542. handler = sdma_interrupt;
  11543. arg = sde;
  11544. snprintf(name, sizeof(name),
  11545. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11546. err_info = "sdma";
  11547. remap_sdma_interrupts(dd, idx, i);
  11548. me->type = IRQ_SDMA;
  11549. } else if (first_rx <= i && i < last_rx) {
  11550. idx = i - first_rx;
  11551. rcd = hfi1_rcd_get_by_index_safe(dd, idx);
  11552. if (rcd) {
  11553. /*
  11554. * Set the interrupt register and mask for this
  11555. * context's interrupt.
  11556. */
  11557. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11558. rcd->imask = ((u64)1) <<
  11559. ((IS_RCVAVAIL_START + idx) % 64);
  11560. handler = receive_context_interrupt;
  11561. thread = receive_context_thread;
  11562. arg = rcd;
  11563. snprintf(name, sizeof(name),
  11564. DRIVER_NAME "_%d kctxt%d",
  11565. dd->unit, idx);
  11566. err_info = "receive context";
  11567. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11568. me->type = IRQ_RCVCTXT;
  11569. rcd->msix_intr = i;
  11570. hfi1_rcd_put(rcd);
  11571. }
  11572. } else {
  11573. /* not in our expected range - complain, then
  11574. * ignore it
  11575. */
  11576. dd_dev_err(dd,
  11577. "Unexpected extra MSI-X interrupt %d\n", i);
  11578. continue;
  11579. }
  11580. /* no argument, no interrupt */
  11581. if (!arg)
  11582. continue;
  11583. /* make sure the name is terminated */
  11584. name[sizeof(name) - 1] = 0;
  11585. me->irq = pci_irq_vector(dd->pcidev, i);
  11586. ret = pci_request_irq(dd->pcidev, i, handler, thread, arg,
  11587. name);
  11588. if (ret) {
  11589. dd_dev_err(dd,
  11590. "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
  11591. err_info, me->irq, idx, ret);
  11592. return ret;
  11593. }
  11594. /*
  11595. * assign arg after pci_request_irq call, so it will be
  11596. * cleaned up
  11597. */
  11598. me->arg = arg;
  11599. ret = hfi1_get_irq_affinity(dd, me);
  11600. if (ret)
  11601. dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
  11602. }
  11603. return ret;
  11604. }
  11605. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
  11606. {
  11607. int i;
  11608. for (i = 0; i < dd->vnic.num_ctxt; i++) {
  11609. struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
  11610. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11611. synchronize_irq(me->irq);
  11612. }
  11613. }
  11614. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11615. {
  11616. struct hfi1_devdata *dd = rcd->dd;
  11617. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11618. if (!me->arg) /* => no irq, no affinity */
  11619. return;
  11620. hfi1_put_irq_affinity(dd, me);
  11621. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11622. me->arg = NULL;
  11623. }
  11624. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11625. {
  11626. struct hfi1_devdata *dd = rcd->dd;
  11627. struct hfi1_msix_entry *me;
  11628. int idx = rcd->ctxt;
  11629. void *arg = rcd;
  11630. int ret;
  11631. rcd->msix_intr = dd->vnic.msix_idx++;
  11632. me = &dd->msix_entries[rcd->msix_intr];
  11633. /*
  11634. * Set the interrupt register and mask for this
  11635. * context's interrupt.
  11636. */
  11637. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11638. rcd->imask = ((u64)1) <<
  11639. ((IS_RCVAVAIL_START + idx) % 64);
  11640. me->type = IRQ_RCVCTXT;
  11641. me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
  11642. remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
  11643. ret = pci_request_irq(dd->pcidev, rcd->msix_intr,
  11644. receive_context_interrupt,
  11645. receive_context_thread, arg,
  11646. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11647. if (ret) {
  11648. dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
  11649. me->irq, idx, ret);
  11650. return;
  11651. }
  11652. /*
  11653. * assign arg after pci_request_irq call, so it will be
  11654. * cleaned up
  11655. */
  11656. me->arg = arg;
  11657. ret = hfi1_get_irq_affinity(dd, me);
  11658. if (ret) {
  11659. dd_dev_err(dd,
  11660. "unable to pin IRQ %d\n", ret);
  11661. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11662. }
  11663. }
  11664. /*
  11665. * Set the general handler to accept all interrupts, remap all
  11666. * chip interrupts back to MSI-X 0.
  11667. */
  11668. static void reset_interrupts(struct hfi1_devdata *dd)
  11669. {
  11670. int i;
  11671. /* all interrupts handled by the general handler */
  11672. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11673. dd->gi_mask[i] = ~(u64)0;
  11674. /* all chip interrupts map to MSI-X 0 */
  11675. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11676. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11677. }
  11678. static int set_up_interrupts(struct hfi1_devdata *dd)
  11679. {
  11680. u32 total;
  11681. int ret, request;
  11682. /*
  11683. * Interrupt count:
  11684. * 1 general, "slow path" interrupt (includes the SDMA engines
  11685. * slow source, SDMACleanupDone)
  11686. * N interrupts - one per used SDMA engine
  11687. * M interrupt - one per kernel receive context
  11688. * V interrupt - one for each VNIC context
  11689. */
  11690. total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
  11691. /* ask for MSI-X interrupts */
  11692. request = request_msix(dd, total);
  11693. if (request < 0) {
  11694. ret = request;
  11695. goto fail;
  11696. } else {
  11697. dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
  11698. GFP_KERNEL);
  11699. if (!dd->msix_entries) {
  11700. ret = -ENOMEM;
  11701. goto fail;
  11702. }
  11703. /* using MSI-X */
  11704. dd->num_msix_entries = total;
  11705. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11706. }
  11707. /* mask all interrupts */
  11708. set_intr_state(dd, 0);
  11709. /* clear all pending interrupts */
  11710. clear_all_interrupts(dd);
  11711. /* reset general handler mask, chip MSI-X mappings */
  11712. reset_interrupts(dd);
  11713. ret = request_msix_irqs(dd);
  11714. if (ret)
  11715. goto fail;
  11716. return 0;
  11717. fail:
  11718. hfi1_clean_up_interrupts(dd);
  11719. return ret;
  11720. }
  11721. /*
  11722. * Set up context values in dd. Sets:
  11723. *
  11724. * num_rcv_contexts - number of contexts being used
  11725. * n_krcv_queues - number of kernel contexts
  11726. * first_dyn_alloc_ctxt - first dynamically allocated context
  11727. * in array of contexts
  11728. * freectxts - number of free user contexts
  11729. * num_send_contexts - number of PIO send contexts being used
  11730. * num_vnic_contexts - number of contexts reserved for VNIC
  11731. */
  11732. static int set_up_context_variables(struct hfi1_devdata *dd)
  11733. {
  11734. unsigned long num_kernel_contexts;
  11735. u16 num_vnic_contexts = HFI1_NUM_VNIC_CTXT;
  11736. int total_contexts;
  11737. int ret;
  11738. unsigned ngroups;
  11739. int qos_rmt_count;
  11740. int user_rmt_reduced;
  11741. u32 n_usr_ctxts;
  11742. u32 send_contexts = chip_send_contexts(dd);
  11743. u32 rcv_contexts = chip_rcv_contexts(dd);
  11744. /*
  11745. * Kernel receive contexts:
  11746. * - Context 0 - control context (VL15/multicast/error)
  11747. * - Context 1 - first kernel context
  11748. * - Context 2 - second kernel context
  11749. * ...
  11750. */
  11751. if (n_krcvqs)
  11752. /*
  11753. * n_krcvqs is the sum of module parameter kernel receive
  11754. * contexts, krcvqs[]. It does not include the control
  11755. * context, so add that.
  11756. */
  11757. num_kernel_contexts = n_krcvqs + 1;
  11758. else
  11759. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11760. /*
  11761. * Every kernel receive context needs an ACK send context.
  11762. * one send context is allocated for each VL{0-7} and VL15
  11763. */
  11764. if (num_kernel_contexts > (send_contexts - num_vls - 1)) {
  11765. dd_dev_err(dd,
  11766. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11767. send_contexts - num_vls - 1,
  11768. num_kernel_contexts);
  11769. num_kernel_contexts = send_contexts - num_vls - 1;
  11770. }
  11771. /* Accommodate VNIC contexts if possible */
  11772. if ((num_kernel_contexts + num_vnic_contexts) > rcv_contexts) {
  11773. dd_dev_err(dd, "No receive contexts available for VNIC\n");
  11774. num_vnic_contexts = 0;
  11775. }
  11776. total_contexts = num_kernel_contexts + num_vnic_contexts;
  11777. /*
  11778. * User contexts:
  11779. * - default to 1 user context per real (non-HT) CPU core if
  11780. * num_user_contexts is negative
  11781. */
  11782. if (num_user_contexts < 0)
  11783. n_usr_ctxts = cpumask_weight(&node_affinity.real_cpu_mask);
  11784. else
  11785. n_usr_ctxts = num_user_contexts;
  11786. /*
  11787. * Adjust the counts given a global max.
  11788. */
  11789. if (total_contexts + n_usr_ctxts > rcv_contexts) {
  11790. dd_dev_err(dd,
  11791. "Reducing # user receive contexts to: %d, from %u\n",
  11792. rcv_contexts - total_contexts,
  11793. n_usr_ctxts);
  11794. /* recalculate */
  11795. n_usr_ctxts = rcv_contexts - total_contexts;
  11796. }
  11797. /* each user context requires an entry in the RMT */
  11798. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11799. if (qos_rmt_count + n_usr_ctxts > NUM_MAP_ENTRIES) {
  11800. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11801. dd_dev_err(dd,
  11802. "RMT size is reducing the number of user receive contexts from %u to %d\n",
  11803. n_usr_ctxts,
  11804. user_rmt_reduced);
  11805. /* recalculate */
  11806. n_usr_ctxts = user_rmt_reduced;
  11807. }
  11808. total_contexts += n_usr_ctxts;
  11809. /* the first N are kernel contexts, the rest are user/vnic contexts */
  11810. dd->num_rcv_contexts = total_contexts;
  11811. dd->n_krcv_queues = num_kernel_contexts;
  11812. dd->first_dyn_alloc_ctxt = num_kernel_contexts;
  11813. dd->num_vnic_contexts = num_vnic_contexts;
  11814. dd->num_user_contexts = n_usr_ctxts;
  11815. dd->freectxts = n_usr_ctxts;
  11816. dd_dev_info(dd,
  11817. "rcv contexts: chip %d, used %d (kernel %d, vnic %u, user %u)\n",
  11818. rcv_contexts,
  11819. (int)dd->num_rcv_contexts,
  11820. (int)dd->n_krcv_queues,
  11821. dd->num_vnic_contexts,
  11822. dd->num_user_contexts);
  11823. /*
  11824. * Receive array allocation:
  11825. * All RcvArray entries are divided into groups of 8. This
  11826. * is required by the hardware and will speed up writes to
  11827. * consecutive entries by using write-combining of the entire
  11828. * cacheline.
  11829. *
  11830. * The number of groups are evenly divided among all contexts.
  11831. * any left over groups will be given to the first N user
  11832. * contexts.
  11833. */
  11834. dd->rcv_entries.group_size = RCV_INCREMENT;
  11835. ngroups = chip_rcv_array_count(dd) / dd->rcv_entries.group_size;
  11836. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11837. dd->rcv_entries.nctxt_extra = ngroups -
  11838. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11839. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11840. dd->rcv_entries.ngroups,
  11841. dd->rcv_entries.nctxt_extra);
  11842. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11843. MAX_EAGER_ENTRIES * 2) {
  11844. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11845. dd->rcv_entries.group_size;
  11846. dd_dev_info(dd,
  11847. "RcvArray group count too high, change to %u\n",
  11848. dd->rcv_entries.ngroups);
  11849. dd->rcv_entries.nctxt_extra = 0;
  11850. }
  11851. /*
  11852. * PIO send contexts
  11853. */
  11854. ret = init_sc_pools_and_sizes(dd);
  11855. if (ret >= 0) { /* success */
  11856. dd->num_send_contexts = ret;
  11857. dd_dev_info(
  11858. dd,
  11859. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11860. send_contexts,
  11861. dd->num_send_contexts,
  11862. dd->sc_sizes[SC_KERNEL].count,
  11863. dd->sc_sizes[SC_ACK].count,
  11864. dd->sc_sizes[SC_USER].count,
  11865. dd->sc_sizes[SC_VL15].count);
  11866. ret = 0; /* success */
  11867. }
  11868. return ret;
  11869. }
  11870. /*
  11871. * Set the device/port partition key table. The MAD code
  11872. * will ensure that, at least, the partial management
  11873. * partition key is present in the table.
  11874. */
  11875. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11876. {
  11877. struct hfi1_devdata *dd = ppd->dd;
  11878. u64 reg = 0;
  11879. int i;
  11880. dd_dev_info(dd, "Setting partition keys\n");
  11881. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11882. reg |= (ppd->pkeys[i] &
  11883. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11884. ((i % 4) *
  11885. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11886. /* Each register holds 4 PKey values. */
  11887. if ((i % 4) == 3) {
  11888. write_csr(dd, RCV_PARTITION_KEY +
  11889. ((i - 3) * 2), reg);
  11890. reg = 0;
  11891. }
  11892. }
  11893. /* Always enable HW pkeys check when pkeys table is set */
  11894. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11895. }
  11896. /*
  11897. * These CSRs and memories are uninitialized on reset and must be
  11898. * written before reading to set the ECC/parity bits.
  11899. *
  11900. * NOTE: All user context CSRs that are not mmaped write-only
  11901. * (e.g. the TID flows) must be initialized even if the driver never
  11902. * reads them.
  11903. */
  11904. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11905. {
  11906. int i, j;
  11907. /* CceIntMap */
  11908. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11909. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11910. /* SendCtxtCreditReturnAddr */
  11911. for (i = 0; i < chip_send_contexts(dd); i++)
  11912. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11913. /* PIO Send buffers */
  11914. /* SDMA Send buffers */
  11915. /*
  11916. * These are not normally read, and (presently) have no method
  11917. * to be read, so are not pre-initialized
  11918. */
  11919. /* RcvHdrAddr */
  11920. /* RcvHdrTailAddr */
  11921. /* RcvTidFlowTable */
  11922. for (i = 0; i < chip_rcv_contexts(dd); i++) {
  11923. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11924. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11925. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11926. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11927. }
  11928. /* RcvArray */
  11929. for (i = 0; i < chip_rcv_array_count(dd); i++)
  11930. hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
  11931. /* RcvQPMapTable */
  11932. for (i = 0; i < 32; i++)
  11933. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11934. }
  11935. /*
  11936. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11937. */
  11938. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11939. u64 ctrl_bits)
  11940. {
  11941. unsigned long timeout;
  11942. u64 reg;
  11943. /* is the condition present? */
  11944. reg = read_csr(dd, CCE_STATUS);
  11945. if ((reg & status_bits) == 0)
  11946. return;
  11947. /* clear the condition */
  11948. write_csr(dd, CCE_CTRL, ctrl_bits);
  11949. /* wait for the condition to clear */
  11950. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11951. while (1) {
  11952. reg = read_csr(dd, CCE_STATUS);
  11953. if ((reg & status_bits) == 0)
  11954. return;
  11955. if (time_after(jiffies, timeout)) {
  11956. dd_dev_err(dd,
  11957. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11958. status_bits, reg & status_bits);
  11959. return;
  11960. }
  11961. udelay(1);
  11962. }
  11963. }
  11964. /* set CCE CSRs to chip reset defaults */
  11965. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11966. {
  11967. int i;
  11968. /* CCE_REVISION read-only */
  11969. /* CCE_REVISION2 read-only */
  11970. /* CCE_CTRL - bits clear automatically */
  11971. /* CCE_STATUS read-only, use CceCtrl to clear */
  11972. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11973. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  11974. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  11975. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  11976. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  11977. /* CCE_ERR_STATUS read-only */
  11978. write_csr(dd, CCE_ERR_MASK, 0);
  11979. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  11980. /* CCE_ERR_FORCE leave alone */
  11981. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  11982. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  11983. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  11984. /* CCE_PCIE_CTRL leave alone */
  11985. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  11986. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  11987. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  11988. CCE_MSIX_TABLE_UPPER_RESETCSR);
  11989. }
  11990. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  11991. /* CCE_MSIX_PBA read-only */
  11992. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  11993. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  11994. }
  11995. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11996. write_csr(dd, CCE_INT_MAP, 0);
  11997. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11998. /* CCE_INT_STATUS read-only */
  11999. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  12000. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  12001. /* CCE_INT_FORCE leave alone */
  12002. /* CCE_INT_BLOCKED read-only */
  12003. }
  12004. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  12005. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  12006. }
  12007. /* set MISC CSRs to chip reset defaults */
  12008. static void reset_misc_csrs(struct hfi1_devdata *dd)
  12009. {
  12010. int i;
  12011. for (i = 0; i < 32; i++) {
  12012. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  12013. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  12014. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  12015. }
  12016. /*
  12017. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  12018. * only be written 128-byte chunks
  12019. */
  12020. /* init RSA engine to clear lingering errors */
  12021. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  12022. write_csr(dd, MISC_CFG_RSA_MU, 0);
  12023. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  12024. /* MISC_STS_8051_DIGEST read-only */
  12025. /* MISC_STS_SBM_DIGEST read-only */
  12026. /* MISC_STS_PCIE_DIGEST read-only */
  12027. /* MISC_STS_FAB_DIGEST read-only */
  12028. /* MISC_ERR_STATUS read-only */
  12029. write_csr(dd, MISC_ERR_MASK, 0);
  12030. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  12031. /* MISC_ERR_FORCE leave alone */
  12032. }
  12033. /* set TXE CSRs to chip reset defaults */
  12034. static void reset_txe_csrs(struct hfi1_devdata *dd)
  12035. {
  12036. int i;
  12037. /*
  12038. * TXE Kernel CSRs
  12039. */
  12040. write_csr(dd, SEND_CTRL, 0);
  12041. __cm_reset(dd, 0); /* reset CM internal state */
  12042. /* SEND_CONTEXTS read-only */
  12043. /* SEND_DMA_ENGINES read-only */
  12044. /* SEND_PIO_MEM_SIZE read-only */
  12045. /* SEND_DMA_MEM_SIZE read-only */
  12046. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  12047. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  12048. /* SEND_PIO_ERR_STATUS read-only */
  12049. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  12050. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  12051. /* SEND_PIO_ERR_FORCE leave alone */
  12052. /* SEND_DMA_ERR_STATUS read-only */
  12053. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  12054. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  12055. /* SEND_DMA_ERR_FORCE leave alone */
  12056. /* SEND_EGRESS_ERR_STATUS read-only */
  12057. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  12058. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  12059. /* SEND_EGRESS_ERR_FORCE leave alone */
  12060. write_csr(dd, SEND_BTH_QP, 0);
  12061. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  12062. write_csr(dd, SEND_SC2VLT0, 0);
  12063. write_csr(dd, SEND_SC2VLT1, 0);
  12064. write_csr(dd, SEND_SC2VLT2, 0);
  12065. write_csr(dd, SEND_SC2VLT3, 0);
  12066. write_csr(dd, SEND_LEN_CHECK0, 0);
  12067. write_csr(dd, SEND_LEN_CHECK1, 0);
  12068. /* SEND_ERR_STATUS read-only */
  12069. write_csr(dd, SEND_ERR_MASK, 0);
  12070. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  12071. /* SEND_ERR_FORCE read-only */
  12072. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  12073. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  12074. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  12075. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  12076. for (i = 0; i < chip_send_contexts(dd) / NUM_CONTEXTS_PER_SET; i++)
  12077. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  12078. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  12079. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  12080. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  12081. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  12082. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  12083. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  12084. /* SEND_CM_CREDIT_USED_STATUS read-only */
  12085. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  12086. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  12087. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  12088. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  12089. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  12090. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  12091. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  12092. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  12093. /* SEND_CM_CREDIT_USED_VL read-only */
  12094. /* SEND_CM_CREDIT_USED_VL15 read-only */
  12095. /* SEND_EGRESS_CTXT_STATUS read-only */
  12096. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  12097. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  12098. /* SEND_EGRESS_ERR_INFO read-only */
  12099. /* SEND_EGRESS_ERR_SOURCE read-only */
  12100. /*
  12101. * TXE Per-Context CSRs
  12102. */
  12103. for (i = 0; i < chip_send_contexts(dd); i++) {
  12104. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12105. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  12106. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  12107. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  12108. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  12109. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  12110. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  12111. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  12112. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  12113. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12114. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  12115. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  12116. }
  12117. /*
  12118. * TXE Per-SDMA CSRs
  12119. */
  12120. for (i = 0; i < chip_sdma_engines(dd); i++) {
  12121. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12122. /* SEND_DMA_STATUS read-only */
  12123. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  12124. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  12125. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  12126. /* SEND_DMA_HEAD read-only */
  12127. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  12128. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  12129. /* SEND_DMA_IDLE_CNT read-only */
  12130. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  12131. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  12132. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  12133. /* SEND_DMA_ENG_ERR_STATUS read-only */
  12134. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  12135. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  12136. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  12137. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  12138. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  12139. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  12140. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  12141. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  12142. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  12143. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  12144. }
  12145. }
  12146. /*
  12147. * Expect on entry:
  12148. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  12149. */
  12150. static void init_rbufs(struct hfi1_devdata *dd)
  12151. {
  12152. u64 reg;
  12153. int count;
  12154. /*
  12155. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  12156. * clear.
  12157. */
  12158. count = 0;
  12159. while (1) {
  12160. reg = read_csr(dd, RCV_STATUS);
  12161. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  12162. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  12163. break;
  12164. /*
  12165. * Give up after 1ms - maximum wait time.
  12166. *
  12167. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  12168. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  12169. * 136 KB / (66% * 250MB/s) = 844us
  12170. */
  12171. if (count++ > 500) {
  12172. dd_dev_err(dd,
  12173. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  12174. __func__, reg);
  12175. break;
  12176. }
  12177. udelay(2); /* do not busy-wait the CSR */
  12178. }
  12179. /* start the init - expect RcvCtrl to be 0 */
  12180. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  12181. /*
  12182. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  12183. * period after the write before RcvStatus.RxRbufInitDone is valid.
  12184. * The delay in the first run through the loop below is sufficient and
  12185. * required before the first read of RcvStatus.RxRbufInintDone.
  12186. */
  12187. read_csr(dd, RCV_CTRL);
  12188. /* wait for the init to finish */
  12189. count = 0;
  12190. while (1) {
  12191. /* delay is required first time through - see above */
  12192. udelay(2); /* do not busy-wait the CSR */
  12193. reg = read_csr(dd, RCV_STATUS);
  12194. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  12195. break;
  12196. /* give up after 100us - slowest possible at 33MHz is 73us */
  12197. if (count++ > 50) {
  12198. dd_dev_err(dd,
  12199. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  12200. __func__);
  12201. break;
  12202. }
  12203. }
  12204. }
  12205. /* set RXE CSRs to chip reset defaults */
  12206. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  12207. {
  12208. int i, j;
  12209. /*
  12210. * RXE Kernel CSRs
  12211. */
  12212. write_csr(dd, RCV_CTRL, 0);
  12213. init_rbufs(dd);
  12214. /* RCV_STATUS read-only */
  12215. /* RCV_CONTEXTS read-only */
  12216. /* RCV_ARRAY_CNT read-only */
  12217. /* RCV_BUF_SIZE read-only */
  12218. write_csr(dd, RCV_BTH_QP, 0);
  12219. write_csr(dd, RCV_MULTICAST, 0);
  12220. write_csr(dd, RCV_BYPASS, 0);
  12221. write_csr(dd, RCV_VL15, 0);
  12222. /* this is a clear-down */
  12223. write_csr(dd, RCV_ERR_INFO,
  12224. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  12225. /* RCV_ERR_STATUS read-only */
  12226. write_csr(dd, RCV_ERR_MASK, 0);
  12227. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  12228. /* RCV_ERR_FORCE leave alone */
  12229. for (i = 0; i < 32; i++)
  12230. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  12231. for (i = 0; i < 4; i++)
  12232. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  12233. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  12234. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  12235. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  12236. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  12237. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
  12238. clear_rsm_rule(dd, i);
  12239. for (i = 0; i < 32; i++)
  12240. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  12241. /*
  12242. * RXE Kernel and User Per-Context CSRs
  12243. */
  12244. for (i = 0; i < chip_rcv_contexts(dd); i++) {
  12245. /* kernel */
  12246. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  12247. /* RCV_CTXT_STATUS read-only */
  12248. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  12249. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  12250. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  12251. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  12252. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  12253. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  12254. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  12255. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  12256. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  12257. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  12258. /* user */
  12259. /* RCV_HDR_TAIL read-only */
  12260. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  12261. /* RCV_EGR_INDEX_TAIL read-only */
  12262. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  12263. /* RCV_EGR_OFFSET_TAIL read-only */
  12264. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  12265. write_uctxt_csr(dd, i,
  12266. RCV_TID_FLOW_TABLE + (8 * j), 0);
  12267. }
  12268. }
  12269. }
  12270. /*
  12271. * Set sc2vl tables.
  12272. *
  12273. * They power on to zeros, so to avoid send context errors
  12274. * they need to be set:
  12275. *
  12276. * SC 0-7 -> VL 0-7 (respectively)
  12277. * SC 15 -> VL 15
  12278. * otherwise
  12279. * -> VL 0
  12280. */
  12281. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  12282. {
  12283. int i;
  12284. /* init per architecture spec, constrained by hardware capability */
  12285. /* HFI maps sent packets */
  12286. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  12287. 0,
  12288. 0, 0, 1, 1,
  12289. 2, 2, 3, 3,
  12290. 4, 4, 5, 5,
  12291. 6, 6, 7, 7));
  12292. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  12293. 1,
  12294. 8, 0, 9, 0,
  12295. 10, 0, 11, 0,
  12296. 12, 0, 13, 0,
  12297. 14, 0, 15, 15));
  12298. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  12299. 2,
  12300. 16, 0, 17, 0,
  12301. 18, 0, 19, 0,
  12302. 20, 0, 21, 0,
  12303. 22, 0, 23, 0));
  12304. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  12305. 3,
  12306. 24, 0, 25, 0,
  12307. 26, 0, 27, 0,
  12308. 28, 0, 29, 0,
  12309. 30, 0, 31, 0));
  12310. /* DC maps received packets */
  12311. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  12312. 15_0,
  12313. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  12314. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  12315. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  12316. 31_16,
  12317. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  12318. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  12319. /* initialize the cached sc2vl values consistently with h/w */
  12320. for (i = 0; i < 32; i++) {
  12321. if (i < 8 || i == 15)
  12322. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  12323. else
  12324. *((u8 *)(dd->sc2vl) + i) = 0;
  12325. }
  12326. }
  12327. /*
  12328. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  12329. * depend on the chip going through a power-on reset - a driver may be loaded
  12330. * and unloaded many times.
  12331. *
  12332. * Do not write any CSR values to the chip in this routine - there may be
  12333. * a reset following the (possible) FLR in this routine.
  12334. *
  12335. */
  12336. static int init_chip(struct hfi1_devdata *dd)
  12337. {
  12338. int i;
  12339. int ret = 0;
  12340. /*
  12341. * Put the HFI CSRs in a known state.
  12342. * Combine this with a DC reset.
  12343. *
  12344. * Stop the device from doing anything while we do a
  12345. * reset. We know there are no other active users of
  12346. * the device since we are now in charge. Turn off
  12347. * off all outbound and inbound traffic and make sure
  12348. * the device does not generate any interrupts.
  12349. */
  12350. /* disable send contexts and SDMA engines */
  12351. write_csr(dd, SEND_CTRL, 0);
  12352. for (i = 0; i < chip_send_contexts(dd); i++)
  12353. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12354. for (i = 0; i < chip_sdma_engines(dd); i++)
  12355. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12356. /* disable port (turn off RXE inbound traffic) and contexts */
  12357. write_csr(dd, RCV_CTRL, 0);
  12358. for (i = 0; i < chip_rcv_contexts(dd); i++)
  12359. write_csr(dd, RCV_CTXT_CTRL, 0);
  12360. /* mask all interrupt sources */
  12361. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  12362. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  12363. /*
  12364. * DC Reset: do a full DC reset before the register clear.
  12365. * A recommended length of time to hold is one CSR read,
  12366. * so reread the CceDcCtrl. Then, hold the DC in reset
  12367. * across the clear.
  12368. */
  12369. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  12370. (void)read_csr(dd, CCE_DC_CTRL);
  12371. if (use_flr) {
  12372. /*
  12373. * A FLR will reset the SPC core and part of the PCIe.
  12374. * The parts that need to be restored have already been
  12375. * saved.
  12376. */
  12377. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12378. /* do the FLR, the DC reset will remain */
  12379. pcie_flr(dd->pcidev);
  12380. /* restore command and BARs */
  12381. ret = restore_pci_variables(dd);
  12382. if (ret) {
  12383. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12384. __func__);
  12385. return ret;
  12386. }
  12387. if (is_ax(dd)) {
  12388. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12389. pcie_flr(dd->pcidev);
  12390. ret = restore_pci_variables(dd);
  12391. if (ret) {
  12392. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12393. __func__);
  12394. return ret;
  12395. }
  12396. }
  12397. } else {
  12398. dd_dev_info(dd, "Resetting CSRs with writes\n");
  12399. reset_cce_csrs(dd);
  12400. reset_txe_csrs(dd);
  12401. reset_rxe_csrs(dd);
  12402. reset_misc_csrs(dd);
  12403. }
  12404. /* clear the DC reset */
  12405. write_csr(dd, CCE_DC_CTRL, 0);
  12406. /* Set the LED off */
  12407. setextled(dd, 0);
  12408. /*
  12409. * Clear the QSFP reset.
  12410. * An FLR enforces a 0 on all out pins. The driver does not touch
  12411. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  12412. * anything plugged constantly in reset, if it pays attention
  12413. * to RESET_N.
  12414. * Prime examples of this are optical cables. Set all pins high.
  12415. * I2CCLK and I2CDAT will change per direction, and INT_N and
  12416. * MODPRS_N are input only and their value is ignored.
  12417. */
  12418. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  12419. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  12420. init_chip_resources(dd);
  12421. return ret;
  12422. }
  12423. static void init_early_variables(struct hfi1_devdata *dd)
  12424. {
  12425. int i;
  12426. /* assign link credit variables */
  12427. dd->vau = CM_VAU;
  12428. dd->link_credits = CM_GLOBAL_CREDITS;
  12429. if (is_ax(dd))
  12430. dd->link_credits--;
  12431. dd->vcu = cu_to_vcu(hfi1_cu);
  12432. /* enough room for 8 MAD packets plus header - 17K */
  12433. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12434. if (dd->vl15_init > dd->link_credits)
  12435. dd->vl15_init = dd->link_credits;
  12436. write_uninitialized_csrs_and_memories(dd);
  12437. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12438. for (i = 0; i < dd->num_pports; i++) {
  12439. struct hfi1_pportdata *ppd = &dd->pport[i];
  12440. set_partition_keys(ppd);
  12441. }
  12442. init_sc2vl_tables(dd);
  12443. }
  12444. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12445. {
  12446. /* user changed the KDETH_QP */
  12447. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12448. /* out of range or illegal value */
  12449. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12450. kdeth_qp = 0;
  12451. }
  12452. if (kdeth_qp == 0) /* not set, or failed range check */
  12453. kdeth_qp = DEFAULT_KDETH_QP;
  12454. write_csr(dd, SEND_BTH_QP,
  12455. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12456. SEND_BTH_QP_KDETH_QP_SHIFT);
  12457. write_csr(dd, RCV_BTH_QP,
  12458. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12459. RCV_BTH_QP_KDETH_QP_SHIFT);
  12460. }
  12461. /**
  12462. * init_qpmap_table
  12463. * @dd - device data
  12464. * @first_ctxt - first context
  12465. * @last_ctxt - first context
  12466. *
  12467. * This return sets the qpn mapping table that
  12468. * is indexed by qpn[8:1].
  12469. *
  12470. * The routine will round robin the 256 settings
  12471. * from first_ctxt to last_ctxt.
  12472. *
  12473. * The first/last looks ahead to having specialized
  12474. * receive contexts for mgmt and bypass. Normal
  12475. * verbs traffic will assumed to be on a range
  12476. * of receive contexts.
  12477. */
  12478. static void init_qpmap_table(struct hfi1_devdata *dd,
  12479. u32 first_ctxt,
  12480. u32 last_ctxt)
  12481. {
  12482. u64 reg = 0;
  12483. u64 regno = RCV_QP_MAP_TABLE;
  12484. int i;
  12485. u64 ctxt = first_ctxt;
  12486. for (i = 0; i < 256; i++) {
  12487. reg |= ctxt << (8 * (i % 8));
  12488. ctxt++;
  12489. if (ctxt > last_ctxt)
  12490. ctxt = first_ctxt;
  12491. if (i % 8 == 7) {
  12492. write_csr(dd, regno, reg);
  12493. reg = 0;
  12494. regno += 8;
  12495. }
  12496. }
  12497. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12498. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12499. }
  12500. struct rsm_map_table {
  12501. u64 map[NUM_MAP_REGS];
  12502. unsigned int used;
  12503. };
  12504. struct rsm_rule_data {
  12505. u8 offset;
  12506. u8 pkt_type;
  12507. u32 field1_off;
  12508. u32 field2_off;
  12509. u32 index1_off;
  12510. u32 index1_width;
  12511. u32 index2_off;
  12512. u32 index2_width;
  12513. u32 mask1;
  12514. u32 value1;
  12515. u32 mask2;
  12516. u32 value2;
  12517. };
  12518. /*
  12519. * Return an initialized RMT map table for users to fill in. OK if it
  12520. * returns NULL, indicating no table.
  12521. */
  12522. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12523. {
  12524. struct rsm_map_table *rmt;
  12525. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12526. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12527. if (rmt) {
  12528. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12529. rmt->used = 0;
  12530. }
  12531. return rmt;
  12532. }
  12533. /*
  12534. * Write the final RMT map table to the chip and free the table. OK if
  12535. * table is NULL.
  12536. */
  12537. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12538. struct rsm_map_table *rmt)
  12539. {
  12540. int i;
  12541. if (rmt) {
  12542. /* write table to chip */
  12543. for (i = 0; i < NUM_MAP_REGS; i++)
  12544. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12545. /* enable RSM */
  12546. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12547. }
  12548. }
  12549. /*
  12550. * Add a receive side mapping rule.
  12551. */
  12552. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12553. struct rsm_rule_data *rrd)
  12554. {
  12555. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12556. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12557. 1ull << rule_index | /* enable bit */
  12558. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12559. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12560. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12561. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12562. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12563. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12564. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12565. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12566. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12567. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12568. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12569. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12570. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12571. }
  12572. /*
  12573. * Clear a receive side mapping rule.
  12574. */
  12575. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
  12576. {
  12577. write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
  12578. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
  12579. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
  12580. }
  12581. /* return the number of RSM map table entries that will be used for QOS */
  12582. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12583. unsigned int *np)
  12584. {
  12585. int i;
  12586. unsigned int m, n;
  12587. u8 max_by_vl = 0;
  12588. /* is QOS active at all? */
  12589. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12590. num_vls == 1 ||
  12591. krcvqsset <= 1)
  12592. goto no_qos;
  12593. /* determine bits for qpn */
  12594. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12595. if (krcvqs[i] > max_by_vl)
  12596. max_by_vl = krcvqs[i];
  12597. if (max_by_vl > 32)
  12598. goto no_qos;
  12599. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12600. /* determine bits for vl */
  12601. n = ilog2(__roundup_pow_of_two(num_vls));
  12602. /* reject if too much is used */
  12603. if ((m + n) > 7)
  12604. goto no_qos;
  12605. if (mp)
  12606. *mp = m;
  12607. if (np)
  12608. *np = n;
  12609. return 1 << (m + n);
  12610. no_qos:
  12611. if (mp)
  12612. *mp = 0;
  12613. if (np)
  12614. *np = 0;
  12615. return 0;
  12616. }
  12617. /**
  12618. * init_qos - init RX qos
  12619. * @dd - device data
  12620. * @rmt - RSM map table
  12621. *
  12622. * This routine initializes Rule 0 and the RSM map table to implement
  12623. * quality of service (qos).
  12624. *
  12625. * If all of the limit tests succeed, qos is applied based on the array
  12626. * interpretation of krcvqs where entry 0 is VL0.
  12627. *
  12628. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12629. * feed both the RSM map table and the single rule.
  12630. */
  12631. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12632. {
  12633. struct rsm_rule_data rrd;
  12634. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12635. unsigned int rmt_entries;
  12636. u64 reg;
  12637. if (!rmt)
  12638. goto bail;
  12639. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12640. if (rmt_entries == 0)
  12641. goto bail;
  12642. qpns_per_vl = 1 << m;
  12643. /* enough room in the map table? */
  12644. rmt_entries = 1 << (m + n);
  12645. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12646. goto bail;
  12647. /* add qos entries to the the RSM map table */
  12648. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12649. unsigned tctxt;
  12650. for (qpn = 0, tctxt = ctxt;
  12651. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12652. unsigned idx, regoff, regidx;
  12653. /* generate the index the hardware will produce */
  12654. idx = rmt->used + ((qpn << n) ^ i);
  12655. regoff = (idx % 8) * 8;
  12656. regidx = idx / 8;
  12657. /* replace default with context number */
  12658. reg = rmt->map[regidx];
  12659. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12660. << regoff);
  12661. reg |= (u64)(tctxt++) << regoff;
  12662. rmt->map[regidx] = reg;
  12663. if (tctxt == ctxt + krcvqs[i])
  12664. tctxt = ctxt;
  12665. }
  12666. ctxt += krcvqs[i];
  12667. }
  12668. rrd.offset = rmt->used;
  12669. rrd.pkt_type = 2;
  12670. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12671. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12672. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12673. rrd.index1_width = n;
  12674. rrd.index2_off = QPN_SELECT_OFFSET;
  12675. rrd.index2_width = m + n;
  12676. rrd.mask1 = LRH_BTH_MASK;
  12677. rrd.value1 = LRH_BTH_VALUE;
  12678. rrd.mask2 = LRH_SC_MASK;
  12679. rrd.value2 = LRH_SC_VALUE;
  12680. /* add rule 0 */
  12681. add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
  12682. /* mark RSM map entries as used */
  12683. rmt->used += rmt_entries;
  12684. /* map everything else to the mcast/err/vl15 context */
  12685. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12686. dd->qos_shift = n + 1;
  12687. return;
  12688. bail:
  12689. dd->qos_shift = 1;
  12690. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12691. }
  12692. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12693. struct rsm_map_table *rmt)
  12694. {
  12695. struct rsm_rule_data rrd;
  12696. u64 reg;
  12697. int i, idx, regoff, regidx;
  12698. u8 offset;
  12699. /* there needs to be enough room in the map table */
  12700. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12701. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12702. return;
  12703. }
  12704. /*
  12705. * RSM will extract the destination context as an index into the
  12706. * map table. The destination contexts are a sequential block
  12707. * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
  12708. * Map entries are accessed as offset + extracted value. Adjust
  12709. * the added offset so this sequence can be placed anywhere in
  12710. * the table - as long as the entries themselves do not wrap.
  12711. * There are only enough bits in offset for the table size, so
  12712. * start with that to allow for a "negative" offset.
  12713. */
  12714. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12715. (int)dd->first_dyn_alloc_ctxt);
  12716. for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
  12717. i < dd->num_rcv_contexts; i++, idx++) {
  12718. /* replace with identity mapping */
  12719. regoff = (idx % 8) * 8;
  12720. regidx = idx / 8;
  12721. reg = rmt->map[regidx];
  12722. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12723. reg |= (u64)i << regoff;
  12724. rmt->map[regidx] = reg;
  12725. }
  12726. /*
  12727. * For RSM intercept of Expected FECN packets:
  12728. * o packet type 0 - expected
  12729. * o match on F (bit 95), using select/match 1, and
  12730. * o match on SH (bit 133), using select/match 2.
  12731. *
  12732. * Use index 1 to extract the 8-bit receive context from DestQP
  12733. * (start at bit 64). Use that as the RSM map table index.
  12734. */
  12735. rrd.offset = offset;
  12736. rrd.pkt_type = 0;
  12737. rrd.field1_off = 95;
  12738. rrd.field2_off = 133;
  12739. rrd.index1_off = 64;
  12740. rrd.index1_width = 8;
  12741. rrd.index2_off = 0;
  12742. rrd.index2_width = 0;
  12743. rrd.mask1 = 1;
  12744. rrd.value1 = 1;
  12745. rrd.mask2 = 1;
  12746. rrd.value2 = 1;
  12747. /* add rule 1 */
  12748. add_rsm_rule(dd, RSM_INS_FECN, &rrd);
  12749. rmt->used += dd->num_user_contexts;
  12750. }
  12751. /* Initialize RSM for VNIC */
  12752. void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
  12753. {
  12754. u8 i, j;
  12755. u8 ctx_id = 0;
  12756. u64 reg;
  12757. u32 regoff;
  12758. struct rsm_rule_data rrd;
  12759. if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
  12760. dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
  12761. dd->vnic.rmt_start);
  12762. return;
  12763. }
  12764. dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
  12765. dd->vnic.rmt_start,
  12766. dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
  12767. /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
  12768. regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
  12769. reg = read_csr(dd, regoff);
  12770. for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
  12771. /* Update map register with vnic context */
  12772. j = (dd->vnic.rmt_start + i) % 8;
  12773. reg &= ~(0xffllu << (j * 8));
  12774. reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
  12775. /* Wrap up vnic ctx index */
  12776. ctx_id %= dd->vnic.num_ctxt;
  12777. /* Write back map register */
  12778. if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
  12779. dev_dbg(&(dd)->pcidev->dev,
  12780. "Vnic rsm map reg[%d] =0x%llx\n",
  12781. regoff - RCV_RSM_MAP_TABLE, reg);
  12782. write_csr(dd, regoff, reg);
  12783. regoff += 8;
  12784. if (i < (NUM_VNIC_MAP_ENTRIES - 1))
  12785. reg = read_csr(dd, regoff);
  12786. }
  12787. }
  12788. /* Add rule for vnic */
  12789. rrd.offset = dd->vnic.rmt_start;
  12790. rrd.pkt_type = 4;
  12791. /* Match 16B packets */
  12792. rrd.field1_off = L2_TYPE_MATCH_OFFSET;
  12793. rrd.mask1 = L2_TYPE_MASK;
  12794. rrd.value1 = L2_16B_VALUE;
  12795. /* Match ETH L4 packets */
  12796. rrd.field2_off = L4_TYPE_MATCH_OFFSET;
  12797. rrd.mask2 = L4_16B_TYPE_MASK;
  12798. rrd.value2 = L4_16B_ETH_VALUE;
  12799. /* Calc context from veswid and entropy */
  12800. rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
  12801. rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12802. rrd.index2_off = L2_16B_ENTROPY_OFFSET;
  12803. rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12804. add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
  12805. /* Enable RSM if not already enabled */
  12806. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12807. }
  12808. void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
  12809. {
  12810. clear_rsm_rule(dd, RSM_INS_VNIC);
  12811. /* Disable RSM if used only by vnic */
  12812. if (dd->vnic.rmt_start == 0)
  12813. clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12814. }
  12815. static void init_rxe(struct hfi1_devdata *dd)
  12816. {
  12817. struct rsm_map_table *rmt;
  12818. u64 val;
  12819. /* enable all receive errors */
  12820. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12821. rmt = alloc_rsm_map_table(dd);
  12822. /* set up QOS, including the QPN map table */
  12823. init_qos(dd, rmt);
  12824. init_user_fecn_handling(dd, rmt);
  12825. complete_rsm_map_table(dd, rmt);
  12826. /* record number of used rsm map entries for vnic */
  12827. dd->vnic.rmt_start = rmt->used;
  12828. kfree(rmt);
  12829. /*
  12830. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12831. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12832. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12833. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12834. * Max_PayLoad_Size set to its minimum of 128.
  12835. *
  12836. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12837. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12838. * tune_pcie_caps() which is called after this routine.
  12839. */
  12840. /* Have 16 bytes (4DW) of bypass header available in header queue */
  12841. val = read_csr(dd, RCV_BYPASS);
  12842. val &= ~RCV_BYPASS_HDR_SIZE_SMASK;
  12843. val |= ((4ull & RCV_BYPASS_HDR_SIZE_MASK) <<
  12844. RCV_BYPASS_HDR_SIZE_SHIFT);
  12845. write_csr(dd, RCV_BYPASS, val);
  12846. }
  12847. static void init_other(struct hfi1_devdata *dd)
  12848. {
  12849. /* enable all CCE errors */
  12850. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12851. /* enable *some* Misc errors */
  12852. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12853. /* enable all DC errors, except LCB */
  12854. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12855. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12856. }
  12857. /*
  12858. * Fill out the given AU table using the given CU. A CU is defined in terms
  12859. * AUs. The table is a an encoding: given the index, how many AUs does that
  12860. * represent?
  12861. *
  12862. * NOTE: Assumes that the register layout is the same for the
  12863. * local and remote tables.
  12864. */
  12865. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12866. u32 csr0to3, u32 csr4to7)
  12867. {
  12868. write_csr(dd, csr0to3,
  12869. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12870. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12871. 2ull * cu <<
  12872. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12873. 4ull * cu <<
  12874. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12875. write_csr(dd, csr4to7,
  12876. 8ull * cu <<
  12877. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12878. 16ull * cu <<
  12879. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12880. 32ull * cu <<
  12881. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12882. 64ull * cu <<
  12883. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12884. }
  12885. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12886. {
  12887. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12888. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12889. }
  12890. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12891. {
  12892. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12893. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12894. }
  12895. static void init_txe(struct hfi1_devdata *dd)
  12896. {
  12897. int i;
  12898. /* enable all PIO, SDMA, general, and Egress errors */
  12899. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12900. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12901. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12902. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12903. /* enable all per-context and per-SDMA engine errors */
  12904. for (i = 0; i < chip_send_contexts(dd); i++)
  12905. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12906. for (i = 0; i < chip_sdma_engines(dd); i++)
  12907. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12908. /* set the local CU to AU mapping */
  12909. assign_local_cm_au_table(dd, dd->vcu);
  12910. /*
  12911. * Set reasonable default for Credit Return Timer
  12912. * Don't set on Simulator - causes it to choke.
  12913. */
  12914. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12915. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12916. }
  12917. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12918. u16 jkey)
  12919. {
  12920. u8 hw_ctxt;
  12921. u64 reg;
  12922. if (!rcd || !rcd->sc)
  12923. return -EINVAL;
  12924. hw_ctxt = rcd->sc->hw_context;
  12925. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12926. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12927. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12928. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12929. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12930. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12931. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12932. /*
  12933. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12934. */
  12935. if (!is_ax(dd)) {
  12936. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12937. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12938. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12939. }
  12940. /* Enable J_KEY check on receive context. */
  12941. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12942. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12943. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12944. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
  12945. return 0;
  12946. }
  12947. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
  12948. {
  12949. u8 hw_ctxt;
  12950. u64 reg;
  12951. if (!rcd || !rcd->sc)
  12952. return -EINVAL;
  12953. hw_ctxt = rcd->sc->hw_context;
  12954. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12955. /*
  12956. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12957. * This check would not have been enabled for A0 h/w, see
  12958. * set_ctxt_jkey().
  12959. */
  12960. if (!is_ax(dd)) {
  12961. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12962. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12963. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12964. }
  12965. /* Turn off the J_KEY on the receive side */
  12966. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
  12967. return 0;
  12968. }
  12969. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12970. u16 pkey)
  12971. {
  12972. u8 hw_ctxt;
  12973. u64 reg;
  12974. if (!rcd || !rcd->sc)
  12975. return -EINVAL;
  12976. hw_ctxt = rcd->sc->hw_context;
  12977. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  12978. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  12979. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  12980. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12981. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12982. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  12983. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12984. return 0;
  12985. }
  12986. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
  12987. {
  12988. u8 hw_ctxt;
  12989. u64 reg;
  12990. if (!ctxt || !ctxt->sc)
  12991. return -EINVAL;
  12992. hw_ctxt = ctxt->sc->hw_context;
  12993. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12994. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12995. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12996. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12997. return 0;
  12998. }
  12999. /*
  13000. * Start doing the clean up the the chip. Our clean up happens in multiple
  13001. * stages and this is just the first.
  13002. */
  13003. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  13004. {
  13005. aspm_exit(dd);
  13006. free_cntrs(dd);
  13007. free_rcverr(dd);
  13008. finish_chip_resources(dd);
  13009. }
  13010. #define HFI_BASE_GUID(dev) \
  13011. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  13012. /*
  13013. * Information can be shared between the two HFIs on the same ASIC
  13014. * in the same OS. This function finds the peer device and sets
  13015. * up a shared structure.
  13016. */
  13017. static int init_asic_data(struct hfi1_devdata *dd)
  13018. {
  13019. unsigned long flags;
  13020. struct hfi1_devdata *tmp, *peer = NULL;
  13021. struct hfi1_asic_data *asic_data;
  13022. int ret = 0;
  13023. /* pre-allocate the asic structure in case we are the first device */
  13024. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  13025. if (!asic_data)
  13026. return -ENOMEM;
  13027. spin_lock_irqsave(&hfi1_devs_lock, flags);
  13028. /* Find our peer device */
  13029. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  13030. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  13031. dd->unit != tmp->unit) {
  13032. peer = tmp;
  13033. break;
  13034. }
  13035. }
  13036. if (peer) {
  13037. /* use already allocated structure */
  13038. dd->asic_data = peer->asic_data;
  13039. kfree(asic_data);
  13040. } else {
  13041. dd->asic_data = asic_data;
  13042. mutex_init(&dd->asic_data->asic_resource_mutex);
  13043. }
  13044. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  13045. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  13046. /* first one through - set up i2c devices */
  13047. if (!peer)
  13048. ret = set_up_i2c(dd, dd->asic_data);
  13049. return ret;
  13050. }
  13051. /*
  13052. * Set dd->boardname. Use a generic name if a name is not returned from
  13053. * EFI variable space.
  13054. *
  13055. * Return 0 on success, -ENOMEM if space could not be allocated.
  13056. */
  13057. static int obtain_boardname(struct hfi1_devdata *dd)
  13058. {
  13059. /* generic board description */
  13060. const char generic[] =
  13061. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  13062. unsigned long size;
  13063. int ret;
  13064. ret = read_hfi1_efi_var(dd, "description", &size,
  13065. (void **)&dd->boardname);
  13066. if (ret) {
  13067. dd_dev_info(dd, "Board description not found\n");
  13068. /* use generic description */
  13069. dd->boardname = kstrdup(generic, GFP_KERNEL);
  13070. if (!dd->boardname)
  13071. return -ENOMEM;
  13072. }
  13073. return 0;
  13074. }
  13075. /*
  13076. * Check the interrupt registers to make sure that they are mapped correctly.
  13077. * It is intended to help user identify any mismapping by VMM when the driver
  13078. * is running in a VM. This function should only be called before interrupt
  13079. * is set up properly.
  13080. *
  13081. * Return 0 on success, -EINVAL on failure.
  13082. */
  13083. static int check_int_registers(struct hfi1_devdata *dd)
  13084. {
  13085. u64 reg;
  13086. u64 all_bits = ~(u64)0;
  13087. u64 mask;
  13088. /* Clear CceIntMask[0] to avoid raising any interrupts */
  13089. mask = read_csr(dd, CCE_INT_MASK);
  13090. write_csr(dd, CCE_INT_MASK, 0ull);
  13091. reg = read_csr(dd, CCE_INT_MASK);
  13092. if (reg)
  13093. goto err_exit;
  13094. /* Clear all interrupt status bits */
  13095. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13096. reg = read_csr(dd, CCE_INT_STATUS);
  13097. if (reg)
  13098. goto err_exit;
  13099. /* Set all interrupt status bits */
  13100. write_csr(dd, CCE_INT_FORCE, all_bits);
  13101. reg = read_csr(dd, CCE_INT_STATUS);
  13102. if (reg != all_bits)
  13103. goto err_exit;
  13104. /* Restore the interrupt mask */
  13105. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13106. write_csr(dd, CCE_INT_MASK, mask);
  13107. return 0;
  13108. err_exit:
  13109. write_csr(dd, CCE_INT_MASK, mask);
  13110. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  13111. return -EINVAL;
  13112. }
  13113. /**
  13114. * Allocate and initialize the device structure for the hfi.
  13115. * @dev: the pci_dev for hfi1_ib device
  13116. * @ent: pci_device_id struct for this dev
  13117. *
  13118. * Also allocates, initializes, and returns the devdata struct for this
  13119. * device instance
  13120. *
  13121. * This is global, and is called directly at init to set up the
  13122. * chip-specific function pointers for later use.
  13123. */
  13124. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  13125. const struct pci_device_id *ent)
  13126. {
  13127. struct hfi1_devdata *dd;
  13128. struct hfi1_pportdata *ppd;
  13129. u64 reg;
  13130. int i, ret;
  13131. static const char * const inames[] = { /* implementation names */
  13132. "RTL silicon",
  13133. "RTL VCS simulation",
  13134. "RTL FPGA emulation",
  13135. "Functional simulator"
  13136. };
  13137. struct pci_dev *parent = pdev->bus->self;
  13138. u32 sdma_engines;
  13139. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  13140. sizeof(struct hfi1_pportdata));
  13141. if (IS_ERR(dd))
  13142. goto bail;
  13143. sdma_engines = chip_sdma_engines(dd);
  13144. ppd = dd->pport;
  13145. for (i = 0; i < dd->num_pports; i++, ppd++) {
  13146. int vl;
  13147. /* init common fields */
  13148. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  13149. /* DC supports 4 link widths */
  13150. ppd->link_width_supported =
  13151. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  13152. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  13153. ppd->link_width_downgrade_supported =
  13154. ppd->link_width_supported;
  13155. /* start out enabling only 4X */
  13156. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  13157. ppd->link_width_downgrade_enabled =
  13158. ppd->link_width_downgrade_supported;
  13159. /* link width active is 0 when link is down */
  13160. /* link width downgrade active is 0 when link is down */
  13161. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  13162. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  13163. dd_dev_err(dd, "Invalid num_vls %u, using %u VLs\n",
  13164. num_vls, HFI1_MAX_VLS_SUPPORTED);
  13165. num_vls = HFI1_MAX_VLS_SUPPORTED;
  13166. }
  13167. ppd->vls_supported = num_vls;
  13168. ppd->vls_operational = ppd->vls_supported;
  13169. /* Set the default MTU. */
  13170. for (vl = 0; vl < num_vls; vl++)
  13171. dd->vld[vl].mtu = hfi1_max_mtu;
  13172. dd->vld[15].mtu = MAX_MAD_PACKET;
  13173. /*
  13174. * Set the initial values to reasonable default, will be set
  13175. * for real when link is up.
  13176. */
  13177. ppd->overrun_threshold = 0x4;
  13178. ppd->phy_error_threshold = 0xf;
  13179. ppd->port_crc_mode_enabled = link_crc_mask;
  13180. /* initialize supported LTP CRC mode */
  13181. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  13182. /* initialize enabled LTP CRC mode */
  13183. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  13184. /* start in offline */
  13185. ppd->host_link_state = HLS_DN_OFFLINE;
  13186. init_vl_arb_caches(ppd);
  13187. }
  13188. /*
  13189. * Do remaining PCIe setup and save PCIe values in dd.
  13190. * Any error printing is already done by the init code.
  13191. * On return, we have the chip mapped.
  13192. */
  13193. ret = hfi1_pcie_ddinit(dd, pdev);
  13194. if (ret < 0)
  13195. goto bail_free;
  13196. /* Save PCI space registers to rewrite after device reset */
  13197. ret = save_pci_variables(dd);
  13198. if (ret < 0)
  13199. goto bail_cleanup;
  13200. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  13201. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  13202. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  13203. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  13204. /*
  13205. * Check interrupt registers mapping if the driver has no access to
  13206. * the upstream component. In this case, it is likely that the driver
  13207. * is running in a VM.
  13208. */
  13209. if (!parent) {
  13210. ret = check_int_registers(dd);
  13211. if (ret)
  13212. goto bail_cleanup;
  13213. }
  13214. /*
  13215. * obtain the hardware ID - NOT related to unit, which is a
  13216. * software enumeration
  13217. */
  13218. reg = read_csr(dd, CCE_REVISION2);
  13219. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  13220. & CCE_REVISION2_HFI_ID_MASK;
  13221. /* the variable size will remove unwanted bits */
  13222. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  13223. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  13224. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  13225. dd->icode < ARRAY_SIZE(inames) ?
  13226. inames[dd->icode] : "unknown", (int)dd->irev);
  13227. /* speeds the hardware can support */
  13228. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  13229. /* speeds allowed to run at */
  13230. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  13231. /* give a reasonable active value, will be set on link up */
  13232. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  13233. /* fix up link widths for emulation _p */
  13234. ppd = dd->pport;
  13235. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  13236. ppd->link_width_supported =
  13237. ppd->link_width_enabled =
  13238. ppd->link_width_downgrade_supported =
  13239. ppd->link_width_downgrade_enabled =
  13240. OPA_LINK_WIDTH_1X;
  13241. }
  13242. /* insure num_vls isn't larger than number of sdma engines */
  13243. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > sdma_engines) {
  13244. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  13245. num_vls, sdma_engines);
  13246. num_vls = sdma_engines;
  13247. ppd->vls_supported = sdma_engines;
  13248. ppd->vls_operational = ppd->vls_supported;
  13249. }
  13250. /*
  13251. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  13252. * Limit the max if larger than the field holds. If timeout is
  13253. * non-zero, then the calculated field will be at least 1.
  13254. *
  13255. * Must be after icode is set up - the cclock rate depends
  13256. * on knowing the hardware being used.
  13257. */
  13258. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  13259. if (dd->rcv_intr_timeout_csr >
  13260. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  13261. dd->rcv_intr_timeout_csr =
  13262. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  13263. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  13264. dd->rcv_intr_timeout_csr = 1;
  13265. /* needs to be done before we look for the peer device */
  13266. read_guid(dd);
  13267. /* set up shared ASIC data with peer device */
  13268. ret = init_asic_data(dd);
  13269. if (ret)
  13270. goto bail_cleanup;
  13271. /* obtain chip sizes, reset chip CSRs */
  13272. ret = init_chip(dd);
  13273. if (ret)
  13274. goto bail_cleanup;
  13275. /* read in the PCIe link speed information */
  13276. ret = pcie_speeds(dd);
  13277. if (ret)
  13278. goto bail_cleanup;
  13279. /* call before get_platform_config(), after init_chip_resources() */
  13280. ret = eprom_init(dd);
  13281. if (ret)
  13282. goto bail_free_rcverr;
  13283. /* Needs to be called before hfi1_firmware_init */
  13284. get_platform_config(dd);
  13285. /* read in firmware */
  13286. ret = hfi1_firmware_init(dd);
  13287. if (ret)
  13288. goto bail_cleanup;
  13289. /*
  13290. * In general, the PCIe Gen3 transition must occur after the
  13291. * chip has been idled (so it won't initiate any PCIe transactions
  13292. * e.g. an interrupt) and before the driver changes any registers
  13293. * (the transition will reset the registers).
  13294. *
  13295. * In particular, place this call after:
  13296. * - init_chip() - the chip will not initiate any PCIe transactions
  13297. * - pcie_speeds() - reads the current link speed
  13298. * - hfi1_firmware_init() - the needed firmware is ready to be
  13299. * downloaded
  13300. */
  13301. ret = do_pcie_gen3_transition(dd);
  13302. if (ret)
  13303. goto bail_cleanup;
  13304. /* start setting dd values and adjusting CSRs */
  13305. init_early_variables(dd);
  13306. parse_platform_config(dd);
  13307. ret = obtain_boardname(dd);
  13308. if (ret)
  13309. goto bail_cleanup;
  13310. snprintf(dd->boardversion, BOARD_VERS_MAX,
  13311. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  13312. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  13313. (u32)dd->majrev,
  13314. (u32)dd->minrev,
  13315. (dd->revision >> CCE_REVISION_SW_SHIFT)
  13316. & CCE_REVISION_SW_MASK);
  13317. ret = set_up_context_variables(dd);
  13318. if (ret)
  13319. goto bail_cleanup;
  13320. /* set initial RXE CSRs */
  13321. init_rxe(dd);
  13322. /* set initial TXE CSRs */
  13323. init_txe(dd);
  13324. /* set initial non-RXE, non-TXE CSRs */
  13325. init_other(dd);
  13326. /* set up KDETH QP prefix in both RX and TX CSRs */
  13327. init_kdeth_qp(dd);
  13328. ret = hfi1_dev_affinity_init(dd);
  13329. if (ret)
  13330. goto bail_cleanup;
  13331. /* send contexts must be set up before receive contexts */
  13332. ret = init_send_contexts(dd);
  13333. if (ret)
  13334. goto bail_cleanup;
  13335. ret = hfi1_create_kctxts(dd);
  13336. if (ret)
  13337. goto bail_cleanup;
  13338. /*
  13339. * Initialize aspm, to be done after gen3 transition and setting up
  13340. * contexts and before enabling interrupts
  13341. */
  13342. aspm_init(dd);
  13343. ret = init_pervl_scs(dd);
  13344. if (ret)
  13345. goto bail_cleanup;
  13346. /* sdma init */
  13347. for (i = 0; i < dd->num_pports; ++i) {
  13348. ret = sdma_init(dd, i);
  13349. if (ret)
  13350. goto bail_cleanup;
  13351. }
  13352. /* use contexts created by hfi1_create_kctxts */
  13353. ret = set_up_interrupts(dd);
  13354. if (ret)
  13355. goto bail_cleanup;
  13356. ret = hfi1_comp_vectors_set_up(dd);
  13357. if (ret)
  13358. goto bail_clear_intr;
  13359. /* set up LCB access - must be after set_up_interrupts() */
  13360. init_lcb_access(dd);
  13361. /*
  13362. * Serial number is created from the base guid:
  13363. * [27:24] = base guid [38:35]
  13364. * [23: 0] = base guid [23: 0]
  13365. */
  13366. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  13367. (dd->base_guid & 0xFFFFFF) |
  13368. ((dd->base_guid >> 11) & 0xF000000));
  13369. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  13370. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  13371. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  13372. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  13373. if (ret)
  13374. goto bail_clear_intr;
  13375. thermal_init(dd);
  13376. ret = init_cntrs(dd);
  13377. if (ret)
  13378. goto bail_clear_intr;
  13379. ret = init_rcverr(dd);
  13380. if (ret)
  13381. goto bail_free_cntrs;
  13382. init_completion(&dd->user_comp);
  13383. /* The user refcount starts with one to inidicate an active device */
  13384. atomic_set(&dd->user_refcount, 1);
  13385. goto bail;
  13386. bail_free_rcverr:
  13387. free_rcverr(dd);
  13388. bail_free_cntrs:
  13389. free_cntrs(dd);
  13390. bail_clear_intr:
  13391. hfi1_comp_vectors_clean_up(dd);
  13392. hfi1_clean_up_interrupts(dd);
  13393. bail_cleanup:
  13394. hfi1_pcie_ddcleanup(dd);
  13395. bail_free:
  13396. hfi1_free_devdata(dd);
  13397. dd = ERR_PTR(ret);
  13398. bail:
  13399. return dd;
  13400. }
  13401. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  13402. u32 dw_len)
  13403. {
  13404. u32 delta_cycles;
  13405. u32 current_egress_rate = ppd->current_egress_rate;
  13406. /* rates here are in units of 10^6 bits/sec */
  13407. if (desired_egress_rate == -1)
  13408. return 0; /* shouldn't happen */
  13409. if (desired_egress_rate >= current_egress_rate)
  13410. return 0; /* we can't help go faster, only slower */
  13411. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  13412. egress_cycles(dw_len * 4, current_egress_rate);
  13413. return (u16)delta_cycles;
  13414. }
  13415. /**
  13416. * create_pbc - build a pbc for transmission
  13417. * @flags: special case flags or-ed in built pbc
  13418. * @srate: static rate
  13419. * @vl: vl
  13420. * @dwlen: dword length (header words + data words + pbc words)
  13421. *
  13422. * Create a PBC with the given flags, rate, VL, and length.
  13423. *
  13424. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  13425. * for verbs, which does not use this PSM feature. The lone other caller
  13426. * is for the diagnostic interface which calls this if the user does not
  13427. * supply their own PBC.
  13428. */
  13429. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  13430. u32 dw_len)
  13431. {
  13432. u64 pbc, delay = 0;
  13433. if (unlikely(srate_mbs))
  13434. delay = delay_cycles(ppd, srate_mbs, dw_len);
  13435. pbc = flags
  13436. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  13437. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  13438. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  13439. | (dw_len & PBC_LENGTH_DWS_MASK)
  13440. << PBC_LENGTH_DWS_SHIFT;
  13441. return pbc;
  13442. }
  13443. #define SBUS_THERMAL 0x4f
  13444. #define SBUS_THERM_MONITOR_MODE 0x1
  13445. #define THERM_FAILURE(dev, ret, reason) \
  13446. dd_dev_err((dd), \
  13447. "Thermal sensor initialization failed: %s (%d)\n", \
  13448. (reason), (ret))
  13449. /*
  13450. * Initialize the thermal sensor.
  13451. *
  13452. * After initialization, enable polling of thermal sensor through
  13453. * SBus interface. In order for this to work, the SBus Master
  13454. * firmware has to be loaded due to the fact that the HW polling
  13455. * logic uses SBus interrupts, which are not supported with
  13456. * default firmware. Otherwise, no data will be returned through
  13457. * the ASIC_STS_THERM CSR.
  13458. */
  13459. static int thermal_init(struct hfi1_devdata *dd)
  13460. {
  13461. int ret = 0;
  13462. if (dd->icode != ICODE_RTL_SILICON ||
  13463. check_chip_resource(dd, CR_THERM_INIT, NULL))
  13464. return ret;
  13465. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  13466. if (ret) {
  13467. THERM_FAILURE(dd, ret, "Acquire SBus");
  13468. return ret;
  13469. }
  13470. dd_dev_info(dd, "Initializing thermal sensor\n");
  13471. /* Disable polling of thermal readings */
  13472. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13473. msleep(100);
  13474. /* Thermal Sensor Initialization */
  13475. /* Step 1: Reset the Thermal SBus Receiver */
  13476. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13477. RESET_SBUS_RECEIVER, 0);
  13478. if (ret) {
  13479. THERM_FAILURE(dd, ret, "Bus Reset");
  13480. goto done;
  13481. }
  13482. /* Step 2: Set Reset bit in Thermal block */
  13483. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13484. WRITE_SBUS_RECEIVER, 0x1);
  13485. if (ret) {
  13486. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13487. goto done;
  13488. }
  13489. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13490. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13491. WRITE_SBUS_RECEIVER, 0x32);
  13492. if (ret) {
  13493. THERM_FAILURE(dd, ret, "Write Clock Div");
  13494. goto done;
  13495. }
  13496. /* Step 4: Select temperature mode */
  13497. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13498. WRITE_SBUS_RECEIVER,
  13499. SBUS_THERM_MONITOR_MODE);
  13500. if (ret) {
  13501. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13502. goto done;
  13503. }
  13504. /* Step 5: De-assert block reset and start conversion */
  13505. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13506. WRITE_SBUS_RECEIVER, 0x2);
  13507. if (ret) {
  13508. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13509. goto done;
  13510. }
  13511. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13512. msleep(22);
  13513. /* Enable polling of thermal readings */
  13514. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13515. /* Set initialized flag */
  13516. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13517. if (ret)
  13518. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13519. done:
  13520. release_chip_resource(dd, CR_SBUS);
  13521. return ret;
  13522. }
  13523. static void handle_temp_err(struct hfi1_devdata *dd)
  13524. {
  13525. struct hfi1_pportdata *ppd = &dd->pport[0];
  13526. /*
  13527. * Thermal Critical Interrupt
  13528. * Put the device into forced freeze mode, take link down to
  13529. * offline, and put DC into reset.
  13530. */
  13531. dd_dev_emerg(dd,
  13532. "Critical temperature reached! Forcing device into freeze mode!\n");
  13533. dd->flags |= HFI1_FORCED_FREEZE;
  13534. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13535. /*
  13536. * Shut DC down as much and as quickly as possible.
  13537. *
  13538. * Step 1: Take the link down to OFFLINE. This will cause the
  13539. * 8051 to put the Serdes in reset. However, we don't want to
  13540. * go through the entire link state machine since we want to
  13541. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13542. * but rather an attempt to save the chip.
  13543. * Code below is almost the same as quiet_serdes() but avoids
  13544. * all the extra work and the sleeps.
  13545. */
  13546. ppd->driver_link_ready = 0;
  13547. ppd->link_enabled = 0;
  13548. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13549. PLS_OFFLINE);
  13550. /*
  13551. * Step 2: Shutdown LCB and 8051
  13552. * After shutdown, do not restore DC_CFG_RESET value.
  13553. */
  13554. dc_shutdown(dd);
  13555. }