chip.c 449 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407
  1. /*
  2. * Copyright(c) 2015 - 2017 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. #define NUM_IB_PORTS 1
  66. uint kdeth_qp;
  67. module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
  68. MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
  69. uint num_vls = HFI1_MAX_VLS_SUPPORTED;
  70. module_param(num_vls, uint, S_IRUGO);
  71. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  72. /*
  73. * Default time to aggregate two 10K packets from the idle state
  74. * (timer not running). The timer starts at the end of the first packet,
  75. * so only the time for one 10K packet and header plus a bit extra is needed.
  76. * 10 * 1024 + 64 header byte = 10304 byte
  77. * 10304 byte / 12.5 GB/s = 824.32ns
  78. */
  79. uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
  80. module_param(rcv_intr_timeout, uint, S_IRUGO);
  81. MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
  82. uint rcv_intr_count = 16; /* same as qib */
  83. module_param(rcv_intr_count, uint, S_IRUGO);
  84. MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
  85. ushort link_crc_mask = SUPPORTED_CRCS;
  86. module_param(link_crc_mask, ushort, S_IRUGO);
  87. MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
  88. uint loopback;
  89. module_param_named(loopback, loopback, uint, S_IRUGO);
  90. MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
  91. /* Other driver tunables */
  92. uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
  93. static ushort crc_14b_sideband = 1;
  94. static uint use_flr = 1;
  95. uint quick_linkup; /* skip LNI */
  96. struct flag_table {
  97. u64 flag; /* the flag */
  98. char *str; /* description string */
  99. u16 extra; /* extra information */
  100. u16 unused0;
  101. u32 unused1;
  102. };
  103. /* str must be a string constant */
  104. #define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
  105. #define FLAG_ENTRY0(str, flag) {flag, str, 0}
  106. /* Send Error Consequences */
  107. #define SEC_WRITE_DROPPED 0x1
  108. #define SEC_PACKET_DROPPED 0x2
  109. #define SEC_SC_HALTED 0x4 /* per-context only */
  110. #define SEC_SPC_FREEZE 0x8 /* per-HFI only */
  111. #define DEFAULT_KRCVQS 2
  112. #define MIN_KERNEL_KCTXTS 2
  113. #define FIRST_KERNEL_KCTXT 1
  114. /*
  115. * RSM instance allocation
  116. * 0 - Verbs
  117. * 1 - User Fecn Handling
  118. * 2 - Vnic
  119. */
  120. #define RSM_INS_VERBS 0
  121. #define RSM_INS_FECN 1
  122. #define RSM_INS_VNIC 2
  123. /* Bit offset into the GUID which carries HFI id information */
  124. #define GUID_HFI_INDEX_SHIFT 39
  125. /* extract the emulation revision */
  126. #define emulator_rev(dd) ((dd)->irev >> 8)
  127. /* parallel and serial emulation versions are 3 and 4 respectively */
  128. #define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
  129. #define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
  130. /* RSM fields for Verbs */
  131. /* packet type */
  132. #define IB_PACKET_TYPE 2ull
  133. #define QW_SHIFT 6ull
  134. /* QPN[7..1] */
  135. #define QPN_WIDTH 7ull
  136. /* LRH.BTH: QW 0, OFFSET 48 - for match */
  137. #define LRH_BTH_QW 0ull
  138. #define LRH_BTH_BIT_OFFSET 48ull
  139. #define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
  140. #define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
  141. #define LRH_BTH_SELECT
  142. #define LRH_BTH_MASK 3ull
  143. #define LRH_BTH_VALUE 2ull
  144. /* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
  145. #define LRH_SC_QW 0ull
  146. #define LRH_SC_BIT_OFFSET 56ull
  147. #define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
  148. #define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
  149. #define LRH_SC_MASK 128ull
  150. #define LRH_SC_VALUE 0ull
  151. /* SC[n..0] QW 0, OFFSET 60 - for select */
  152. #define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
  153. /* QPN[m+n:1] QW 1, OFFSET 1 */
  154. #define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
  155. /* RSM fields for Vnic */
  156. /* L2_TYPE: QW 0, OFFSET 61 - for match */
  157. #define L2_TYPE_QW 0ull
  158. #define L2_TYPE_BIT_OFFSET 61ull
  159. #define L2_TYPE_OFFSET(off) ((L2_TYPE_QW << QW_SHIFT) | (off))
  160. #define L2_TYPE_MATCH_OFFSET L2_TYPE_OFFSET(L2_TYPE_BIT_OFFSET)
  161. #define L2_TYPE_MASK 3ull
  162. #define L2_16B_VALUE 2ull
  163. /* L4_TYPE QW 1, OFFSET 0 - for match */
  164. #define L4_TYPE_QW 1ull
  165. #define L4_TYPE_BIT_OFFSET 0ull
  166. #define L4_TYPE_OFFSET(off) ((L4_TYPE_QW << QW_SHIFT) | (off))
  167. #define L4_TYPE_MATCH_OFFSET L4_TYPE_OFFSET(L4_TYPE_BIT_OFFSET)
  168. #define L4_16B_TYPE_MASK 0xFFull
  169. #define L4_16B_ETH_VALUE 0x78ull
  170. /* 16B VESWID - for select */
  171. #define L4_16B_HDR_VESWID_OFFSET ((2 << QW_SHIFT) | (16ull))
  172. /* 16B ENTROPY - for select */
  173. #define L2_16B_ENTROPY_OFFSET ((1 << QW_SHIFT) | (32ull))
  174. /* defines to build power on SC2VL table */
  175. #define SC2VL_VAL( \
  176. num, \
  177. sc0, sc0val, \
  178. sc1, sc1val, \
  179. sc2, sc2val, \
  180. sc3, sc3val, \
  181. sc4, sc4val, \
  182. sc5, sc5val, \
  183. sc6, sc6val, \
  184. sc7, sc7val) \
  185. ( \
  186. ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
  187. ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
  188. ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
  189. ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
  190. ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
  191. ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
  192. ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
  193. ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
  194. )
  195. #define DC_SC_VL_VAL( \
  196. range, \
  197. e0, e0val, \
  198. e1, e1val, \
  199. e2, e2val, \
  200. e3, e3val, \
  201. e4, e4val, \
  202. e5, e5val, \
  203. e6, e6val, \
  204. e7, e7val, \
  205. e8, e8val, \
  206. e9, e9val, \
  207. e10, e10val, \
  208. e11, e11val, \
  209. e12, e12val, \
  210. e13, e13val, \
  211. e14, e14val, \
  212. e15, e15val) \
  213. ( \
  214. ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
  215. ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
  216. ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
  217. ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
  218. ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
  219. ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
  220. ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
  221. ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
  222. ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
  223. ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
  224. ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
  225. ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
  226. ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
  227. ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
  228. ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
  229. ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
  230. )
  231. /* all CceStatus sub-block freeze bits */
  232. #define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
  233. | CCE_STATUS_RXE_FROZE_SMASK \
  234. | CCE_STATUS_TXE_FROZE_SMASK \
  235. | CCE_STATUS_TXE_PIO_FROZE_SMASK)
  236. /* all CceStatus sub-block TXE pause bits */
  237. #define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
  238. | CCE_STATUS_TXE_PAUSED_SMASK \
  239. | CCE_STATUS_SDMA_PAUSED_SMASK)
  240. /* all CceStatus sub-block RXE pause bits */
  241. #define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
  242. #define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
  243. #define CNTR_32BIT_MAX 0x00000000FFFFFFFF
  244. /*
  245. * CCE Error flags.
  246. */
  247. static struct flag_table cce_err_status_flags[] = {
  248. /* 0*/ FLAG_ENTRY0("CceCsrParityErr",
  249. CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
  250. /* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
  251. CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
  252. /* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
  253. CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
  254. /* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
  255. CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
  256. /* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
  257. CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
  258. /* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
  259. CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
  260. /* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
  261. CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
  262. /* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
  263. CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
  264. /* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
  265. CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
  266. /* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  267. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
  268. /*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  269. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
  270. /*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
  271. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
  272. /*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
  273. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
  274. /*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  275. CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
  276. /*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  277. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
  278. /*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  279. CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
  280. /*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  281. CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
  282. /*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  283. CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
  284. /*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
  285. CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
  286. /*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
  287. CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
  288. /*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
  289. CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
  290. /*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
  291. CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
  292. /*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
  293. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
  294. /*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
  295. CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
  296. /*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
  297. CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
  298. /*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
  299. CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
  300. /*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
  301. CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
  302. /*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
  303. CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
  304. /*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
  305. CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
  306. /*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
  307. CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
  308. /*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
  309. CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
  310. /*31*/ FLAG_ENTRY0("LATriggered",
  311. CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
  312. /*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
  313. CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
  314. /*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
  315. CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
  316. /*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
  317. CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
  318. /*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
  319. CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
  320. /*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
  321. CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
  322. /*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
  323. CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
  324. /*38*/ FLAG_ENTRY0("CceIntMapCorErr",
  325. CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
  326. /*39*/ FLAG_ENTRY0("CceIntMapUncErr",
  327. CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
  328. /*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
  329. CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
  330. /*41-63 reserved*/
  331. };
  332. /*
  333. * Misc Error flags
  334. */
  335. #define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
  336. static struct flag_table misc_err_status_flags[] = {
  337. /* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
  338. /* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
  339. /* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
  340. /* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
  341. /* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
  342. /* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
  343. /* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
  344. /* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
  345. /* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
  346. /* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
  347. /*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
  348. /*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
  349. /*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
  350. };
  351. /*
  352. * TXE PIO Error flags and consequences
  353. */
  354. static struct flag_table pio_err_status_flags[] = {
  355. /* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
  356. SEC_WRITE_DROPPED,
  357. SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
  358. /* 1*/ FLAG_ENTRY("PioWriteAddrParity",
  359. SEC_SPC_FREEZE,
  360. SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
  361. /* 2*/ FLAG_ENTRY("PioCsrParity",
  362. SEC_SPC_FREEZE,
  363. SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
  364. /* 3*/ FLAG_ENTRY("PioSbMemFifo0",
  365. SEC_SPC_FREEZE,
  366. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
  367. /* 4*/ FLAG_ENTRY("PioSbMemFifo1",
  368. SEC_SPC_FREEZE,
  369. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
  370. /* 5*/ FLAG_ENTRY("PioPccFifoParity",
  371. SEC_SPC_FREEZE,
  372. SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
  373. /* 6*/ FLAG_ENTRY("PioPecFifoParity",
  374. SEC_SPC_FREEZE,
  375. SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
  376. /* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
  377. SEC_SPC_FREEZE,
  378. SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
  379. /* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
  380. SEC_SPC_FREEZE,
  381. SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
  382. /* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
  383. SEC_SPC_FREEZE,
  384. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
  385. /*10*/ FLAG_ENTRY("PioSmPktResetParity",
  386. SEC_SPC_FREEZE,
  387. SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
  388. /*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
  389. SEC_SPC_FREEZE,
  390. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
  391. /*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
  392. SEC_SPC_FREEZE,
  393. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
  394. /*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
  395. 0,
  396. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
  397. /*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
  398. 0,
  399. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
  400. /*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
  401. SEC_SPC_FREEZE,
  402. SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
  403. /*16*/ FLAG_ENTRY("PioPpmcPblFifo",
  404. SEC_SPC_FREEZE,
  405. SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
  406. /*17*/ FLAG_ENTRY("PioInitSmIn",
  407. 0,
  408. SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
  409. /*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
  410. SEC_SPC_FREEZE,
  411. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
  412. /*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
  413. SEC_SPC_FREEZE,
  414. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
  415. /*20*/ FLAG_ENTRY("PioHostAddrMemCor",
  416. 0,
  417. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
  418. /*21*/ FLAG_ENTRY("PioWriteDataParity",
  419. SEC_SPC_FREEZE,
  420. SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
  421. /*22*/ FLAG_ENTRY("PioStateMachine",
  422. SEC_SPC_FREEZE,
  423. SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
  424. /*23*/ FLAG_ENTRY("PioWriteQwValidParity",
  425. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  426. SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
  427. /*24*/ FLAG_ENTRY("PioBlockQwCountParity",
  428. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  429. SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
  430. /*25*/ FLAG_ENTRY("PioVlfVlLenParity",
  431. SEC_SPC_FREEZE,
  432. SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
  433. /*26*/ FLAG_ENTRY("PioVlfSopParity",
  434. SEC_SPC_FREEZE,
  435. SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
  436. /*27*/ FLAG_ENTRY("PioVlFifoParity",
  437. SEC_SPC_FREEZE,
  438. SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
  439. /*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
  440. SEC_SPC_FREEZE,
  441. SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
  442. /*29*/ FLAG_ENTRY("PioPpmcSopLen",
  443. SEC_SPC_FREEZE,
  444. SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
  445. /*30-31 reserved*/
  446. /*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
  447. SEC_SPC_FREEZE,
  448. SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
  449. /*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
  450. SEC_SPC_FREEZE,
  451. SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
  452. /*34*/ FLAG_ENTRY("PioPccSopHeadParity",
  453. SEC_SPC_FREEZE,
  454. SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
  455. /*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
  456. SEC_SPC_FREEZE,
  457. SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
  458. /*36-63 reserved*/
  459. };
  460. /* TXE PIO errors that cause an SPC freeze */
  461. #define ALL_PIO_FREEZE_ERR \
  462. (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
  463. | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
  464. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
  465. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
  466. | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
  467. | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
  468. | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
  469. | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
  470. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
  471. | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
  472. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
  473. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
  474. | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
  475. | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
  476. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
  477. | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
  478. | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
  479. | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
  480. | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
  481. | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
  482. | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
  483. | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
  484. | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
  485. | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
  486. | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
  487. | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
  488. | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
  489. | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
  490. | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
  491. /*
  492. * TXE SDMA Error flags
  493. */
  494. static struct flag_table sdma_err_status_flags[] = {
  495. /* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
  496. SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
  497. /* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
  498. SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
  499. /* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
  500. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
  501. /* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
  502. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
  503. /*04-63 reserved*/
  504. };
  505. /* TXE SDMA errors that cause an SPC freeze */
  506. #define ALL_SDMA_FREEZE_ERR \
  507. (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
  508. | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
  509. | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
  510. /* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
  511. #define PORT_DISCARD_EGRESS_ERRS \
  512. (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
  513. | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
  514. | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
  515. /*
  516. * TXE Egress Error flags
  517. */
  518. #define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
  519. static struct flag_table egress_err_status_flags[] = {
  520. /* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
  521. /* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
  522. /* 2 reserved */
  523. /* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
  524. SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
  525. /* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
  526. /* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
  527. /* 6 reserved */
  528. /* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
  529. SEES(TX_PIO_LAUNCH_INTF_PARITY)),
  530. /* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
  531. SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
  532. /* 9-10 reserved */
  533. /*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
  534. SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
  535. /*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
  536. /*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
  537. /*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
  538. /*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
  539. /*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
  540. SEES(TX_SDMA0_DISALLOWED_PACKET)),
  541. /*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
  542. SEES(TX_SDMA1_DISALLOWED_PACKET)),
  543. /*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
  544. SEES(TX_SDMA2_DISALLOWED_PACKET)),
  545. /*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
  546. SEES(TX_SDMA3_DISALLOWED_PACKET)),
  547. /*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
  548. SEES(TX_SDMA4_DISALLOWED_PACKET)),
  549. /*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
  550. SEES(TX_SDMA5_DISALLOWED_PACKET)),
  551. /*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
  552. SEES(TX_SDMA6_DISALLOWED_PACKET)),
  553. /*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
  554. SEES(TX_SDMA7_DISALLOWED_PACKET)),
  555. /*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
  556. SEES(TX_SDMA8_DISALLOWED_PACKET)),
  557. /*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
  558. SEES(TX_SDMA9_DISALLOWED_PACKET)),
  559. /*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
  560. SEES(TX_SDMA10_DISALLOWED_PACKET)),
  561. /*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
  562. SEES(TX_SDMA11_DISALLOWED_PACKET)),
  563. /*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
  564. SEES(TX_SDMA12_DISALLOWED_PACKET)),
  565. /*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
  566. SEES(TX_SDMA13_DISALLOWED_PACKET)),
  567. /*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
  568. SEES(TX_SDMA14_DISALLOWED_PACKET)),
  569. /*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
  570. SEES(TX_SDMA15_DISALLOWED_PACKET)),
  571. /*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
  572. SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
  573. /*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
  574. SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
  575. /*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
  576. SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
  577. /*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
  578. SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
  579. /*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
  580. SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
  581. /*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
  582. SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
  583. /*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
  584. SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
  585. /*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
  586. SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
  587. /*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
  588. SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
  589. /*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
  590. /*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
  591. /*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
  592. /*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
  593. /*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
  594. /*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
  595. /*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
  596. /*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
  597. /*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
  598. /*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
  599. /*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
  600. /*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
  601. /*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
  602. /*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
  603. /*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
  604. /*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
  605. /*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
  606. /*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
  607. /*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
  608. /*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
  609. /*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
  610. /*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
  611. SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
  612. /*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
  613. SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
  614. };
  615. /*
  616. * TXE Egress Error Info flags
  617. */
  618. #define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
  619. static struct flag_table egress_err_info_flags[] = {
  620. /* 0*/ FLAG_ENTRY0("Reserved", 0ull),
  621. /* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
  622. /* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  623. /* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  624. /* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
  625. /* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
  626. /* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
  627. /* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
  628. /* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
  629. /* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
  630. /*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
  631. /*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
  632. /*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
  633. /*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
  634. /*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
  635. /*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
  636. /*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
  637. /*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
  638. /*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
  639. /*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
  640. /*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
  641. /*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
  642. };
  643. /* TXE Egress errors that cause an SPC freeze */
  644. #define ALL_TXE_EGRESS_FREEZE_ERR \
  645. (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
  646. | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
  647. | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
  648. | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
  649. | SEES(TX_LAUNCH_CSR_PARITY) \
  650. | SEES(TX_SBRD_CTL_CSR_PARITY) \
  651. | SEES(TX_CONFIG_PARITY) \
  652. | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
  653. | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
  654. | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
  655. | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
  656. | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
  657. | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
  658. | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
  659. | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
  660. | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
  661. | SEES(TX_CREDIT_RETURN_PARITY))
  662. /*
  663. * TXE Send error flags
  664. */
  665. #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
  666. static struct flag_table send_err_status_flags[] = {
  667. /* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
  668. /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
  669. /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
  670. };
  671. /*
  672. * TXE Send Context Error flags and consequences
  673. */
  674. static struct flag_table sc_err_status_flags[] = {
  675. /* 0*/ FLAG_ENTRY("InconsistentSop",
  676. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  677. SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
  678. /* 1*/ FLAG_ENTRY("DisallowedPacket",
  679. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  680. SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
  681. /* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
  682. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  683. SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
  684. /* 3*/ FLAG_ENTRY("WriteOverflow",
  685. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  686. SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
  687. /* 4*/ FLAG_ENTRY("WriteOutOfBounds",
  688. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  689. SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
  690. /* 5-63 reserved*/
  691. };
  692. /*
  693. * RXE Receive Error flags
  694. */
  695. #define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
  696. static struct flag_table rxe_err_status_flags[] = {
  697. /* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
  698. /* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
  699. /* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
  700. /* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
  701. /* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
  702. /* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
  703. /* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
  704. /* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
  705. /* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
  706. /* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
  707. /*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
  708. /*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
  709. /*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
  710. /*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
  711. /*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
  712. /*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
  713. /*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
  714. RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
  715. /*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
  716. /*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
  717. /*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
  718. RXES(RBUF_BLOCK_LIST_READ_UNC)),
  719. /*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
  720. RXES(RBUF_BLOCK_LIST_READ_COR)),
  721. /*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
  722. RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
  723. /*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
  724. RXES(RBUF_CSR_QENT_CNT_PARITY)),
  725. /*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
  726. RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
  727. /*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
  728. RXES(RBUF_CSR_QVLD_BIT_PARITY)),
  729. /*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
  730. /*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
  731. /*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
  732. RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
  733. /*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
  734. /*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
  735. /*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
  736. /*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
  737. /*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
  738. /*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
  739. /*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
  740. /*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
  741. RXES(RBUF_FL_INITDONE_PARITY)),
  742. /*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
  743. RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
  744. /*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
  745. /*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
  746. /*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
  747. /*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
  748. RXES(LOOKUP_DES_PART1_UNC_COR)),
  749. /*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
  750. RXES(LOOKUP_DES_PART2_PARITY)),
  751. /*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
  752. /*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
  753. /*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
  754. /*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
  755. /*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
  756. /*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
  757. /*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
  758. /*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
  759. /*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
  760. /*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
  761. /*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
  762. /*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
  763. /*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
  764. /*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
  765. /*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
  766. /*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
  767. /*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
  768. /*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
  769. /*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
  770. /*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
  771. /*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
  772. /*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
  773. };
  774. /* RXE errors that will trigger an SPC freeze */
  775. #define ALL_RXE_FREEZE_ERR \
  776. (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
  777. | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
  778. | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
  779. | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
  780. | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
  781. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
  782. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
  783. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
  784. | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
  785. | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
  786. | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
  787. | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
  788. | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
  789. | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
  790. | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
  791. | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
  792. | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
  793. | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
  794. | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
  795. | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
  796. | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
  797. | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
  798. | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
  799. | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
  800. | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
  801. | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
  802. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
  803. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
  804. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
  805. | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
  806. | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
  807. | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
  808. | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
  809. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
  810. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
  811. | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
  812. | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
  813. | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
  814. | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
  815. | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
  816. | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
  817. | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
  818. | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
  819. | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
  820. #define RXE_FREEZE_ABORT_MASK \
  821. (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
  822. RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
  823. RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
  824. /*
  825. * DCC Error Flags
  826. */
  827. #define DCCE(name) DCC_ERR_FLG_##name##_SMASK
  828. static struct flag_table dcc_err_flags[] = {
  829. FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
  830. FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
  831. FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
  832. FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
  833. FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
  834. FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
  835. FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
  836. FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
  837. FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
  838. FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
  839. FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
  840. FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
  841. FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
  842. FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
  843. FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
  844. FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
  845. FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
  846. FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
  847. FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
  848. FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
  849. FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
  850. FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
  851. FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
  852. FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
  853. FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
  854. FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
  855. FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
  856. FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
  857. FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
  858. FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
  859. FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
  860. FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
  861. FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
  862. FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
  863. FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
  864. FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
  865. FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
  866. FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
  867. FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
  868. FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
  869. FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
  870. FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
  871. FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
  872. FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
  873. FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
  874. FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
  875. };
  876. /*
  877. * LCB error flags
  878. */
  879. #define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
  880. static struct flag_table lcb_err_flags[] = {
  881. /* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
  882. /* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
  883. /* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
  884. /* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
  885. LCBE(ALL_LNS_FAILED_REINIT_TEST)),
  886. /* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
  887. /* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
  888. /* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
  889. /* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
  890. /* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
  891. /* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
  892. /*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
  893. /*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
  894. /*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
  895. /*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
  896. LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
  897. /*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
  898. /*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
  899. /*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
  900. /*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
  901. /*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
  902. /*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
  903. LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
  904. /*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
  905. /*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
  906. /*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
  907. /*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
  908. /*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
  909. /*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
  910. /*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
  911. LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
  912. /*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
  913. /*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
  914. LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
  915. /*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
  916. LCBE(REDUNDANT_FLIT_PARITY_ERR))
  917. };
  918. /*
  919. * DC8051 Error Flags
  920. */
  921. #define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
  922. static struct flag_table dc8051_err_flags[] = {
  923. FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
  924. FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
  925. FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
  926. FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
  927. FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
  928. FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
  929. FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
  930. FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
  931. FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
  932. D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
  933. FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
  934. };
  935. /*
  936. * DC8051 Information Error flags
  937. *
  938. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
  939. */
  940. static struct flag_table dc8051_info_err_flags[] = {
  941. FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
  942. FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
  943. FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
  944. FLAG_ENTRY0("Serdes internal loopback failure",
  945. FAILED_SERDES_INTERNAL_LOOPBACK),
  946. FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
  947. FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
  948. FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
  949. FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
  950. FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
  951. FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
  952. FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
  953. FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
  954. FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
  955. FLAG_ENTRY0("External Device Request Timeout",
  956. EXTERNAL_DEVICE_REQ_TIMEOUT),
  957. };
  958. /*
  959. * DC8051 Information Host Information flags
  960. *
  961. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
  962. */
  963. static struct flag_table dc8051_info_host_msg_flags[] = {
  964. FLAG_ENTRY0("Host request done", 0x0001),
  965. FLAG_ENTRY0("BC PWR_MGM message", 0x0002),
  966. FLAG_ENTRY0("BC SMA message", 0x0004),
  967. FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
  968. FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
  969. FLAG_ENTRY0("External device config request", 0x0020),
  970. FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
  971. FLAG_ENTRY0("LinkUp achieved", 0x0080),
  972. FLAG_ENTRY0("Link going down", 0x0100),
  973. FLAG_ENTRY0("Link width downgraded", 0x0200),
  974. };
  975. static u32 encoded_size(u32 size);
  976. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
  977. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
  978. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  979. u8 *continuous);
  980. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  981. u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
  982. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  983. u8 *remote_tx_rate, u16 *link_widths);
  984. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  985. u8 *flag_bits, u16 *link_widths);
  986. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  987. u8 *device_rev);
  988. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed);
  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. /*
  1036. * Error interrupt table entry. This is used as input to the interrupt
  1037. * "clear down" routine used for all second tier error interrupt register.
  1038. * Second tier interrupt registers have a single bit representing them
  1039. * in the top-level CceIntStatus.
  1040. */
  1041. struct err_reg_info {
  1042. u32 status; /* status CSR offset */
  1043. u32 clear; /* clear CSR offset */
  1044. u32 mask; /* mask CSR offset */
  1045. void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
  1046. const char *desc;
  1047. };
  1048. #define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
  1049. #define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
  1050. #define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
  1051. /*
  1052. * Helpers for building HFI and DC error interrupt table entries. Different
  1053. * helpers are needed because of inconsistent register names.
  1054. */
  1055. #define EE(reg, handler, desc) \
  1056. { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
  1057. handler, desc }
  1058. #define DC_EE1(reg, handler, desc) \
  1059. { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
  1060. #define DC_EE2(reg, handler, desc) \
  1061. { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
  1062. /*
  1063. * Table of the "misc" grouping of error interrupts. Each entry refers to
  1064. * another register containing more information.
  1065. */
  1066. static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
  1067. /* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
  1068. /* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
  1069. /* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
  1070. /* 3*/ { 0, 0, 0, NULL }, /* reserved */
  1071. /* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
  1072. /* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
  1073. /* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
  1074. /* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
  1075. /* the rest are reserved */
  1076. };
  1077. /*
  1078. * Index into the Various section of the interrupt sources
  1079. * corresponding to the Critical Temperature interrupt.
  1080. */
  1081. #define TCRIT_INT_SOURCE 4
  1082. /*
  1083. * SDMA error interrupt entry - refers to another register containing more
  1084. * information.
  1085. */
  1086. static const struct err_reg_info sdma_eng_err =
  1087. EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
  1088. static const struct err_reg_info various_err[NUM_VARIOUS] = {
  1089. /* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
  1090. /* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
  1091. /* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
  1092. /* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
  1093. /* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
  1094. /* rest are reserved */
  1095. };
  1096. /*
  1097. * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
  1098. * register can not be derived from the MTU value because 10K is not
  1099. * a power of 2. Therefore, we need a constant. Everything else can
  1100. * be calculated.
  1101. */
  1102. #define DCC_CFG_PORT_MTU_CAP_10240 7
  1103. /*
  1104. * Table of the DC grouping of error interrupts. Each entry refers to
  1105. * another register containing more information.
  1106. */
  1107. static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
  1108. /* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
  1109. /* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
  1110. /* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
  1111. /* 3*/ /* dc_lbm_int - special, see is_dc_int() */
  1112. /* the rest are reserved */
  1113. };
  1114. struct cntr_entry {
  1115. /*
  1116. * counter name
  1117. */
  1118. char *name;
  1119. /*
  1120. * csr to read for name (if applicable)
  1121. */
  1122. u64 csr;
  1123. /*
  1124. * offset into dd or ppd to store the counter's value
  1125. */
  1126. int offset;
  1127. /*
  1128. * flags
  1129. */
  1130. u8 flags;
  1131. /*
  1132. * accessor for stat element, context either dd or ppd
  1133. */
  1134. u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
  1135. int mode, u64 data);
  1136. };
  1137. #define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
  1138. #define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
  1139. #define CNTR_ELEM(name, csr, offset, flags, accessor) \
  1140. { \
  1141. name, \
  1142. csr, \
  1143. offset, \
  1144. flags, \
  1145. accessor \
  1146. }
  1147. /* 32bit RXE */
  1148. #define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1149. CNTR_ELEM(#name, \
  1150. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1151. 0, flags | CNTR_32BIT, \
  1152. port_access_u32_csr)
  1153. #define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
  1154. CNTR_ELEM(#name, \
  1155. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1156. 0, flags | CNTR_32BIT, \
  1157. dev_access_u32_csr)
  1158. /* 64bit RXE */
  1159. #define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1160. CNTR_ELEM(#name, \
  1161. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1162. 0, flags, \
  1163. port_access_u64_csr)
  1164. #define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
  1165. CNTR_ELEM(#name, \
  1166. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1167. 0, flags, \
  1168. dev_access_u64_csr)
  1169. #define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
  1170. #define OVR_ELM(ctx) \
  1171. CNTR_ELEM("RcvHdrOvr" #ctx, \
  1172. (RCV_HDR_OVFL_CNT + ctx * 0x100), \
  1173. 0, CNTR_NORMAL, port_access_u64_csr)
  1174. /* 32bit TXE */
  1175. #define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1176. CNTR_ELEM(#name, \
  1177. (counter * 8 + SEND_COUNTER_ARRAY32), \
  1178. 0, flags | CNTR_32BIT, \
  1179. port_access_u32_csr)
  1180. /* 64bit TXE */
  1181. #define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1182. CNTR_ELEM(#name, \
  1183. (counter * 8 + SEND_COUNTER_ARRAY64), \
  1184. 0, flags, \
  1185. port_access_u64_csr)
  1186. # define TX64_DEV_CNTR_ELEM(name, counter, flags) \
  1187. CNTR_ELEM(#name,\
  1188. counter * 8 + SEND_COUNTER_ARRAY64, \
  1189. 0, \
  1190. flags, \
  1191. dev_access_u64_csr)
  1192. /* CCE */
  1193. #define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
  1194. CNTR_ELEM(#name, \
  1195. (counter * 8 + CCE_COUNTER_ARRAY32), \
  1196. 0, flags | CNTR_32BIT, \
  1197. dev_access_u32_csr)
  1198. #define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
  1199. CNTR_ELEM(#name, \
  1200. (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
  1201. 0, flags | CNTR_32BIT, \
  1202. dev_access_u32_csr)
  1203. /* DC */
  1204. #define DC_PERF_CNTR(name, counter, flags) \
  1205. CNTR_ELEM(#name, \
  1206. counter, \
  1207. 0, \
  1208. flags, \
  1209. dev_access_u64_csr)
  1210. #define DC_PERF_CNTR_LCB(name, counter, flags) \
  1211. CNTR_ELEM(#name, \
  1212. counter, \
  1213. 0, \
  1214. flags, \
  1215. dc_access_lcb_cntr)
  1216. /* ibp counters */
  1217. #define SW_IBP_CNTR(name, cntr) \
  1218. CNTR_ELEM(#name, \
  1219. 0, \
  1220. 0, \
  1221. CNTR_SYNTH, \
  1222. access_ibp_##cntr)
  1223. /**
  1224. * hfi_addr_from_offset - return addr for readq/writeq
  1225. * @dd - the dd device
  1226. * @offset - the offset of the CSR within bar0
  1227. *
  1228. * This routine selects the appropriate base address
  1229. * based on the indicated offset.
  1230. */
  1231. static inline void __iomem *hfi1_addr_from_offset(
  1232. const struct hfi1_devdata *dd,
  1233. u32 offset)
  1234. {
  1235. if (offset >= dd->base2_start)
  1236. return dd->kregbase2 + (offset - dd->base2_start);
  1237. return dd->kregbase1 + offset;
  1238. }
  1239. /**
  1240. * read_csr - read CSR at the indicated offset
  1241. * @dd - the dd device
  1242. * @offset - the offset of the CSR within bar0
  1243. *
  1244. * Return: the value read or all FF's if there
  1245. * is no mapping
  1246. */
  1247. u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
  1248. {
  1249. if (dd->flags & HFI1_PRESENT)
  1250. return readq(hfi1_addr_from_offset(dd, offset));
  1251. return -1;
  1252. }
  1253. /**
  1254. * write_csr - write CSR at the indicated offset
  1255. * @dd - the dd device
  1256. * @offset - the offset of the CSR within bar0
  1257. * @value - value to write
  1258. */
  1259. void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
  1260. {
  1261. if (dd->flags & HFI1_PRESENT) {
  1262. void __iomem *base = hfi1_addr_from_offset(dd, offset);
  1263. /* avoid write to RcvArray */
  1264. if (WARN_ON(offset >= RCV_ARRAY && offset < dd->base2_start))
  1265. return;
  1266. writeq(value, base);
  1267. }
  1268. }
  1269. /**
  1270. * get_csr_addr - return te iomem address for offset
  1271. * @dd - the dd device
  1272. * @offset - the offset of the CSR within bar0
  1273. *
  1274. * Return: The iomem address to use in subsequent
  1275. * writeq/readq operations.
  1276. */
  1277. void __iomem *get_csr_addr(
  1278. const struct hfi1_devdata *dd,
  1279. u32 offset)
  1280. {
  1281. if (dd->flags & HFI1_PRESENT)
  1282. return hfi1_addr_from_offset(dd, offset);
  1283. return NULL;
  1284. }
  1285. static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
  1286. int mode, u64 value)
  1287. {
  1288. u64 ret;
  1289. if (mode == CNTR_MODE_R) {
  1290. ret = read_csr(dd, csr);
  1291. } else if (mode == CNTR_MODE_W) {
  1292. write_csr(dd, csr, value);
  1293. ret = value;
  1294. } else {
  1295. dd_dev_err(dd, "Invalid cntr register access mode");
  1296. return 0;
  1297. }
  1298. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
  1299. return ret;
  1300. }
  1301. /* Dev Access */
  1302. static u64 dev_access_u32_csr(const struct cntr_entry *entry,
  1303. void *context, int vl, int mode, u64 data)
  1304. {
  1305. struct hfi1_devdata *dd = context;
  1306. u64 csr = entry->csr;
  1307. if (entry->flags & CNTR_SDMA) {
  1308. if (vl == CNTR_INVALID_VL)
  1309. return 0;
  1310. csr += 0x100 * vl;
  1311. } else {
  1312. if (vl != CNTR_INVALID_VL)
  1313. return 0;
  1314. }
  1315. return read_write_csr(dd, csr, mode, data);
  1316. }
  1317. static u64 access_sde_err_cnt(const struct cntr_entry *entry,
  1318. void *context, int idx, int mode, u64 data)
  1319. {
  1320. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1321. if (dd->per_sdma && idx < dd->num_sdma)
  1322. return dd->per_sdma[idx].err_cnt;
  1323. return 0;
  1324. }
  1325. static u64 access_sde_int_cnt(const struct cntr_entry *entry,
  1326. void *context, int idx, int mode, u64 data)
  1327. {
  1328. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1329. if (dd->per_sdma && idx < dd->num_sdma)
  1330. return dd->per_sdma[idx].sdma_int_cnt;
  1331. return 0;
  1332. }
  1333. static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
  1334. void *context, int idx, int mode, u64 data)
  1335. {
  1336. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1337. if (dd->per_sdma && idx < dd->num_sdma)
  1338. return dd->per_sdma[idx].idle_int_cnt;
  1339. return 0;
  1340. }
  1341. static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
  1342. void *context, int idx, int mode,
  1343. u64 data)
  1344. {
  1345. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1346. if (dd->per_sdma && idx < dd->num_sdma)
  1347. return dd->per_sdma[idx].progress_int_cnt;
  1348. return 0;
  1349. }
  1350. static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
  1351. int vl, int mode, u64 data)
  1352. {
  1353. struct hfi1_devdata *dd = context;
  1354. u64 val = 0;
  1355. u64 csr = entry->csr;
  1356. if (entry->flags & CNTR_VL) {
  1357. if (vl == CNTR_INVALID_VL)
  1358. return 0;
  1359. csr += 8 * vl;
  1360. } else {
  1361. if (vl != CNTR_INVALID_VL)
  1362. return 0;
  1363. }
  1364. val = read_write_csr(dd, csr, mode, data);
  1365. return val;
  1366. }
  1367. static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
  1368. int vl, int mode, u64 data)
  1369. {
  1370. struct hfi1_devdata *dd = context;
  1371. u32 csr = entry->csr;
  1372. int ret = 0;
  1373. if (vl != CNTR_INVALID_VL)
  1374. return 0;
  1375. if (mode == CNTR_MODE_R)
  1376. ret = read_lcb_csr(dd, csr, &data);
  1377. else if (mode == CNTR_MODE_W)
  1378. ret = write_lcb_csr(dd, csr, data);
  1379. if (ret) {
  1380. dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
  1381. return 0;
  1382. }
  1383. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
  1384. return data;
  1385. }
  1386. /* Port Access */
  1387. static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
  1388. int vl, int mode, u64 data)
  1389. {
  1390. struct hfi1_pportdata *ppd = context;
  1391. if (vl != CNTR_INVALID_VL)
  1392. return 0;
  1393. return read_write_csr(ppd->dd, entry->csr, mode, data);
  1394. }
  1395. static u64 port_access_u64_csr(const struct cntr_entry *entry,
  1396. void *context, int vl, int mode, u64 data)
  1397. {
  1398. struct hfi1_pportdata *ppd = context;
  1399. u64 val;
  1400. u64 csr = entry->csr;
  1401. if (entry->flags & CNTR_VL) {
  1402. if (vl == CNTR_INVALID_VL)
  1403. return 0;
  1404. csr += 8 * vl;
  1405. } else {
  1406. if (vl != CNTR_INVALID_VL)
  1407. return 0;
  1408. }
  1409. val = read_write_csr(ppd->dd, csr, mode, data);
  1410. return val;
  1411. }
  1412. /* Software defined */
  1413. static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
  1414. u64 data)
  1415. {
  1416. u64 ret;
  1417. if (mode == CNTR_MODE_R) {
  1418. ret = *cntr;
  1419. } else if (mode == CNTR_MODE_W) {
  1420. *cntr = data;
  1421. ret = data;
  1422. } else {
  1423. dd_dev_err(dd, "Invalid cntr sw access mode");
  1424. return 0;
  1425. }
  1426. hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
  1427. return ret;
  1428. }
  1429. static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
  1430. int vl, int mode, u64 data)
  1431. {
  1432. struct hfi1_pportdata *ppd = context;
  1433. if (vl != CNTR_INVALID_VL)
  1434. return 0;
  1435. return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
  1436. }
  1437. static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
  1438. int vl, int mode, u64 data)
  1439. {
  1440. struct hfi1_pportdata *ppd = context;
  1441. if (vl != CNTR_INVALID_VL)
  1442. return 0;
  1443. return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
  1444. }
  1445. static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
  1446. void *context, int vl, int mode,
  1447. u64 data)
  1448. {
  1449. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1450. if (vl != CNTR_INVALID_VL)
  1451. return 0;
  1452. return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
  1453. }
  1454. static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
  1455. void *context, int vl, int mode, u64 data)
  1456. {
  1457. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1458. u64 zero = 0;
  1459. u64 *counter;
  1460. if (vl == CNTR_INVALID_VL)
  1461. counter = &ppd->port_xmit_discards;
  1462. else if (vl >= 0 && vl < C_VL_COUNT)
  1463. counter = &ppd->port_xmit_discards_vl[vl];
  1464. else
  1465. counter = &zero;
  1466. return read_write_sw(ppd->dd, counter, mode, data);
  1467. }
  1468. static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
  1469. void *context, int vl, int mode,
  1470. u64 data)
  1471. {
  1472. struct hfi1_pportdata *ppd = context;
  1473. if (vl != CNTR_INVALID_VL)
  1474. return 0;
  1475. return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
  1476. mode, data);
  1477. }
  1478. static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
  1479. void *context, int vl, int mode, u64 data)
  1480. {
  1481. struct hfi1_pportdata *ppd = context;
  1482. if (vl != CNTR_INVALID_VL)
  1483. return 0;
  1484. return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
  1485. mode, data);
  1486. }
  1487. u64 get_all_cpu_total(u64 __percpu *cntr)
  1488. {
  1489. int cpu;
  1490. u64 counter = 0;
  1491. for_each_possible_cpu(cpu)
  1492. counter += *per_cpu_ptr(cntr, cpu);
  1493. return counter;
  1494. }
  1495. static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
  1496. u64 __percpu *cntr,
  1497. int vl, int mode, u64 data)
  1498. {
  1499. u64 ret = 0;
  1500. if (vl != CNTR_INVALID_VL)
  1501. return 0;
  1502. if (mode == CNTR_MODE_R) {
  1503. ret = get_all_cpu_total(cntr) - *z_val;
  1504. } else if (mode == CNTR_MODE_W) {
  1505. /* A write can only zero the counter */
  1506. if (data == 0)
  1507. *z_val = get_all_cpu_total(cntr);
  1508. else
  1509. dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
  1510. } else {
  1511. dd_dev_err(dd, "Invalid cntr sw cpu access mode");
  1512. return 0;
  1513. }
  1514. return ret;
  1515. }
  1516. static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
  1517. void *context, int vl, int mode, u64 data)
  1518. {
  1519. struct hfi1_devdata *dd = context;
  1520. return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
  1521. mode, data);
  1522. }
  1523. static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
  1524. void *context, int vl, int mode, u64 data)
  1525. {
  1526. struct hfi1_devdata *dd = context;
  1527. return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
  1528. mode, data);
  1529. }
  1530. static u64 access_sw_pio_wait(const struct cntr_entry *entry,
  1531. void *context, int vl, int mode, u64 data)
  1532. {
  1533. struct hfi1_devdata *dd = context;
  1534. return dd->verbs_dev.n_piowait;
  1535. }
  1536. static u64 access_sw_pio_drain(const struct cntr_entry *entry,
  1537. void *context, int vl, int mode, u64 data)
  1538. {
  1539. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1540. return dd->verbs_dev.n_piodrain;
  1541. }
  1542. static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
  1543. void *context, int vl, int mode, u64 data)
  1544. {
  1545. struct hfi1_devdata *dd = context;
  1546. return dd->verbs_dev.n_txwait;
  1547. }
  1548. static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
  1549. void *context, int vl, int mode, u64 data)
  1550. {
  1551. struct hfi1_devdata *dd = context;
  1552. return dd->verbs_dev.n_kmem_wait;
  1553. }
  1554. static u64 access_sw_send_schedule(const struct cntr_entry *entry,
  1555. void *context, int vl, int mode, u64 data)
  1556. {
  1557. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1558. return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
  1559. mode, data);
  1560. }
  1561. /* Software counters for the error status bits within MISC_ERR_STATUS */
  1562. static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
  1563. void *context, int vl, int mode,
  1564. u64 data)
  1565. {
  1566. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1567. return dd->misc_err_status_cnt[12];
  1568. }
  1569. static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
  1570. void *context, int vl, int mode,
  1571. u64 data)
  1572. {
  1573. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1574. return dd->misc_err_status_cnt[11];
  1575. }
  1576. static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
  1577. void *context, int vl, int mode,
  1578. u64 data)
  1579. {
  1580. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1581. return dd->misc_err_status_cnt[10];
  1582. }
  1583. static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
  1584. void *context, int vl,
  1585. int mode, u64 data)
  1586. {
  1587. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1588. return dd->misc_err_status_cnt[9];
  1589. }
  1590. static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
  1591. void *context, int vl, int mode,
  1592. u64 data)
  1593. {
  1594. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1595. return dd->misc_err_status_cnt[8];
  1596. }
  1597. static u64 access_misc_efuse_read_bad_addr_err_cnt(
  1598. const struct cntr_entry *entry,
  1599. void *context, int vl, int mode, u64 data)
  1600. {
  1601. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1602. return dd->misc_err_status_cnt[7];
  1603. }
  1604. static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
  1605. void *context, int vl,
  1606. int mode, u64 data)
  1607. {
  1608. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1609. return dd->misc_err_status_cnt[6];
  1610. }
  1611. static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
  1612. void *context, int vl, int mode,
  1613. u64 data)
  1614. {
  1615. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1616. return dd->misc_err_status_cnt[5];
  1617. }
  1618. static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
  1619. void *context, int vl, int mode,
  1620. u64 data)
  1621. {
  1622. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1623. return dd->misc_err_status_cnt[4];
  1624. }
  1625. static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
  1626. void *context, int vl,
  1627. int mode, u64 data)
  1628. {
  1629. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1630. return dd->misc_err_status_cnt[3];
  1631. }
  1632. static u64 access_misc_csr_write_bad_addr_err_cnt(
  1633. const struct cntr_entry *entry,
  1634. void *context, int vl, int mode, u64 data)
  1635. {
  1636. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1637. return dd->misc_err_status_cnt[2];
  1638. }
  1639. static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1640. void *context, int vl,
  1641. int mode, u64 data)
  1642. {
  1643. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1644. return dd->misc_err_status_cnt[1];
  1645. }
  1646. static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
  1647. void *context, int vl, int mode,
  1648. u64 data)
  1649. {
  1650. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1651. return dd->misc_err_status_cnt[0];
  1652. }
  1653. /*
  1654. * Software counter for the aggregate of
  1655. * individual CceErrStatus counters
  1656. */
  1657. static u64 access_sw_cce_err_status_aggregated_cnt(
  1658. const struct cntr_entry *entry,
  1659. void *context, int vl, int mode, u64 data)
  1660. {
  1661. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1662. return dd->sw_cce_err_status_aggregate;
  1663. }
  1664. /*
  1665. * Software counters corresponding to each of the
  1666. * error status bits within CceErrStatus
  1667. */
  1668. static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
  1669. void *context, int vl, int mode,
  1670. u64 data)
  1671. {
  1672. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1673. return dd->cce_err_status_cnt[40];
  1674. }
  1675. static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
  1676. void *context, int vl, int mode,
  1677. u64 data)
  1678. {
  1679. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1680. return dd->cce_err_status_cnt[39];
  1681. }
  1682. static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
  1683. void *context, int vl, int mode,
  1684. u64 data)
  1685. {
  1686. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1687. return dd->cce_err_status_cnt[38];
  1688. }
  1689. static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
  1690. void *context, int vl, int mode,
  1691. u64 data)
  1692. {
  1693. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1694. return dd->cce_err_status_cnt[37];
  1695. }
  1696. static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
  1697. void *context, int vl, int mode,
  1698. u64 data)
  1699. {
  1700. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1701. return dd->cce_err_status_cnt[36];
  1702. }
  1703. static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
  1704. const struct cntr_entry *entry,
  1705. void *context, int vl, int mode, u64 data)
  1706. {
  1707. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1708. return dd->cce_err_status_cnt[35];
  1709. }
  1710. static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
  1711. const struct cntr_entry *entry,
  1712. void *context, int vl, int mode, u64 data)
  1713. {
  1714. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1715. return dd->cce_err_status_cnt[34];
  1716. }
  1717. static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1718. void *context, int vl,
  1719. int mode, u64 data)
  1720. {
  1721. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1722. return dd->cce_err_status_cnt[33];
  1723. }
  1724. static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1725. void *context, int vl, int mode,
  1726. u64 data)
  1727. {
  1728. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1729. return dd->cce_err_status_cnt[32];
  1730. }
  1731. static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
  1732. void *context, int vl, int mode, u64 data)
  1733. {
  1734. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1735. return dd->cce_err_status_cnt[31];
  1736. }
  1737. static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
  1738. void *context, int vl, int mode,
  1739. u64 data)
  1740. {
  1741. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1742. return dd->cce_err_status_cnt[30];
  1743. }
  1744. static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
  1745. void *context, int vl, int mode,
  1746. u64 data)
  1747. {
  1748. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1749. return dd->cce_err_status_cnt[29];
  1750. }
  1751. static u64 access_pcic_transmit_back_parity_err_cnt(
  1752. const struct cntr_entry *entry,
  1753. void *context, int vl, int mode, u64 data)
  1754. {
  1755. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1756. return dd->cce_err_status_cnt[28];
  1757. }
  1758. static u64 access_pcic_transmit_front_parity_err_cnt(
  1759. const struct cntr_entry *entry,
  1760. void *context, int vl, int mode, u64 data)
  1761. {
  1762. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1763. return dd->cce_err_status_cnt[27];
  1764. }
  1765. static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1766. void *context, int vl, int mode,
  1767. u64 data)
  1768. {
  1769. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1770. return dd->cce_err_status_cnt[26];
  1771. }
  1772. static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1773. void *context, int vl, int mode,
  1774. u64 data)
  1775. {
  1776. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1777. return dd->cce_err_status_cnt[25];
  1778. }
  1779. static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1780. void *context, int vl, int mode,
  1781. u64 data)
  1782. {
  1783. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1784. return dd->cce_err_status_cnt[24];
  1785. }
  1786. static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1787. void *context, int vl, int mode,
  1788. u64 data)
  1789. {
  1790. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1791. return dd->cce_err_status_cnt[23];
  1792. }
  1793. static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
  1794. void *context, int vl,
  1795. int mode, u64 data)
  1796. {
  1797. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1798. return dd->cce_err_status_cnt[22];
  1799. }
  1800. static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
  1801. void *context, int vl, int mode,
  1802. u64 data)
  1803. {
  1804. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1805. return dd->cce_err_status_cnt[21];
  1806. }
  1807. static u64 access_pcic_n_post_dat_q_parity_err_cnt(
  1808. const struct cntr_entry *entry,
  1809. void *context, int vl, int mode, u64 data)
  1810. {
  1811. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1812. return dd->cce_err_status_cnt[20];
  1813. }
  1814. static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
  1815. void *context, int vl,
  1816. int mode, u64 data)
  1817. {
  1818. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1819. return dd->cce_err_status_cnt[19];
  1820. }
  1821. static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1822. void *context, int vl, int mode,
  1823. u64 data)
  1824. {
  1825. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1826. return dd->cce_err_status_cnt[18];
  1827. }
  1828. static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1829. void *context, int vl, int mode,
  1830. u64 data)
  1831. {
  1832. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1833. return dd->cce_err_status_cnt[17];
  1834. }
  1835. static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1836. void *context, int vl, int mode,
  1837. u64 data)
  1838. {
  1839. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1840. return dd->cce_err_status_cnt[16];
  1841. }
  1842. static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1843. void *context, int vl, int mode,
  1844. u64 data)
  1845. {
  1846. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1847. return dd->cce_err_status_cnt[15];
  1848. }
  1849. static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
  1850. void *context, int vl,
  1851. int mode, u64 data)
  1852. {
  1853. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1854. return dd->cce_err_status_cnt[14];
  1855. }
  1856. static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
  1857. void *context, int vl, int mode,
  1858. u64 data)
  1859. {
  1860. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1861. return dd->cce_err_status_cnt[13];
  1862. }
  1863. static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
  1864. const struct cntr_entry *entry,
  1865. void *context, int vl, int mode, u64 data)
  1866. {
  1867. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1868. return dd->cce_err_status_cnt[12];
  1869. }
  1870. static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
  1871. const struct cntr_entry *entry,
  1872. void *context, int vl, int mode, u64 data)
  1873. {
  1874. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1875. return dd->cce_err_status_cnt[11];
  1876. }
  1877. static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
  1878. const struct cntr_entry *entry,
  1879. void *context, int vl, int mode, u64 data)
  1880. {
  1881. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1882. return dd->cce_err_status_cnt[10];
  1883. }
  1884. static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
  1885. const struct cntr_entry *entry,
  1886. void *context, int vl, int mode, u64 data)
  1887. {
  1888. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1889. return dd->cce_err_status_cnt[9];
  1890. }
  1891. static u64 access_cce_cli2_async_fifo_parity_err_cnt(
  1892. const struct cntr_entry *entry,
  1893. void *context, int vl, int mode, u64 data)
  1894. {
  1895. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1896. return dd->cce_err_status_cnt[8];
  1897. }
  1898. static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
  1899. void *context, int vl,
  1900. int mode, u64 data)
  1901. {
  1902. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1903. return dd->cce_err_status_cnt[7];
  1904. }
  1905. static u64 access_cce_cli0_async_fifo_parity_err_cnt(
  1906. const struct cntr_entry *entry,
  1907. void *context, int vl, int mode, u64 data)
  1908. {
  1909. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1910. return dd->cce_err_status_cnt[6];
  1911. }
  1912. static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
  1913. void *context, int vl, int mode,
  1914. u64 data)
  1915. {
  1916. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1917. return dd->cce_err_status_cnt[5];
  1918. }
  1919. static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry,
  1920. void *context, int vl, int mode,
  1921. u64 data)
  1922. {
  1923. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1924. return dd->cce_err_status_cnt[4];
  1925. }
  1926. static u64 access_cce_trgt_async_fifo_parity_err_cnt(
  1927. const struct cntr_entry *entry,
  1928. void *context, int vl, int mode, u64 data)
  1929. {
  1930. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1931. return dd->cce_err_status_cnt[3];
  1932. }
  1933. static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1934. void *context, int vl,
  1935. int mode, u64 data)
  1936. {
  1937. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1938. return dd->cce_err_status_cnt[2];
  1939. }
  1940. static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1941. void *context, int vl,
  1942. int mode, u64 data)
  1943. {
  1944. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1945. return dd->cce_err_status_cnt[1];
  1946. }
  1947. static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
  1948. void *context, int vl, int mode,
  1949. u64 data)
  1950. {
  1951. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1952. return dd->cce_err_status_cnt[0];
  1953. }
  1954. /*
  1955. * Software counters corresponding to each of the
  1956. * error status bits within RcvErrStatus
  1957. */
  1958. static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
  1959. void *context, int vl, int mode,
  1960. u64 data)
  1961. {
  1962. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1963. return dd->rcv_err_status_cnt[63];
  1964. }
  1965. static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1966. void *context, int vl,
  1967. int mode, u64 data)
  1968. {
  1969. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1970. return dd->rcv_err_status_cnt[62];
  1971. }
  1972. static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1973. void *context, int vl, int mode,
  1974. u64 data)
  1975. {
  1976. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1977. return dd->rcv_err_status_cnt[61];
  1978. }
  1979. static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
  1980. void *context, int vl, int mode,
  1981. u64 data)
  1982. {
  1983. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1984. return dd->rcv_err_status_cnt[60];
  1985. }
  1986. static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1987. void *context, int vl,
  1988. int mode, u64 data)
  1989. {
  1990. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1991. return dd->rcv_err_status_cnt[59];
  1992. }
  1993. static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1994. void *context, int vl,
  1995. int mode, u64 data)
  1996. {
  1997. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1998. return dd->rcv_err_status_cnt[58];
  1999. }
  2000. static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2001. void *context, int vl, int mode,
  2002. u64 data)
  2003. {
  2004. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2005. return dd->rcv_err_status_cnt[57];
  2006. }
  2007. static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
  2008. void *context, int vl, int mode,
  2009. u64 data)
  2010. {
  2011. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2012. return dd->rcv_err_status_cnt[56];
  2013. }
  2014. static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
  2015. void *context, int vl, int mode,
  2016. u64 data)
  2017. {
  2018. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2019. return dd->rcv_err_status_cnt[55];
  2020. }
  2021. static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
  2022. const struct cntr_entry *entry,
  2023. void *context, int vl, int mode, u64 data)
  2024. {
  2025. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2026. return dd->rcv_err_status_cnt[54];
  2027. }
  2028. static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
  2029. const struct cntr_entry *entry,
  2030. void *context, int vl, int mode, u64 data)
  2031. {
  2032. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2033. return dd->rcv_err_status_cnt[53];
  2034. }
  2035. static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
  2036. void *context, int vl,
  2037. int mode, u64 data)
  2038. {
  2039. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2040. return dd->rcv_err_status_cnt[52];
  2041. }
  2042. static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
  2043. void *context, int vl,
  2044. int mode, u64 data)
  2045. {
  2046. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2047. return dd->rcv_err_status_cnt[51];
  2048. }
  2049. static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
  2050. void *context, int vl,
  2051. int mode, u64 data)
  2052. {
  2053. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2054. return dd->rcv_err_status_cnt[50];
  2055. }
  2056. static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
  2057. void *context, int vl,
  2058. int mode, u64 data)
  2059. {
  2060. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2061. return dd->rcv_err_status_cnt[49];
  2062. }
  2063. static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
  2064. void *context, int vl,
  2065. int mode, u64 data)
  2066. {
  2067. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2068. return dd->rcv_err_status_cnt[48];
  2069. }
  2070. static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
  2071. void *context, int vl,
  2072. int mode, u64 data)
  2073. {
  2074. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2075. return dd->rcv_err_status_cnt[47];
  2076. }
  2077. static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
  2078. void *context, int vl, int mode,
  2079. u64 data)
  2080. {
  2081. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2082. return dd->rcv_err_status_cnt[46];
  2083. }
  2084. static u64 access_rx_hq_intr_csr_parity_err_cnt(
  2085. const struct cntr_entry *entry,
  2086. void *context, int vl, int mode, u64 data)
  2087. {
  2088. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2089. return dd->rcv_err_status_cnt[45];
  2090. }
  2091. static u64 access_rx_lookup_csr_parity_err_cnt(
  2092. const struct cntr_entry *entry,
  2093. void *context, int vl, int mode, u64 data)
  2094. {
  2095. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2096. return dd->rcv_err_status_cnt[44];
  2097. }
  2098. static u64 access_rx_lookup_rcv_array_cor_err_cnt(
  2099. const struct cntr_entry *entry,
  2100. void *context, int vl, int mode, u64 data)
  2101. {
  2102. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2103. return dd->rcv_err_status_cnt[43];
  2104. }
  2105. static u64 access_rx_lookup_rcv_array_unc_err_cnt(
  2106. const struct cntr_entry *entry,
  2107. void *context, int vl, int mode, u64 data)
  2108. {
  2109. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2110. return dd->rcv_err_status_cnt[42];
  2111. }
  2112. static u64 access_rx_lookup_des_part2_parity_err_cnt(
  2113. const struct cntr_entry *entry,
  2114. void *context, int vl, int mode, u64 data)
  2115. {
  2116. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2117. return dd->rcv_err_status_cnt[41];
  2118. }
  2119. static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
  2120. const struct cntr_entry *entry,
  2121. void *context, int vl, int mode, u64 data)
  2122. {
  2123. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2124. return dd->rcv_err_status_cnt[40];
  2125. }
  2126. static u64 access_rx_lookup_des_part1_unc_err_cnt(
  2127. const struct cntr_entry *entry,
  2128. void *context, int vl, int mode, u64 data)
  2129. {
  2130. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2131. return dd->rcv_err_status_cnt[39];
  2132. }
  2133. static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
  2134. const struct cntr_entry *entry,
  2135. void *context, int vl, int mode, u64 data)
  2136. {
  2137. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2138. return dd->rcv_err_status_cnt[38];
  2139. }
  2140. static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
  2141. const struct cntr_entry *entry,
  2142. void *context, int vl, int mode, u64 data)
  2143. {
  2144. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2145. return dd->rcv_err_status_cnt[37];
  2146. }
  2147. static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
  2148. const struct cntr_entry *entry,
  2149. void *context, int vl, int mode, u64 data)
  2150. {
  2151. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2152. return dd->rcv_err_status_cnt[36];
  2153. }
  2154. static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
  2155. const struct cntr_entry *entry,
  2156. void *context, int vl, int mode, u64 data)
  2157. {
  2158. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2159. return dd->rcv_err_status_cnt[35];
  2160. }
  2161. static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
  2162. const struct cntr_entry *entry,
  2163. void *context, int vl, int mode, u64 data)
  2164. {
  2165. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2166. return dd->rcv_err_status_cnt[34];
  2167. }
  2168. static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
  2169. const struct cntr_entry *entry,
  2170. void *context, int vl, int mode, u64 data)
  2171. {
  2172. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2173. return dd->rcv_err_status_cnt[33];
  2174. }
  2175. static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
  2176. void *context, int vl, int mode,
  2177. u64 data)
  2178. {
  2179. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2180. return dd->rcv_err_status_cnt[32];
  2181. }
  2182. static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
  2183. void *context, int vl, int mode,
  2184. u64 data)
  2185. {
  2186. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2187. return dd->rcv_err_status_cnt[31];
  2188. }
  2189. static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
  2190. void *context, int vl, int mode,
  2191. u64 data)
  2192. {
  2193. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2194. return dd->rcv_err_status_cnt[30];
  2195. }
  2196. static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
  2197. void *context, int vl, int mode,
  2198. u64 data)
  2199. {
  2200. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2201. return dd->rcv_err_status_cnt[29];
  2202. }
  2203. static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
  2204. void *context, int vl,
  2205. int mode, u64 data)
  2206. {
  2207. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2208. return dd->rcv_err_status_cnt[28];
  2209. }
  2210. static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
  2211. const struct cntr_entry *entry,
  2212. void *context, int vl, int mode, u64 data)
  2213. {
  2214. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2215. return dd->rcv_err_status_cnt[27];
  2216. }
  2217. static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
  2218. const struct cntr_entry *entry,
  2219. void *context, int vl, int mode, u64 data)
  2220. {
  2221. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2222. return dd->rcv_err_status_cnt[26];
  2223. }
  2224. static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
  2225. const struct cntr_entry *entry,
  2226. void *context, int vl, int mode, u64 data)
  2227. {
  2228. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2229. return dd->rcv_err_status_cnt[25];
  2230. }
  2231. static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
  2232. const struct cntr_entry *entry,
  2233. void *context, int vl, int mode, u64 data)
  2234. {
  2235. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2236. return dd->rcv_err_status_cnt[24];
  2237. }
  2238. static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
  2239. const struct cntr_entry *entry,
  2240. void *context, int vl, int mode, u64 data)
  2241. {
  2242. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2243. return dd->rcv_err_status_cnt[23];
  2244. }
  2245. static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
  2246. const struct cntr_entry *entry,
  2247. void *context, int vl, int mode, u64 data)
  2248. {
  2249. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2250. return dd->rcv_err_status_cnt[22];
  2251. }
  2252. static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
  2253. const struct cntr_entry *entry,
  2254. void *context, int vl, int mode, u64 data)
  2255. {
  2256. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2257. return dd->rcv_err_status_cnt[21];
  2258. }
  2259. static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
  2260. const struct cntr_entry *entry,
  2261. void *context, int vl, int mode, u64 data)
  2262. {
  2263. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2264. return dd->rcv_err_status_cnt[20];
  2265. }
  2266. static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
  2267. const struct cntr_entry *entry,
  2268. void *context, int vl, int mode, u64 data)
  2269. {
  2270. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2271. return dd->rcv_err_status_cnt[19];
  2272. }
  2273. static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
  2274. void *context, int vl,
  2275. int mode, u64 data)
  2276. {
  2277. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2278. return dd->rcv_err_status_cnt[18];
  2279. }
  2280. static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
  2281. void *context, int vl,
  2282. int mode, u64 data)
  2283. {
  2284. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2285. return dd->rcv_err_status_cnt[17];
  2286. }
  2287. static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
  2288. const struct cntr_entry *entry,
  2289. void *context, int vl, int mode, u64 data)
  2290. {
  2291. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2292. return dd->rcv_err_status_cnt[16];
  2293. }
  2294. static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
  2295. const struct cntr_entry *entry,
  2296. void *context, int vl, int mode, u64 data)
  2297. {
  2298. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2299. return dd->rcv_err_status_cnt[15];
  2300. }
  2301. static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
  2302. void *context, int vl,
  2303. int mode, u64 data)
  2304. {
  2305. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2306. return dd->rcv_err_status_cnt[14];
  2307. }
  2308. static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
  2309. void *context, int vl,
  2310. int mode, u64 data)
  2311. {
  2312. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2313. return dd->rcv_err_status_cnt[13];
  2314. }
  2315. static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  2316. void *context, int vl, int mode,
  2317. u64 data)
  2318. {
  2319. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2320. return dd->rcv_err_status_cnt[12];
  2321. }
  2322. static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
  2323. void *context, int vl, int mode,
  2324. u64 data)
  2325. {
  2326. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2327. return dd->rcv_err_status_cnt[11];
  2328. }
  2329. static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
  2330. void *context, int vl, int mode,
  2331. u64 data)
  2332. {
  2333. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2334. return dd->rcv_err_status_cnt[10];
  2335. }
  2336. static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
  2337. void *context, int vl, int mode,
  2338. u64 data)
  2339. {
  2340. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2341. return dd->rcv_err_status_cnt[9];
  2342. }
  2343. static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
  2344. void *context, int vl, int mode,
  2345. u64 data)
  2346. {
  2347. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2348. return dd->rcv_err_status_cnt[8];
  2349. }
  2350. static u64 access_rx_rcv_qp_map_table_cor_err_cnt(
  2351. const struct cntr_entry *entry,
  2352. void *context, int vl, int mode, u64 data)
  2353. {
  2354. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2355. return dd->rcv_err_status_cnt[7];
  2356. }
  2357. static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
  2358. const struct cntr_entry *entry,
  2359. void *context, int vl, int mode, u64 data)
  2360. {
  2361. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2362. return dd->rcv_err_status_cnt[6];
  2363. }
  2364. static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry,
  2365. void *context, int vl, int mode,
  2366. u64 data)
  2367. {
  2368. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2369. return dd->rcv_err_status_cnt[5];
  2370. }
  2371. static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry,
  2372. void *context, int vl, int mode,
  2373. u64 data)
  2374. {
  2375. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2376. return dd->rcv_err_status_cnt[4];
  2377. }
  2378. static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2379. void *context, int vl, int mode,
  2380. u64 data)
  2381. {
  2382. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2383. return dd->rcv_err_status_cnt[3];
  2384. }
  2385. static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2386. void *context, int vl, int mode,
  2387. u64 data)
  2388. {
  2389. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2390. return dd->rcv_err_status_cnt[2];
  2391. }
  2392. static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry,
  2393. void *context, int vl, int mode,
  2394. u64 data)
  2395. {
  2396. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2397. return dd->rcv_err_status_cnt[1];
  2398. }
  2399. static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
  2400. void *context, int vl, int mode,
  2401. u64 data)
  2402. {
  2403. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2404. return dd->rcv_err_status_cnt[0];
  2405. }
  2406. /*
  2407. * Software counters corresponding to each of the
  2408. * error status bits within SendPioErrStatus
  2409. */
  2410. static u64 access_pio_pec_sop_head_parity_err_cnt(
  2411. const struct cntr_entry *entry,
  2412. void *context, int vl, int mode, u64 data)
  2413. {
  2414. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2415. return dd->send_pio_err_status_cnt[35];
  2416. }
  2417. static u64 access_pio_pcc_sop_head_parity_err_cnt(
  2418. const struct cntr_entry *entry,
  2419. void *context, int vl, int mode, u64 data)
  2420. {
  2421. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2422. return dd->send_pio_err_status_cnt[34];
  2423. }
  2424. static u64 access_pio_last_returned_cnt_parity_err_cnt(
  2425. const struct cntr_entry *entry,
  2426. void *context, int vl, int mode, u64 data)
  2427. {
  2428. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2429. return dd->send_pio_err_status_cnt[33];
  2430. }
  2431. static u64 access_pio_current_free_cnt_parity_err_cnt(
  2432. const struct cntr_entry *entry,
  2433. void *context, int vl, int mode, u64 data)
  2434. {
  2435. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2436. return dd->send_pio_err_status_cnt[32];
  2437. }
  2438. static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
  2439. void *context, int vl, int mode,
  2440. u64 data)
  2441. {
  2442. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2443. return dd->send_pio_err_status_cnt[31];
  2444. }
  2445. static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
  2446. void *context, int vl, int mode,
  2447. u64 data)
  2448. {
  2449. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2450. return dd->send_pio_err_status_cnt[30];
  2451. }
  2452. static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
  2453. void *context, int vl, int mode,
  2454. u64 data)
  2455. {
  2456. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2457. return dd->send_pio_err_status_cnt[29];
  2458. }
  2459. static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
  2460. const struct cntr_entry *entry,
  2461. void *context, int vl, int mode, u64 data)
  2462. {
  2463. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2464. return dd->send_pio_err_status_cnt[28];
  2465. }
  2466. static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2467. void *context, int vl, int mode,
  2468. u64 data)
  2469. {
  2470. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2471. return dd->send_pio_err_status_cnt[27];
  2472. }
  2473. static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
  2474. void *context, int vl, int mode,
  2475. u64 data)
  2476. {
  2477. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2478. return dd->send_pio_err_status_cnt[26];
  2479. }
  2480. static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
  2481. void *context, int vl,
  2482. int mode, u64 data)
  2483. {
  2484. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2485. return dd->send_pio_err_status_cnt[25];
  2486. }
  2487. static u64 access_pio_block_qw_count_parity_err_cnt(
  2488. const struct cntr_entry *entry,
  2489. void *context, int vl, int mode, u64 data)
  2490. {
  2491. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2492. return dd->send_pio_err_status_cnt[24];
  2493. }
  2494. static u64 access_pio_write_qw_valid_parity_err_cnt(
  2495. const struct cntr_entry *entry,
  2496. void *context, int vl, int mode, u64 data)
  2497. {
  2498. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2499. return dd->send_pio_err_status_cnt[23];
  2500. }
  2501. static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
  2502. void *context, int vl, int mode,
  2503. u64 data)
  2504. {
  2505. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2506. return dd->send_pio_err_status_cnt[22];
  2507. }
  2508. static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
  2509. void *context, int vl,
  2510. int mode, u64 data)
  2511. {
  2512. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2513. return dd->send_pio_err_status_cnt[21];
  2514. }
  2515. static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
  2516. void *context, int vl,
  2517. int mode, u64 data)
  2518. {
  2519. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2520. return dd->send_pio_err_status_cnt[20];
  2521. }
  2522. static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
  2523. void *context, int vl,
  2524. int mode, u64 data)
  2525. {
  2526. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2527. return dd->send_pio_err_status_cnt[19];
  2528. }
  2529. static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
  2530. const struct cntr_entry *entry,
  2531. void *context, int vl, int mode, u64 data)
  2532. {
  2533. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2534. return dd->send_pio_err_status_cnt[18];
  2535. }
  2536. static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
  2537. void *context, int vl, int mode,
  2538. u64 data)
  2539. {
  2540. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2541. return dd->send_pio_err_status_cnt[17];
  2542. }
  2543. static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
  2544. void *context, int vl, int mode,
  2545. u64 data)
  2546. {
  2547. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2548. return dd->send_pio_err_status_cnt[16];
  2549. }
  2550. static u64 access_pio_credit_ret_fifo_parity_err_cnt(
  2551. const struct cntr_entry *entry,
  2552. void *context, int vl, int mode, u64 data)
  2553. {
  2554. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2555. return dd->send_pio_err_status_cnt[15];
  2556. }
  2557. static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
  2558. const struct cntr_entry *entry,
  2559. void *context, int vl, int mode, u64 data)
  2560. {
  2561. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2562. return dd->send_pio_err_status_cnt[14];
  2563. }
  2564. static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
  2565. const struct cntr_entry *entry,
  2566. void *context, int vl, int mode, u64 data)
  2567. {
  2568. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2569. return dd->send_pio_err_status_cnt[13];
  2570. }
  2571. static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
  2572. const struct cntr_entry *entry,
  2573. void *context, int vl, int mode, u64 data)
  2574. {
  2575. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2576. return dd->send_pio_err_status_cnt[12];
  2577. }
  2578. static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
  2579. const struct cntr_entry *entry,
  2580. void *context, int vl, int mode, u64 data)
  2581. {
  2582. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2583. return dd->send_pio_err_status_cnt[11];
  2584. }
  2585. static u64 access_pio_sm_pkt_reset_parity_err_cnt(
  2586. const struct cntr_entry *entry,
  2587. void *context, int vl, int mode, u64 data)
  2588. {
  2589. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2590. return dd->send_pio_err_status_cnt[10];
  2591. }
  2592. static u64 access_pio_pkt_evict_fifo_parity_err_cnt(
  2593. const struct cntr_entry *entry,
  2594. void *context, int vl, int mode, u64 data)
  2595. {
  2596. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2597. return dd->send_pio_err_status_cnt[9];
  2598. }
  2599. static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
  2600. const struct cntr_entry *entry,
  2601. void *context, int vl, int mode, u64 data)
  2602. {
  2603. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2604. return dd->send_pio_err_status_cnt[8];
  2605. }
  2606. static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
  2607. const struct cntr_entry *entry,
  2608. void *context, int vl, int mode, u64 data)
  2609. {
  2610. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2611. return dd->send_pio_err_status_cnt[7];
  2612. }
  2613. static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2614. void *context, int vl, int mode,
  2615. u64 data)
  2616. {
  2617. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2618. return dd->send_pio_err_status_cnt[6];
  2619. }
  2620. static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2621. void *context, int vl, int mode,
  2622. u64 data)
  2623. {
  2624. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2625. return dd->send_pio_err_status_cnt[5];
  2626. }
  2627. static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
  2628. void *context, int vl, int mode,
  2629. u64 data)
  2630. {
  2631. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2632. return dd->send_pio_err_status_cnt[4];
  2633. }
  2634. static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
  2635. void *context, int vl, int mode,
  2636. u64 data)
  2637. {
  2638. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2639. return dd->send_pio_err_status_cnt[3];
  2640. }
  2641. static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
  2642. void *context, int vl, int mode,
  2643. u64 data)
  2644. {
  2645. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2646. return dd->send_pio_err_status_cnt[2];
  2647. }
  2648. static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
  2649. void *context, int vl,
  2650. int mode, u64 data)
  2651. {
  2652. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2653. return dd->send_pio_err_status_cnt[1];
  2654. }
  2655. static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
  2656. void *context, int vl, int mode,
  2657. u64 data)
  2658. {
  2659. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2660. return dd->send_pio_err_status_cnt[0];
  2661. }
  2662. /*
  2663. * Software counters corresponding to each of the
  2664. * error status bits within SendDmaErrStatus
  2665. */
  2666. static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
  2667. const struct cntr_entry *entry,
  2668. void *context, int vl, int mode, u64 data)
  2669. {
  2670. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2671. return dd->send_dma_err_status_cnt[3];
  2672. }
  2673. static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
  2674. const struct cntr_entry *entry,
  2675. void *context, int vl, int mode, u64 data)
  2676. {
  2677. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2678. return dd->send_dma_err_status_cnt[2];
  2679. }
  2680. static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2681. void *context, int vl, int mode,
  2682. u64 data)
  2683. {
  2684. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2685. return dd->send_dma_err_status_cnt[1];
  2686. }
  2687. static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry,
  2688. void *context, int vl, int mode,
  2689. u64 data)
  2690. {
  2691. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2692. return dd->send_dma_err_status_cnt[0];
  2693. }
  2694. /*
  2695. * Software counters corresponding to each of the
  2696. * error status bits within SendEgressErrStatus
  2697. */
  2698. static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
  2699. const struct cntr_entry *entry,
  2700. void *context, int vl, int mode, u64 data)
  2701. {
  2702. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2703. return dd->send_egress_err_status_cnt[63];
  2704. }
  2705. static u64 access_tx_read_sdma_memory_csr_err_cnt(
  2706. const struct cntr_entry *entry,
  2707. void *context, int vl, int mode, u64 data)
  2708. {
  2709. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2710. return dd->send_egress_err_status_cnt[62];
  2711. }
  2712. static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
  2713. void *context, int vl, int mode,
  2714. u64 data)
  2715. {
  2716. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2717. return dd->send_egress_err_status_cnt[61];
  2718. }
  2719. static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
  2720. void *context, int vl,
  2721. int mode, u64 data)
  2722. {
  2723. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2724. return dd->send_egress_err_status_cnt[60];
  2725. }
  2726. static u64 access_tx_read_sdma_memory_cor_err_cnt(
  2727. const struct cntr_entry *entry,
  2728. void *context, int vl, int mode, u64 data)
  2729. {
  2730. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2731. return dd->send_egress_err_status_cnt[59];
  2732. }
  2733. static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2734. void *context, int vl, int mode,
  2735. u64 data)
  2736. {
  2737. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2738. return dd->send_egress_err_status_cnt[58];
  2739. }
  2740. static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
  2741. void *context, int vl, int mode,
  2742. u64 data)
  2743. {
  2744. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2745. return dd->send_egress_err_status_cnt[57];
  2746. }
  2747. static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
  2748. void *context, int vl, int mode,
  2749. u64 data)
  2750. {
  2751. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2752. return dd->send_egress_err_status_cnt[56];
  2753. }
  2754. static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
  2755. void *context, int vl, int mode,
  2756. u64 data)
  2757. {
  2758. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2759. return dd->send_egress_err_status_cnt[55];
  2760. }
  2761. static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
  2762. void *context, int vl, int mode,
  2763. u64 data)
  2764. {
  2765. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2766. return dd->send_egress_err_status_cnt[54];
  2767. }
  2768. static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
  2769. void *context, int vl, int mode,
  2770. u64 data)
  2771. {
  2772. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2773. return dd->send_egress_err_status_cnt[53];
  2774. }
  2775. static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
  2776. void *context, int vl, int mode,
  2777. u64 data)
  2778. {
  2779. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2780. return dd->send_egress_err_status_cnt[52];
  2781. }
  2782. static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
  2783. void *context, int vl, int mode,
  2784. u64 data)
  2785. {
  2786. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2787. return dd->send_egress_err_status_cnt[51];
  2788. }
  2789. static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
  2790. void *context, int vl, int mode,
  2791. u64 data)
  2792. {
  2793. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2794. return dd->send_egress_err_status_cnt[50];
  2795. }
  2796. static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
  2797. void *context, int vl, int mode,
  2798. u64 data)
  2799. {
  2800. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2801. return dd->send_egress_err_status_cnt[49];
  2802. }
  2803. static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
  2804. void *context, int vl, int mode,
  2805. u64 data)
  2806. {
  2807. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2808. return dd->send_egress_err_status_cnt[48];
  2809. }
  2810. static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
  2811. void *context, int vl, int mode,
  2812. u64 data)
  2813. {
  2814. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2815. return dd->send_egress_err_status_cnt[47];
  2816. }
  2817. static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
  2818. void *context, int vl, int mode,
  2819. u64 data)
  2820. {
  2821. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2822. return dd->send_egress_err_status_cnt[46];
  2823. }
  2824. static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
  2825. void *context, int vl, int mode,
  2826. u64 data)
  2827. {
  2828. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2829. return dd->send_egress_err_status_cnt[45];
  2830. }
  2831. static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
  2832. void *context, int vl,
  2833. int mode, u64 data)
  2834. {
  2835. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2836. return dd->send_egress_err_status_cnt[44];
  2837. }
  2838. static u64 access_tx_read_sdma_memory_unc_err_cnt(
  2839. const struct cntr_entry *entry,
  2840. void *context, int vl, int mode, u64 data)
  2841. {
  2842. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2843. return dd->send_egress_err_status_cnt[43];
  2844. }
  2845. static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2846. void *context, int vl, int mode,
  2847. u64 data)
  2848. {
  2849. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2850. return dd->send_egress_err_status_cnt[42];
  2851. }
  2852. static u64 access_tx_credit_return_partiy_err_cnt(
  2853. const struct cntr_entry *entry,
  2854. void *context, int vl, int mode, u64 data)
  2855. {
  2856. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2857. return dd->send_egress_err_status_cnt[41];
  2858. }
  2859. static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
  2860. const struct cntr_entry *entry,
  2861. void *context, int vl, int mode, u64 data)
  2862. {
  2863. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2864. return dd->send_egress_err_status_cnt[40];
  2865. }
  2866. static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
  2867. const struct cntr_entry *entry,
  2868. void *context, int vl, int mode, u64 data)
  2869. {
  2870. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2871. return dd->send_egress_err_status_cnt[39];
  2872. }
  2873. static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
  2874. const struct cntr_entry *entry,
  2875. void *context, int vl, int mode, u64 data)
  2876. {
  2877. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2878. return dd->send_egress_err_status_cnt[38];
  2879. }
  2880. static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
  2881. const struct cntr_entry *entry,
  2882. void *context, int vl, int mode, u64 data)
  2883. {
  2884. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2885. return dd->send_egress_err_status_cnt[37];
  2886. }
  2887. static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
  2888. const struct cntr_entry *entry,
  2889. void *context, int vl, int mode, u64 data)
  2890. {
  2891. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2892. return dd->send_egress_err_status_cnt[36];
  2893. }
  2894. static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
  2895. const struct cntr_entry *entry,
  2896. void *context, int vl, int mode, u64 data)
  2897. {
  2898. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2899. return dd->send_egress_err_status_cnt[35];
  2900. }
  2901. static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
  2902. const struct cntr_entry *entry,
  2903. void *context, int vl, int mode, u64 data)
  2904. {
  2905. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2906. return dd->send_egress_err_status_cnt[34];
  2907. }
  2908. static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
  2909. const struct cntr_entry *entry,
  2910. void *context, int vl, int mode, u64 data)
  2911. {
  2912. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2913. return dd->send_egress_err_status_cnt[33];
  2914. }
  2915. static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
  2916. const struct cntr_entry *entry,
  2917. void *context, int vl, int mode, u64 data)
  2918. {
  2919. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2920. return dd->send_egress_err_status_cnt[32];
  2921. }
  2922. static u64 access_tx_sdma15_disallowed_packet_err_cnt(
  2923. const struct cntr_entry *entry,
  2924. void *context, int vl, int mode, u64 data)
  2925. {
  2926. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2927. return dd->send_egress_err_status_cnt[31];
  2928. }
  2929. static u64 access_tx_sdma14_disallowed_packet_err_cnt(
  2930. const struct cntr_entry *entry,
  2931. void *context, int vl, int mode, u64 data)
  2932. {
  2933. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2934. return dd->send_egress_err_status_cnt[30];
  2935. }
  2936. static u64 access_tx_sdma13_disallowed_packet_err_cnt(
  2937. const struct cntr_entry *entry,
  2938. void *context, int vl, int mode, u64 data)
  2939. {
  2940. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2941. return dd->send_egress_err_status_cnt[29];
  2942. }
  2943. static u64 access_tx_sdma12_disallowed_packet_err_cnt(
  2944. const struct cntr_entry *entry,
  2945. void *context, int vl, int mode, u64 data)
  2946. {
  2947. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2948. return dd->send_egress_err_status_cnt[28];
  2949. }
  2950. static u64 access_tx_sdma11_disallowed_packet_err_cnt(
  2951. const struct cntr_entry *entry,
  2952. void *context, int vl, int mode, u64 data)
  2953. {
  2954. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2955. return dd->send_egress_err_status_cnt[27];
  2956. }
  2957. static u64 access_tx_sdma10_disallowed_packet_err_cnt(
  2958. const struct cntr_entry *entry,
  2959. void *context, int vl, int mode, u64 data)
  2960. {
  2961. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2962. return dd->send_egress_err_status_cnt[26];
  2963. }
  2964. static u64 access_tx_sdma9_disallowed_packet_err_cnt(
  2965. const struct cntr_entry *entry,
  2966. void *context, int vl, int mode, u64 data)
  2967. {
  2968. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2969. return dd->send_egress_err_status_cnt[25];
  2970. }
  2971. static u64 access_tx_sdma8_disallowed_packet_err_cnt(
  2972. const struct cntr_entry *entry,
  2973. void *context, int vl, int mode, u64 data)
  2974. {
  2975. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2976. return dd->send_egress_err_status_cnt[24];
  2977. }
  2978. static u64 access_tx_sdma7_disallowed_packet_err_cnt(
  2979. const struct cntr_entry *entry,
  2980. void *context, int vl, int mode, u64 data)
  2981. {
  2982. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2983. return dd->send_egress_err_status_cnt[23];
  2984. }
  2985. static u64 access_tx_sdma6_disallowed_packet_err_cnt(
  2986. const struct cntr_entry *entry,
  2987. void *context, int vl, int mode, u64 data)
  2988. {
  2989. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2990. return dd->send_egress_err_status_cnt[22];
  2991. }
  2992. static u64 access_tx_sdma5_disallowed_packet_err_cnt(
  2993. const struct cntr_entry *entry,
  2994. void *context, int vl, int mode, u64 data)
  2995. {
  2996. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2997. return dd->send_egress_err_status_cnt[21];
  2998. }
  2999. static u64 access_tx_sdma4_disallowed_packet_err_cnt(
  3000. const struct cntr_entry *entry,
  3001. void *context, int vl, int mode, u64 data)
  3002. {
  3003. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3004. return dd->send_egress_err_status_cnt[20];
  3005. }
  3006. static u64 access_tx_sdma3_disallowed_packet_err_cnt(
  3007. const struct cntr_entry *entry,
  3008. void *context, int vl, int mode, u64 data)
  3009. {
  3010. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3011. return dd->send_egress_err_status_cnt[19];
  3012. }
  3013. static u64 access_tx_sdma2_disallowed_packet_err_cnt(
  3014. const struct cntr_entry *entry,
  3015. void *context, int vl, int mode, u64 data)
  3016. {
  3017. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3018. return dd->send_egress_err_status_cnt[18];
  3019. }
  3020. static u64 access_tx_sdma1_disallowed_packet_err_cnt(
  3021. const struct cntr_entry *entry,
  3022. void *context, int vl, int mode, u64 data)
  3023. {
  3024. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3025. return dd->send_egress_err_status_cnt[17];
  3026. }
  3027. static u64 access_tx_sdma0_disallowed_packet_err_cnt(
  3028. const struct cntr_entry *entry,
  3029. void *context, int vl, int mode, u64 data)
  3030. {
  3031. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3032. return dd->send_egress_err_status_cnt[16];
  3033. }
  3034. static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
  3035. void *context, int vl, int mode,
  3036. u64 data)
  3037. {
  3038. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3039. return dd->send_egress_err_status_cnt[15];
  3040. }
  3041. static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
  3042. void *context, int vl,
  3043. int mode, u64 data)
  3044. {
  3045. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3046. return dd->send_egress_err_status_cnt[14];
  3047. }
  3048. static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
  3049. void *context, int vl, int mode,
  3050. u64 data)
  3051. {
  3052. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3053. return dd->send_egress_err_status_cnt[13];
  3054. }
  3055. static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
  3056. void *context, int vl, int mode,
  3057. u64 data)
  3058. {
  3059. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3060. return dd->send_egress_err_status_cnt[12];
  3061. }
  3062. static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
  3063. const struct cntr_entry *entry,
  3064. void *context, int vl, int mode, u64 data)
  3065. {
  3066. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3067. return dd->send_egress_err_status_cnt[11];
  3068. }
  3069. static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
  3070. void *context, int vl, int mode,
  3071. u64 data)
  3072. {
  3073. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3074. return dd->send_egress_err_status_cnt[10];
  3075. }
  3076. static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
  3077. void *context, int vl, int mode,
  3078. u64 data)
  3079. {
  3080. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3081. return dd->send_egress_err_status_cnt[9];
  3082. }
  3083. static u64 access_tx_sdma_launch_intf_parity_err_cnt(
  3084. const struct cntr_entry *entry,
  3085. void *context, int vl, int mode, u64 data)
  3086. {
  3087. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3088. return dd->send_egress_err_status_cnt[8];
  3089. }
  3090. static u64 access_tx_pio_launch_intf_parity_err_cnt(
  3091. const struct cntr_entry *entry,
  3092. void *context, int vl, int mode, u64 data)
  3093. {
  3094. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3095. return dd->send_egress_err_status_cnt[7];
  3096. }
  3097. static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
  3098. void *context, int vl, int mode,
  3099. u64 data)
  3100. {
  3101. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3102. return dd->send_egress_err_status_cnt[6];
  3103. }
  3104. static u64 access_tx_incorrect_link_state_err_cnt(
  3105. const struct cntr_entry *entry,
  3106. void *context, int vl, int mode, u64 data)
  3107. {
  3108. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3109. return dd->send_egress_err_status_cnt[5];
  3110. }
  3111. static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
  3112. void *context, int vl, int mode,
  3113. u64 data)
  3114. {
  3115. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3116. return dd->send_egress_err_status_cnt[4];
  3117. }
  3118. static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
  3119. const struct cntr_entry *entry,
  3120. void *context, int vl, int mode, u64 data)
  3121. {
  3122. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3123. return dd->send_egress_err_status_cnt[3];
  3124. }
  3125. static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
  3126. void *context, int vl, int mode,
  3127. u64 data)
  3128. {
  3129. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3130. return dd->send_egress_err_status_cnt[2];
  3131. }
  3132. static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
  3133. const struct cntr_entry *entry,
  3134. void *context, int vl, int mode, u64 data)
  3135. {
  3136. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3137. return dd->send_egress_err_status_cnt[1];
  3138. }
  3139. static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
  3140. const struct cntr_entry *entry,
  3141. void *context, int vl, int mode, u64 data)
  3142. {
  3143. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3144. return dd->send_egress_err_status_cnt[0];
  3145. }
  3146. /*
  3147. * Software counters corresponding to each of the
  3148. * error status bits within SendErrStatus
  3149. */
  3150. static u64 access_send_csr_write_bad_addr_err_cnt(
  3151. const struct cntr_entry *entry,
  3152. void *context, int vl, int mode, u64 data)
  3153. {
  3154. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3155. return dd->send_err_status_cnt[2];
  3156. }
  3157. static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  3158. void *context, int vl,
  3159. int mode, u64 data)
  3160. {
  3161. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3162. return dd->send_err_status_cnt[1];
  3163. }
  3164. static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
  3165. void *context, int vl, int mode,
  3166. u64 data)
  3167. {
  3168. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3169. return dd->send_err_status_cnt[0];
  3170. }
  3171. /*
  3172. * Software counters corresponding to each of the
  3173. * error status bits within SendCtxtErrStatus
  3174. */
  3175. static u64 access_pio_write_out_of_bounds_err_cnt(
  3176. const struct cntr_entry *entry,
  3177. void *context, int vl, int mode, u64 data)
  3178. {
  3179. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3180. return dd->sw_ctxt_err_status_cnt[4];
  3181. }
  3182. static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
  3183. void *context, int vl, int mode,
  3184. u64 data)
  3185. {
  3186. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3187. return dd->sw_ctxt_err_status_cnt[3];
  3188. }
  3189. static u64 access_pio_write_crosses_boundary_err_cnt(
  3190. const struct cntr_entry *entry,
  3191. void *context, int vl, int mode, u64 data)
  3192. {
  3193. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3194. return dd->sw_ctxt_err_status_cnt[2];
  3195. }
  3196. static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
  3197. void *context, int vl,
  3198. int mode, u64 data)
  3199. {
  3200. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3201. return dd->sw_ctxt_err_status_cnt[1];
  3202. }
  3203. static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry,
  3204. void *context, int vl, int mode,
  3205. u64 data)
  3206. {
  3207. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3208. return dd->sw_ctxt_err_status_cnt[0];
  3209. }
  3210. /*
  3211. * Software counters corresponding to each of the
  3212. * error status bits within SendDmaEngErrStatus
  3213. */
  3214. static u64 access_sdma_header_request_fifo_cor_err_cnt(
  3215. const struct cntr_entry *entry,
  3216. void *context, int vl, int mode, u64 data)
  3217. {
  3218. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3219. return dd->sw_send_dma_eng_err_status_cnt[23];
  3220. }
  3221. static u64 access_sdma_header_storage_cor_err_cnt(
  3222. const struct cntr_entry *entry,
  3223. void *context, int vl, int mode, u64 data)
  3224. {
  3225. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3226. return dd->sw_send_dma_eng_err_status_cnt[22];
  3227. }
  3228. static u64 access_sdma_packet_tracking_cor_err_cnt(
  3229. const struct cntr_entry *entry,
  3230. void *context, int vl, int mode, u64 data)
  3231. {
  3232. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3233. return dd->sw_send_dma_eng_err_status_cnt[21];
  3234. }
  3235. static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
  3236. void *context, int vl, int mode,
  3237. u64 data)
  3238. {
  3239. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3240. return dd->sw_send_dma_eng_err_status_cnt[20];
  3241. }
  3242. static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
  3243. void *context, int vl, int mode,
  3244. u64 data)
  3245. {
  3246. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3247. return dd->sw_send_dma_eng_err_status_cnt[19];
  3248. }
  3249. static u64 access_sdma_header_request_fifo_unc_err_cnt(
  3250. const struct cntr_entry *entry,
  3251. void *context, int vl, int mode, u64 data)
  3252. {
  3253. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3254. return dd->sw_send_dma_eng_err_status_cnt[18];
  3255. }
  3256. static u64 access_sdma_header_storage_unc_err_cnt(
  3257. const struct cntr_entry *entry,
  3258. void *context, int vl, int mode, u64 data)
  3259. {
  3260. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3261. return dd->sw_send_dma_eng_err_status_cnt[17];
  3262. }
  3263. static u64 access_sdma_packet_tracking_unc_err_cnt(
  3264. const struct cntr_entry *entry,
  3265. void *context, int vl, int mode, u64 data)
  3266. {
  3267. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3268. return dd->sw_send_dma_eng_err_status_cnt[16];
  3269. }
  3270. static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
  3271. void *context, int vl, int mode,
  3272. u64 data)
  3273. {
  3274. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3275. return dd->sw_send_dma_eng_err_status_cnt[15];
  3276. }
  3277. static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
  3278. void *context, int vl, int mode,
  3279. u64 data)
  3280. {
  3281. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3282. return dd->sw_send_dma_eng_err_status_cnt[14];
  3283. }
  3284. static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
  3285. void *context, int vl, int mode,
  3286. u64 data)
  3287. {
  3288. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3289. return dd->sw_send_dma_eng_err_status_cnt[13];
  3290. }
  3291. static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
  3292. void *context, int vl, int mode,
  3293. u64 data)
  3294. {
  3295. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3296. return dd->sw_send_dma_eng_err_status_cnt[12];
  3297. }
  3298. static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
  3299. void *context, int vl, int mode,
  3300. u64 data)
  3301. {
  3302. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3303. return dd->sw_send_dma_eng_err_status_cnt[11];
  3304. }
  3305. static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
  3306. void *context, int vl, int mode,
  3307. u64 data)
  3308. {
  3309. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3310. return dd->sw_send_dma_eng_err_status_cnt[10];
  3311. }
  3312. static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
  3313. void *context, int vl, int mode,
  3314. u64 data)
  3315. {
  3316. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3317. return dd->sw_send_dma_eng_err_status_cnt[9];
  3318. }
  3319. static u64 access_sdma_packet_desc_overflow_err_cnt(
  3320. const struct cntr_entry *entry,
  3321. void *context, int vl, int mode, u64 data)
  3322. {
  3323. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3324. return dd->sw_send_dma_eng_err_status_cnt[8];
  3325. }
  3326. static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
  3327. void *context, int vl,
  3328. int mode, u64 data)
  3329. {
  3330. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3331. return dd->sw_send_dma_eng_err_status_cnt[7];
  3332. }
  3333. static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
  3334. void *context, int vl, int mode, u64 data)
  3335. {
  3336. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3337. return dd->sw_send_dma_eng_err_status_cnt[6];
  3338. }
  3339. static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
  3340. void *context, int vl, int mode,
  3341. u64 data)
  3342. {
  3343. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3344. return dd->sw_send_dma_eng_err_status_cnt[5];
  3345. }
  3346. static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
  3347. void *context, int vl, int mode,
  3348. u64 data)
  3349. {
  3350. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3351. return dd->sw_send_dma_eng_err_status_cnt[4];
  3352. }
  3353. static u64 access_sdma_tail_out_of_bounds_err_cnt(
  3354. const struct cntr_entry *entry,
  3355. void *context, int vl, int mode, u64 data)
  3356. {
  3357. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3358. return dd->sw_send_dma_eng_err_status_cnt[3];
  3359. }
  3360. static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
  3361. void *context, int vl, int mode,
  3362. u64 data)
  3363. {
  3364. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3365. return dd->sw_send_dma_eng_err_status_cnt[2];
  3366. }
  3367. static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
  3368. void *context, int vl, int mode,
  3369. u64 data)
  3370. {
  3371. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3372. return dd->sw_send_dma_eng_err_status_cnt[1];
  3373. }
  3374. static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
  3375. void *context, int vl, int mode,
  3376. u64 data)
  3377. {
  3378. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3379. return dd->sw_send_dma_eng_err_status_cnt[0];
  3380. }
  3381. static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
  3382. void *context, int vl, int mode,
  3383. u64 data)
  3384. {
  3385. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3386. u64 val = 0;
  3387. u64 csr = entry->csr;
  3388. val = read_write_csr(dd, csr, mode, data);
  3389. if (mode == CNTR_MODE_R) {
  3390. val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
  3391. CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
  3392. } else if (mode == CNTR_MODE_W) {
  3393. dd->sw_rcv_bypass_packet_errors = 0;
  3394. } else {
  3395. dd_dev_err(dd, "Invalid cntr register access mode");
  3396. return 0;
  3397. }
  3398. return val;
  3399. }
  3400. #define def_access_sw_cpu(cntr) \
  3401. static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
  3402. void *context, int vl, int mode, u64 data) \
  3403. { \
  3404. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3405. return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
  3406. ppd->ibport_data.rvp.cntr, vl, \
  3407. mode, data); \
  3408. }
  3409. def_access_sw_cpu(rc_acks);
  3410. def_access_sw_cpu(rc_qacks);
  3411. def_access_sw_cpu(rc_delayed_comp);
  3412. #define def_access_ibp_counter(cntr) \
  3413. static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
  3414. void *context, int vl, int mode, u64 data) \
  3415. { \
  3416. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3417. \
  3418. if (vl != CNTR_INVALID_VL) \
  3419. return 0; \
  3420. \
  3421. return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
  3422. mode, data); \
  3423. }
  3424. def_access_ibp_counter(loop_pkts);
  3425. def_access_ibp_counter(rc_resends);
  3426. def_access_ibp_counter(rnr_naks);
  3427. def_access_ibp_counter(other_naks);
  3428. def_access_ibp_counter(rc_timeouts);
  3429. def_access_ibp_counter(pkt_drops);
  3430. def_access_ibp_counter(dmawait);
  3431. def_access_ibp_counter(rc_seqnak);
  3432. def_access_ibp_counter(rc_dupreq);
  3433. def_access_ibp_counter(rdma_seq);
  3434. def_access_ibp_counter(unaligned);
  3435. def_access_ibp_counter(seq_naks);
  3436. static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
  3437. [C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
  3438. [C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
  3439. CNTR_NORMAL),
  3440. [C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
  3441. CNTR_NORMAL),
  3442. [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
  3443. RCV_TID_FLOW_GEN_MISMATCH_CNT,
  3444. CNTR_NORMAL),
  3445. [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
  3446. CNTR_NORMAL),
  3447. [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
  3448. RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
  3449. [C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
  3450. CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
  3451. [C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
  3452. CNTR_NORMAL),
  3453. [C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
  3454. CNTR_NORMAL),
  3455. [C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
  3456. CNTR_NORMAL),
  3457. [C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
  3458. CNTR_NORMAL),
  3459. [C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
  3460. CNTR_NORMAL),
  3461. [C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
  3462. CNTR_NORMAL),
  3463. [C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
  3464. CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
  3465. [C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
  3466. CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
  3467. [C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
  3468. CNTR_SYNTH),
  3469. [C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
  3470. access_dc_rcv_err_cnt),
  3471. [C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
  3472. CNTR_SYNTH),
  3473. [C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
  3474. CNTR_SYNTH),
  3475. [C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
  3476. CNTR_SYNTH),
  3477. [C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
  3478. DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
  3479. [C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
  3480. DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
  3481. CNTR_SYNTH),
  3482. [C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
  3483. DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
  3484. [C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
  3485. CNTR_SYNTH),
  3486. [C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
  3487. CNTR_SYNTH),
  3488. [C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
  3489. CNTR_SYNTH),
  3490. [C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
  3491. CNTR_SYNTH),
  3492. [C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
  3493. CNTR_SYNTH),
  3494. [C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
  3495. CNTR_SYNTH),
  3496. [C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
  3497. CNTR_SYNTH),
  3498. [C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
  3499. CNTR_SYNTH | CNTR_VL),
  3500. [C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
  3501. CNTR_SYNTH | CNTR_VL),
  3502. [C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
  3503. [C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
  3504. CNTR_SYNTH | CNTR_VL),
  3505. [C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
  3506. [C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
  3507. CNTR_SYNTH | CNTR_VL),
  3508. [C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
  3509. CNTR_SYNTH),
  3510. [C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
  3511. CNTR_SYNTH | CNTR_VL),
  3512. [C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
  3513. CNTR_SYNTH),
  3514. [C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
  3515. CNTR_SYNTH | CNTR_VL),
  3516. [C_DC_TOTAL_CRC] =
  3517. DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
  3518. CNTR_SYNTH),
  3519. [C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
  3520. CNTR_SYNTH),
  3521. [C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
  3522. CNTR_SYNTH),
  3523. [C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
  3524. CNTR_SYNTH),
  3525. [C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
  3526. CNTR_SYNTH),
  3527. [C_DC_CRC_MULT_LN] =
  3528. DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
  3529. CNTR_SYNTH),
  3530. [C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
  3531. CNTR_SYNTH),
  3532. [C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
  3533. CNTR_SYNTH),
  3534. [C_DC_SEQ_CRC_CNT] =
  3535. DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
  3536. CNTR_SYNTH),
  3537. [C_DC_ESC0_ONLY_CNT] =
  3538. DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
  3539. CNTR_SYNTH),
  3540. [C_DC_ESC0_PLUS1_CNT] =
  3541. DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
  3542. CNTR_SYNTH),
  3543. [C_DC_ESC0_PLUS2_CNT] =
  3544. DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
  3545. CNTR_SYNTH),
  3546. [C_DC_REINIT_FROM_PEER_CNT] =
  3547. DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
  3548. CNTR_SYNTH),
  3549. [C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
  3550. CNTR_SYNTH),
  3551. [C_DC_MISC_FLG_CNT] =
  3552. DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
  3553. CNTR_SYNTH),
  3554. [C_DC_PRF_GOOD_LTP_CNT] =
  3555. DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
  3556. [C_DC_PRF_ACCEPTED_LTP_CNT] =
  3557. DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
  3558. CNTR_SYNTH),
  3559. [C_DC_PRF_RX_FLIT_CNT] =
  3560. DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
  3561. [C_DC_PRF_TX_FLIT_CNT] =
  3562. DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
  3563. [C_DC_PRF_CLK_CNTR] =
  3564. DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
  3565. [C_DC_PG_DBG_FLIT_CRDTS_CNT] =
  3566. DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
  3567. [C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
  3568. DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
  3569. CNTR_SYNTH),
  3570. [C_DC_PG_STS_TX_SBE_CNT] =
  3571. DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
  3572. [C_DC_PG_STS_TX_MBE_CNT] =
  3573. DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
  3574. CNTR_SYNTH),
  3575. [C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
  3576. access_sw_cpu_intr),
  3577. [C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
  3578. access_sw_cpu_rcv_limit),
  3579. [C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
  3580. access_sw_vtx_wait),
  3581. [C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
  3582. access_sw_pio_wait),
  3583. [C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
  3584. access_sw_pio_drain),
  3585. [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
  3586. access_sw_kmem_wait),
  3587. [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
  3588. access_sw_send_schedule),
  3589. [C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
  3590. SEND_DMA_DESC_FETCHED_CNT, 0,
  3591. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3592. dev_access_u32_csr),
  3593. [C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
  3594. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3595. access_sde_int_cnt),
  3596. [C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
  3597. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3598. access_sde_err_cnt),
  3599. [C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
  3600. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3601. access_sde_idle_int_cnt),
  3602. [C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
  3603. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3604. access_sde_progress_int_cnt),
  3605. /* MISC_ERR_STATUS */
  3606. [C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
  3607. CNTR_NORMAL,
  3608. access_misc_pll_lock_fail_err_cnt),
  3609. [C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
  3610. CNTR_NORMAL,
  3611. access_misc_mbist_fail_err_cnt),
  3612. [C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
  3613. CNTR_NORMAL,
  3614. access_misc_invalid_eep_cmd_err_cnt),
  3615. [C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
  3616. CNTR_NORMAL,
  3617. access_misc_efuse_done_parity_err_cnt),
  3618. [C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
  3619. CNTR_NORMAL,
  3620. access_misc_efuse_write_err_cnt),
  3621. [C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
  3622. 0, CNTR_NORMAL,
  3623. access_misc_efuse_read_bad_addr_err_cnt),
  3624. [C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
  3625. CNTR_NORMAL,
  3626. access_misc_efuse_csr_parity_err_cnt),
  3627. [C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
  3628. CNTR_NORMAL,
  3629. access_misc_fw_auth_failed_err_cnt),
  3630. [C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
  3631. CNTR_NORMAL,
  3632. access_misc_key_mismatch_err_cnt),
  3633. [C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
  3634. CNTR_NORMAL,
  3635. access_misc_sbus_write_failed_err_cnt),
  3636. [C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
  3637. CNTR_NORMAL,
  3638. access_misc_csr_write_bad_addr_err_cnt),
  3639. [C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
  3640. CNTR_NORMAL,
  3641. access_misc_csr_read_bad_addr_err_cnt),
  3642. [C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
  3643. CNTR_NORMAL,
  3644. access_misc_csr_parity_err_cnt),
  3645. /* CceErrStatus */
  3646. [C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
  3647. CNTR_NORMAL,
  3648. access_sw_cce_err_status_aggregated_cnt),
  3649. [C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
  3650. CNTR_NORMAL,
  3651. access_cce_msix_csr_parity_err_cnt),
  3652. [C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
  3653. CNTR_NORMAL,
  3654. access_cce_int_map_unc_err_cnt),
  3655. [C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
  3656. CNTR_NORMAL,
  3657. access_cce_int_map_cor_err_cnt),
  3658. [C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
  3659. CNTR_NORMAL,
  3660. access_cce_msix_table_unc_err_cnt),
  3661. [C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
  3662. CNTR_NORMAL,
  3663. access_cce_msix_table_cor_err_cnt),
  3664. [C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
  3665. 0, CNTR_NORMAL,
  3666. access_cce_rxdma_conv_fifo_parity_err_cnt),
  3667. [C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
  3668. 0, CNTR_NORMAL,
  3669. access_cce_rcpl_async_fifo_parity_err_cnt),
  3670. [C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
  3671. CNTR_NORMAL,
  3672. access_cce_seg_write_bad_addr_err_cnt),
  3673. [C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
  3674. CNTR_NORMAL,
  3675. access_cce_seg_read_bad_addr_err_cnt),
  3676. [C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
  3677. CNTR_NORMAL,
  3678. access_la_triggered_cnt),
  3679. [C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
  3680. CNTR_NORMAL,
  3681. access_cce_trgt_cpl_timeout_err_cnt),
  3682. [C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
  3683. CNTR_NORMAL,
  3684. access_pcic_receive_parity_err_cnt),
  3685. [C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
  3686. CNTR_NORMAL,
  3687. access_pcic_transmit_back_parity_err_cnt),
  3688. [C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
  3689. 0, CNTR_NORMAL,
  3690. access_pcic_transmit_front_parity_err_cnt),
  3691. [C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
  3692. CNTR_NORMAL,
  3693. access_pcic_cpl_dat_q_unc_err_cnt),
  3694. [C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
  3695. CNTR_NORMAL,
  3696. access_pcic_cpl_hd_q_unc_err_cnt),
  3697. [C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
  3698. CNTR_NORMAL,
  3699. access_pcic_post_dat_q_unc_err_cnt),
  3700. [C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
  3701. CNTR_NORMAL,
  3702. access_pcic_post_hd_q_unc_err_cnt),
  3703. [C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
  3704. CNTR_NORMAL,
  3705. access_pcic_retry_sot_mem_unc_err_cnt),
  3706. [C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
  3707. CNTR_NORMAL,
  3708. access_pcic_retry_mem_unc_err),
  3709. [C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
  3710. CNTR_NORMAL,
  3711. access_pcic_n_post_dat_q_parity_err_cnt),
  3712. [C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
  3713. CNTR_NORMAL,
  3714. access_pcic_n_post_h_q_parity_err_cnt),
  3715. [C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
  3716. CNTR_NORMAL,
  3717. access_pcic_cpl_dat_q_cor_err_cnt),
  3718. [C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
  3719. CNTR_NORMAL,
  3720. access_pcic_cpl_hd_q_cor_err_cnt),
  3721. [C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
  3722. CNTR_NORMAL,
  3723. access_pcic_post_dat_q_cor_err_cnt),
  3724. [C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
  3725. CNTR_NORMAL,
  3726. access_pcic_post_hd_q_cor_err_cnt),
  3727. [C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
  3728. CNTR_NORMAL,
  3729. access_pcic_retry_sot_mem_cor_err_cnt),
  3730. [C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
  3731. CNTR_NORMAL,
  3732. access_pcic_retry_mem_cor_err_cnt),
  3733. [C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
  3734. "CceCli1AsyncFifoDbgParityError", 0, 0,
  3735. CNTR_NORMAL,
  3736. access_cce_cli1_async_fifo_dbg_parity_err_cnt),
  3737. [C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
  3738. "CceCli1AsyncFifoRxdmaParityError", 0, 0,
  3739. CNTR_NORMAL,
  3740. access_cce_cli1_async_fifo_rxdma_parity_err_cnt
  3741. ),
  3742. [C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
  3743. "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
  3744. CNTR_NORMAL,
  3745. access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
  3746. [C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
  3747. "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
  3748. CNTR_NORMAL,
  3749. access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
  3750. [C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
  3751. 0, CNTR_NORMAL,
  3752. access_cce_cli2_async_fifo_parity_err_cnt),
  3753. [C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
  3754. CNTR_NORMAL,
  3755. access_cce_csr_cfg_bus_parity_err_cnt),
  3756. [C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
  3757. 0, CNTR_NORMAL,
  3758. access_cce_cli0_async_fifo_parity_err_cnt),
  3759. [C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
  3760. CNTR_NORMAL,
  3761. access_cce_rspd_data_parity_err_cnt),
  3762. [C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
  3763. CNTR_NORMAL,
  3764. access_cce_trgt_access_err_cnt),
  3765. [C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
  3766. 0, CNTR_NORMAL,
  3767. access_cce_trgt_async_fifo_parity_err_cnt),
  3768. [C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
  3769. CNTR_NORMAL,
  3770. access_cce_csr_write_bad_addr_err_cnt),
  3771. [C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
  3772. CNTR_NORMAL,
  3773. access_cce_csr_read_bad_addr_err_cnt),
  3774. [C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
  3775. CNTR_NORMAL,
  3776. access_ccs_csr_parity_err_cnt),
  3777. /* RcvErrStatus */
  3778. [C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
  3779. CNTR_NORMAL,
  3780. access_rx_csr_parity_err_cnt),
  3781. [C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
  3782. CNTR_NORMAL,
  3783. access_rx_csr_write_bad_addr_err_cnt),
  3784. [C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
  3785. CNTR_NORMAL,
  3786. access_rx_csr_read_bad_addr_err_cnt),
  3787. [C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
  3788. CNTR_NORMAL,
  3789. access_rx_dma_csr_unc_err_cnt),
  3790. [C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
  3791. CNTR_NORMAL,
  3792. access_rx_dma_dq_fsm_encoding_err_cnt),
  3793. [C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
  3794. CNTR_NORMAL,
  3795. access_rx_dma_eq_fsm_encoding_err_cnt),
  3796. [C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
  3797. CNTR_NORMAL,
  3798. access_rx_dma_csr_parity_err_cnt),
  3799. [C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
  3800. CNTR_NORMAL,
  3801. access_rx_rbuf_data_cor_err_cnt),
  3802. [C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
  3803. CNTR_NORMAL,
  3804. access_rx_rbuf_data_unc_err_cnt),
  3805. [C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
  3806. CNTR_NORMAL,
  3807. access_rx_dma_data_fifo_rd_cor_err_cnt),
  3808. [C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
  3809. CNTR_NORMAL,
  3810. access_rx_dma_data_fifo_rd_unc_err_cnt),
  3811. [C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
  3812. CNTR_NORMAL,
  3813. access_rx_dma_hdr_fifo_rd_cor_err_cnt),
  3814. [C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
  3815. CNTR_NORMAL,
  3816. access_rx_dma_hdr_fifo_rd_unc_err_cnt),
  3817. [C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
  3818. CNTR_NORMAL,
  3819. access_rx_rbuf_desc_part2_cor_err_cnt),
  3820. [C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
  3821. CNTR_NORMAL,
  3822. access_rx_rbuf_desc_part2_unc_err_cnt),
  3823. [C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
  3824. CNTR_NORMAL,
  3825. access_rx_rbuf_desc_part1_cor_err_cnt),
  3826. [C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
  3827. CNTR_NORMAL,
  3828. access_rx_rbuf_desc_part1_unc_err_cnt),
  3829. [C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
  3830. CNTR_NORMAL,
  3831. access_rx_hq_intr_fsm_err_cnt),
  3832. [C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
  3833. CNTR_NORMAL,
  3834. access_rx_hq_intr_csr_parity_err_cnt),
  3835. [C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
  3836. CNTR_NORMAL,
  3837. access_rx_lookup_csr_parity_err_cnt),
  3838. [C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
  3839. CNTR_NORMAL,
  3840. access_rx_lookup_rcv_array_cor_err_cnt),
  3841. [C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
  3842. CNTR_NORMAL,
  3843. access_rx_lookup_rcv_array_unc_err_cnt),
  3844. [C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
  3845. 0, CNTR_NORMAL,
  3846. access_rx_lookup_des_part2_parity_err_cnt),
  3847. [C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
  3848. 0, CNTR_NORMAL,
  3849. access_rx_lookup_des_part1_unc_cor_err_cnt),
  3850. [C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
  3851. CNTR_NORMAL,
  3852. access_rx_lookup_des_part1_unc_err_cnt),
  3853. [C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
  3854. CNTR_NORMAL,
  3855. access_rx_rbuf_next_free_buf_cor_err_cnt),
  3856. [C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
  3857. CNTR_NORMAL,
  3858. access_rx_rbuf_next_free_buf_unc_err_cnt),
  3859. [C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
  3860. "RxRbufFlInitWrAddrParityErr", 0, 0,
  3861. CNTR_NORMAL,
  3862. access_rbuf_fl_init_wr_addr_parity_err_cnt),
  3863. [C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
  3864. 0, CNTR_NORMAL,
  3865. access_rx_rbuf_fl_initdone_parity_err_cnt),
  3866. [C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
  3867. 0, CNTR_NORMAL,
  3868. access_rx_rbuf_fl_write_addr_parity_err_cnt),
  3869. [C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
  3870. CNTR_NORMAL,
  3871. access_rx_rbuf_fl_rd_addr_parity_err_cnt),
  3872. [C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
  3873. CNTR_NORMAL,
  3874. access_rx_rbuf_empty_err_cnt),
  3875. [C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
  3876. CNTR_NORMAL,
  3877. access_rx_rbuf_full_err_cnt),
  3878. [C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
  3879. CNTR_NORMAL,
  3880. access_rbuf_bad_lookup_err_cnt),
  3881. [C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
  3882. CNTR_NORMAL,
  3883. access_rbuf_ctx_id_parity_err_cnt),
  3884. [C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
  3885. CNTR_NORMAL,
  3886. access_rbuf_csr_qeopdw_parity_err_cnt),
  3887. [C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
  3888. "RxRbufCsrQNumOfPktParityErr", 0, 0,
  3889. CNTR_NORMAL,
  3890. access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
  3891. [C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
  3892. "RxRbufCsrQTlPtrParityErr", 0, 0,
  3893. CNTR_NORMAL,
  3894. access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
  3895. [C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
  3896. 0, CNTR_NORMAL,
  3897. access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
  3898. [C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
  3899. 0, CNTR_NORMAL,
  3900. access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
  3901. [C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
  3902. 0, 0, CNTR_NORMAL,
  3903. access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
  3904. [C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
  3905. 0, CNTR_NORMAL,
  3906. access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
  3907. [C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
  3908. "RxRbufCsrQHeadBufNumParityErr", 0, 0,
  3909. CNTR_NORMAL,
  3910. access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
  3911. [C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
  3912. 0, CNTR_NORMAL,
  3913. access_rx_rbuf_block_list_read_cor_err_cnt),
  3914. [C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
  3915. 0, CNTR_NORMAL,
  3916. access_rx_rbuf_block_list_read_unc_err_cnt),
  3917. [C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
  3918. CNTR_NORMAL,
  3919. access_rx_rbuf_lookup_des_cor_err_cnt),
  3920. [C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
  3921. CNTR_NORMAL,
  3922. access_rx_rbuf_lookup_des_unc_err_cnt),
  3923. [C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
  3924. "RxRbufLookupDesRegUncCorErr", 0, 0,
  3925. CNTR_NORMAL,
  3926. access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
  3927. [C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
  3928. CNTR_NORMAL,
  3929. access_rx_rbuf_lookup_des_reg_unc_err_cnt),
  3930. [C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
  3931. CNTR_NORMAL,
  3932. access_rx_rbuf_free_list_cor_err_cnt),
  3933. [C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
  3934. CNTR_NORMAL,
  3935. access_rx_rbuf_free_list_unc_err_cnt),
  3936. [C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
  3937. CNTR_NORMAL,
  3938. access_rx_rcv_fsm_encoding_err_cnt),
  3939. [C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
  3940. CNTR_NORMAL,
  3941. access_rx_dma_flag_cor_err_cnt),
  3942. [C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
  3943. CNTR_NORMAL,
  3944. access_rx_dma_flag_unc_err_cnt),
  3945. [C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
  3946. CNTR_NORMAL,
  3947. access_rx_dc_sop_eop_parity_err_cnt),
  3948. [C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
  3949. CNTR_NORMAL,
  3950. access_rx_rcv_csr_parity_err_cnt),
  3951. [C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
  3952. CNTR_NORMAL,
  3953. access_rx_rcv_qp_map_table_cor_err_cnt),
  3954. [C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
  3955. CNTR_NORMAL,
  3956. access_rx_rcv_qp_map_table_unc_err_cnt),
  3957. [C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
  3958. CNTR_NORMAL,
  3959. access_rx_rcv_data_cor_err_cnt),
  3960. [C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
  3961. CNTR_NORMAL,
  3962. access_rx_rcv_data_unc_err_cnt),
  3963. [C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
  3964. CNTR_NORMAL,
  3965. access_rx_rcv_hdr_cor_err_cnt),
  3966. [C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
  3967. CNTR_NORMAL,
  3968. access_rx_rcv_hdr_unc_err_cnt),
  3969. [C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
  3970. CNTR_NORMAL,
  3971. access_rx_dc_intf_parity_err_cnt),
  3972. [C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
  3973. CNTR_NORMAL,
  3974. access_rx_dma_csr_cor_err_cnt),
  3975. /* SendPioErrStatus */
  3976. [C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
  3977. CNTR_NORMAL,
  3978. access_pio_pec_sop_head_parity_err_cnt),
  3979. [C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
  3980. CNTR_NORMAL,
  3981. access_pio_pcc_sop_head_parity_err_cnt),
  3982. [C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
  3983. 0, 0, CNTR_NORMAL,
  3984. access_pio_last_returned_cnt_parity_err_cnt),
  3985. [C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
  3986. 0, CNTR_NORMAL,
  3987. access_pio_current_free_cnt_parity_err_cnt),
  3988. [C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
  3989. CNTR_NORMAL,
  3990. access_pio_reserved_31_err_cnt),
  3991. [C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
  3992. CNTR_NORMAL,
  3993. access_pio_reserved_30_err_cnt),
  3994. [C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
  3995. CNTR_NORMAL,
  3996. access_pio_ppmc_sop_len_err_cnt),
  3997. [C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
  3998. CNTR_NORMAL,
  3999. access_pio_ppmc_bqc_mem_parity_err_cnt),
  4000. [C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
  4001. CNTR_NORMAL,
  4002. access_pio_vl_fifo_parity_err_cnt),
  4003. [C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
  4004. CNTR_NORMAL,
  4005. access_pio_vlf_sop_parity_err_cnt),
  4006. [C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
  4007. CNTR_NORMAL,
  4008. access_pio_vlf_v1_len_parity_err_cnt),
  4009. [C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
  4010. CNTR_NORMAL,
  4011. access_pio_block_qw_count_parity_err_cnt),
  4012. [C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
  4013. CNTR_NORMAL,
  4014. access_pio_write_qw_valid_parity_err_cnt),
  4015. [C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
  4016. CNTR_NORMAL,
  4017. access_pio_state_machine_err_cnt),
  4018. [C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
  4019. CNTR_NORMAL,
  4020. access_pio_write_data_parity_err_cnt),
  4021. [C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
  4022. CNTR_NORMAL,
  4023. access_pio_host_addr_mem_cor_err_cnt),
  4024. [C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
  4025. CNTR_NORMAL,
  4026. access_pio_host_addr_mem_unc_err_cnt),
  4027. [C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
  4028. CNTR_NORMAL,
  4029. access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
  4030. [C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
  4031. CNTR_NORMAL,
  4032. access_pio_init_sm_in_err_cnt),
  4033. [C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
  4034. CNTR_NORMAL,
  4035. access_pio_ppmc_pbl_fifo_err_cnt),
  4036. [C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
  4037. 0, CNTR_NORMAL,
  4038. access_pio_credit_ret_fifo_parity_err_cnt),
  4039. [C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
  4040. CNTR_NORMAL,
  4041. access_pio_v1_len_mem_bank1_cor_err_cnt),
  4042. [C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
  4043. CNTR_NORMAL,
  4044. access_pio_v1_len_mem_bank0_cor_err_cnt),
  4045. [C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
  4046. CNTR_NORMAL,
  4047. access_pio_v1_len_mem_bank1_unc_err_cnt),
  4048. [C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
  4049. CNTR_NORMAL,
  4050. access_pio_v1_len_mem_bank0_unc_err_cnt),
  4051. [C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
  4052. CNTR_NORMAL,
  4053. access_pio_sm_pkt_reset_parity_err_cnt),
  4054. [C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
  4055. CNTR_NORMAL,
  4056. access_pio_pkt_evict_fifo_parity_err_cnt),
  4057. [C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
  4058. "PioSbrdctrlCrrelFifoParityErr", 0, 0,
  4059. CNTR_NORMAL,
  4060. access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
  4061. [C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
  4062. CNTR_NORMAL,
  4063. access_pio_sbrdctl_crrel_parity_err_cnt),
  4064. [C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
  4065. CNTR_NORMAL,
  4066. access_pio_pec_fifo_parity_err_cnt),
  4067. [C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
  4068. CNTR_NORMAL,
  4069. access_pio_pcc_fifo_parity_err_cnt),
  4070. [C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
  4071. CNTR_NORMAL,
  4072. access_pio_sb_mem_fifo1_err_cnt),
  4073. [C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
  4074. CNTR_NORMAL,
  4075. access_pio_sb_mem_fifo0_err_cnt),
  4076. [C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
  4077. CNTR_NORMAL,
  4078. access_pio_csr_parity_err_cnt),
  4079. [C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
  4080. CNTR_NORMAL,
  4081. access_pio_write_addr_parity_err_cnt),
  4082. [C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
  4083. CNTR_NORMAL,
  4084. access_pio_write_bad_ctxt_err_cnt),
  4085. /* SendDmaErrStatus */
  4086. [C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
  4087. 0, CNTR_NORMAL,
  4088. access_sdma_pcie_req_tracking_cor_err_cnt),
  4089. [C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
  4090. 0, CNTR_NORMAL,
  4091. access_sdma_pcie_req_tracking_unc_err_cnt),
  4092. [C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
  4093. CNTR_NORMAL,
  4094. access_sdma_csr_parity_err_cnt),
  4095. [C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
  4096. CNTR_NORMAL,
  4097. access_sdma_rpy_tag_err_cnt),
  4098. /* SendEgressErrStatus */
  4099. [C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
  4100. CNTR_NORMAL,
  4101. access_tx_read_pio_memory_csr_unc_err_cnt),
  4102. [C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
  4103. 0, CNTR_NORMAL,
  4104. access_tx_read_sdma_memory_csr_err_cnt),
  4105. [C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
  4106. CNTR_NORMAL,
  4107. access_tx_egress_fifo_cor_err_cnt),
  4108. [C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
  4109. CNTR_NORMAL,
  4110. access_tx_read_pio_memory_cor_err_cnt),
  4111. [C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
  4112. CNTR_NORMAL,
  4113. access_tx_read_sdma_memory_cor_err_cnt),
  4114. [C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
  4115. CNTR_NORMAL,
  4116. access_tx_sb_hdr_cor_err_cnt),
  4117. [C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
  4118. CNTR_NORMAL,
  4119. access_tx_credit_overrun_err_cnt),
  4120. [C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
  4121. CNTR_NORMAL,
  4122. access_tx_launch_fifo8_cor_err_cnt),
  4123. [C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
  4124. CNTR_NORMAL,
  4125. access_tx_launch_fifo7_cor_err_cnt),
  4126. [C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
  4127. CNTR_NORMAL,
  4128. access_tx_launch_fifo6_cor_err_cnt),
  4129. [C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
  4130. CNTR_NORMAL,
  4131. access_tx_launch_fifo5_cor_err_cnt),
  4132. [C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
  4133. CNTR_NORMAL,
  4134. access_tx_launch_fifo4_cor_err_cnt),
  4135. [C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
  4136. CNTR_NORMAL,
  4137. access_tx_launch_fifo3_cor_err_cnt),
  4138. [C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
  4139. CNTR_NORMAL,
  4140. access_tx_launch_fifo2_cor_err_cnt),
  4141. [C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
  4142. CNTR_NORMAL,
  4143. access_tx_launch_fifo1_cor_err_cnt),
  4144. [C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
  4145. CNTR_NORMAL,
  4146. access_tx_launch_fifo0_cor_err_cnt),
  4147. [C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
  4148. CNTR_NORMAL,
  4149. access_tx_credit_return_vl_err_cnt),
  4150. [C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
  4151. CNTR_NORMAL,
  4152. access_tx_hcrc_insertion_err_cnt),
  4153. [C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
  4154. CNTR_NORMAL,
  4155. access_tx_egress_fifo_unc_err_cnt),
  4156. [C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
  4157. CNTR_NORMAL,
  4158. access_tx_read_pio_memory_unc_err_cnt),
  4159. [C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
  4160. CNTR_NORMAL,
  4161. access_tx_read_sdma_memory_unc_err_cnt),
  4162. [C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
  4163. CNTR_NORMAL,
  4164. access_tx_sb_hdr_unc_err_cnt),
  4165. [C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
  4166. CNTR_NORMAL,
  4167. access_tx_credit_return_partiy_err_cnt),
  4168. [C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
  4169. 0, 0, CNTR_NORMAL,
  4170. access_tx_launch_fifo8_unc_or_parity_err_cnt),
  4171. [C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
  4172. 0, 0, CNTR_NORMAL,
  4173. access_tx_launch_fifo7_unc_or_parity_err_cnt),
  4174. [C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
  4175. 0, 0, CNTR_NORMAL,
  4176. access_tx_launch_fifo6_unc_or_parity_err_cnt),
  4177. [C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
  4178. 0, 0, CNTR_NORMAL,
  4179. access_tx_launch_fifo5_unc_or_parity_err_cnt),
  4180. [C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
  4181. 0, 0, CNTR_NORMAL,
  4182. access_tx_launch_fifo4_unc_or_parity_err_cnt),
  4183. [C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
  4184. 0, 0, CNTR_NORMAL,
  4185. access_tx_launch_fifo3_unc_or_parity_err_cnt),
  4186. [C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
  4187. 0, 0, CNTR_NORMAL,
  4188. access_tx_launch_fifo2_unc_or_parity_err_cnt),
  4189. [C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
  4190. 0, 0, CNTR_NORMAL,
  4191. access_tx_launch_fifo1_unc_or_parity_err_cnt),
  4192. [C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
  4193. 0, 0, CNTR_NORMAL,
  4194. access_tx_launch_fifo0_unc_or_parity_err_cnt),
  4195. [C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
  4196. 0, 0, CNTR_NORMAL,
  4197. access_tx_sdma15_disallowed_packet_err_cnt),
  4198. [C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
  4199. 0, 0, CNTR_NORMAL,
  4200. access_tx_sdma14_disallowed_packet_err_cnt),
  4201. [C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
  4202. 0, 0, CNTR_NORMAL,
  4203. access_tx_sdma13_disallowed_packet_err_cnt),
  4204. [C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
  4205. 0, 0, CNTR_NORMAL,
  4206. access_tx_sdma12_disallowed_packet_err_cnt),
  4207. [C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
  4208. 0, 0, CNTR_NORMAL,
  4209. access_tx_sdma11_disallowed_packet_err_cnt),
  4210. [C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
  4211. 0, 0, CNTR_NORMAL,
  4212. access_tx_sdma10_disallowed_packet_err_cnt),
  4213. [C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
  4214. 0, 0, CNTR_NORMAL,
  4215. access_tx_sdma9_disallowed_packet_err_cnt),
  4216. [C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
  4217. 0, 0, CNTR_NORMAL,
  4218. access_tx_sdma8_disallowed_packet_err_cnt),
  4219. [C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
  4220. 0, 0, CNTR_NORMAL,
  4221. access_tx_sdma7_disallowed_packet_err_cnt),
  4222. [C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
  4223. 0, 0, CNTR_NORMAL,
  4224. access_tx_sdma6_disallowed_packet_err_cnt),
  4225. [C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
  4226. 0, 0, CNTR_NORMAL,
  4227. access_tx_sdma5_disallowed_packet_err_cnt),
  4228. [C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
  4229. 0, 0, CNTR_NORMAL,
  4230. access_tx_sdma4_disallowed_packet_err_cnt),
  4231. [C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
  4232. 0, 0, CNTR_NORMAL,
  4233. access_tx_sdma3_disallowed_packet_err_cnt),
  4234. [C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
  4235. 0, 0, CNTR_NORMAL,
  4236. access_tx_sdma2_disallowed_packet_err_cnt),
  4237. [C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
  4238. 0, 0, CNTR_NORMAL,
  4239. access_tx_sdma1_disallowed_packet_err_cnt),
  4240. [C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
  4241. 0, 0, CNTR_NORMAL,
  4242. access_tx_sdma0_disallowed_packet_err_cnt),
  4243. [C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
  4244. CNTR_NORMAL,
  4245. access_tx_config_parity_err_cnt),
  4246. [C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
  4247. CNTR_NORMAL,
  4248. access_tx_sbrd_ctl_csr_parity_err_cnt),
  4249. [C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
  4250. CNTR_NORMAL,
  4251. access_tx_launch_csr_parity_err_cnt),
  4252. [C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
  4253. CNTR_NORMAL,
  4254. access_tx_illegal_vl_err_cnt),
  4255. [C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
  4256. "TxSbrdCtlStateMachineParityErr", 0, 0,
  4257. CNTR_NORMAL,
  4258. access_tx_sbrd_ctl_state_machine_parity_err_cnt),
  4259. [C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
  4260. CNTR_NORMAL,
  4261. access_egress_reserved_10_err_cnt),
  4262. [C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
  4263. CNTR_NORMAL,
  4264. access_egress_reserved_9_err_cnt),
  4265. [C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
  4266. 0, 0, CNTR_NORMAL,
  4267. access_tx_sdma_launch_intf_parity_err_cnt),
  4268. [C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
  4269. CNTR_NORMAL,
  4270. access_tx_pio_launch_intf_parity_err_cnt),
  4271. [C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
  4272. CNTR_NORMAL,
  4273. access_egress_reserved_6_err_cnt),
  4274. [C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
  4275. CNTR_NORMAL,
  4276. access_tx_incorrect_link_state_err_cnt),
  4277. [C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
  4278. CNTR_NORMAL,
  4279. access_tx_linkdown_err_cnt),
  4280. [C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
  4281. "EgressFifoUnderrunOrParityErr", 0, 0,
  4282. CNTR_NORMAL,
  4283. access_tx_egress_fifi_underrun_or_parity_err_cnt),
  4284. [C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
  4285. CNTR_NORMAL,
  4286. access_egress_reserved_2_err_cnt),
  4287. [C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
  4288. CNTR_NORMAL,
  4289. access_tx_pkt_integrity_mem_unc_err_cnt),
  4290. [C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
  4291. CNTR_NORMAL,
  4292. access_tx_pkt_integrity_mem_cor_err_cnt),
  4293. /* SendErrStatus */
  4294. [C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
  4295. CNTR_NORMAL,
  4296. access_send_csr_write_bad_addr_err_cnt),
  4297. [C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
  4298. CNTR_NORMAL,
  4299. access_send_csr_read_bad_addr_err_cnt),
  4300. [C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
  4301. CNTR_NORMAL,
  4302. access_send_csr_parity_cnt),
  4303. /* SendCtxtErrStatus */
  4304. [C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
  4305. CNTR_NORMAL,
  4306. access_pio_write_out_of_bounds_err_cnt),
  4307. [C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
  4308. CNTR_NORMAL,
  4309. access_pio_write_overflow_err_cnt),
  4310. [C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
  4311. 0, 0, CNTR_NORMAL,
  4312. access_pio_write_crosses_boundary_err_cnt),
  4313. [C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
  4314. CNTR_NORMAL,
  4315. access_pio_disallowed_packet_err_cnt),
  4316. [C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
  4317. CNTR_NORMAL,
  4318. access_pio_inconsistent_sop_err_cnt),
  4319. /* SendDmaEngErrStatus */
  4320. [C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
  4321. 0, 0, CNTR_NORMAL,
  4322. access_sdma_header_request_fifo_cor_err_cnt),
  4323. [C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
  4324. CNTR_NORMAL,
  4325. access_sdma_header_storage_cor_err_cnt),
  4326. [C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
  4327. CNTR_NORMAL,
  4328. access_sdma_packet_tracking_cor_err_cnt),
  4329. [C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
  4330. CNTR_NORMAL,
  4331. access_sdma_assembly_cor_err_cnt),
  4332. [C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
  4333. CNTR_NORMAL,
  4334. access_sdma_desc_table_cor_err_cnt),
  4335. [C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
  4336. 0, 0, CNTR_NORMAL,
  4337. access_sdma_header_request_fifo_unc_err_cnt),
  4338. [C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
  4339. CNTR_NORMAL,
  4340. access_sdma_header_storage_unc_err_cnt),
  4341. [C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
  4342. CNTR_NORMAL,
  4343. access_sdma_packet_tracking_unc_err_cnt),
  4344. [C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
  4345. CNTR_NORMAL,
  4346. access_sdma_assembly_unc_err_cnt),
  4347. [C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
  4348. CNTR_NORMAL,
  4349. access_sdma_desc_table_unc_err_cnt),
  4350. [C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
  4351. CNTR_NORMAL,
  4352. access_sdma_timeout_err_cnt),
  4353. [C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
  4354. CNTR_NORMAL,
  4355. access_sdma_header_length_err_cnt),
  4356. [C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
  4357. CNTR_NORMAL,
  4358. access_sdma_header_address_err_cnt),
  4359. [C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
  4360. CNTR_NORMAL,
  4361. access_sdma_header_select_err_cnt),
  4362. [C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
  4363. CNTR_NORMAL,
  4364. access_sdma_reserved_9_err_cnt),
  4365. [C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
  4366. CNTR_NORMAL,
  4367. access_sdma_packet_desc_overflow_err_cnt),
  4368. [C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
  4369. CNTR_NORMAL,
  4370. access_sdma_length_mismatch_err_cnt),
  4371. [C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
  4372. CNTR_NORMAL,
  4373. access_sdma_halt_err_cnt),
  4374. [C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
  4375. CNTR_NORMAL,
  4376. access_sdma_mem_read_err_cnt),
  4377. [C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
  4378. CNTR_NORMAL,
  4379. access_sdma_first_desc_err_cnt),
  4380. [C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
  4381. CNTR_NORMAL,
  4382. access_sdma_tail_out_of_bounds_err_cnt),
  4383. [C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
  4384. CNTR_NORMAL,
  4385. access_sdma_too_long_err_cnt),
  4386. [C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
  4387. CNTR_NORMAL,
  4388. access_sdma_gen_mismatch_err_cnt),
  4389. [C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
  4390. CNTR_NORMAL,
  4391. access_sdma_wrong_dw_err_cnt),
  4392. };
  4393. static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
  4394. [C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
  4395. CNTR_NORMAL),
  4396. [C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
  4397. CNTR_NORMAL),
  4398. [C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
  4399. CNTR_NORMAL),
  4400. [C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
  4401. CNTR_NORMAL),
  4402. [C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
  4403. CNTR_NORMAL),
  4404. [C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
  4405. CNTR_NORMAL),
  4406. [C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
  4407. CNTR_NORMAL),
  4408. [C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
  4409. [C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
  4410. [C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
  4411. [C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
  4412. CNTR_SYNTH | CNTR_VL),
  4413. [C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
  4414. CNTR_SYNTH | CNTR_VL),
  4415. [C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
  4416. CNTR_SYNTH | CNTR_VL),
  4417. [C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
  4418. [C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
  4419. [C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4420. access_sw_link_dn_cnt),
  4421. [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4422. access_sw_link_up_cnt),
  4423. [C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
  4424. access_sw_unknown_frame_cnt),
  4425. [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4426. access_sw_xmit_discards),
  4427. [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
  4428. CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
  4429. access_sw_xmit_discards),
  4430. [C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
  4431. access_xmit_constraint_errs),
  4432. [C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
  4433. access_rcv_constraint_errs),
  4434. [C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
  4435. [C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
  4436. [C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
  4437. [C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
  4438. [C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
  4439. [C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
  4440. [C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
  4441. [C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
  4442. [C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
  4443. [C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
  4444. [C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
  4445. [C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
  4446. [C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
  4447. access_sw_cpu_rc_acks),
  4448. [C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
  4449. access_sw_cpu_rc_qacks),
  4450. [C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
  4451. access_sw_cpu_rc_delayed_comp),
  4452. [OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
  4453. [OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
  4454. [OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
  4455. [OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
  4456. [OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
  4457. [OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
  4458. [OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
  4459. [OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
  4460. [OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
  4461. [OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
  4462. [OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
  4463. [OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
  4464. [OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
  4465. [OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
  4466. [OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
  4467. [OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
  4468. [OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
  4469. [OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
  4470. [OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
  4471. [OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
  4472. [OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
  4473. [OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
  4474. [OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
  4475. [OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
  4476. [OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
  4477. [OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
  4478. [OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
  4479. [OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
  4480. [OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
  4481. [OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
  4482. [OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
  4483. [OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
  4484. [OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
  4485. [OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
  4486. [OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
  4487. [OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
  4488. [OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
  4489. [OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
  4490. [OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
  4491. [OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
  4492. [OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
  4493. [OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
  4494. [OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
  4495. [OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
  4496. [OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
  4497. [OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
  4498. [OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
  4499. [OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
  4500. [OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
  4501. [OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
  4502. [OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
  4503. [OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
  4504. [OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
  4505. [OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
  4506. [OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
  4507. [OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
  4508. [OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
  4509. [OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
  4510. [OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
  4511. [OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
  4512. [OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
  4513. [OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
  4514. [OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
  4515. [OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
  4516. [OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
  4517. [OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
  4518. [OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
  4519. [OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
  4520. [OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
  4521. [OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
  4522. [OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
  4523. [OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
  4524. [OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
  4525. [OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
  4526. [OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
  4527. [OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
  4528. [OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
  4529. [OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
  4530. [OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
  4531. [OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
  4532. };
  4533. /* ======================================================================== */
  4534. /* return true if this is chip revision revision a */
  4535. int is_ax(struct hfi1_devdata *dd)
  4536. {
  4537. u8 chip_rev_minor =
  4538. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4539. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4540. return (chip_rev_minor & 0xf0) == 0;
  4541. }
  4542. /* return true if this is chip revision revision b */
  4543. int is_bx(struct hfi1_devdata *dd)
  4544. {
  4545. u8 chip_rev_minor =
  4546. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4547. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4548. return (chip_rev_minor & 0xF0) == 0x10;
  4549. }
  4550. /*
  4551. * Append string s to buffer buf. Arguments curp and len are the current
  4552. * position and remaining length, respectively.
  4553. *
  4554. * return 0 on success, 1 on out of room
  4555. */
  4556. static int append_str(char *buf, char **curp, int *lenp, const char *s)
  4557. {
  4558. char *p = *curp;
  4559. int len = *lenp;
  4560. int result = 0; /* success */
  4561. char c;
  4562. /* add a comma, if first in the buffer */
  4563. if (p != buf) {
  4564. if (len == 0) {
  4565. result = 1; /* out of room */
  4566. goto done;
  4567. }
  4568. *p++ = ',';
  4569. len--;
  4570. }
  4571. /* copy the string */
  4572. while ((c = *s++) != 0) {
  4573. if (len == 0) {
  4574. result = 1; /* out of room */
  4575. goto done;
  4576. }
  4577. *p++ = c;
  4578. len--;
  4579. }
  4580. done:
  4581. /* write return values */
  4582. *curp = p;
  4583. *lenp = len;
  4584. return result;
  4585. }
  4586. /*
  4587. * Using the given flag table, print a comma separated string into
  4588. * the buffer. End in '*' if the buffer is too short.
  4589. */
  4590. static char *flag_string(char *buf, int buf_len, u64 flags,
  4591. struct flag_table *table, int table_size)
  4592. {
  4593. char extra[32];
  4594. char *p = buf;
  4595. int len = buf_len;
  4596. int no_room = 0;
  4597. int i;
  4598. /* make sure there is at least 2 so we can form "*" */
  4599. if (len < 2)
  4600. return "";
  4601. len--; /* leave room for a nul */
  4602. for (i = 0; i < table_size; i++) {
  4603. if (flags & table[i].flag) {
  4604. no_room = append_str(buf, &p, &len, table[i].str);
  4605. if (no_room)
  4606. break;
  4607. flags &= ~table[i].flag;
  4608. }
  4609. }
  4610. /* any undocumented bits left? */
  4611. if (!no_room && flags) {
  4612. snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
  4613. no_room = append_str(buf, &p, &len, extra);
  4614. }
  4615. /* add * if ran out of room */
  4616. if (no_room) {
  4617. /* may need to back up to add space for a '*' */
  4618. if (len == 0)
  4619. --p;
  4620. *p++ = '*';
  4621. }
  4622. /* add final nul - space already allocated above */
  4623. *p = 0;
  4624. return buf;
  4625. }
  4626. /* first 8 CCE error interrupt source names */
  4627. static const char * const cce_misc_names[] = {
  4628. "CceErrInt", /* 0 */
  4629. "RxeErrInt", /* 1 */
  4630. "MiscErrInt", /* 2 */
  4631. "Reserved3", /* 3 */
  4632. "PioErrInt", /* 4 */
  4633. "SDmaErrInt", /* 5 */
  4634. "EgressErrInt", /* 6 */
  4635. "TxeErrInt" /* 7 */
  4636. };
  4637. /*
  4638. * Return the miscellaneous error interrupt name.
  4639. */
  4640. static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
  4641. {
  4642. if (source < ARRAY_SIZE(cce_misc_names))
  4643. strncpy(buf, cce_misc_names[source], bsize);
  4644. else
  4645. snprintf(buf, bsize, "Reserved%u",
  4646. source + IS_GENERAL_ERR_START);
  4647. return buf;
  4648. }
  4649. /*
  4650. * Return the SDMA engine error interrupt name.
  4651. */
  4652. static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
  4653. {
  4654. snprintf(buf, bsize, "SDmaEngErrInt%u", source);
  4655. return buf;
  4656. }
  4657. /*
  4658. * Return the send context error interrupt name.
  4659. */
  4660. static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
  4661. {
  4662. snprintf(buf, bsize, "SendCtxtErrInt%u", source);
  4663. return buf;
  4664. }
  4665. static const char * const various_names[] = {
  4666. "PbcInt",
  4667. "GpioAssertInt",
  4668. "Qsfp1Int",
  4669. "Qsfp2Int",
  4670. "TCritInt"
  4671. };
  4672. /*
  4673. * Return the various interrupt name.
  4674. */
  4675. static char *is_various_name(char *buf, size_t bsize, unsigned int source)
  4676. {
  4677. if (source < ARRAY_SIZE(various_names))
  4678. strncpy(buf, various_names[source], bsize);
  4679. else
  4680. snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
  4681. return buf;
  4682. }
  4683. /*
  4684. * Return the DC interrupt name.
  4685. */
  4686. static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
  4687. {
  4688. static const char * const dc_int_names[] = {
  4689. "common",
  4690. "lcb",
  4691. "8051",
  4692. "lbm" /* local block merge */
  4693. };
  4694. if (source < ARRAY_SIZE(dc_int_names))
  4695. snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
  4696. else
  4697. snprintf(buf, bsize, "DCInt%u", source);
  4698. return buf;
  4699. }
  4700. static const char * const sdma_int_names[] = {
  4701. "SDmaInt",
  4702. "SdmaIdleInt",
  4703. "SdmaProgressInt",
  4704. };
  4705. /*
  4706. * Return the SDMA engine interrupt name.
  4707. */
  4708. static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
  4709. {
  4710. /* what interrupt */
  4711. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  4712. /* which engine */
  4713. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  4714. if (likely(what < 3))
  4715. snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
  4716. else
  4717. snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
  4718. return buf;
  4719. }
  4720. /*
  4721. * Return the receive available interrupt name.
  4722. */
  4723. static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
  4724. {
  4725. snprintf(buf, bsize, "RcvAvailInt%u", source);
  4726. return buf;
  4727. }
  4728. /*
  4729. * Return the receive urgent interrupt name.
  4730. */
  4731. static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
  4732. {
  4733. snprintf(buf, bsize, "RcvUrgentInt%u", source);
  4734. return buf;
  4735. }
  4736. /*
  4737. * Return the send credit interrupt name.
  4738. */
  4739. static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
  4740. {
  4741. snprintf(buf, bsize, "SendCreditInt%u", source);
  4742. return buf;
  4743. }
  4744. /*
  4745. * Return the reserved interrupt name.
  4746. */
  4747. static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
  4748. {
  4749. snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
  4750. return buf;
  4751. }
  4752. static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
  4753. {
  4754. return flag_string(buf, buf_len, flags,
  4755. cce_err_status_flags,
  4756. ARRAY_SIZE(cce_err_status_flags));
  4757. }
  4758. static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
  4759. {
  4760. return flag_string(buf, buf_len, flags,
  4761. rxe_err_status_flags,
  4762. ARRAY_SIZE(rxe_err_status_flags));
  4763. }
  4764. static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
  4765. {
  4766. return flag_string(buf, buf_len, flags, misc_err_status_flags,
  4767. ARRAY_SIZE(misc_err_status_flags));
  4768. }
  4769. static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
  4770. {
  4771. return flag_string(buf, buf_len, flags,
  4772. pio_err_status_flags,
  4773. ARRAY_SIZE(pio_err_status_flags));
  4774. }
  4775. static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
  4776. {
  4777. return flag_string(buf, buf_len, flags,
  4778. sdma_err_status_flags,
  4779. ARRAY_SIZE(sdma_err_status_flags));
  4780. }
  4781. static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
  4782. {
  4783. return flag_string(buf, buf_len, flags,
  4784. egress_err_status_flags,
  4785. ARRAY_SIZE(egress_err_status_flags));
  4786. }
  4787. static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
  4788. {
  4789. return flag_string(buf, buf_len, flags,
  4790. egress_err_info_flags,
  4791. ARRAY_SIZE(egress_err_info_flags));
  4792. }
  4793. static char *send_err_status_string(char *buf, int buf_len, u64 flags)
  4794. {
  4795. return flag_string(buf, buf_len, flags,
  4796. send_err_status_flags,
  4797. ARRAY_SIZE(send_err_status_flags));
  4798. }
  4799. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4800. {
  4801. char buf[96];
  4802. int i = 0;
  4803. /*
  4804. * For most these errors, there is nothing that can be done except
  4805. * report or record it.
  4806. */
  4807. dd_dev_info(dd, "CCE Error: %s\n",
  4808. cce_err_status_string(buf, sizeof(buf), reg));
  4809. if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
  4810. is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
  4811. /* this error requires a manual drop into SPC freeze mode */
  4812. /* then a fix up */
  4813. start_freeze_handling(dd->pport, FREEZE_SELF);
  4814. }
  4815. for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
  4816. if (reg & (1ull << i)) {
  4817. incr_cntr64(&dd->cce_err_status_cnt[i]);
  4818. /* maintain a counter over all cce_err_status errors */
  4819. incr_cntr64(&dd->sw_cce_err_status_aggregate);
  4820. }
  4821. }
  4822. }
  4823. /*
  4824. * Check counters for receive errors that do not have an interrupt
  4825. * associated with them.
  4826. */
  4827. #define RCVERR_CHECK_TIME 10
  4828. static void update_rcverr_timer(unsigned long opaque)
  4829. {
  4830. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  4831. struct hfi1_pportdata *ppd = dd->pport;
  4832. u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  4833. if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
  4834. ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
  4835. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  4836. set_link_down_reason(
  4837. ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
  4838. OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
  4839. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  4840. }
  4841. dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
  4842. mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4843. }
  4844. static int init_rcverr(struct hfi1_devdata *dd)
  4845. {
  4846. setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
  4847. /* Assume the hardware counter has been reset */
  4848. dd->rcv_ovfl_cnt = 0;
  4849. return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4850. }
  4851. static void free_rcverr(struct hfi1_devdata *dd)
  4852. {
  4853. if (dd->rcverr_timer.data)
  4854. del_timer_sync(&dd->rcverr_timer);
  4855. dd->rcverr_timer.data = 0;
  4856. }
  4857. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4858. {
  4859. char buf[96];
  4860. int i = 0;
  4861. dd_dev_info(dd, "Receive Error: %s\n",
  4862. rxe_err_status_string(buf, sizeof(buf), reg));
  4863. if (reg & ALL_RXE_FREEZE_ERR) {
  4864. int flags = 0;
  4865. /*
  4866. * Freeze mode recovery is disabled for the errors
  4867. * in RXE_FREEZE_ABORT_MASK
  4868. */
  4869. if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
  4870. flags = FREEZE_ABORT;
  4871. start_freeze_handling(dd->pport, flags);
  4872. }
  4873. for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
  4874. if (reg & (1ull << i))
  4875. incr_cntr64(&dd->rcv_err_status_cnt[i]);
  4876. }
  4877. }
  4878. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4879. {
  4880. char buf[96];
  4881. int i = 0;
  4882. dd_dev_info(dd, "Misc Error: %s",
  4883. misc_err_status_string(buf, sizeof(buf), reg));
  4884. for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
  4885. if (reg & (1ull << i))
  4886. incr_cntr64(&dd->misc_err_status_cnt[i]);
  4887. }
  4888. }
  4889. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4890. {
  4891. char buf[96];
  4892. int i = 0;
  4893. dd_dev_info(dd, "PIO Error: %s\n",
  4894. pio_err_status_string(buf, sizeof(buf), reg));
  4895. if (reg & ALL_PIO_FREEZE_ERR)
  4896. start_freeze_handling(dd->pport, 0);
  4897. for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
  4898. if (reg & (1ull << i))
  4899. incr_cntr64(&dd->send_pio_err_status_cnt[i]);
  4900. }
  4901. }
  4902. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4903. {
  4904. char buf[96];
  4905. int i = 0;
  4906. dd_dev_info(dd, "SDMA Error: %s\n",
  4907. sdma_err_status_string(buf, sizeof(buf), reg));
  4908. if (reg & ALL_SDMA_FREEZE_ERR)
  4909. start_freeze_handling(dd->pport, 0);
  4910. for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
  4911. if (reg & (1ull << i))
  4912. incr_cntr64(&dd->send_dma_err_status_cnt[i]);
  4913. }
  4914. }
  4915. static inline void __count_port_discards(struct hfi1_pportdata *ppd)
  4916. {
  4917. incr_cntr64(&ppd->port_xmit_discards);
  4918. }
  4919. static void count_port_inactive(struct hfi1_devdata *dd)
  4920. {
  4921. __count_port_discards(dd->pport);
  4922. }
  4923. /*
  4924. * We have had a "disallowed packet" error during egress. Determine the
  4925. * integrity check which failed, and update relevant error counter, etc.
  4926. *
  4927. * Note that the SEND_EGRESS_ERR_INFO register has only a single
  4928. * bit of state per integrity check, and so we can miss the reason for an
  4929. * egress error if more than one packet fails the same integrity check
  4930. * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
  4931. */
  4932. static void handle_send_egress_err_info(struct hfi1_devdata *dd,
  4933. int vl)
  4934. {
  4935. struct hfi1_pportdata *ppd = dd->pport;
  4936. u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
  4937. u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
  4938. char buf[96];
  4939. /* clear down all observed info as quickly as possible after read */
  4940. write_csr(dd, SEND_EGRESS_ERR_INFO, info);
  4941. dd_dev_info(dd,
  4942. "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
  4943. info, egress_err_info_string(buf, sizeof(buf), info), src);
  4944. /* Eventually add other counters for each bit */
  4945. if (info & PORT_DISCARD_EGRESS_ERRS) {
  4946. int weight, i;
  4947. /*
  4948. * Count all applicable bits as individual errors and
  4949. * attribute them to the packet that triggered this handler.
  4950. * This may not be completely accurate due to limitations
  4951. * on the available hardware error information. There is
  4952. * a single information register and any number of error
  4953. * packets may have occurred and contributed to it before
  4954. * this routine is called. This means that:
  4955. * a) If multiple packets with the same error occur before
  4956. * this routine is called, earlier packets are missed.
  4957. * There is only a single bit for each error type.
  4958. * b) Errors may not be attributed to the correct VL.
  4959. * The driver is attributing all bits in the info register
  4960. * to the packet that triggered this call, but bits
  4961. * could be an accumulation of different packets with
  4962. * different VLs.
  4963. * c) A single error packet may have multiple counts attached
  4964. * to it. There is no way for the driver to know if
  4965. * multiple bits set in the info register are due to a
  4966. * single packet or multiple packets. The driver assumes
  4967. * multiple packets.
  4968. */
  4969. weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
  4970. for (i = 0; i < weight; i++) {
  4971. __count_port_discards(ppd);
  4972. if (vl >= 0 && vl < TXE_NUM_DATA_VL)
  4973. incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
  4974. else if (vl == 15)
  4975. incr_cntr64(&ppd->port_xmit_discards_vl
  4976. [C_VL_15]);
  4977. }
  4978. }
  4979. }
  4980. /*
  4981. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4982. * register. Does it represent a 'port inactive' error?
  4983. */
  4984. static inline int port_inactive_err(u64 posn)
  4985. {
  4986. return (posn >= SEES(TX_LINKDOWN) &&
  4987. posn <= SEES(TX_INCORRECT_LINK_STATE));
  4988. }
  4989. /*
  4990. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4991. * register. Does it represent a 'disallowed packet' error?
  4992. */
  4993. static inline int disallowed_pkt_err(int posn)
  4994. {
  4995. return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
  4996. posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
  4997. }
  4998. /*
  4999. * Input value is a bit position of one of the SDMA engine disallowed
  5000. * packet errors. Return which engine. Use of this must be guarded by
  5001. * disallowed_pkt_err().
  5002. */
  5003. static inline int disallowed_pkt_engine(int posn)
  5004. {
  5005. return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
  5006. }
  5007. /*
  5008. * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
  5009. * be done.
  5010. */
  5011. static int engine_to_vl(struct hfi1_devdata *dd, int engine)
  5012. {
  5013. struct sdma_vl_map *m;
  5014. int vl;
  5015. /* range check */
  5016. if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
  5017. return -1;
  5018. rcu_read_lock();
  5019. m = rcu_dereference(dd->sdma_map);
  5020. vl = m->engine_to_vl[engine];
  5021. rcu_read_unlock();
  5022. return vl;
  5023. }
  5024. /*
  5025. * Translate the send context (sofware index) into a VL. Return -1 if the
  5026. * translation cannot be done.
  5027. */
  5028. static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
  5029. {
  5030. struct send_context_info *sci;
  5031. struct send_context *sc;
  5032. int i;
  5033. sci = &dd->send_contexts[sw_index];
  5034. /* there is no information for user (PSM) and ack contexts */
  5035. if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
  5036. return -1;
  5037. sc = sci->sc;
  5038. if (!sc)
  5039. return -1;
  5040. if (dd->vld[15].sc == sc)
  5041. return 15;
  5042. for (i = 0; i < num_vls; i++)
  5043. if (dd->vld[i].sc == sc)
  5044. return i;
  5045. return -1;
  5046. }
  5047. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5048. {
  5049. u64 reg_copy = reg, handled = 0;
  5050. char buf[96];
  5051. int i = 0;
  5052. if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
  5053. start_freeze_handling(dd->pport, 0);
  5054. else if (is_ax(dd) &&
  5055. (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
  5056. (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
  5057. start_freeze_handling(dd->pport, 0);
  5058. while (reg_copy) {
  5059. int posn = fls64(reg_copy);
  5060. /* fls64() returns a 1-based offset, we want it zero based */
  5061. int shift = posn - 1;
  5062. u64 mask = 1ULL << shift;
  5063. if (port_inactive_err(shift)) {
  5064. count_port_inactive(dd);
  5065. handled |= mask;
  5066. } else if (disallowed_pkt_err(shift)) {
  5067. int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
  5068. handle_send_egress_err_info(dd, vl);
  5069. handled |= mask;
  5070. }
  5071. reg_copy &= ~mask;
  5072. }
  5073. reg &= ~handled;
  5074. if (reg)
  5075. dd_dev_info(dd, "Egress Error: %s\n",
  5076. egress_err_status_string(buf, sizeof(buf), reg));
  5077. for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
  5078. if (reg & (1ull << i))
  5079. incr_cntr64(&dd->send_egress_err_status_cnt[i]);
  5080. }
  5081. }
  5082. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5083. {
  5084. char buf[96];
  5085. int i = 0;
  5086. dd_dev_info(dd, "Send Error: %s\n",
  5087. send_err_status_string(buf, sizeof(buf), reg));
  5088. for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
  5089. if (reg & (1ull << i))
  5090. incr_cntr64(&dd->send_err_status_cnt[i]);
  5091. }
  5092. }
  5093. /*
  5094. * The maximum number of times the error clear down will loop before
  5095. * blocking a repeating error. This value is arbitrary.
  5096. */
  5097. #define MAX_CLEAR_COUNT 20
  5098. /*
  5099. * Clear and handle an error register. All error interrupts are funneled
  5100. * through here to have a central location to correctly handle single-
  5101. * or multi-shot errors.
  5102. *
  5103. * For non per-context registers, call this routine with a context value
  5104. * of 0 so the per-context offset is zero.
  5105. *
  5106. * If the handler loops too many times, assume that something is wrong
  5107. * and can't be fixed, so mask the error bits.
  5108. */
  5109. static void interrupt_clear_down(struct hfi1_devdata *dd,
  5110. u32 context,
  5111. const struct err_reg_info *eri)
  5112. {
  5113. u64 reg;
  5114. u32 count;
  5115. /* read in a loop until no more errors are seen */
  5116. count = 0;
  5117. while (1) {
  5118. reg = read_kctxt_csr(dd, context, eri->status);
  5119. if (reg == 0)
  5120. break;
  5121. write_kctxt_csr(dd, context, eri->clear, reg);
  5122. if (likely(eri->handler))
  5123. eri->handler(dd, context, reg);
  5124. count++;
  5125. if (count > MAX_CLEAR_COUNT) {
  5126. u64 mask;
  5127. dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
  5128. eri->desc, reg);
  5129. /*
  5130. * Read-modify-write so any other masked bits
  5131. * remain masked.
  5132. */
  5133. mask = read_kctxt_csr(dd, context, eri->mask);
  5134. mask &= ~reg;
  5135. write_kctxt_csr(dd, context, eri->mask, mask);
  5136. break;
  5137. }
  5138. }
  5139. }
  5140. /*
  5141. * CCE block "misc" interrupt. Source is < 16.
  5142. */
  5143. static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
  5144. {
  5145. const struct err_reg_info *eri = &misc_errs[source];
  5146. if (eri->handler) {
  5147. interrupt_clear_down(dd, 0, eri);
  5148. } else {
  5149. dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
  5150. source);
  5151. }
  5152. }
  5153. static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
  5154. {
  5155. return flag_string(buf, buf_len, flags,
  5156. sc_err_status_flags,
  5157. ARRAY_SIZE(sc_err_status_flags));
  5158. }
  5159. /*
  5160. * Send context error interrupt. Source (hw_context) is < 160.
  5161. *
  5162. * All send context errors cause the send context to halt. The normal
  5163. * clear-down mechanism cannot be used because we cannot clear the
  5164. * error bits until several other long-running items are done first.
  5165. * This is OK because with the context halted, nothing else is going
  5166. * to happen on it anyway.
  5167. */
  5168. static void is_sendctxt_err_int(struct hfi1_devdata *dd,
  5169. unsigned int hw_context)
  5170. {
  5171. struct send_context_info *sci;
  5172. struct send_context *sc;
  5173. char flags[96];
  5174. u64 status;
  5175. u32 sw_index;
  5176. int i = 0;
  5177. sw_index = dd->hw_to_sw[hw_context];
  5178. if (sw_index >= dd->num_send_contexts) {
  5179. dd_dev_err(dd,
  5180. "out of range sw index %u for send context %u\n",
  5181. sw_index, hw_context);
  5182. return;
  5183. }
  5184. sci = &dd->send_contexts[sw_index];
  5185. sc = sci->sc;
  5186. if (!sc) {
  5187. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5188. sw_index, hw_context);
  5189. return;
  5190. }
  5191. /* tell the software that a halt has begun */
  5192. sc_stop(sc, SCF_HALTED);
  5193. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5194. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5195. send_context_err_status_string(flags, sizeof(flags),
  5196. status));
  5197. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5198. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5199. /*
  5200. * Automatically restart halted kernel contexts out of interrupt
  5201. * context. User contexts must ask the driver to restart the context.
  5202. */
  5203. if (sc->type != SC_USER)
  5204. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5205. /*
  5206. * Update the counters for the corresponding status bits.
  5207. * Note that these particular counters are aggregated over all
  5208. * 160 contexts.
  5209. */
  5210. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5211. if (status & (1ull << i))
  5212. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5213. }
  5214. }
  5215. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5216. unsigned int source, u64 status)
  5217. {
  5218. struct sdma_engine *sde;
  5219. int i = 0;
  5220. sde = &dd->per_sdma[source];
  5221. #ifdef CONFIG_SDMA_VERBOSITY
  5222. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5223. slashstrip(__FILE__), __LINE__, __func__);
  5224. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5225. sde->this_idx, source, (unsigned long long)status);
  5226. #endif
  5227. sde->err_cnt++;
  5228. sdma_engine_error(sde, status);
  5229. /*
  5230. * Update the counters for the corresponding status bits.
  5231. * Note that these particular counters are aggregated over
  5232. * all 16 DMA engines.
  5233. */
  5234. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5235. if (status & (1ull << i))
  5236. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5237. }
  5238. }
  5239. /*
  5240. * CCE block SDMA error interrupt. Source is < 16.
  5241. */
  5242. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5243. {
  5244. #ifdef CONFIG_SDMA_VERBOSITY
  5245. struct sdma_engine *sde = &dd->per_sdma[source];
  5246. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5247. slashstrip(__FILE__), __LINE__, __func__);
  5248. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5249. source);
  5250. sdma_dumpstate(sde);
  5251. #endif
  5252. interrupt_clear_down(dd, source, &sdma_eng_err);
  5253. }
  5254. /*
  5255. * CCE block "various" interrupt. Source is < 8.
  5256. */
  5257. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5258. {
  5259. const struct err_reg_info *eri = &various_err[source];
  5260. /*
  5261. * TCritInt cannot go through interrupt_clear_down()
  5262. * because it is not a second tier interrupt. The handler
  5263. * should be called directly.
  5264. */
  5265. if (source == TCRIT_INT_SOURCE)
  5266. handle_temp_err(dd);
  5267. else if (eri->handler)
  5268. interrupt_clear_down(dd, 0, eri);
  5269. else
  5270. dd_dev_info(dd,
  5271. "%s: Unimplemented/reserved interrupt %d\n",
  5272. __func__, source);
  5273. }
  5274. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5275. {
  5276. /* src_ctx is always zero */
  5277. struct hfi1_pportdata *ppd = dd->pport;
  5278. unsigned long flags;
  5279. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5280. if (reg & QSFP_HFI0_MODPRST_N) {
  5281. if (!qsfp_mod_present(ppd)) {
  5282. dd_dev_info(dd, "%s: QSFP module removed\n",
  5283. __func__);
  5284. ppd->driver_link_ready = 0;
  5285. /*
  5286. * Cable removed, reset all our information about the
  5287. * cache and cable capabilities
  5288. */
  5289. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5290. /*
  5291. * We don't set cache_refresh_required here as we expect
  5292. * an interrupt when a cable is inserted
  5293. */
  5294. ppd->qsfp_info.cache_valid = 0;
  5295. ppd->qsfp_info.reset_needed = 0;
  5296. ppd->qsfp_info.limiting_active = 0;
  5297. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5298. flags);
  5299. /* Invert the ModPresent pin now to detect plug-in */
  5300. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5301. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5302. if ((ppd->offline_disabled_reason >
  5303. HFI1_ODR_MASK(
  5304. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5305. (ppd->offline_disabled_reason ==
  5306. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5307. ppd->offline_disabled_reason =
  5308. HFI1_ODR_MASK(
  5309. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5310. if (ppd->host_link_state == HLS_DN_POLL) {
  5311. /*
  5312. * The link is still in POLL. This means
  5313. * that the normal link down processing
  5314. * will not happen. We have to do it here
  5315. * before turning the DC off.
  5316. */
  5317. queue_work(ppd->link_wq, &ppd->link_down_work);
  5318. }
  5319. } else {
  5320. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5321. __func__);
  5322. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5323. ppd->qsfp_info.cache_valid = 0;
  5324. ppd->qsfp_info.cache_refresh_required = 1;
  5325. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5326. flags);
  5327. /*
  5328. * Stop inversion of ModPresent pin to detect
  5329. * removal of the cable
  5330. */
  5331. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5332. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5333. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5334. ppd->offline_disabled_reason =
  5335. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5336. }
  5337. }
  5338. if (reg & QSFP_HFI0_INT_N) {
  5339. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5340. __func__);
  5341. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5342. ppd->qsfp_info.check_interrupt_flags = 1;
  5343. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5344. }
  5345. /* Schedule the QSFP work only if there is a cable attached. */
  5346. if (qsfp_mod_present(ppd))
  5347. queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
  5348. }
  5349. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5350. {
  5351. int ret;
  5352. ret = do_8051_command(dd, HCMD_MISC,
  5353. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5354. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5355. if (ret != HCMD_SUCCESS) {
  5356. dd_dev_err(dd, "%s: command failed with error %d\n",
  5357. __func__, ret);
  5358. }
  5359. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5360. }
  5361. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5362. {
  5363. int ret;
  5364. ret = do_8051_command(dd, HCMD_MISC,
  5365. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5366. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5367. if (ret != HCMD_SUCCESS) {
  5368. dd_dev_err(dd, "%s: command failed with error %d\n",
  5369. __func__, ret);
  5370. }
  5371. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5372. }
  5373. /*
  5374. * Set the LCB selector - allow host access. The DCC selector always
  5375. * points to the host.
  5376. */
  5377. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5378. {
  5379. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5380. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5381. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5382. }
  5383. /*
  5384. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5385. * points to the host.
  5386. */
  5387. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5388. {
  5389. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5390. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5391. }
  5392. /*
  5393. * Acquire LCB access from the 8051. If the host already has access,
  5394. * just increment a counter. Otherwise, inform the 8051 that the
  5395. * host is taking access.
  5396. *
  5397. * Returns:
  5398. * 0 on success
  5399. * -EBUSY if the 8051 has control and cannot be disturbed
  5400. * -errno if unable to acquire access from the 8051
  5401. */
  5402. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5403. {
  5404. struct hfi1_pportdata *ppd = dd->pport;
  5405. int ret = 0;
  5406. /*
  5407. * Use the host link state lock so the operation of this routine
  5408. * { link state check, selector change, count increment } can occur
  5409. * as a unit against a link state change. Otherwise there is a
  5410. * race between the state change and the count increment.
  5411. */
  5412. if (sleep_ok) {
  5413. mutex_lock(&ppd->hls_lock);
  5414. } else {
  5415. while (!mutex_trylock(&ppd->hls_lock))
  5416. udelay(1);
  5417. }
  5418. /* this access is valid only when the link is up */
  5419. if (ppd->host_link_state & HLS_DOWN) {
  5420. dd_dev_info(dd, "%s: link state %s not up\n",
  5421. __func__, link_state_name(ppd->host_link_state));
  5422. ret = -EBUSY;
  5423. goto done;
  5424. }
  5425. if (dd->lcb_access_count == 0) {
  5426. ret = request_host_lcb_access(dd);
  5427. if (ret) {
  5428. dd_dev_err(dd,
  5429. "%s: unable to acquire LCB access, err %d\n",
  5430. __func__, ret);
  5431. goto done;
  5432. }
  5433. set_host_lcb_access(dd);
  5434. }
  5435. dd->lcb_access_count++;
  5436. done:
  5437. mutex_unlock(&ppd->hls_lock);
  5438. return ret;
  5439. }
  5440. /*
  5441. * Release LCB access by decrementing the use count. If the count is moving
  5442. * from 1 to 0, inform 8051 that it has control back.
  5443. *
  5444. * Returns:
  5445. * 0 on success
  5446. * -errno if unable to release access to the 8051
  5447. */
  5448. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5449. {
  5450. int ret = 0;
  5451. /*
  5452. * Use the host link state lock because the acquire needed it.
  5453. * Here, we only need to keep { selector change, count decrement }
  5454. * as a unit.
  5455. */
  5456. if (sleep_ok) {
  5457. mutex_lock(&dd->pport->hls_lock);
  5458. } else {
  5459. while (!mutex_trylock(&dd->pport->hls_lock))
  5460. udelay(1);
  5461. }
  5462. if (dd->lcb_access_count == 0) {
  5463. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5464. __func__);
  5465. goto done;
  5466. }
  5467. if (dd->lcb_access_count == 1) {
  5468. set_8051_lcb_access(dd);
  5469. ret = request_8051_lcb_access(dd);
  5470. if (ret) {
  5471. dd_dev_err(dd,
  5472. "%s: unable to release LCB access, err %d\n",
  5473. __func__, ret);
  5474. /* restore host access if the grant didn't work */
  5475. set_host_lcb_access(dd);
  5476. goto done;
  5477. }
  5478. }
  5479. dd->lcb_access_count--;
  5480. done:
  5481. mutex_unlock(&dd->pport->hls_lock);
  5482. return ret;
  5483. }
  5484. /*
  5485. * Initialize LCB access variables and state. Called during driver load,
  5486. * after most of the initialization is finished.
  5487. *
  5488. * The DC default is LCB access on for the host. The driver defaults to
  5489. * leaving access to the 8051. Assign access now - this constrains the call
  5490. * to this routine to be after all LCB set-up is done. In particular, after
  5491. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5492. */
  5493. static void init_lcb_access(struct hfi1_devdata *dd)
  5494. {
  5495. dd->lcb_access_count = 0;
  5496. }
  5497. /*
  5498. * Write a response back to a 8051 request.
  5499. */
  5500. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5501. {
  5502. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5503. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5504. (u64)return_code <<
  5505. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5506. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5507. }
  5508. /*
  5509. * Handle host requests from the 8051.
  5510. */
  5511. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5512. {
  5513. struct hfi1_devdata *dd = ppd->dd;
  5514. u64 reg;
  5515. u16 data = 0;
  5516. u8 type;
  5517. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5518. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5519. return; /* no request */
  5520. /* zero out COMPLETED so the response is seen */
  5521. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5522. /* extract request details */
  5523. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5524. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5525. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5526. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5527. switch (type) {
  5528. case HREQ_LOAD_CONFIG:
  5529. case HREQ_SAVE_CONFIG:
  5530. case HREQ_READ_CONFIG:
  5531. case HREQ_SET_TX_EQ_ABS:
  5532. case HREQ_SET_TX_EQ_REL:
  5533. case HREQ_ENABLE:
  5534. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5535. type);
  5536. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5537. break;
  5538. case HREQ_CONFIG_DONE:
  5539. hreq_response(dd, HREQ_SUCCESS, 0);
  5540. break;
  5541. case HREQ_INTERFACE_TEST:
  5542. hreq_response(dd, HREQ_SUCCESS, data);
  5543. break;
  5544. default:
  5545. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5546. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5547. break;
  5548. }
  5549. }
  5550. /*
  5551. * Set up allocation unit vaulue.
  5552. */
  5553. void set_up_vau(struct hfi1_devdata *dd, u8 vau)
  5554. {
  5555. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5556. /* do not modify other values in the register */
  5557. reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
  5558. reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
  5559. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5560. }
  5561. /*
  5562. * Set up initial VL15 credits of the remote. Assumes the rest of
  5563. * the CM credit registers are zero from a previous global or credit reset.
  5564. * Shared limit for VL15 will always be 0.
  5565. */
  5566. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
  5567. {
  5568. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5569. /* set initial values for total and shared credit limit */
  5570. reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
  5571. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
  5572. /*
  5573. * Set total limit to be equal to VL15 credits.
  5574. * Leave shared limit at 0.
  5575. */
  5576. reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  5577. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5578. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5579. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5580. }
  5581. /*
  5582. * Zero all credit details from the previous connection and
  5583. * reset the CM manager's internal counters.
  5584. */
  5585. void reset_link_credits(struct hfi1_devdata *dd)
  5586. {
  5587. int i;
  5588. /* remove all previous VL credit limits */
  5589. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5590. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5591. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5592. write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
  5593. /* reset the CM block */
  5594. pio_send_control(dd, PSC_CM_RESET);
  5595. /* reset cached value */
  5596. dd->vl15buf_cached = 0;
  5597. }
  5598. /* convert a vCU to a CU */
  5599. static u32 vcu_to_cu(u8 vcu)
  5600. {
  5601. return 1 << vcu;
  5602. }
  5603. /* convert a CU to a vCU */
  5604. static u8 cu_to_vcu(u32 cu)
  5605. {
  5606. return ilog2(cu);
  5607. }
  5608. /* convert a vAU to an AU */
  5609. static u32 vau_to_au(u8 vau)
  5610. {
  5611. return 8 * (1 << vau);
  5612. }
  5613. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5614. {
  5615. ppd->sm_trap_qp = 0x0;
  5616. ppd->sa_qp = 0x1;
  5617. }
  5618. /*
  5619. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5620. */
  5621. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5622. {
  5623. u64 reg;
  5624. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5625. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5626. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5627. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5628. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5629. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5630. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5631. reg = read_csr(dd, DCC_CFG_RESET);
  5632. write_csr(dd, DCC_CFG_RESET, reg |
  5633. (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
  5634. (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
  5635. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5636. if (!abort) {
  5637. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5638. write_csr(dd, DCC_CFG_RESET, reg);
  5639. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5640. }
  5641. }
  5642. /*
  5643. * This routine should be called after the link has been transitioned to
  5644. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5645. * reset).
  5646. *
  5647. * The expectation is that the caller of this routine would have taken
  5648. * care of properly transitioning the link into the correct state.
  5649. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5650. * before calling this function.
  5651. */
  5652. static void _dc_shutdown(struct hfi1_devdata *dd)
  5653. {
  5654. lockdep_assert_held(&dd->dc8051_lock);
  5655. if (dd->dc_shutdown)
  5656. return;
  5657. dd->dc_shutdown = 1;
  5658. /* Shutdown the LCB */
  5659. lcb_shutdown(dd, 1);
  5660. /*
  5661. * Going to OFFLINE would have causes the 8051 to put the
  5662. * SerDes into reset already. Just need to shut down the 8051,
  5663. * itself.
  5664. */
  5665. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5666. }
  5667. static void dc_shutdown(struct hfi1_devdata *dd)
  5668. {
  5669. mutex_lock(&dd->dc8051_lock);
  5670. _dc_shutdown(dd);
  5671. mutex_unlock(&dd->dc8051_lock);
  5672. }
  5673. /*
  5674. * Calling this after the DC has been brought out of reset should not
  5675. * do any damage.
  5676. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5677. * before calling this function.
  5678. */
  5679. static void _dc_start(struct hfi1_devdata *dd)
  5680. {
  5681. lockdep_assert_held(&dd->dc8051_lock);
  5682. if (!dd->dc_shutdown)
  5683. return;
  5684. /* Take the 8051 out of reset */
  5685. write_csr(dd, DC_DC8051_CFG_RST, 0ull);
  5686. /* Wait until 8051 is ready */
  5687. if (wait_fm_ready(dd, TIMEOUT_8051_START))
  5688. dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
  5689. __func__);
  5690. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5691. write_csr(dd, DCC_CFG_RESET, 0x10);
  5692. /* lcb_shutdown() with abort=1 does not restore these */
  5693. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5694. dd->dc_shutdown = 0;
  5695. }
  5696. static void dc_start(struct hfi1_devdata *dd)
  5697. {
  5698. mutex_lock(&dd->dc8051_lock);
  5699. _dc_start(dd);
  5700. mutex_unlock(&dd->dc8051_lock);
  5701. }
  5702. /*
  5703. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5704. */
  5705. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5706. {
  5707. u64 rx_radr, tx_radr;
  5708. u32 version;
  5709. if (dd->icode != ICODE_FPGA_EMULATION)
  5710. return;
  5711. /*
  5712. * These LCB defaults on emulator _s are good, nothing to do here:
  5713. * LCB_CFG_TX_FIFOS_RADR
  5714. * LCB_CFG_RX_FIFOS_RADR
  5715. * LCB_CFG_LN_DCLK
  5716. * LCB_CFG_IGNORE_LOST_RCLK
  5717. */
  5718. if (is_emulator_s(dd))
  5719. return;
  5720. /* else this is _p */
  5721. version = emulator_rev(dd);
  5722. if (!is_ax(dd))
  5723. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5724. if (version <= 0x12) {
  5725. /* release 0x12 and below */
  5726. /*
  5727. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5728. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5729. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5730. */
  5731. rx_radr =
  5732. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5733. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5734. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5735. /*
  5736. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5737. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5738. */
  5739. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5740. } else if (version <= 0x18) {
  5741. /* release 0x13 up to 0x18 */
  5742. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5743. rx_radr =
  5744. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5745. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5746. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5747. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5748. } else if (version == 0x19) {
  5749. /* release 0x19 */
  5750. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5751. rx_radr =
  5752. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5753. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5754. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5755. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5756. } else if (version == 0x1a) {
  5757. /* release 0x1a */
  5758. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5759. rx_radr =
  5760. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5761. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5762. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5763. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5764. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5765. } else {
  5766. /* release 0x1b and higher */
  5767. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5768. rx_radr =
  5769. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5770. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5771. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5772. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5773. }
  5774. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5775. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5776. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5777. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5778. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5779. }
  5780. /*
  5781. * Handle a SMA idle message
  5782. *
  5783. * This is a work-queue function outside of the interrupt.
  5784. */
  5785. void handle_sma_message(struct work_struct *work)
  5786. {
  5787. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5788. sma_message_work);
  5789. struct hfi1_devdata *dd = ppd->dd;
  5790. u64 msg;
  5791. int ret;
  5792. /*
  5793. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5794. * is stripped off
  5795. */
  5796. ret = read_idle_sma(dd, &msg);
  5797. if (ret)
  5798. return;
  5799. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5800. /*
  5801. * React to the SMA message. Byte[1] (0 for us) is the command.
  5802. */
  5803. switch (msg & 0xff) {
  5804. case SMA_IDLE_ARM:
  5805. /*
  5806. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5807. * State Transitions
  5808. *
  5809. * Only expected in INIT or ARMED, discard otherwise.
  5810. */
  5811. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5812. ppd->neighbor_normal = 1;
  5813. break;
  5814. case SMA_IDLE_ACTIVE:
  5815. /*
  5816. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5817. * State Transitions
  5818. *
  5819. * Can activate the node. Discard otherwise.
  5820. */
  5821. if (ppd->host_link_state == HLS_UP_ARMED &&
  5822. ppd->is_active_optimize_enabled) {
  5823. ppd->neighbor_normal = 1;
  5824. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5825. if (ret)
  5826. dd_dev_err(
  5827. dd,
  5828. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5829. __func__);
  5830. }
  5831. break;
  5832. default:
  5833. dd_dev_err(dd,
  5834. "%s: received unexpected SMA idle message 0x%llx\n",
  5835. __func__, msg);
  5836. break;
  5837. }
  5838. }
  5839. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5840. {
  5841. u64 rcvctrl;
  5842. unsigned long flags;
  5843. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5844. rcvctrl = read_csr(dd, RCV_CTRL);
  5845. rcvctrl |= add;
  5846. rcvctrl &= ~clear;
  5847. write_csr(dd, RCV_CTRL, rcvctrl);
  5848. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5849. }
  5850. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5851. {
  5852. adjust_rcvctrl(dd, add, 0);
  5853. }
  5854. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5855. {
  5856. adjust_rcvctrl(dd, 0, clear);
  5857. }
  5858. /*
  5859. * Called from all interrupt handlers to start handling an SPC freeze.
  5860. */
  5861. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5862. {
  5863. struct hfi1_devdata *dd = ppd->dd;
  5864. struct send_context *sc;
  5865. int i;
  5866. if (flags & FREEZE_SELF)
  5867. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5868. /* enter frozen mode */
  5869. dd->flags |= HFI1_FROZEN;
  5870. /* notify all SDMA engines that they are going into a freeze */
  5871. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5872. /* do halt pre-handling on all enabled send contexts */
  5873. for (i = 0; i < dd->num_send_contexts; i++) {
  5874. sc = dd->send_contexts[i].sc;
  5875. if (sc && (sc->flags & SCF_ENABLED))
  5876. sc_stop(sc, SCF_FROZEN | SCF_HALTED);
  5877. }
  5878. /* Send context are frozen. Notify user space */
  5879. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5880. if (flags & FREEZE_ABORT) {
  5881. dd_dev_err(dd,
  5882. "Aborted freeze recovery. Please REBOOT system\n");
  5883. return;
  5884. }
  5885. /* queue non-interrupt handler */
  5886. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5887. }
  5888. /*
  5889. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5890. * depending on the "freeze" parameter.
  5891. *
  5892. * No need to return an error if it times out, our only option
  5893. * is to proceed anyway.
  5894. */
  5895. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5896. {
  5897. unsigned long timeout;
  5898. u64 reg;
  5899. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5900. while (1) {
  5901. reg = read_csr(dd, CCE_STATUS);
  5902. if (freeze) {
  5903. /* waiting until all indicators are set */
  5904. if ((reg & ALL_FROZE) == ALL_FROZE)
  5905. return; /* all done */
  5906. } else {
  5907. /* waiting until all indicators are clear */
  5908. if ((reg & ALL_FROZE) == 0)
  5909. return; /* all done */
  5910. }
  5911. if (time_after(jiffies, timeout)) {
  5912. dd_dev_err(dd,
  5913. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5914. freeze ? "" : "un", reg & ALL_FROZE,
  5915. freeze ? ALL_FROZE : 0ull);
  5916. return;
  5917. }
  5918. usleep_range(80, 120);
  5919. }
  5920. }
  5921. /*
  5922. * Do all freeze handling for the RXE block.
  5923. */
  5924. static void rxe_freeze(struct hfi1_devdata *dd)
  5925. {
  5926. int i;
  5927. struct hfi1_ctxtdata *rcd;
  5928. /* disable port */
  5929. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5930. /* disable all receive contexts */
  5931. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5932. rcd = hfi1_rcd_get_by_index(dd, i);
  5933. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
  5934. hfi1_rcd_put(rcd);
  5935. }
  5936. }
  5937. /*
  5938. * Unfreeze handling for the RXE block - kernel contexts only.
  5939. * This will also enable the port. User contexts will do unfreeze
  5940. * handling on a per-context basis as they call into the driver.
  5941. *
  5942. */
  5943. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5944. {
  5945. u32 rcvmask;
  5946. u16 i;
  5947. struct hfi1_ctxtdata *rcd;
  5948. /* enable all kernel contexts */
  5949. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5950. rcd = hfi1_rcd_get_by_index(dd, i);
  5951. /* Ensure all non-user contexts(including vnic) are enabled */
  5952. if (!rcd || !rcd->sc || (rcd->sc->type == SC_USER)) {
  5953. hfi1_rcd_put(rcd);
  5954. continue;
  5955. }
  5956. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5957. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5958. rcvmask |= HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
  5959. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5960. hfi1_rcvctrl(dd, rcvmask, rcd);
  5961. hfi1_rcd_put(rcd);
  5962. }
  5963. /* enable port */
  5964. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5965. }
  5966. /*
  5967. * Non-interrupt SPC freeze handling.
  5968. *
  5969. * This is a work-queue function outside of the triggering interrupt.
  5970. */
  5971. void handle_freeze(struct work_struct *work)
  5972. {
  5973. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5974. freeze_work);
  5975. struct hfi1_devdata *dd = ppd->dd;
  5976. /* wait for freeze indicators on all affected blocks */
  5977. wait_for_freeze_status(dd, 1);
  5978. /* SPC is now frozen */
  5979. /* do send PIO freeze steps */
  5980. pio_freeze(dd);
  5981. /* do send DMA freeze steps */
  5982. sdma_freeze(dd);
  5983. /* do send egress freeze steps - nothing to do */
  5984. /* do receive freeze steps */
  5985. rxe_freeze(dd);
  5986. /*
  5987. * Unfreeze the hardware - clear the freeze, wait for each
  5988. * block's frozen bit to clear, then clear the frozen flag.
  5989. */
  5990. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5991. wait_for_freeze_status(dd, 0);
  5992. if (is_ax(dd)) {
  5993. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5994. wait_for_freeze_status(dd, 1);
  5995. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5996. wait_for_freeze_status(dd, 0);
  5997. }
  5998. /* do send PIO unfreeze steps for kernel contexts */
  5999. pio_kernel_unfreeze(dd);
  6000. /* do send DMA unfreeze steps */
  6001. sdma_unfreeze(dd);
  6002. /* do send egress unfreeze steps - nothing to do */
  6003. /* do receive unfreeze steps for kernel contexts */
  6004. rxe_kernel_unfreeze(dd);
  6005. /*
  6006. * The unfreeze procedure touches global device registers when
  6007. * it disables and re-enables RXE. Mark the device unfrozen
  6008. * after all that is done so other parts of the driver waiting
  6009. * for the device to unfreeze don't do things out of order.
  6010. *
  6011. * The above implies that the meaning of HFI1_FROZEN flag is
  6012. * "Device has gone into freeze mode and freeze mode handling
  6013. * is still in progress."
  6014. *
  6015. * The flag will be removed when freeze mode processing has
  6016. * completed.
  6017. */
  6018. dd->flags &= ~HFI1_FROZEN;
  6019. wake_up(&dd->event_queue);
  6020. /* no longer frozen */
  6021. }
  6022. /*
  6023. * Handle a link up interrupt from the 8051.
  6024. *
  6025. * This is a work-queue function outside of the interrupt.
  6026. */
  6027. void handle_link_up(struct work_struct *work)
  6028. {
  6029. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6030. link_up_work);
  6031. struct hfi1_devdata *dd = ppd->dd;
  6032. set_link_state(ppd, HLS_UP_INIT);
  6033. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  6034. read_ltp_rtt(dd);
  6035. /*
  6036. * OPA specifies that certain counters are cleared on a transition
  6037. * to link up, so do that.
  6038. */
  6039. clear_linkup_counters(dd);
  6040. /*
  6041. * And (re)set link up default values.
  6042. */
  6043. set_linkup_defaults(ppd);
  6044. /*
  6045. * Set VL15 credits. Use cached value from verify cap interrupt.
  6046. * In case of quick linkup or simulator, vl15 value will be set by
  6047. * handle_linkup_change. VerifyCap interrupt handler will not be
  6048. * called in those scenarios.
  6049. */
  6050. if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
  6051. set_up_vl15(dd, dd->vl15buf_cached);
  6052. /* enforce link speed enabled */
  6053. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  6054. /* oops - current speed is not enabled, bounce */
  6055. dd_dev_err(dd,
  6056. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  6057. ppd->link_speed_active, ppd->link_speed_enabled);
  6058. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  6059. OPA_LINKDOWN_REASON_SPEED_POLICY);
  6060. set_link_state(ppd, HLS_DN_OFFLINE);
  6061. start_link(ppd);
  6062. }
  6063. }
  6064. /*
  6065. * Several pieces of LNI information were cached for SMA in ppd.
  6066. * Reset these on link down
  6067. */
  6068. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  6069. {
  6070. ppd->neighbor_guid = 0;
  6071. ppd->neighbor_port_number = 0;
  6072. ppd->neighbor_type = 0;
  6073. ppd->neighbor_fm_security = 0;
  6074. }
  6075. static const char * const link_down_reason_strs[] = {
  6076. [OPA_LINKDOWN_REASON_NONE] = "None",
  6077. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
  6078. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  6079. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  6080. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  6081. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  6082. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  6083. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  6084. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  6085. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  6086. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  6087. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  6088. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  6089. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  6090. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  6091. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  6092. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  6093. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  6094. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  6095. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  6096. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  6097. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  6098. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  6099. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  6100. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  6101. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  6102. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  6103. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  6104. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  6105. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  6106. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  6107. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  6108. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  6109. "Excessive buffer overrun",
  6110. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  6111. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  6112. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  6113. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  6114. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  6115. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  6116. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6117. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6118. "Local media not installed",
  6119. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6120. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6121. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6122. "End to end not installed",
  6123. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6124. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6125. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6126. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6127. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6128. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6129. };
  6130. /* return the neighbor link down reason string */
  6131. static const char *link_down_reason_str(u8 reason)
  6132. {
  6133. const char *str = NULL;
  6134. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6135. str = link_down_reason_strs[reason];
  6136. if (!str)
  6137. str = "(invalid)";
  6138. return str;
  6139. }
  6140. /*
  6141. * Handle a link down interrupt from the 8051.
  6142. *
  6143. * This is a work-queue function outside of the interrupt.
  6144. */
  6145. void handle_link_down(struct work_struct *work)
  6146. {
  6147. u8 lcl_reason, neigh_reason = 0;
  6148. u8 link_down_reason;
  6149. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6150. link_down_work);
  6151. int was_up;
  6152. static const char ldr_str[] = "Link down reason: ";
  6153. if ((ppd->host_link_state &
  6154. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6155. ppd->port_type == PORT_TYPE_FIXED)
  6156. ppd->offline_disabled_reason =
  6157. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6158. /* Go offline first, then deal with reading/writing through 8051 */
  6159. was_up = !!(ppd->host_link_state & HLS_UP);
  6160. set_link_state(ppd, HLS_DN_OFFLINE);
  6161. xchg(&ppd->is_link_down_queued, 0);
  6162. if (was_up) {
  6163. lcl_reason = 0;
  6164. /* link down reason is only valid if the link was up */
  6165. read_link_down_reason(ppd->dd, &link_down_reason);
  6166. switch (link_down_reason) {
  6167. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6168. /* the link went down, no idle message reason */
  6169. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6170. ldr_str);
  6171. break;
  6172. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6173. /*
  6174. * The neighbor reason is only valid if an idle message
  6175. * was received for it.
  6176. */
  6177. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6178. dd_dev_info(ppd->dd,
  6179. "%sNeighbor link down message %d, %s\n",
  6180. ldr_str, neigh_reason,
  6181. link_down_reason_str(neigh_reason));
  6182. break;
  6183. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6184. dd_dev_info(ppd->dd,
  6185. "%sHost requested link to go offline\n",
  6186. ldr_str);
  6187. break;
  6188. default:
  6189. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6190. ldr_str, link_down_reason);
  6191. break;
  6192. }
  6193. /*
  6194. * If no reason, assume peer-initiated but missed
  6195. * LinkGoingDown idle flits.
  6196. */
  6197. if (neigh_reason == 0)
  6198. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6199. } else {
  6200. /* went down while polling or going up */
  6201. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6202. }
  6203. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6204. /* inform the SMA when the link transitions from up to down */
  6205. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6206. ppd->neigh_link_down_reason.sma == 0) {
  6207. ppd->local_link_down_reason.sma =
  6208. ppd->local_link_down_reason.latest;
  6209. ppd->neigh_link_down_reason.sma =
  6210. ppd->neigh_link_down_reason.latest;
  6211. }
  6212. reset_neighbor_info(ppd);
  6213. /* disable the port */
  6214. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6215. /*
  6216. * If there is no cable attached, turn the DC off. Otherwise,
  6217. * start the link bring up.
  6218. */
  6219. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6220. dc_shutdown(ppd->dd);
  6221. else
  6222. start_link(ppd);
  6223. }
  6224. void handle_link_bounce(struct work_struct *work)
  6225. {
  6226. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6227. link_bounce_work);
  6228. /*
  6229. * Only do something if the link is currently up.
  6230. */
  6231. if (ppd->host_link_state & HLS_UP) {
  6232. set_link_state(ppd, HLS_DN_OFFLINE);
  6233. start_link(ppd);
  6234. } else {
  6235. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6236. __func__, link_state_name(ppd->host_link_state));
  6237. }
  6238. }
  6239. /*
  6240. * Mask conversion: Capability exchange to Port LTP. The capability
  6241. * exchange has an implicit 16b CRC that is mandatory.
  6242. */
  6243. static int cap_to_port_ltp(int cap)
  6244. {
  6245. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6246. if (cap & CAP_CRC_14B)
  6247. port_ltp |= PORT_LTP_CRC_MODE_14;
  6248. if (cap & CAP_CRC_48B)
  6249. port_ltp |= PORT_LTP_CRC_MODE_48;
  6250. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6251. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6252. return port_ltp;
  6253. }
  6254. /*
  6255. * Convert an OPA Port LTP mask to capability mask
  6256. */
  6257. int port_ltp_to_cap(int port_ltp)
  6258. {
  6259. int cap_mask = 0;
  6260. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6261. cap_mask |= CAP_CRC_14B;
  6262. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6263. cap_mask |= CAP_CRC_48B;
  6264. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6265. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6266. return cap_mask;
  6267. }
  6268. /*
  6269. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6270. */
  6271. static int lcb_to_port_ltp(int lcb_crc)
  6272. {
  6273. int port_ltp = 0;
  6274. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6275. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6276. else if (lcb_crc == LCB_CRC_48B)
  6277. port_ltp = PORT_LTP_CRC_MODE_48;
  6278. else if (lcb_crc == LCB_CRC_14B)
  6279. port_ltp = PORT_LTP_CRC_MODE_14;
  6280. else
  6281. port_ltp = PORT_LTP_CRC_MODE_16;
  6282. return port_ltp;
  6283. }
  6284. /*
  6285. * Our neighbor has indicated that we are allowed to act as a fabric
  6286. * manager, so place the full management partition key in the second
  6287. * (0-based) pkey array position (see OPAv1, section 20.2.2.6.8). Note
  6288. * that we should already have the limited management partition key in
  6289. * array element 1, and also that the port is not yet up when
  6290. * add_full_mgmt_pkey() is invoked.
  6291. */
  6292. static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6293. {
  6294. struct hfi1_devdata *dd = ppd->dd;
  6295. /* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
  6296. if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
  6297. dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
  6298. __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
  6299. ppd->pkeys[2] = FULL_MGMT_P_KEY;
  6300. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6301. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6302. }
  6303. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6304. {
  6305. if (ppd->pkeys[2] != 0) {
  6306. ppd->pkeys[2] = 0;
  6307. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6308. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6309. }
  6310. }
  6311. /*
  6312. * Convert the given link width to the OPA link width bitmask.
  6313. */
  6314. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6315. {
  6316. switch (width) {
  6317. case 0:
  6318. /*
  6319. * Simulator and quick linkup do not set the width.
  6320. * Just set it to 4x without complaint.
  6321. */
  6322. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6323. return OPA_LINK_WIDTH_4X;
  6324. return 0; /* no lanes up */
  6325. case 1: return OPA_LINK_WIDTH_1X;
  6326. case 2: return OPA_LINK_WIDTH_2X;
  6327. case 3: return OPA_LINK_WIDTH_3X;
  6328. default:
  6329. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6330. __func__, width);
  6331. /* fall through */
  6332. case 4: return OPA_LINK_WIDTH_4X;
  6333. }
  6334. }
  6335. /*
  6336. * Do a population count on the bottom nibble.
  6337. */
  6338. static const u8 bit_counts[16] = {
  6339. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6340. };
  6341. static inline u8 nibble_to_count(u8 nibble)
  6342. {
  6343. return bit_counts[nibble & 0xf];
  6344. }
  6345. /*
  6346. * Read the active lane information from the 8051 registers and return
  6347. * their widths.
  6348. *
  6349. * Active lane information is found in these 8051 registers:
  6350. * enable_lane_tx
  6351. * enable_lane_rx
  6352. */
  6353. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6354. u16 *rx_width)
  6355. {
  6356. u16 tx, rx;
  6357. u8 enable_lane_rx;
  6358. u8 enable_lane_tx;
  6359. u8 tx_polarity_inversion;
  6360. u8 rx_polarity_inversion;
  6361. u8 max_rate;
  6362. /* read the active lanes */
  6363. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6364. &rx_polarity_inversion, &max_rate);
  6365. read_local_lni(dd, &enable_lane_rx);
  6366. /* convert to counts */
  6367. tx = nibble_to_count(enable_lane_tx);
  6368. rx = nibble_to_count(enable_lane_rx);
  6369. /*
  6370. * Set link_speed_active here, overriding what was set in
  6371. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6372. * set the max_rate field in handle_verify_cap until v0.19.
  6373. */
  6374. if ((dd->icode == ICODE_RTL_SILICON) &&
  6375. (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
  6376. /* max_rate: 0 = 12.5G, 1 = 25G */
  6377. switch (max_rate) {
  6378. case 0:
  6379. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6380. break;
  6381. default:
  6382. dd_dev_err(dd,
  6383. "%s: unexpected max rate %d, using 25Gb\n",
  6384. __func__, (int)max_rate);
  6385. /* fall through */
  6386. case 1:
  6387. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6388. break;
  6389. }
  6390. }
  6391. dd_dev_info(dd,
  6392. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6393. enable_lane_tx, tx, enable_lane_rx, rx);
  6394. *tx_width = link_width_to_bits(dd, tx);
  6395. *rx_width = link_width_to_bits(dd, rx);
  6396. }
  6397. /*
  6398. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6399. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6400. * after link up. I.e. look elsewhere for downgrade information.
  6401. *
  6402. * Bits are:
  6403. * + bits [7:4] contain the number of active transmitters
  6404. * + bits [3:0] contain the number of active receivers
  6405. * These are numbers 1 through 4 and can be different values if the
  6406. * link is asymmetric.
  6407. *
  6408. * verify_cap_local_fm_link_width[0] retains its original value.
  6409. */
  6410. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6411. u16 *rx_width)
  6412. {
  6413. u16 widths, tx, rx;
  6414. u8 misc_bits, local_flags;
  6415. u16 active_tx, active_rx;
  6416. read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
  6417. tx = widths >> 12;
  6418. rx = (widths >> 8) & 0xf;
  6419. *tx_width = link_width_to_bits(dd, tx);
  6420. *rx_width = link_width_to_bits(dd, rx);
  6421. /* print the active widths */
  6422. get_link_widths(dd, &active_tx, &active_rx);
  6423. }
  6424. /*
  6425. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6426. * hardware information when the link first comes up.
  6427. *
  6428. * The link width is not available until after VerifyCap.AllFramesReceived
  6429. * (the trigger for handle_verify_cap), so this is outside that routine
  6430. * and should be called when the 8051 signals linkup.
  6431. */
  6432. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6433. {
  6434. u16 tx_width, rx_width;
  6435. /* get end-of-LNI link widths */
  6436. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6437. /* use tx_width as the link is supposed to be symmetric on link up */
  6438. ppd->link_width_active = tx_width;
  6439. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6440. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6441. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6442. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6443. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6444. /* cache the active egress rate (units {10^6 bits/sec]) */
  6445. ppd->current_egress_rate = active_egress_rate(ppd);
  6446. }
  6447. /*
  6448. * Handle a verify capabilities interrupt from the 8051.
  6449. *
  6450. * This is a work-queue function outside of the interrupt.
  6451. */
  6452. void handle_verify_cap(struct work_struct *work)
  6453. {
  6454. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6455. link_vc_work);
  6456. struct hfi1_devdata *dd = ppd->dd;
  6457. u64 reg;
  6458. u8 power_management;
  6459. u8 continuous;
  6460. u8 vcu;
  6461. u8 vau;
  6462. u8 z;
  6463. u16 vl15buf;
  6464. u16 link_widths;
  6465. u16 crc_mask;
  6466. u16 crc_val;
  6467. u16 device_id;
  6468. u16 active_tx, active_rx;
  6469. u8 partner_supported_crc;
  6470. u8 remote_tx_rate;
  6471. u8 device_rev;
  6472. set_link_state(ppd, HLS_VERIFY_CAP);
  6473. lcb_shutdown(dd, 0);
  6474. adjust_lcb_for_fpga_serdes(dd);
  6475. read_vc_remote_phy(dd, &power_management, &continuous);
  6476. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6477. &partner_supported_crc);
  6478. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6479. read_remote_device_id(dd, &device_id, &device_rev);
  6480. /*
  6481. * And the 'MgmtAllowed' information, which is exchanged during
  6482. * LNI, is also be available at this point.
  6483. */
  6484. read_mgmt_allowed(dd, &ppd->mgmt_allowed);
  6485. /* print the active widths */
  6486. get_link_widths(dd, &active_tx, &active_rx);
  6487. dd_dev_info(dd,
  6488. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6489. (int)power_management, (int)continuous);
  6490. dd_dev_info(dd,
  6491. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6492. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6493. (int)partner_supported_crc);
  6494. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6495. (u32)remote_tx_rate, (u32)link_widths);
  6496. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6497. (u32)device_id, (u32)device_rev);
  6498. /*
  6499. * The peer vAU value just read is the peer receiver value. HFI does
  6500. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6501. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6502. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6503. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6504. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6505. * subject to the Z value exception.
  6506. */
  6507. if (vau == 0)
  6508. vau = 1;
  6509. set_up_vau(dd, vau);
  6510. /*
  6511. * Set VL15 credits to 0 in global credit register. Cache remote VL15
  6512. * credits value and wait for link-up interrupt ot set it.
  6513. */
  6514. set_up_vl15(dd, 0);
  6515. dd->vl15buf_cached = vl15buf;
  6516. /* set up the LCB CRC mode */
  6517. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6518. /* order is important: use the lowest bit in common */
  6519. if (crc_mask & CAP_CRC_14B)
  6520. crc_val = LCB_CRC_14B;
  6521. else if (crc_mask & CAP_CRC_48B)
  6522. crc_val = LCB_CRC_48B;
  6523. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6524. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6525. else
  6526. crc_val = LCB_CRC_16B;
  6527. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6528. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6529. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6530. /* set (14b only) or clear sideband credit */
  6531. reg = read_csr(dd, SEND_CM_CTRL);
  6532. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6533. write_csr(dd, SEND_CM_CTRL,
  6534. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6535. } else {
  6536. write_csr(dd, SEND_CM_CTRL,
  6537. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6538. }
  6539. ppd->link_speed_active = 0; /* invalid value */
  6540. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  6541. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6542. switch (remote_tx_rate) {
  6543. case 0:
  6544. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6545. break;
  6546. case 1:
  6547. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6548. break;
  6549. }
  6550. } else {
  6551. /* actual rate is highest bit of the ANDed rates */
  6552. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6553. if (rate & 2)
  6554. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6555. else if (rate & 1)
  6556. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6557. }
  6558. if (ppd->link_speed_active == 0) {
  6559. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6560. __func__, (int)remote_tx_rate);
  6561. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6562. }
  6563. /*
  6564. * Cache the values of the supported, enabled, and active
  6565. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6566. * flags that are returned in the portinfo query differ from
  6567. * what's in the link_crc_mask, crc_sizes, and crc_val
  6568. * variables. Convert these here.
  6569. */
  6570. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6571. /* supported crc modes */
  6572. ppd->port_ltp_crc_mode |=
  6573. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6574. /* enabled crc modes */
  6575. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6576. /* active crc mode */
  6577. /* set up the remote credit return table */
  6578. assign_remote_cm_au_table(dd, vcu);
  6579. /*
  6580. * The LCB is reset on entry to handle_verify_cap(), so this must
  6581. * be applied on every link up.
  6582. *
  6583. * Adjust LCB error kill enable to kill the link if
  6584. * these RBUF errors are seen:
  6585. * REPLAY_BUF_MBE_SMASK
  6586. * FLIT_INPUT_BUF_MBE_SMASK
  6587. */
  6588. if (is_ax(dd)) { /* fixed in B0 */
  6589. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6590. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6591. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6592. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6593. }
  6594. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6595. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6596. /* give 8051 access to the LCB CSRs */
  6597. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6598. set_8051_lcb_access(dd);
  6599. if (ppd->mgmt_allowed)
  6600. add_full_mgmt_pkey(ppd);
  6601. /* tell the 8051 to go to LinkUp */
  6602. set_link_state(ppd, HLS_GOING_UP);
  6603. }
  6604. /*
  6605. * Apply the link width downgrade enabled policy against the current active
  6606. * link widths.
  6607. *
  6608. * Called when the enabled policy changes or the active link widths change.
  6609. */
  6610. void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
  6611. {
  6612. int do_bounce = 0;
  6613. int tries;
  6614. u16 lwde;
  6615. u16 tx, rx;
  6616. /* use the hls lock to avoid a race with actual link up */
  6617. tries = 0;
  6618. retry:
  6619. mutex_lock(&ppd->hls_lock);
  6620. /* only apply if the link is up */
  6621. if (ppd->host_link_state & HLS_DOWN) {
  6622. /* still going up..wait and retry */
  6623. if (ppd->host_link_state & HLS_GOING_UP) {
  6624. if (++tries < 1000) {
  6625. mutex_unlock(&ppd->hls_lock);
  6626. usleep_range(100, 120); /* arbitrary */
  6627. goto retry;
  6628. }
  6629. dd_dev_err(ppd->dd,
  6630. "%s: giving up waiting for link state change\n",
  6631. __func__);
  6632. }
  6633. goto done;
  6634. }
  6635. lwde = ppd->link_width_downgrade_enabled;
  6636. if (refresh_widths) {
  6637. get_link_widths(ppd->dd, &tx, &rx);
  6638. ppd->link_width_downgrade_tx_active = tx;
  6639. ppd->link_width_downgrade_rx_active = rx;
  6640. }
  6641. if (ppd->link_width_downgrade_tx_active == 0 ||
  6642. ppd->link_width_downgrade_rx_active == 0) {
  6643. /* the 8051 reported a dead link as a downgrade */
  6644. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6645. } else if (lwde == 0) {
  6646. /* downgrade is disabled */
  6647. /* bounce if not at starting active width */
  6648. if ((ppd->link_width_active !=
  6649. ppd->link_width_downgrade_tx_active) ||
  6650. (ppd->link_width_active !=
  6651. ppd->link_width_downgrade_rx_active)) {
  6652. dd_dev_err(ppd->dd,
  6653. "Link downgrade is disabled and link has downgraded, downing link\n");
  6654. dd_dev_err(ppd->dd,
  6655. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6656. ppd->link_width_active,
  6657. ppd->link_width_downgrade_tx_active,
  6658. ppd->link_width_downgrade_rx_active);
  6659. do_bounce = 1;
  6660. }
  6661. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6662. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6663. /* Tx or Rx is outside the enabled policy */
  6664. dd_dev_err(ppd->dd,
  6665. "Link is outside of downgrade allowed, downing link\n");
  6666. dd_dev_err(ppd->dd,
  6667. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6668. lwde, ppd->link_width_downgrade_tx_active,
  6669. ppd->link_width_downgrade_rx_active);
  6670. do_bounce = 1;
  6671. }
  6672. done:
  6673. mutex_unlock(&ppd->hls_lock);
  6674. if (do_bounce) {
  6675. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6676. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6677. set_link_state(ppd, HLS_DN_OFFLINE);
  6678. start_link(ppd);
  6679. }
  6680. }
  6681. /*
  6682. * Handle a link downgrade interrupt from the 8051.
  6683. *
  6684. * This is a work-queue function outside of the interrupt.
  6685. */
  6686. void handle_link_downgrade(struct work_struct *work)
  6687. {
  6688. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6689. link_downgrade_work);
  6690. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6691. apply_link_downgrade_policy(ppd, 1);
  6692. }
  6693. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6694. {
  6695. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6696. ARRAY_SIZE(dcc_err_flags));
  6697. }
  6698. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6699. {
  6700. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6701. ARRAY_SIZE(lcb_err_flags));
  6702. }
  6703. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6704. {
  6705. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6706. ARRAY_SIZE(dc8051_err_flags));
  6707. }
  6708. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6709. {
  6710. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6711. ARRAY_SIZE(dc8051_info_err_flags));
  6712. }
  6713. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6714. {
  6715. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6716. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6717. }
  6718. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6719. {
  6720. struct hfi1_pportdata *ppd = dd->pport;
  6721. u64 info, err, host_msg;
  6722. int queue_link_down = 0;
  6723. char buf[96];
  6724. /* look at the flags */
  6725. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6726. /* 8051 information set by firmware */
  6727. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6728. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6729. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6730. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6731. host_msg = (info >>
  6732. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6733. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6734. /*
  6735. * Handle error flags.
  6736. */
  6737. if (err & FAILED_LNI) {
  6738. /*
  6739. * LNI error indications are cleared by the 8051
  6740. * only when starting polling. Only pay attention
  6741. * to them when in the states that occur during
  6742. * LNI.
  6743. */
  6744. if (ppd->host_link_state
  6745. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6746. queue_link_down = 1;
  6747. dd_dev_info(dd, "Link error: %s\n",
  6748. dc8051_info_err_string(buf,
  6749. sizeof(buf),
  6750. err &
  6751. FAILED_LNI));
  6752. }
  6753. err &= ~(u64)FAILED_LNI;
  6754. }
  6755. /* unknown frames can happen durning LNI, just count */
  6756. if (err & UNKNOWN_FRAME) {
  6757. ppd->unknown_frame_count++;
  6758. err &= ~(u64)UNKNOWN_FRAME;
  6759. }
  6760. if (err) {
  6761. /* report remaining errors, but do not do anything */
  6762. dd_dev_err(dd, "8051 info error: %s\n",
  6763. dc8051_info_err_string(buf, sizeof(buf),
  6764. err));
  6765. }
  6766. /*
  6767. * Handle host message flags.
  6768. */
  6769. if (host_msg & HOST_REQ_DONE) {
  6770. /*
  6771. * Presently, the driver does a busy wait for
  6772. * host requests to complete. This is only an
  6773. * informational message.
  6774. * NOTE: The 8051 clears the host message
  6775. * information *on the next 8051 command*.
  6776. * Therefore, when linkup is achieved,
  6777. * this flag will still be set.
  6778. */
  6779. host_msg &= ~(u64)HOST_REQ_DONE;
  6780. }
  6781. if (host_msg & BC_SMA_MSG) {
  6782. queue_work(ppd->link_wq, &ppd->sma_message_work);
  6783. host_msg &= ~(u64)BC_SMA_MSG;
  6784. }
  6785. if (host_msg & LINKUP_ACHIEVED) {
  6786. dd_dev_info(dd, "8051: Link up\n");
  6787. queue_work(ppd->link_wq, &ppd->link_up_work);
  6788. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6789. }
  6790. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6791. handle_8051_request(ppd);
  6792. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6793. }
  6794. if (host_msg & VERIFY_CAP_FRAME) {
  6795. queue_work(ppd->link_wq, &ppd->link_vc_work);
  6796. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6797. }
  6798. if (host_msg & LINK_GOING_DOWN) {
  6799. const char *extra = "";
  6800. /* no downgrade action needed if going down */
  6801. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6802. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6803. extra = " (ignoring downgrade)";
  6804. }
  6805. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6806. queue_link_down = 1;
  6807. host_msg &= ~(u64)LINK_GOING_DOWN;
  6808. }
  6809. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6810. queue_work(ppd->link_wq, &ppd->link_downgrade_work);
  6811. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6812. }
  6813. if (host_msg) {
  6814. /* report remaining messages, but do not do anything */
  6815. dd_dev_info(dd, "8051 info host message: %s\n",
  6816. dc8051_info_host_msg_string(buf,
  6817. sizeof(buf),
  6818. host_msg));
  6819. }
  6820. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6821. }
  6822. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6823. /*
  6824. * Lost the 8051 heartbeat. If this happens, we
  6825. * receive constant interrupts about it. Disable
  6826. * the interrupt after the first.
  6827. */
  6828. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6829. write_csr(dd, DC_DC8051_ERR_EN,
  6830. read_csr(dd, DC_DC8051_ERR_EN) &
  6831. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6832. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6833. }
  6834. if (reg) {
  6835. /* report the error, but do not do anything */
  6836. dd_dev_err(dd, "8051 error: %s\n",
  6837. dc8051_err_string(buf, sizeof(buf), reg));
  6838. }
  6839. if (queue_link_down) {
  6840. /*
  6841. * if the link is already going down or disabled, do not
  6842. * queue another. If there's a link down entry already
  6843. * queued, don't queue another one.
  6844. */
  6845. if ((ppd->host_link_state &
  6846. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6847. ppd->link_enabled == 0) {
  6848. dd_dev_info(dd, "%s: not queuing link down. host_link_state %x, link_enabled %x\n",
  6849. __func__, ppd->host_link_state,
  6850. ppd->link_enabled);
  6851. } else {
  6852. if (xchg(&ppd->is_link_down_queued, 1) == 1)
  6853. dd_dev_info(dd,
  6854. "%s: link down request already queued\n",
  6855. __func__);
  6856. else
  6857. queue_work(ppd->link_wq, &ppd->link_down_work);
  6858. }
  6859. }
  6860. }
  6861. static const char * const fm_config_txt[] = {
  6862. [0] =
  6863. "BadHeadDist: Distance violation between two head flits",
  6864. [1] =
  6865. "BadTailDist: Distance violation between two tail flits",
  6866. [2] =
  6867. "BadCtrlDist: Distance violation between two credit control flits",
  6868. [3] =
  6869. "BadCrdAck: Credits return for unsupported VL",
  6870. [4] =
  6871. "UnsupportedVLMarker: Received VL Marker",
  6872. [5] =
  6873. "BadPreempt: Exceeded the preemption nesting level",
  6874. [6] =
  6875. "BadControlFlit: Received unsupported control flit",
  6876. /* no 7 */
  6877. [8] =
  6878. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6879. };
  6880. static const char * const port_rcv_txt[] = {
  6881. [1] =
  6882. "BadPktLen: Illegal PktLen",
  6883. [2] =
  6884. "PktLenTooLong: Packet longer than PktLen",
  6885. [3] =
  6886. "PktLenTooShort: Packet shorter than PktLen",
  6887. [4] =
  6888. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6889. [5] =
  6890. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6891. [6] =
  6892. "BadL2: Illegal L2 opcode",
  6893. [7] =
  6894. "BadSC: Unsupported SC",
  6895. [9] =
  6896. "BadRC: Illegal RC",
  6897. [11] =
  6898. "PreemptError: Preempting with same VL",
  6899. [12] =
  6900. "PreemptVL15: Preempting a VL15 packet",
  6901. };
  6902. #define OPA_LDR_FMCONFIG_OFFSET 16
  6903. #define OPA_LDR_PORTRCV_OFFSET 0
  6904. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6905. {
  6906. u64 info, hdr0, hdr1;
  6907. const char *extra;
  6908. char buf[96];
  6909. struct hfi1_pportdata *ppd = dd->pport;
  6910. u8 lcl_reason = 0;
  6911. int do_bounce = 0;
  6912. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6913. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6914. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6915. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6916. /* set status bit */
  6917. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6918. }
  6919. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6920. }
  6921. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6922. struct hfi1_pportdata *ppd = dd->pport;
  6923. /* this counter saturates at (2^32) - 1 */
  6924. if (ppd->link_downed < (u32)UINT_MAX)
  6925. ppd->link_downed++;
  6926. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6927. }
  6928. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6929. u8 reason_valid = 1;
  6930. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6931. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6932. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6933. /* set status bit */
  6934. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6935. }
  6936. switch (info) {
  6937. case 0:
  6938. case 1:
  6939. case 2:
  6940. case 3:
  6941. case 4:
  6942. case 5:
  6943. case 6:
  6944. extra = fm_config_txt[info];
  6945. break;
  6946. case 8:
  6947. extra = fm_config_txt[info];
  6948. if (ppd->port_error_action &
  6949. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6950. do_bounce = 1;
  6951. /*
  6952. * lcl_reason cannot be derived from info
  6953. * for this error
  6954. */
  6955. lcl_reason =
  6956. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6957. }
  6958. break;
  6959. default:
  6960. reason_valid = 0;
  6961. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6962. extra = buf;
  6963. break;
  6964. }
  6965. if (reason_valid && !do_bounce) {
  6966. do_bounce = ppd->port_error_action &
  6967. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6968. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  6969. }
  6970. /* just report this */
  6971. dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
  6972. extra);
  6973. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  6974. }
  6975. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  6976. u8 reason_valid = 1;
  6977. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  6978. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  6979. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  6980. if (!(dd->err_info_rcvport.status_and_code &
  6981. OPA_EI_STATUS_SMASK)) {
  6982. dd->err_info_rcvport.status_and_code =
  6983. info & OPA_EI_CODE_SMASK;
  6984. /* set status bit */
  6985. dd->err_info_rcvport.status_and_code |=
  6986. OPA_EI_STATUS_SMASK;
  6987. /*
  6988. * save first 2 flits in the packet that caused
  6989. * the error
  6990. */
  6991. dd->err_info_rcvport.packet_flit1 = hdr0;
  6992. dd->err_info_rcvport.packet_flit2 = hdr1;
  6993. }
  6994. switch (info) {
  6995. case 1:
  6996. case 2:
  6997. case 3:
  6998. case 4:
  6999. case 5:
  7000. case 6:
  7001. case 7:
  7002. case 9:
  7003. case 11:
  7004. case 12:
  7005. extra = port_rcv_txt[info];
  7006. break;
  7007. default:
  7008. reason_valid = 0;
  7009. snprintf(buf, sizeof(buf), "reserved%lld", info);
  7010. extra = buf;
  7011. break;
  7012. }
  7013. if (reason_valid && !do_bounce) {
  7014. do_bounce = ppd->port_error_action &
  7015. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  7016. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  7017. }
  7018. /* just report this */
  7019. dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
  7020. " hdr0 0x%llx, hdr1 0x%llx\n",
  7021. extra, hdr0, hdr1);
  7022. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  7023. }
  7024. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  7025. /* informative only */
  7026. dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
  7027. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  7028. }
  7029. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  7030. /* informative only */
  7031. dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
  7032. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  7033. }
  7034. if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
  7035. reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
  7036. /* report any remaining errors */
  7037. if (reg)
  7038. dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
  7039. dcc_err_string(buf, sizeof(buf), reg));
  7040. if (lcl_reason == 0)
  7041. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  7042. if (do_bounce) {
  7043. dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
  7044. __func__);
  7045. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  7046. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  7047. }
  7048. }
  7049. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  7050. {
  7051. char buf[96];
  7052. dd_dev_info(dd, "LCB Error: %s\n",
  7053. lcb_err_string(buf, sizeof(buf), reg));
  7054. }
  7055. /*
  7056. * CCE block DC interrupt. Source is < 8.
  7057. */
  7058. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  7059. {
  7060. const struct err_reg_info *eri = &dc_errs[source];
  7061. if (eri->handler) {
  7062. interrupt_clear_down(dd, 0, eri);
  7063. } else if (source == 3 /* dc_lbm_int */) {
  7064. /*
  7065. * This indicates that a parity error has occurred on the
  7066. * address/control lines presented to the LBM. The error
  7067. * is a single pulse, there is no associated error flag,
  7068. * and it is non-maskable. This is because if a parity
  7069. * error occurs on the request the request is dropped.
  7070. * This should never occur, but it is nice to know if it
  7071. * ever does.
  7072. */
  7073. dd_dev_err(dd, "Parity error in DC LBM block\n");
  7074. } else {
  7075. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  7076. }
  7077. }
  7078. /*
  7079. * TX block send credit interrupt. Source is < 160.
  7080. */
  7081. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  7082. {
  7083. sc_group_release_update(dd, source);
  7084. }
  7085. /*
  7086. * TX block SDMA interrupt. Source is < 48.
  7087. *
  7088. * SDMA interrupts are grouped by type:
  7089. *
  7090. * 0 - N-1 = SDma
  7091. * N - 2N-1 = SDmaProgress
  7092. * 2N - 3N-1 = SDmaIdle
  7093. */
  7094. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  7095. {
  7096. /* what interrupt */
  7097. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  7098. /* which engine */
  7099. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  7100. #ifdef CONFIG_SDMA_VERBOSITY
  7101. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  7102. slashstrip(__FILE__), __LINE__, __func__);
  7103. sdma_dumpstate(&dd->per_sdma[which]);
  7104. #endif
  7105. if (likely(what < 3 && which < dd->num_sdma)) {
  7106. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  7107. } else {
  7108. /* should not happen */
  7109. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  7110. }
  7111. }
  7112. /*
  7113. * RX block receive available interrupt. Source is < 160.
  7114. */
  7115. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7116. {
  7117. struct hfi1_ctxtdata *rcd;
  7118. char *err_detail;
  7119. if (likely(source < dd->num_rcv_contexts)) {
  7120. rcd = hfi1_rcd_get_by_index(dd, source);
  7121. if (rcd) {
  7122. /* Check for non-user contexts, including vnic */
  7123. if ((source < dd->first_dyn_alloc_ctxt) ||
  7124. (rcd->sc && (rcd->sc->type == SC_KERNEL)))
  7125. rcd->do_interrupt(rcd, 0);
  7126. else
  7127. handle_user_interrupt(rcd);
  7128. hfi1_rcd_put(rcd);
  7129. return; /* OK */
  7130. }
  7131. /* received an interrupt, but no rcd */
  7132. err_detail = "dataless";
  7133. } else {
  7134. /* received an interrupt, but are not using that context */
  7135. err_detail = "out of range";
  7136. }
  7137. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7138. err_detail, source);
  7139. }
  7140. /*
  7141. * RX block receive urgent interrupt. Source is < 160.
  7142. */
  7143. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7144. {
  7145. struct hfi1_ctxtdata *rcd;
  7146. char *err_detail;
  7147. if (likely(source < dd->num_rcv_contexts)) {
  7148. rcd = hfi1_rcd_get_by_index(dd, source);
  7149. if (rcd) {
  7150. /* only pay attention to user urgent interrupts */
  7151. if ((source >= dd->first_dyn_alloc_ctxt) &&
  7152. (!rcd->sc || (rcd->sc->type == SC_USER)))
  7153. handle_user_interrupt(rcd);
  7154. hfi1_rcd_put(rcd);
  7155. return; /* OK */
  7156. }
  7157. /* received an interrupt, but no rcd */
  7158. err_detail = "dataless";
  7159. } else {
  7160. /* received an interrupt, but are not using that context */
  7161. err_detail = "out of range";
  7162. }
  7163. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7164. err_detail, source);
  7165. }
  7166. /*
  7167. * Reserved range interrupt. Should not be called in normal operation.
  7168. */
  7169. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7170. {
  7171. char name[64];
  7172. dd_dev_err(dd, "unexpected %s interrupt\n",
  7173. is_reserved_name(name, sizeof(name), source));
  7174. }
  7175. static const struct is_table is_table[] = {
  7176. /*
  7177. * start end
  7178. * name func interrupt func
  7179. */
  7180. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7181. is_misc_err_name, is_misc_err_int },
  7182. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7183. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7184. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7185. is_sendctxt_err_name, is_sendctxt_err_int },
  7186. { IS_SDMA_START, IS_SDMA_END,
  7187. is_sdma_eng_name, is_sdma_eng_int },
  7188. { IS_VARIOUS_START, IS_VARIOUS_END,
  7189. is_various_name, is_various_int },
  7190. { IS_DC_START, IS_DC_END,
  7191. is_dc_name, is_dc_int },
  7192. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7193. is_rcv_avail_name, is_rcv_avail_int },
  7194. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7195. is_rcv_urgent_name, is_rcv_urgent_int },
  7196. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7197. is_send_credit_name, is_send_credit_int},
  7198. { IS_RESERVED_START, IS_RESERVED_END,
  7199. is_reserved_name, is_reserved_int},
  7200. };
  7201. /*
  7202. * Interrupt source interrupt - called when the given source has an interrupt.
  7203. * Source is a bit index into an array of 64-bit integers.
  7204. */
  7205. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7206. {
  7207. const struct is_table *entry;
  7208. /* avoids a double compare by walking the table in-order */
  7209. for (entry = &is_table[0]; entry->is_name; entry++) {
  7210. if (source < entry->end) {
  7211. trace_hfi1_interrupt(dd, entry, source);
  7212. entry->is_int(dd, source - entry->start);
  7213. return;
  7214. }
  7215. }
  7216. /* fell off the end */
  7217. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7218. }
  7219. /*
  7220. * General interrupt handler. This is able to correctly handle
  7221. * all interrupts in case INTx is used.
  7222. */
  7223. static irqreturn_t general_interrupt(int irq, void *data)
  7224. {
  7225. struct hfi1_devdata *dd = data;
  7226. u64 regs[CCE_NUM_INT_CSRS];
  7227. u32 bit;
  7228. int i;
  7229. irqreturn_t handled = IRQ_NONE;
  7230. this_cpu_inc(*dd->int_counter);
  7231. /* phase 1: scan and clear all handled interrupts */
  7232. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7233. if (dd->gi_mask[i] == 0) {
  7234. regs[i] = 0; /* used later */
  7235. continue;
  7236. }
  7237. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7238. dd->gi_mask[i];
  7239. /* only clear if anything is set */
  7240. if (regs[i])
  7241. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7242. }
  7243. /* phase 2: call the appropriate handler */
  7244. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7245. CCE_NUM_INT_CSRS * 64) {
  7246. is_interrupt(dd, bit);
  7247. handled = IRQ_HANDLED;
  7248. }
  7249. return handled;
  7250. }
  7251. static irqreturn_t sdma_interrupt(int irq, void *data)
  7252. {
  7253. struct sdma_engine *sde = data;
  7254. struct hfi1_devdata *dd = sde->dd;
  7255. u64 status;
  7256. #ifdef CONFIG_SDMA_VERBOSITY
  7257. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7258. slashstrip(__FILE__), __LINE__, __func__);
  7259. sdma_dumpstate(sde);
  7260. #endif
  7261. this_cpu_inc(*dd->int_counter);
  7262. /* This read_csr is really bad in the hot path */
  7263. status = read_csr(dd,
  7264. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7265. & sde->imask;
  7266. if (likely(status)) {
  7267. /* clear the interrupt(s) */
  7268. write_csr(dd,
  7269. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7270. status);
  7271. /* handle the interrupt(s) */
  7272. sdma_engine_interrupt(sde, status);
  7273. } else {
  7274. dd_dev_err_ratelimited(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7275. sde->this_idx);
  7276. }
  7277. return IRQ_HANDLED;
  7278. }
  7279. /*
  7280. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7281. * to insure that the write completed. This does NOT guarantee that
  7282. * queued DMA writes to memory from the chip are pushed.
  7283. */
  7284. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7285. {
  7286. struct hfi1_devdata *dd = rcd->dd;
  7287. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7288. mmiowb(); /* make sure everything before is written */
  7289. write_csr(dd, addr, rcd->imask);
  7290. /* force the above write on the chip and get a value back */
  7291. (void)read_csr(dd, addr);
  7292. }
  7293. /* force the receive interrupt */
  7294. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7295. {
  7296. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7297. }
  7298. /*
  7299. * Return non-zero if a packet is present.
  7300. *
  7301. * This routine is called when rechecking for packets after the RcvAvail
  7302. * interrupt has been cleared down. First, do a quick check of memory for
  7303. * a packet present. If not found, use an expensive CSR read of the context
  7304. * tail to determine the actual tail. The CSR read is necessary because there
  7305. * is no method to push pending DMAs to memory other than an interrupt and we
  7306. * are trying to determine if we need to force an interrupt.
  7307. */
  7308. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7309. {
  7310. u32 tail;
  7311. int present;
  7312. if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
  7313. present = (rcd->seq_cnt ==
  7314. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7315. else /* is RDMA rtail */
  7316. present = (rcd->head != get_rcvhdrtail(rcd));
  7317. if (present)
  7318. return 1;
  7319. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7320. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7321. return rcd->head != tail;
  7322. }
  7323. /*
  7324. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7325. * This routine will try to handle packets immediately (latency), but if
  7326. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7327. * chip receive interrupt is *not* cleared down until this or the thread (if
  7328. * invoked) is finished. The intent is to avoid extra interrupts while we
  7329. * are processing packets anyway.
  7330. */
  7331. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7332. {
  7333. struct hfi1_ctxtdata *rcd = data;
  7334. struct hfi1_devdata *dd = rcd->dd;
  7335. int disposition;
  7336. int present;
  7337. trace_hfi1_receive_interrupt(dd, rcd);
  7338. this_cpu_inc(*dd->int_counter);
  7339. aspm_ctx_disable(rcd);
  7340. /* receive interrupt remains blocked while processing packets */
  7341. disposition = rcd->do_interrupt(rcd, 0);
  7342. /*
  7343. * Too many packets were seen while processing packets in this
  7344. * IRQ handler. Invoke the handler thread. The receive interrupt
  7345. * remains blocked.
  7346. */
  7347. if (disposition == RCV_PKT_LIMIT)
  7348. return IRQ_WAKE_THREAD;
  7349. /*
  7350. * The packet processor detected no more packets. Clear the receive
  7351. * interrupt and recheck for a packet packet that may have arrived
  7352. * after the previous check and interrupt clear. If a packet arrived,
  7353. * force another interrupt.
  7354. */
  7355. clear_recv_intr(rcd);
  7356. present = check_packet_present(rcd);
  7357. if (present)
  7358. force_recv_intr(rcd);
  7359. return IRQ_HANDLED;
  7360. }
  7361. /*
  7362. * Receive packet thread handler. This expects to be invoked with the
  7363. * receive interrupt still blocked.
  7364. */
  7365. static irqreturn_t receive_context_thread(int irq, void *data)
  7366. {
  7367. struct hfi1_ctxtdata *rcd = data;
  7368. int present;
  7369. /* receive interrupt is still blocked from the IRQ handler */
  7370. (void)rcd->do_interrupt(rcd, 1);
  7371. /*
  7372. * The packet processor will only return if it detected no more
  7373. * packets. Hold IRQs here so we can safely clear the interrupt and
  7374. * recheck for a packet that may have arrived after the previous
  7375. * check and the interrupt clear. If a packet arrived, force another
  7376. * interrupt.
  7377. */
  7378. local_irq_disable();
  7379. clear_recv_intr(rcd);
  7380. present = check_packet_present(rcd);
  7381. if (present)
  7382. force_recv_intr(rcd);
  7383. local_irq_enable();
  7384. return IRQ_HANDLED;
  7385. }
  7386. /* ========================================================================= */
  7387. u32 read_physical_state(struct hfi1_devdata *dd)
  7388. {
  7389. u64 reg;
  7390. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7391. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7392. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7393. }
  7394. u32 read_logical_state(struct hfi1_devdata *dd)
  7395. {
  7396. u64 reg;
  7397. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7398. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7399. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7400. }
  7401. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7402. {
  7403. u64 reg;
  7404. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7405. /* clear current state, set new state */
  7406. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7407. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7408. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7409. }
  7410. /*
  7411. * Use the 8051 to read a LCB CSR.
  7412. */
  7413. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7414. {
  7415. u32 regno;
  7416. int ret;
  7417. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7418. if (acquire_lcb_access(dd, 0) == 0) {
  7419. *data = read_csr(dd, addr);
  7420. release_lcb_access(dd, 0);
  7421. return 0;
  7422. }
  7423. return -EBUSY;
  7424. }
  7425. /* register is an index of LCB registers: (offset - base) / 8 */
  7426. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7427. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7428. if (ret != HCMD_SUCCESS)
  7429. return -EBUSY;
  7430. return 0;
  7431. }
  7432. /*
  7433. * Provide a cache for some of the LCB registers in case the LCB is
  7434. * unavailable.
  7435. * (The LCB is unavailable in certain link states, for example.)
  7436. */
  7437. struct lcb_datum {
  7438. u32 off;
  7439. u64 val;
  7440. };
  7441. static struct lcb_datum lcb_cache[] = {
  7442. { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
  7443. { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
  7444. { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
  7445. };
  7446. static void update_lcb_cache(struct hfi1_devdata *dd)
  7447. {
  7448. int i;
  7449. int ret;
  7450. u64 val;
  7451. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7452. ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
  7453. /* Update if we get good data */
  7454. if (likely(ret != -EBUSY))
  7455. lcb_cache[i].val = val;
  7456. }
  7457. }
  7458. static int read_lcb_cache(u32 off, u64 *val)
  7459. {
  7460. int i;
  7461. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7462. if (lcb_cache[i].off == off) {
  7463. *val = lcb_cache[i].val;
  7464. return 0;
  7465. }
  7466. }
  7467. pr_warn("%s bad offset 0x%x\n", __func__, off);
  7468. return -1;
  7469. }
  7470. /*
  7471. * Read an LCB CSR. Access may not be in host control, so check.
  7472. * Return 0 on success, -EBUSY on failure.
  7473. */
  7474. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7475. {
  7476. struct hfi1_pportdata *ppd = dd->pport;
  7477. /* if up, go through the 8051 for the value */
  7478. if (ppd->host_link_state & HLS_UP)
  7479. return read_lcb_via_8051(dd, addr, data);
  7480. /* if going up or down, check the cache, otherwise, no access */
  7481. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
  7482. if (read_lcb_cache(addr, data))
  7483. return -EBUSY;
  7484. return 0;
  7485. }
  7486. /* otherwise, host has access */
  7487. *data = read_csr(dd, addr);
  7488. return 0;
  7489. }
  7490. /*
  7491. * Use the 8051 to write a LCB CSR.
  7492. */
  7493. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7494. {
  7495. u32 regno;
  7496. int ret;
  7497. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7498. (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
  7499. if (acquire_lcb_access(dd, 0) == 0) {
  7500. write_csr(dd, addr, data);
  7501. release_lcb_access(dd, 0);
  7502. return 0;
  7503. }
  7504. return -EBUSY;
  7505. }
  7506. /* register is an index of LCB registers: (offset - base) / 8 */
  7507. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7508. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7509. if (ret != HCMD_SUCCESS)
  7510. return -EBUSY;
  7511. return 0;
  7512. }
  7513. /*
  7514. * Write an LCB CSR. Access may not be in host control, so check.
  7515. * Return 0 on success, -EBUSY on failure.
  7516. */
  7517. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7518. {
  7519. struct hfi1_pportdata *ppd = dd->pport;
  7520. /* if up, go through the 8051 for the value */
  7521. if (ppd->host_link_state & HLS_UP)
  7522. return write_lcb_via_8051(dd, addr, data);
  7523. /* if going up or down, no access */
  7524. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7525. return -EBUSY;
  7526. /* otherwise, host has access */
  7527. write_csr(dd, addr, data);
  7528. return 0;
  7529. }
  7530. /*
  7531. * Returns:
  7532. * < 0 = Linux error, not able to get access
  7533. * > 0 = 8051 command RETURN_CODE
  7534. */
  7535. static int do_8051_command(
  7536. struct hfi1_devdata *dd,
  7537. u32 type,
  7538. u64 in_data,
  7539. u64 *out_data)
  7540. {
  7541. u64 reg, completed;
  7542. int return_code;
  7543. unsigned long timeout;
  7544. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7545. mutex_lock(&dd->dc8051_lock);
  7546. /* We can't send any commands to the 8051 if it's in reset */
  7547. if (dd->dc_shutdown) {
  7548. return_code = -ENODEV;
  7549. goto fail;
  7550. }
  7551. /*
  7552. * If an 8051 host command timed out previously, then the 8051 is
  7553. * stuck.
  7554. *
  7555. * On first timeout, attempt to reset and restart the entire DC
  7556. * block (including 8051). (Is this too big of a hammer?)
  7557. *
  7558. * If the 8051 times out a second time, the reset did not bring it
  7559. * back to healthy life. In that case, fail any subsequent commands.
  7560. */
  7561. if (dd->dc8051_timed_out) {
  7562. if (dd->dc8051_timed_out > 1) {
  7563. dd_dev_err(dd,
  7564. "Previous 8051 host command timed out, skipping command %u\n",
  7565. type);
  7566. return_code = -ENXIO;
  7567. goto fail;
  7568. }
  7569. _dc_shutdown(dd);
  7570. _dc_start(dd);
  7571. }
  7572. /*
  7573. * If there is no timeout, then the 8051 command interface is
  7574. * waiting for a command.
  7575. */
  7576. /*
  7577. * When writing a LCB CSR, out_data contains the full value to
  7578. * to be written, while in_data contains the relative LCB
  7579. * address in 7:0. Do the work here, rather than the caller,
  7580. * of distrubting the write data to where it needs to go:
  7581. *
  7582. * Write data
  7583. * 39:00 -> in_data[47:8]
  7584. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7585. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7586. */
  7587. if (type == HCMD_WRITE_LCB_CSR) {
  7588. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7589. /* must preserve COMPLETED - it is tied to hardware */
  7590. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
  7591. reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
  7592. reg |= ((((*out_data) >> 40) & 0xff) <<
  7593. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7594. | ((((*out_data) >> 48) & 0xffff) <<
  7595. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7596. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7597. }
  7598. /*
  7599. * Do two writes: the first to stabilize the type and req_data, the
  7600. * second to activate.
  7601. */
  7602. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7603. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7604. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7605. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7606. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7607. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7608. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7609. /* wait for completion, alternate: interrupt */
  7610. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7611. while (1) {
  7612. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7613. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7614. if (completed)
  7615. break;
  7616. if (time_after(jiffies, timeout)) {
  7617. dd->dc8051_timed_out++;
  7618. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7619. if (out_data)
  7620. *out_data = 0;
  7621. return_code = -ETIMEDOUT;
  7622. goto fail;
  7623. }
  7624. udelay(2);
  7625. }
  7626. if (out_data) {
  7627. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7628. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7629. if (type == HCMD_READ_LCB_CSR) {
  7630. /* top 16 bits are in a different register */
  7631. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7632. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7633. << (48
  7634. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7635. }
  7636. }
  7637. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7638. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7639. dd->dc8051_timed_out = 0;
  7640. /*
  7641. * Clear command for next user.
  7642. */
  7643. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7644. fail:
  7645. mutex_unlock(&dd->dc8051_lock);
  7646. return return_code;
  7647. }
  7648. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7649. {
  7650. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7651. }
  7652. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7653. u8 lane_id, u32 config_data)
  7654. {
  7655. u64 data;
  7656. int ret;
  7657. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7658. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7659. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7660. ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7661. if (ret != HCMD_SUCCESS) {
  7662. dd_dev_err(dd,
  7663. "load 8051 config: field id %d, lane %d, err %d\n",
  7664. (int)field_id, (int)lane_id, ret);
  7665. }
  7666. return ret;
  7667. }
  7668. /*
  7669. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7670. * set the result, even on error.
  7671. * Return 0 on success, -errno on failure
  7672. */
  7673. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7674. u32 *result)
  7675. {
  7676. u64 big_data;
  7677. u32 addr;
  7678. int ret;
  7679. /* address start depends on the lane_id */
  7680. if (lane_id < 4)
  7681. addr = (4 * NUM_GENERAL_FIELDS)
  7682. + (lane_id * 4 * NUM_LANE_FIELDS);
  7683. else
  7684. addr = 0;
  7685. addr += field_id * 4;
  7686. /* read is in 8-byte chunks, hardware will truncate the address down */
  7687. ret = read_8051_data(dd, addr, 8, &big_data);
  7688. if (ret == 0) {
  7689. /* extract the 4 bytes we want */
  7690. if (addr & 0x4)
  7691. *result = (u32)(big_data >> 32);
  7692. else
  7693. *result = (u32)big_data;
  7694. } else {
  7695. *result = 0;
  7696. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7697. __func__, lane_id, field_id);
  7698. }
  7699. return ret;
  7700. }
  7701. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7702. u8 continuous)
  7703. {
  7704. u32 frame;
  7705. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7706. | power_management << POWER_MANAGEMENT_SHIFT;
  7707. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7708. GENERAL_CONFIG, frame);
  7709. }
  7710. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7711. u16 vl15buf, u8 crc_sizes)
  7712. {
  7713. u32 frame;
  7714. frame = (u32)vau << VAU_SHIFT
  7715. | (u32)z << Z_SHIFT
  7716. | (u32)vcu << VCU_SHIFT
  7717. | (u32)vl15buf << VL15BUF_SHIFT
  7718. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7719. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7720. GENERAL_CONFIG, frame);
  7721. }
  7722. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  7723. u8 *flag_bits, u16 *link_widths)
  7724. {
  7725. u32 frame;
  7726. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7727. &frame);
  7728. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7729. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7730. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7731. }
  7732. static int write_vc_local_link_width(struct hfi1_devdata *dd,
  7733. u8 misc_bits,
  7734. u8 flag_bits,
  7735. u16 link_widths)
  7736. {
  7737. u32 frame;
  7738. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7739. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7740. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7741. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7742. frame);
  7743. }
  7744. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7745. u8 device_rev)
  7746. {
  7747. u32 frame;
  7748. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7749. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7750. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7751. }
  7752. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7753. u8 *device_rev)
  7754. {
  7755. u32 frame;
  7756. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7757. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7758. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7759. & REMOTE_DEVICE_REV_MASK;
  7760. }
  7761. int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
  7762. {
  7763. u32 frame;
  7764. u32 mask;
  7765. mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
  7766. read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
  7767. /* Clear, then set field */
  7768. frame &= ~mask;
  7769. frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
  7770. return load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
  7771. frame);
  7772. }
  7773. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
  7774. u8 *ver_patch)
  7775. {
  7776. u32 frame;
  7777. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7778. *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
  7779. STS_FM_VERSION_MAJOR_MASK;
  7780. *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
  7781. STS_FM_VERSION_MINOR_MASK;
  7782. read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
  7783. *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
  7784. STS_FM_VERSION_PATCH_MASK;
  7785. }
  7786. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7787. u8 *continuous)
  7788. {
  7789. u32 frame;
  7790. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7791. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7792. & POWER_MANAGEMENT_MASK;
  7793. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7794. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7795. }
  7796. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7797. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7798. {
  7799. u32 frame;
  7800. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7801. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7802. *z = (frame >> Z_SHIFT) & Z_MASK;
  7803. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7804. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7805. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7806. }
  7807. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7808. u8 *remote_tx_rate,
  7809. u16 *link_widths)
  7810. {
  7811. u32 frame;
  7812. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7813. &frame);
  7814. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7815. & REMOTE_TX_RATE_MASK;
  7816. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7817. }
  7818. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7819. {
  7820. u32 frame;
  7821. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7822. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7823. }
  7824. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed)
  7825. {
  7826. u32 frame;
  7827. read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
  7828. *mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT) & MGMT_ALLOWED_MASK;
  7829. }
  7830. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7831. {
  7832. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7833. }
  7834. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7835. {
  7836. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7837. }
  7838. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7839. {
  7840. u32 frame;
  7841. int ret;
  7842. *link_quality = 0;
  7843. if (dd->pport->host_link_state & HLS_UP) {
  7844. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7845. &frame);
  7846. if (ret == 0)
  7847. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7848. & LINK_QUALITY_MASK;
  7849. }
  7850. }
  7851. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7852. {
  7853. u32 frame;
  7854. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7855. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7856. }
  7857. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7858. {
  7859. u32 frame;
  7860. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7861. *ldr = (frame & 0xff);
  7862. }
  7863. static int read_tx_settings(struct hfi1_devdata *dd,
  7864. u8 *enable_lane_tx,
  7865. u8 *tx_polarity_inversion,
  7866. u8 *rx_polarity_inversion,
  7867. u8 *max_rate)
  7868. {
  7869. u32 frame;
  7870. int ret;
  7871. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7872. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7873. & ENABLE_LANE_TX_MASK;
  7874. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7875. & TX_POLARITY_INVERSION_MASK;
  7876. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7877. & RX_POLARITY_INVERSION_MASK;
  7878. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7879. return ret;
  7880. }
  7881. static int write_tx_settings(struct hfi1_devdata *dd,
  7882. u8 enable_lane_tx,
  7883. u8 tx_polarity_inversion,
  7884. u8 rx_polarity_inversion,
  7885. u8 max_rate)
  7886. {
  7887. u32 frame;
  7888. /* no need to mask, all variable sizes match field widths */
  7889. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7890. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7891. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7892. | max_rate << MAX_RATE_SHIFT;
  7893. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7894. }
  7895. /*
  7896. * Read an idle LCB message.
  7897. *
  7898. * Returns 0 on success, -EINVAL on error
  7899. */
  7900. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7901. {
  7902. int ret;
  7903. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7904. if (ret != HCMD_SUCCESS) {
  7905. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7906. (u32)type, ret);
  7907. return -EINVAL;
  7908. }
  7909. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7910. /* return only the payload as we already know the type */
  7911. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7912. return 0;
  7913. }
  7914. /*
  7915. * Read an idle SMA message. To be done in response to a notification from
  7916. * the 8051.
  7917. *
  7918. * Returns 0 on success, -EINVAL on error
  7919. */
  7920. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7921. {
  7922. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7923. data);
  7924. }
  7925. /*
  7926. * Send an idle LCB message.
  7927. *
  7928. * Returns 0 on success, -EINVAL on error
  7929. */
  7930. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7931. {
  7932. int ret;
  7933. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7934. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7935. if (ret != HCMD_SUCCESS) {
  7936. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7937. data, ret);
  7938. return -EINVAL;
  7939. }
  7940. return 0;
  7941. }
  7942. /*
  7943. * Send an idle SMA message.
  7944. *
  7945. * Returns 0 on success, -EINVAL on error
  7946. */
  7947. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7948. {
  7949. u64 data;
  7950. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7951. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7952. return send_idle_message(dd, data);
  7953. }
  7954. /*
  7955. * Initialize the LCB then do a quick link up. This may or may not be
  7956. * in loopback.
  7957. *
  7958. * return 0 on success, -errno on error
  7959. */
  7960. static int do_quick_linkup(struct hfi1_devdata *dd)
  7961. {
  7962. int ret;
  7963. lcb_shutdown(dd, 0);
  7964. if (loopback) {
  7965. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7966. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7967. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  7968. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  7969. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  7970. }
  7971. /* start the LCBs */
  7972. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  7973. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  7974. /* simulator only loopback steps */
  7975. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7976. /* LCB_CFG_RUN.EN = 1 */
  7977. write_csr(dd, DC_LCB_CFG_RUN,
  7978. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  7979. ret = wait_link_transfer_active(dd, 10);
  7980. if (ret)
  7981. return ret;
  7982. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  7983. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  7984. }
  7985. if (!loopback) {
  7986. /*
  7987. * When doing quick linkup and not in loopback, both
  7988. * sides must be done with LCB set-up before either
  7989. * starts the quick linkup. Put a delay here so that
  7990. * both sides can be started and have a chance to be
  7991. * done with LCB set up before resuming.
  7992. */
  7993. dd_dev_err(dd,
  7994. "Pausing for peer to be finished with LCB set up\n");
  7995. msleep(5000);
  7996. dd_dev_err(dd, "Continuing with quick linkup\n");
  7997. }
  7998. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  7999. set_8051_lcb_access(dd);
  8000. /*
  8001. * State "quick" LinkUp request sets the physical link state to
  8002. * LinkUp without a verify capability sequence.
  8003. * This state is in simulator v37 and later.
  8004. */
  8005. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  8006. if (ret != HCMD_SUCCESS) {
  8007. dd_dev_err(dd,
  8008. "%s: set physical link state to quick LinkUp failed with return %d\n",
  8009. __func__, ret);
  8010. set_host_lcb_access(dd);
  8011. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8012. if (ret >= 0)
  8013. ret = -EINVAL;
  8014. return ret;
  8015. }
  8016. return 0; /* success */
  8017. }
  8018. /*
  8019. * Set the SerDes to internal loopback mode.
  8020. * Returns 0 on success, -errno on error.
  8021. */
  8022. static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
  8023. {
  8024. int ret;
  8025. ret = set_physical_link_state(dd, PLS_INTERNAL_SERDES_LOOPBACK);
  8026. if (ret == HCMD_SUCCESS)
  8027. return 0;
  8028. dd_dev_err(dd,
  8029. "Set physical link state to SerDes Loopback failed with return %d\n",
  8030. ret);
  8031. if (ret >= 0)
  8032. ret = -EINVAL;
  8033. return ret;
  8034. }
  8035. /*
  8036. * Do all special steps to set up loopback.
  8037. */
  8038. static int init_loopback(struct hfi1_devdata *dd)
  8039. {
  8040. dd_dev_info(dd, "Entering loopback mode\n");
  8041. /* all loopbacks should disable self GUID check */
  8042. write_csr(dd, DC_DC8051_CFG_MODE,
  8043. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  8044. /*
  8045. * The simulator has only one loopback option - LCB. Switch
  8046. * to that option, which includes quick link up.
  8047. *
  8048. * Accept all valid loopback values.
  8049. */
  8050. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  8051. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  8052. loopback == LOOPBACK_CABLE)) {
  8053. loopback = LOOPBACK_LCB;
  8054. quick_linkup = 1;
  8055. return 0;
  8056. }
  8057. /* handle serdes loopback */
  8058. if (loopback == LOOPBACK_SERDES) {
  8059. /* internal serdes loopack needs quick linkup on RTL */
  8060. if (dd->icode == ICODE_RTL_SILICON)
  8061. quick_linkup = 1;
  8062. return set_serdes_loopback_mode(dd);
  8063. }
  8064. /* LCB loopback - handled at poll time */
  8065. if (loopback == LOOPBACK_LCB) {
  8066. quick_linkup = 1; /* LCB is always quick linkup */
  8067. /* not supported in emulation due to emulation RTL changes */
  8068. if (dd->icode == ICODE_FPGA_EMULATION) {
  8069. dd_dev_err(dd,
  8070. "LCB loopback not supported in emulation\n");
  8071. return -EINVAL;
  8072. }
  8073. return 0;
  8074. }
  8075. /* external cable loopback requires no extra steps */
  8076. if (loopback == LOOPBACK_CABLE)
  8077. return 0;
  8078. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  8079. return -EINVAL;
  8080. }
  8081. /*
  8082. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  8083. * used in the Verify Capability link width attribute.
  8084. */
  8085. static u16 opa_to_vc_link_widths(u16 opa_widths)
  8086. {
  8087. int i;
  8088. u16 result = 0;
  8089. static const struct link_bits {
  8090. u16 from;
  8091. u16 to;
  8092. } opa_link_xlate[] = {
  8093. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  8094. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  8095. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  8096. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  8097. };
  8098. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  8099. if (opa_widths & opa_link_xlate[i].from)
  8100. result |= opa_link_xlate[i].to;
  8101. }
  8102. return result;
  8103. }
  8104. /*
  8105. * Set link attributes before moving to polling.
  8106. */
  8107. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  8108. {
  8109. struct hfi1_devdata *dd = ppd->dd;
  8110. u8 enable_lane_tx;
  8111. u8 tx_polarity_inversion;
  8112. u8 rx_polarity_inversion;
  8113. int ret;
  8114. /* reset our fabric serdes to clear any lingering problems */
  8115. fabric_serdes_reset(dd);
  8116. /* set the local tx rate - need to read-modify-write */
  8117. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  8118. &rx_polarity_inversion, &ppd->local_tx_rate);
  8119. if (ret)
  8120. goto set_local_link_attributes_fail;
  8121. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  8122. /* set the tx rate to the fastest enabled */
  8123. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8124. ppd->local_tx_rate = 1;
  8125. else
  8126. ppd->local_tx_rate = 0;
  8127. } else {
  8128. /* set the tx rate to all enabled */
  8129. ppd->local_tx_rate = 0;
  8130. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8131. ppd->local_tx_rate |= 2;
  8132. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  8133. ppd->local_tx_rate |= 1;
  8134. }
  8135. enable_lane_tx = 0xF; /* enable all four lanes */
  8136. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  8137. rx_polarity_inversion, ppd->local_tx_rate);
  8138. if (ret != HCMD_SUCCESS)
  8139. goto set_local_link_attributes_fail;
  8140. /*
  8141. * DC supports continuous updates.
  8142. */
  8143. ret = write_vc_local_phy(dd,
  8144. 0 /* no power management */,
  8145. 1 /* continuous updates */);
  8146. if (ret != HCMD_SUCCESS)
  8147. goto set_local_link_attributes_fail;
  8148. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  8149. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  8150. ppd->port_crc_mode_enabled);
  8151. if (ret != HCMD_SUCCESS)
  8152. goto set_local_link_attributes_fail;
  8153. ret = write_vc_local_link_width(dd, 0, 0,
  8154. opa_to_vc_link_widths(
  8155. ppd->link_width_enabled));
  8156. if (ret != HCMD_SUCCESS)
  8157. goto set_local_link_attributes_fail;
  8158. /* let peer know who we are */
  8159. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  8160. if (ret == HCMD_SUCCESS)
  8161. return 0;
  8162. set_local_link_attributes_fail:
  8163. dd_dev_err(dd,
  8164. "Failed to set local link attributes, return 0x%x\n",
  8165. ret);
  8166. return ret;
  8167. }
  8168. /*
  8169. * Call this to start the link.
  8170. * Do not do anything if the link is disabled.
  8171. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8172. */
  8173. int start_link(struct hfi1_pportdata *ppd)
  8174. {
  8175. /*
  8176. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8177. * error rate. Needs to be done before starting the link.
  8178. */
  8179. tune_serdes(ppd);
  8180. if (!ppd->driver_link_ready) {
  8181. dd_dev_info(ppd->dd,
  8182. "%s: stopping link start because driver is not ready\n",
  8183. __func__);
  8184. return 0;
  8185. }
  8186. /*
  8187. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8188. * pkey table can be configured properly if the HFI unit is connected
  8189. * to switch port with MgmtAllowed=NO
  8190. */
  8191. clear_full_mgmt_pkey(ppd);
  8192. return set_link_state(ppd, HLS_DN_POLL);
  8193. }
  8194. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8195. {
  8196. struct hfi1_devdata *dd = ppd->dd;
  8197. u64 mask;
  8198. unsigned long timeout;
  8199. /*
  8200. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8201. * effect of power up on plug-in. We ignore this false positive
  8202. * interrupt until the module has finished powering up by waiting for
  8203. * a minimum timeout of the module inrush initialization time of
  8204. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8205. * module have stabilized.
  8206. */
  8207. msleep(500);
  8208. /*
  8209. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8210. */
  8211. timeout = jiffies + msecs_to_jiffies(2000);
  8212. while (1) {
  8213. mask = read_csr(dd, dd->hfi1_id ?
  8214. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8215. if (!(mask & QSFP_HFI0_INT_N))
  8216. break;
  8217. if (time_after(jiffies, timeout)) {
  8218. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8219. __func__);
  8220. break;
  8221. }
  8222. udelay(2);
  8223. }
  8224. }
  8225. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8226. {
  8227. struct hfi1_devdata *dd = ppd->dd;
  8228. u64 mask;
  8229. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8230. if (enable) {
  8231. /*
  8232. * Clear the status register to avoid an immediate interrupt
  8233. * when we re-enable the IntN pin
  8234. */
  8235. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8236. QSFP_HFI0_INT_N);
  8237. mask |= (u64)QSFP_HFI0_INT_N;
  8238. } else {
  8239. mask &= ~(u64)QSFP_HFI0_INT_N;
  8240. }
  8241. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8242. }
  8243. int reset_qsfp(struct hfi1_pportdata *ppd)
  8244. {
  8245. struct hfi1_devdata *dd = ppd->dd;
  8246. u64 mask, qsfp_mask;
  8247. /* Disable INT_N from triggering QSFP interrupts */
  8248. set_qsfp_int_n(ppd, 0);
  8249. /* Reset the QSFP */
  8250. mask = (u64)QSFP_HFI0_RESET_N;
  8251. qsfp_mask = read_csr(dd,
  8252. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8253. qsfp_mask &= ~mask;
  8254. write_csr(dd,
  8255. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8256. udelay(10);
  8257. qsfp_mask |= mask;
  8258. write_csr(dd,
  8259. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8260. wait_for_qsfp_init(ppd);
  8261. /*
  8262. * Allow INT_N to trigger the QSFP interrupt to watch
  8263. * for alarms and warnings
  8264. */
  8265. set_qsfp_int_n(ppd, 1);
  8266. /*
  8267. * After the reset, AOC transmitters are enabled by default. They need
  8268. * to be turned off to complete the QSFP setup before they can be
  8269. * enabled again.
  8270. */
  8271. return set_qsfp_tx(ppd, 0);
  8272. }
  8273. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8274. u8 *qsfp_interrupt_status)
  8275. {
  8276. struct hfi1_devdata *dd = ppd->dd;
  8277. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8278. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8279. dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
  8280. __func__);
  8281. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8282. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8283. dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
  8284. __func__);
  8285. /*
  8286. * The remaining alarms/warnings don't matter if the link is down.
  8287. */
  8288. if (ppd->host_link_state & HLS_DOWN)
  8289. return 0;
  8290. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8291. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8292. dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
  8293. __func__);
  8294. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8295. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8296. dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
  8297. __func__);
  8298. /* Byte 2 is vendor specific */
  8299. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8300. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8301. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
  8302. __func__);
  8303. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8304. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8305. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
  8306. __func__);
  8307. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8308. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8309. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
  8310. __func__);
  8311. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8312. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8313. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
  8314. __func__);
  8315. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8316. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8317. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8318. __func__);
  8319. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8320. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8321. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8322. __func__);
  8323. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8324. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8325. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8326. __func__);
  8327. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8328. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8329. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8330. __func__);
  8331. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8332. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8333. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
  8334. __func__);
  8335. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8336. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8337. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
  8338. __func__);
  8339. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8340. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8341. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
  8342. __func__);
  8343. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8344. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8345. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
  8346. __func__);
  8347. /* Bytes 9-10 and 11-12 are reserved */
  8348. /* Bytes 13-15 are vendor specific */
  8349. return 0;
  8350. }
  8351. /* This routine will only be scheduled if the QSFP module present is asserted */
  8352. void qsfp_event(struct work_struct *work)
  8353. {
  8354. struct qsfp_data *qd;
  8355. struct hfi1_pportdata *ppd;
  8356. struct hfi1_devdata *dd;
  8357. qd = container_of(work, struct qsfp_data, qsfp_work);
  8358. ppd = qd->ppd;
  8359. dd = ppd->dd;
  8360. /* Sanity check */
  8361. if (!qsfp_mod_present(ppd))
  8362. return;
  8363. if (ppd->host_link_state == HLS_DN_DISABLE) {
  8364. dd_dev_info(ppd->dd,
  8365. "%s: stopping link start because link is disabled\n",
  8366. __func__);
  8367. return;
  8368. }
  8369. /*
  8370. * Turn DC back on after cable has been re-inserted. Up until
  8371. * now, the DC has been in reset to save power.
  8372. */
  8373. dc_start(dd);
  8374. if (qd->cache_refresh_required) {
  8375. set_qsfp_int_n(ppd, 0);
  8376. wait_for_qsfp_init(ppd);
  8377. /*
  8378. * Allow INT_N to trigger the QSFP interrupt to watch
  8379. * for alarms and warnings
  8380. */
  8381. set_qsfp_int_n(ppd, 1);
  8382. start_link(ppd);
  8383. }
  8384. if (qd->check_interrupt_flags) {
  8385. u8 qsfp_interrupt_status[16] = {0,};
  8386. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8387. &qsfp_interrupt_status[0], 16) != 16) {
  8388. dd_dev_info(dd,
  8389. "%s: Failed to read status of QSFP module\n",
  8390. __func__);
  8391. } else {
  8392. unsigned long flags;
  8393. handle_qsfp_error_conditions(
  8394. ppd, qsfp_interrupt_status);
  8395. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8396. ppd->qsfp_info.check_interrupt_flags = 0;
  8397. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8398. flags);
  8399. }
  8400. }
  8401. }
  8402. static void init_qsfp_int(struct hfi1_devdata *dd)
  8403. {
  8404. struct hfi1_pportdata *ppd = dd->pport;
  8405. u64 qsfp_mask, cce_int_mask;
  8406. const int qsfp1_int_smask = QSFP1_INT % 64;
  8407. const int qsfp2_int_smask = QSFP2_INT % 64;
  8408. /*
  8409. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8410. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8411. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8412. * the index of the appropriate CSR in the CCEIntMask CSR array
  8413. */
  8414. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8415. (8 * (QSFP1_INT / 64)));
  8416. if (dd->hfi1_id) {
  8417. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8418. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8419. cce_int_mask);
  8420. } else {
  8421. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8422. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8423. cce_int_mask);
  8424. }
  8425. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8426. /* Clear current status to avoid spurious interrupts */
  8427. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8428. qsfp_mask);
  8429. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8430. qsfp_mask);
  8431. set_qsfp_int_n(ppd, 0);
  8432. /* Handle active low nature of INT_N and MODPRST_N pins */
  8433. if (qsfp_mod_present(ppd))
  8434. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8435. write_csr(dd,
  8436. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8437. qsfp_mask);
  8438. }
  8439. /*
  8440. * Do a one-time initialize of the LCB block.
  8441. */
  8442. static void init_lcb(struct hfi1_devdata *dd)
  8443. {
  8444. /* simulator does not correctly handle LCB cclk loopback, skip */
  8445. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8446. return;
  8447. /* the DC has been reset earlier in the driver load */
  8448. /* set LCB for cclk loopback on the port */
  8449. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8450. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8451. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8452. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8453. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8454. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8455. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8456. }
  8457. /*
  8458. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8459. * on error.
  8460. */
  8461. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8462. {
  8463. int ret;
  8464. u8 status;
  8465. /*
  8466. * Report success if not a QSFP or, if it is a QSFP, but the cable is
  8467. * not present
  8468. */
  8469. if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
  8470. return 0;
  8471. /* read byte 2, the status byte */
  8472. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8473. if (ret < 0)
  8474. return ret;
  8475. if (ret != 1)
  8476. return -EIO;
  8477. return 0; /* success */
  8478. }
  8479. /*
  8480. * Values for QSFP retry.
  8481. *
  8482. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8483. * arrived at from experience on a large cluster.
  8484. */
  8485. #define MAX_QSFP_RETRIES 20
  8486. #define QSFP_RETRY_WAIT 500 /* msec */
  8487. /*
  8488. * Try a QSFP read. If it fails, schedule a retry for later.
  8489. * Called on first link activation after driver load.
  8490. */
  8491. static void try_start_link(struct hfi1_pportdata *ppd)
  8492. {
  8493. if (test_qsfp_read(ppd)) {
  8494. /* read failed */
  8495. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8496. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8497. return;
  8498. }
  8499. dd_dev_info(ppd->dd,
  8500. "QSFP not responding, waiting and retrying %d\n",
  8501. (int)ppd->qsfp_retry_count);
  8502. ppd->qsfp_retry_count++;
  8503. queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
  8504. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8505. return;
  8506. }
  8507. ppd->qsfp_retry_count = 0;
  8508. start_link(ppd);
  8509. }
  8510. /*
  8511. * Workqueue function to start the link after a delay.
  8512. */
  8513. void handle_start_link(struct work_struct *work)
  8514. {
  8515. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8516. start_link_work.work);
  8517. try_start_link(ppd);
  8518. }
  8519. int bringup_serdes(struct hfi1_pportdata *ppd)
  8520. {
  8521. struct hfi1_devdata *dd = ppd->dd;
  8522. u64 guid;
  8523. int ret;
  8524. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8525. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8526. guid = ppd->guids[HFI1_PORT_GUID_INDEX];
  8527. if (!guid) {
  8528. if (dd->base_guid)
  8529. guid = dd->base_guid + ppd->port - 1;
  8530. ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
  8531. }
  8532. /* Set linkinit_reason on power up per OPA spec */
  8533. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8534. /* one-time init of the LCB */
  8535. init_lcb(dd);
  8536. if (loopback) {
  8537. ret = init_loopback(dd);
  8538. if (ret < 0)
  8539. return ret;
  8540. }
  8541. get_port_type(ppd);
  8542. if (ppd->port_type == PORT_TYPE_QSFP) {
  8543. set_qsfp_int_n(ppd, 0);
  8544. wait_for_qsfp_init(ppd);
  8545. set_qsfp_int_n(ppd, 1);
  8546. }
  8547. try_start_link(ppd);
  8548. return 0;
  8549. }
  8550. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8551. {
  8552. struct hfi1_devdata *dd = ppd->dd;
  8553. /*
  8554. * Shut down the link and keep it down. First turn off that the
  8555. * driver wants to allow the link to be up (driver_link_ready).
  8556. * Then make sure the link is not automatically restarted
  8557. * (link_enabled). Cancel any pending restart. And finally
  8558. * go offline.
  8559. */
  8560. ppd->driver_link_ready = 0;
  8561. ppd->link_enabled = 0;
  8562. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8563. flush_delayed_work(&ppd->start_link_work);
  8564. cancel_delayed_work_sync(&ppd->start_link_work);
  8565. ppd->offline_disabled_reason =
  8566. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
  8567. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
  8568. OPA_LINKDOWN_REASON_SMA_DISABLED);
  8569. set_link_state(ppd, HLS_DN_OFFLINE);
  8570. /* disable the port */
  8571. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8572. }
  8573. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8574. {
  8575. struct hfi1_pportdata *ppd;
  8576. int i;
  8577. ppd = (struct hfi1_pportdata *)(dd + 1);
  8578. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8579. ppd->ibport_data.rvp.rc_acks = NULL;
  8580. ppd->ibport_data.rvp.rc_qacks = NULL;
  8581. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8582. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8583. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8584. if (!ppd->ibport_data.rvp.rc_acks ||
  8585. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8586. !ppd->ibport_data.rvp.rc_qacks)
  8587. return -ENOMEM;
  8588. }
  8589. return 0;
  8590. }
  8591. /*
  8592. * index is the index into the receive array
  8593. */
  8594. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8595. u32 type, unsigned long pa, u16 order)
  8596. {
  8597. u64 reg;
  8598. if (!(dd->flags & HFI1_PRESENT))
  8599. goto done;
  8600. if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
  8601. pa = 0;
  8602. order = 0;
  8603. } else if (type > PT_INVALID) {
  8604. dd_dev_err(dd,
  8605. "unexpected receive array type %u for index %u, not handled\n",
  8606. type, index);
  8607. goto done;
  8608. }
  8609. trace_hfi1_put_tid(dd, index, type, pa, order);
  8610. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8611. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8612. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8613. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8614. << RCV_ARRAY_RT_ADDR_SHIFT;
  8615. trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
  8616. writeq(reg, dd->rcvarray_wc + (index * 8));
  8617. if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
  8618. /*
  8619. * Eager entries are written and flushed
  8620. *
  8621. * Expected entries are flushed every 4 writes
  8622. */
  8623. flush_wc();
  8624. done:
  8625. return;
  8626. }
  8627. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8628. {
  8629. struct hfi1_devdata *dd = rcd->dd;
  8630. u32 i;
  8631. /* this could be optimized */
  8632. for (i = rcd->eager_base; i < rcd->eager_base +
  8633. rcd->egrbufs.alloced; i++)
  8634. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8635. for (i = rcd->expected_base;
  8636. i < rcd->expected_base + rcd->expected_count; i++)
  8637. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8638. }
  8639. static const char * const ib_cfg_name_strings[] = {
  8640. "HFI1_IB_CFG_LIDLMC",
  8641. "HFI1_IB_CFG_LWID_DG_ENB",
  8642. "HFI1_IB_CFG_LWID_ENB",
  8643. "HFI1_IB_CFG_LWID",
  8644. "HFI1_IB_CFG_SPD_ENB",
  8645. "HFI1_IB_CFG_SPD",
  8646. "HFI1_IB_CFG_RXPOL_ENB",
  8647. "HFI1_IB_CFG_LREV_ENB",
  8648. "HFI1_IB_CFG_LINKLATENCY",
  8649. "HFI1_IB_CFG_HRTBT",
  8650. "HFI1_IB_CFG_OP_VLS",
  8651. "HFI1_IB_CFG_VL_HIGH_CAP",
  8652. "HFI1_IB_CFG_VL_LOW_CAP",
  8653. "HFI1_IB_CFG_OVERRUN_THRESH",
  8654. "HFI1_IB_CFG_PHYERR_THRESH",
  8655. "HFI1_IB_CFG_LINKDEFAULT",
  8656. "HFI1_IB_CFG_PKEYS",
  8657. "HFI1_IB_CFG_MTU",
  8658. "HFI1_IB_CFG_LSTATE",
  8659. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8660. "HFI1_IB_CFG_PMA_TICKS",
  8661. "HFI1_IB_CFG_PORT"
  8662. };
  8663. static const char *ib_cfg_name(int which)
  8664. {
  8665. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8666. return "invalid";
  8667. return ib_cfg_name_strings[which];
  8668. }
  8669. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8670. {
  8671. struct hfi1_devdata *dd = ppd->dd;
  8672. int val = 0;
  8673. switch (which) {
  8674. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8675. val = ppd->link_width_enabled;
  8676. break;
  8677. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8678. val = ppd->link_width_active;
  8679. break;
  8680. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8681. val = ppd->link_speed_enabled;
  8682. break;
  8683. case HFI1_IB_CFG_SPD: /* current Link speed */
  8684. val = ppd->link_speed_active;
  8685. break;
  8686. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8687. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8688. case HFI1_IB_CFG_LINKLATENCY:
  8689. goto unimplemented;
  8690. case HFI1_IB_CFG_OP_VLS:
  8691. val = ppd->vls_operational;
  8692. break;
  8693. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8694. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8695. break;
  8696. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8697. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8698. break;
  8699. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8700. val = ppd->overrun_threshold;
  8701. break;
  8702. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8703. val = ppd->phy_error_threshold;
  8704. break;
  8705. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8706. val = dd->link_default;
  8707. break;
  8708. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8709. case HFI1_IB_CFG_PMA_TICKS:
  8710. default:
  8711. unimplemented:
  8712. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8713. dd_dev_info(
  8714. dd,
  8715. "%s: which %s: not implemented\n",
  8716. __func__,
  8717. ib_cfg_name(which));
  8718. break;
  8719. }
  8720. return val;
  8721. }
  8722. /*
  8723. * The largest MAD packet size.
  8724. */
  8725. #define MAX_MAD_PACKET 2048
  8726. /*
  8727. * Return the maximum header bytes that can go on the _wire_
  8728. * for this device. This count includes the ICRC which is
  8729. * not part of the packet held in memory but it is appended
  8730. * by the HW.
  8731. * This is dependent on the device's receive header entry size.
  8732. * HFI allows this to be set per-receive context, but the
  8733. * driver presently enforces a global value.
  8734. */
  8735. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8736. {
  8737. /*
  8738. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8739. * the Receive Header Entry Size minus the PBC (or RHF) size
  8740. * plus one DW for the ICRC appended by HW.
  8741. *
  8742. * dd->rcd[0].rcvhdrqentsize is in DW.
  8743. * We use rcd[0] as all context will have the same value. Also,
  8744. * the first kernel context would have been allocated by now so
  8745. * we are guaranteed a valid value.
  8746. */
  8747. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8748. }
  8749. /*
  8750. * Set Send Length
  8751. * @ppd - per port data
  8752. *
  8753. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8754. * registers compare against LRH.PktLen, so use the max bytes included
  8755. * in the LRH.
  8756. *
  8757. * This routine changes all VL values except VL15, which it maintains at
  8758. * the same value.
  8759. */
  8760. static void set_send_length(struct hfi1_pportdata *ppd)
  8761. {
  8762. struct hfi1_devdata *dd = ppd->dd;
  8763. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8764. u32 maxvlmtu = dd->vld[15].mtu;
  8765. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8766. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8767. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8768. int i, j;
  8769. u32 thres;
  8770. for (i = 0; i < ppd->vls_supported; i++) {
  8771. if (dd->vld[i].mtu > maxvlmtu)
  8772. maxvlmtu = dd->vld[i].mtu;
  8773. if (i <= 3)
  8774. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8775. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8776. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8777. else
  8778. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8779. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8780. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8781. }
  8782. write_csr(dd, SEND_LEN_CHECK0, len1);
  8783. write_csr(dd, SEND_LEN_CHECK1, len2);
  8784. /* adjust kernel credit return thresholds based on new MTUs */
  8785. /* all kernel receive contexts have the same hdrqentsize */
  8786. for (i = 0; i < ppd->vls_supported; i++) {
  8787. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8788. sc_mtu_to_threshold(dd->vld[i].sc,
  8789. dd->vld[i].mtu,
  8790. dd->rcd[0]->rcvhdrqentsize));
  8791. for (j = 0; j < INIT_SC_PER_VL; j++)
  8792. sc_set_cr_threshold(
  8793. pio_select_send_context_vl(dd, j, i),
  8794. thres);
  8795. }
  8796. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8797. sc_mtu_to_threshold(dd->vld[15].sc,
  8798. dd->vld[15].mtu,
  8799. dd->rcd[0]->rcvhdrqentsize));
  8800. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8801. /* Adjust maximum MTU for the port in DC */
  8802. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8803. (ilog2(maxvlmtu >> 8) + 1);
  8804. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8805. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8806. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8807. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8808. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8809. }
  8810. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8811. {
  8812. int i;
  8813. u64 sreg = 0;
  8814. struct hfi1_devdata *dd = ppd->dd;
  8815. u32 mask = ~((1U << ppd->lmc) - 1);
  8816. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8817. u32 lid;
  8818. /*
  8819. * Program 0 in CSR if port lid is extended. This prevents
  8820. * 9B packets being sent out for large lids.
  8821. */
  8822. lid = (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ? 0 : ppd->lid;
  8823. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8824. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8825. c1 |= ((lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8826. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8827. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8828. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8829. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8830. /*
  8831. * Iterate over all the send contexts and set their SLID check
  8832. */
  8833. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8834. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8835. (((lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8836. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8837. for (i = 0; i < dd->chip_send_contexts; i++) {
  8838. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8839. i, (u32)sreg);
  8840. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8841. }
  8842. /* Now we have to do the same thing for the sdma engines */
  8843. sdma_update_lmc(dd, mask, lid);
  8844. }
  8845. static const char *state_completed_string(u32 completed)
  8846. {
  8847. static const char * const state_completed[] = {
  8848. "EstablishComm",
  8849. "OptimizeEQ",
  8850. "VerifyCap"
  8851. };
  8852. if (completed < ARRAY_SIZE(state_completed))
  8853. return state_completed[completed];
  8854. return "unknown";
  8855. }
  8856. static const char all_lanes_dead_timeout_expired[] =
  8857. "All lanes were inactive – was the interconnect media removed?";
  8858. static const char tx_out_of_policy[] =
  8859. "Passing lanes on local port do not meet the local link width policy";
  8860. static const char no_state_complete[] =
  8861. "State timeout occurred before link partner completed the state";
  8862. static const char * const state_complete_reasons[] = {
  8863. [0x00] = "Reason unknown",
  8864. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8865. [0x02] = "Link partner reported failure",
  8866. [0x10] = "Unable to achieve frame sync on any lane",
  8867. [0x11] =
  8868. "Unable to find a common bit rate with the link partner",
  8869. [0x12] =
  8870. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8871. [0x13] =
  8872. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8873. [0x14] = no_state_complete,
  8874. [0x15] =
  8875. "State timeout occurred before link partner identified equalization presets",
  8876. [0x16] =
  8877. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8878. [0x17] = tx_out_of_policy,
  8879. [0x20] = all_lanes_dead_timeout_expired,
  8880. [0x21] =
  8881. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8882. [0x22] = no_state_complete,
  8883. [0x23] =
  8884. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8885. [0x24] = tx_out_of_policy,
  8886. [0x30] = all_lanes_dead_timeout_expired,
  8887. [0x31] =
  8888. "State timeout occurred waiting for host to process received frames",
  8889. [0x32] = no_state_complete,
  8890. [0x33] =
  8891. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8892. [0x34] = tx_out_of_policy,
  8893. };
  8894. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8895. u32 code)
  8896. {
  8897. const char *str = NULL;
  8898. if (code < ARRAY_SIZE(state_complete_reasons))
  8899. str = state_complete_reasons[code];
  8900. if (str)
  8901. return str;
  8902. return "Reserved";
  8903. }
  8904. /* describe the given last state complete frame */
  8905. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8906. const char *prefix)
  8907. {
  8908. struct hfi1_devdata *dd = ppd->dd;
  8909. u32 success;
  8910. u32 state;
  8911. u32 reason;
  8912. u32 lanes;
  8913. /*
  8914. * Decode frame:
  8915. * [ 0: 0] - success
  8916. * [ 3: 1] - state
  8917. * [ 7: 4] - next state timeout
  8918. * [15: 8] - reason code
  8919. * [31:16] - lanes
  8920. */
  8921. success = frame & 0x1;
  8922. state = (frame >> 1) & 0x7;
  8923. reason = (frame >> 8) & 0xff;
  8924. lanes = (frame >> 16) & 0xffff;
  8925. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8926. prefix, frame);
  8927. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8928. state_completed_string(state), state);
  8929. dd_dev_err(dd, " state successfully completed: %s\n",
  8930. success ? "yes" : "no");
  8931. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8932. reason, state_complete_reason_code_string(ppd, reason));
  8933. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8934. }
  8935. /*
  8936. * Read the last state complete frames and explain them. This routine
  8937. * expects to be called if the link went down during link negotiation
  8938. * and initialization (LNI). That is, anywhere between polling and link up.
  8939. */
  8940. static void check_lni_states(struct hfi1_pportdata *ppd)
  8941. {
  8942. u32 last_local_state;
  8943. u32 last_remote_state;
  8944. read_last_local_state(ppd->dd, &last_local_state);
  8945. read_last_remote_state(ppd->dd, &last_remote_state);
  8946. /*
  8947. * Don't report anything if there is nothing to report. A value of
  8948. * 0 means the link was taken down while polling and there was no
  8949. * training in-process.
  8950. */
  8951. if (last_local_state == 0 && last_remote_state == 0)
  8952. return;
  8953. decode_state_complete(ppd, last_local_state, "transmitted");
  8954. decode_state_complete(ppd, last_remote_state, "received");
  8955. }
  8956. /* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
  8957. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
  8958. {
  8959. u64 reg;
  8960. unsigned long timeout;
  8961. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  8962. timeout = jiffies + msecs_to_jiffies(wait_ms);
  8963. while (1) {
  8964. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  8965. if (reg)
  8966. break;
  8967. if (time_after(jiffies, timeout)) {
  8968. dd_dev_err(dd,
  8969. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  8970. return -ETIMEDOUT;
  8971. }
  8972. udelay(2);
  8973. }
  8974. return 0;
  8975. }
  8976. /* called when the logical link state is not down as it should be */
  8977. static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
  8978. {
  8979. struct hfi1_devdata *dd = ppd->dd;
  8980. /*
  8981. * Bring link up in LCB loopback
  8982. */
  8983. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  8984. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  8985. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  8986. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  8987. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
  8988. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8989. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
  8990. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  8991. (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
  8992. udelay(3);
  8993. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
  8994. write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  8995. wait_link_transfer_active(dd, 100);
  8996. /*
  8997. * Bring the link down again.
  8998. */
  8999. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  9000. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
  9001. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
  9002. /* adjust ppd->statusp, if needed */
  9003. update_statusp(ppd, IB_PORT_DOWN);
  9004. dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
  9005. }
  9006. /*
  9007. * Helper for set_link_state(). Do not call except from that routine.
  9008. * Expects ppd->hls_mutex to be held.
  9009. *
  9010. * @rem_reason value to be sent to the neighbor
  9011. *
  9012. * LinkDownReasons only set if transition succeeds.
  9013. */
  9014. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  9015. {
  9016. struct hfi1_devdata *dd = ppd->dd;
  9017. u32 previous_state;
  9018. int offline_state_ret;
  9019. int ret;
  9020. update_lcb_cache(dd);
  9021. previous_state = ppd->host_link_state;
  9022. ppd->host_link_state = HLS_GOING_OFFLINE;
  9023. /* start offline transition */
  9024. ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
  9025. if (ret != HCMD_SUCCESS) {
  9026. dd_dev_err(dd,
  9027. "Failed to transition to Offline link state, return %d\n",
  9028. ret);
  9029. return -EINVAL;
  9030. }
  9031. if (ppd->offline_disabled_reason ==
  9032. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  9033. ppd->offline_disabled_reason =
  9034. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  9035. offline_state_ret = wait_phys_link_offline_substates(ppd, 10000);
  9036. if (offline_state_ret < 0)
  9037. return offline_state_ret;
  9038. /* Disabling AOC transmitters */
  9039. if (ppd->port_type == PORT_TYPE_QSFP &&
  9040. ppd->qsfp_info.limiting_active &&
  9041. qsfp_mod_present(ppd)) {
  9042. int ret;
  9043. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  9044. if (ret == 0) {
  9045. set_qsfp_tx(ppd, 0);
  9046. release_chip_resource(dd, qsfp_resource(dd));
  9047. } else {
  9048. /* not fatal, but should warn */
  9049. dd_dev_err(dd,
  9050. "Unable to acquire lock to turn off QSFP TX\n");
  9051. }
  9052. }
  9053. /*
  9054. * Wait for the offline.Quiet transition if it hasn't happened yet. It
  9055. * can take a while for the link to go down.
  9056. */
  9057. if (offline_state_ret != PLS_OFFLINE_QUIET) {
  9058. ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 30000);
  9059. if (ret < 0)
  9060. return ret;
  9061. }
  9062. /*
  9063. * Now in charge of LCB - must be after the physical state is
  9064. * offline.quiet and before host_link_state is changed.
  9065. */
  9066. set_host_lcb_access(dd);
  9067. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  9068. /* make sure the logical state is also down */
  9069. ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  9070. if (ret)
  9071. force_logical_link_state_down(ppd);
  9072. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  9073. /*
  9074. * The LNI has a mandatory wait time after the physical state
  9075. * moves to Offline.Quiet. The wait time may be different
  9076. * depending on how the link went down. The 8051 firmware
  9077. * will observe the needed wait time and only move to ready
  9078. * when that is completed. The largest of the quiet timeouts
  9079. * is 6s, so wait that long and then at least 0.5s more for
  9080. * other transitions, and another 0.5s for a buffer.
  9081. */
  9082. ret = wait_fm_ready(dd, 7000);
  9083. if (ret) {
  9084. dd_dev_err(dd,
  9085. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  9086. /* state is really offline, so make it so */
  9087. ppd->host_link_state = HLS_DN_OFFLINE;
  9088. return ret;
  9089. }
  9090. /*
  9091. * The state is now offline and the 8051 is ready to accept host
  9092. * requests.
  9093. * - change our state
  9094. * - notify others if we were previously in a linkup state
  9095. */
  9096. ppd->host_link_state = HLS_DN_OFFLINE;
  9097. if (previous_state & HLS_UP) {
  9098. /* went down while link was up */
  9099. handle_linkup_change(dd, 0);
  9100. } else if (previous_state
  9101. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  9102. /* went down while attempting link up */
  9103. check_lni_states(ppd);
  9104. /* The QSFP doesn't need to be reset on LNI failure */
  9105. ppd->qsfp_info.reset_needed = 0;
  9106. }
  9107. /* the active link width (downgrade) is 0 on link down */
  9108. ppd->link_width_active = 0;
  9109. ppd->link_width_downgrade_tx_active = 0;
  9110. ppd->link_width_downgrade_rx_active = 0;
  9111. ppd->current_egress_rate = 0;
  9112. return 0;
  9113. }
  9114. /* return the link state name */
  9115. static const char *link_state_name(u32 state)
  9116. {
  9117. const char *name;
  9118. int n = ilog2(state);
  9119. static const char * const names[] = {
  9120. [__HLS_UP_INIT_BP] = "INIT",
  9121. [__HLS_UP_ARMED_BP] = "ARMED",
  9122. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  9123. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  9124. [__HLS_DN_POLL_BP] = "POLL",
  9125. [__HLS_DN_DISABLE_BP] = "DISABLE",
  9126. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  9127. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  9128. [__HLS_GOING_UP_BP] = "GOING_UP",
  9129. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  9130. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  9131. };
  9132. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  9133. return name ? name : "unknown";
  9134. }
  9135. /* return the link state reason name */
  9136. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  9137. {
  9138. if (state == HLS_UP_INIT) {
  9139. switch (ppd->linkinit_reason) {
  9140. case OPA_LINKINIT_REASON_LINKUP:
  9141. return "(LINKUP)";
  9142. case OPA_LINKINIT_REASON_FLAPPING:
  9143. return "(FLAPPING)";
  9144. case OPA_LINKINIT_OUTSIDE_POLICY:
  9145. return "(OUTSIDE_POLICY)";
  9146. case OPA_LINKINIT_QUARANTINED:
  9147. return "(QUARANTINED)";
  9148. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  9149. return "(INSUFIC_CAPABILITY)";
  9150. default:
  9151. break;
  9152. }
  9153. }
  9154. return "";
  9155. }
  9156. /*
  9157. * driver_pstate - convert the driver's notion of a port's
  9158. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  9159. * Return -1 (converted to a u32) to indicate error.
  9160. */
  9161. u32 driver_pstate(struct hfi1_pportdata *ppd)
  9162. {
  9163. switch (ppd->host_link_state) {
  9164. case HLS_UP_INIT:
  9165. case HLS_UP_ARMED:
  9166. case HLS_UP_ACTIVE:
  9167. return IB_PORTPHYSSTATE_LINKUP;
  9168. case HLS_DN_POLL:
  9169. return IB_PORTPHYSSTATE_POLLING;
  9170. case HLS_DN_DISABLE:
  9171. return IB_PORTPHYSSTATE_DISABLED;
  9172. case HLS_DN_OFFLINE:
  9173. return OPA_PORTPHYSSTATE_OFFLINE;
  9174. case HLS_VERIFY_CAP:
  9175. return IB_PORTPHYSSTATE_POLLING;
  9176. case HLS_GOING_UP:
  9177. return IB_PORTPHYSSTATE_POLLING;
  9178. case HLS_GOING_OFFLINE:
  9179. return OPA_PORTPHYSSTATE_OFFLINE;
  9180. case HLS_LINK_COOLDOWN:
  9181. return OPA_PORTPHYSSTATE_OFFLINE;
  9182. case HLS_DN_DOWNDEF:
  9183. default:
  9184. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9185. ppd->host_link_state);
  9186. return -1;
  9187. }
  9188. }
  9189. /*
  9190. * driver_lstate - convert the driver's notion of a port's
  9191. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9192. * (converted to a u32) to indicate error.
  9193. */
  9194. u32 driver_lstate(struct hfi1_pportdata *ppd)
  9195. {
  9196. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9197. return IB_PORT_DOWN;
  9198. switch (ppd->host_link_state & HLS_UP) {
  9199. case HLS_UP_INIT:
  9200. return IB_PORT_INIT;
  9201. case HLS_UP_ARMED:
  9202. return IB_PORT_ARMED;
  9203. case HLS_UP_ACTIVE:
  9204. return IB_PORT_ACTIVE;
  9205. default:
  9206. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9207. ppd->host_link_state);
  9208. return -1;
  9209. }
  9210. }
  9211. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9212. u8 neigh_reason, u8 rem_reason)
  9213. {
  9214. if (ppd->local_link_down_reason.latest == 0 &&
  9215. ppd->neigh_link_down_reason.latest == 0) {
  9216. ppd->local_link_down_reason.latest = lcl_reason;
  9217. ppd->neigh_link_down_reason.latest = neigh_reason;
  9218. ppd->remote_link_down_reason = rem_reason;
  9219. }
  9220. }
  9221. /*
  9222. * Verify if BCT for data VLs is non-zero.
  9223. */
  9224. static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
  9225. {
  9226. return !!ppd->actual_vls_operational;
  9227. }
  9228. /*
  9229. * Change the physical and/or logical link state.
  9230. *
  9231. * Do not call this routine while inside an interrupt. It contains
  9232. * calls to routines that can take multiple seconds to finish.
  9233. *
  9234. * Returns 0 on success, -errno on failure.
  9235. */
  9236. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9237. {
  9238. struct hfi1_devdata *dd = ppd->dd;
  9239. struct ib_event event = {.device = NULL};
  9240. int ret1, ret = 0;
  9241. int orig_new_state, poll_bounce;
  9242. mutex_lock(&ppd->hls_lock);
  9243. orig_new_state = state;
  9244. if (state == HLS_DN_DOWNDEF)
  9245. state = dd->link_default;
  9246. /* interpret poll -> poll as a link bounce */
  9247. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9248. state == HLS_DN_POLL;
  9249. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9250. link_state_name(ppd->host_link_state),
  9251. link_state_name(orig_new_state),
  9252. poll_bounce ? "(bounce) " : "",
  9253. link_state_reason_name(ppd, state));
  9254. /*
  9255. * If we're going to a (HLS_*) link state that implies the logical
  9256. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9257. * reset is_sm_config_started to 0.
  9258. */
  9259. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9260. ppd->is_sm_config_started = 0;
  9261. /*
  9262. * Do nothing if the states match. Let a poll to poll link bounce
  9263. * go through.
  9264. */
  9265. if (ppd->host_link_state == state && !poll_bounce)
  9266. goto done;
  9267. switch (state) {
  9268. case HLS_UP_INIT:
  9269. if (ppd->host_link_state == HLS_DN_POLL &&
  9270. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9271. /*
  9272. * Quick link up jumps from polling to here.
  9273. *
  9274. * Whether in normal or loopback mode, the
  9275. * simulator jumps from polling to link up.
  9276. * Accept that here.
  9277. */
  9278. /* OK */
  9279. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9280. goto unexpected;
  9281. }
  9282. /*
  9283. * Wait for Link_Up physical state.
  9284. * Physical and Logical states should already be
  9285. * be transitioned to LinkUp and LinkInit respectively.
  9286. */
  9287. ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
  9288. if (ret) {
  9289. dd_dev_err(dd,
  9290. "%s: physical state did not change to LINK-UP\n",
  9291. __func__);
  9292. break;
  9293. }
  9294. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9295. if (ret) {
  9296. dd_dev_err(dd,
  9297. "%s: logical state did not change to INIT\n",
  9298. __func__);
  9299. break;
  9300. }
  9301. /* clear old transient LINKINIT_REASON code */
  9302. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9303. ppd->linkinit_reason =
  9304. OPA_LINKINIT_REASON_LINKUP;
  9305. /* enable the port */
  9306. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9307. handle_linkup_change(dd, 1);
  9308. ppd->host_link_state = HLS_UP_INIT;
  9309. break;
  9310. case HLS_UP_ARMED:
  9311. if (ppd->host_link_state != HLS_UP_INIT)
  9312. goto unexpected;
  9313. if (!data_vls_operational(ppd)) {
  9314. dd_dev_err(dd,
  9315. "%s: data VLs not operational\n", __func__);
  9316. ret = -EINVAL;
  9317. break;
  9318. }
  9319. set_logical_state(dd, LSTATE_ARMED);
  9320. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9321. if (ret) {
  9322. dd_dev_err(dd,
  9323. "%s: logical state did not change to ARMED\n",
  9324. __func__);
  9325. break;
  9326. }
  9327. ppd->host_link_state = HLS_UP_ARMED;
  9328. /*
  9329. * The simulator does not currently implement SMA messages,
  9330. * so neighbor_normal is not set. Set it here when we first
  9331. * move to Armed.
  9332. */
  9333. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9334. ppd->neighbor_normal = 1;
  9335. break;
  9336. case HLS_UP_ACTIVE:
  9337. if (ppd->host_link_state != HLS_UP_ARMED)
  9338. goto unexpected;
  9339. set_logical_state(dd, LSTATE_ACTIVE);
  9340. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9341. if (ret) {
  9342. dd_dev_err(dd,
  9343. "%s: logical state did not change to ACTIVE\n",
  9344. __func__);
  9345. } else {
  9346. /* tell all engines to go running */
  9347. sdma_all_running(dd);
  9348. ppd->host_link_state = HLS_UP_ACTIVE;
  9349. /* Signal the IB layer that the port has went active */
  9350. event.device = &dd->verbs_dev.rdi.ibdev;
  9351. event.element.port_num = ppd->port;
  9352. event.event = IB_EVENT_PORT_ACTIVE;
  9353. }
  9354. break;
  9355. case HLS_DN_POLL:
  9356. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9357. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9358. dd->dc_shutdown)
  9359. dc_start(dd);
  9360. /* Hand LED control to the DC */
  9361. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9362. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9363. u8 tmp = ppd->link_enabled;
  9364. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9365. if (ret) {
  9366. ppd->link_enabled = tmp;
  9367. break;
  9368. }
  9369. ppd->remote_link_down_reason = 0;
  9370. if (ppd->driver_link_ready)
  9371. ppd->link_enabled = 1;
  9372. }
  9373. set_all_slowpath(ppd->dd);
  9374. ret = set_local_link_attributes(ppd);
  9375. if (ret)
  9376. break;
  9377. ppd->port_error_action = 0;
  9378. ppd->host_link_state = HLS_DN_POLL;
  9379. if (quick_linkup) {
  9380. /* quick linkup does not go into polling */
  9381. ret = do_quick_linkup(dd);
  9382. } else {
  9383. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9384. if (ret1 != HCMD_SUCCESS) {
  9385. dd_dev_err(dd,
  9386. "Failed to transition to Polling link state, return 0x%x\n",
  9387. ret1);
  9388. ret = -EINVAL;
  9389. }
  9390. }
  9391. ppd->offline_disabled_reason =
  9392. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9393. /*
  9394. * If an error occurred above, go back to offline. The
  9395. * caller may reschedule another attempt.
  9396. */
  9397. if (ret)
  9398. goto_offline(ppd, 0);
  9399. else
  9400. log_physical_state(ppd, PLS_POLLING);
  9401. break;
  9402. case HLS_DN_DISABLE:
  9403. /* link is disabled */
  9404. ppd->link_enabled = 0;
  9405. /* allow any state to transition to disabled */
  9406. /* must transition to offline first */
  9407. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9408. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9409. if (ret)
  9410. break;
  9411. ppd->remote_link_down_reason = 0;
  9412. }
  9413. if (!dd->dc_shutdown) {
  9414. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9415. if (ret1 != HCMD_SUCCESS) {
  9416. dd_dev_err(dd,
  9417. "Failed to transition to Disabled link state, return 0x%x\n",
  9418. ret1);
  9419. ret = -EINVAL;
  9420. break;
  9421. }
  9422. ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
  9423. if (ret) {
  9424. dd_dev_err(dd,
  9425. "%s: physical state did not change to DISABLED\n",
  9426. __func__);
  9427. break;
  9428. }
  9429. dc_shutdown(dd);
  9430. }
  9431. ppd->host_link_state = HLS_DN_DISABLE;
  9432. break;
  9433. case HLS_DN_OFFLINE:
  9434. if (ppd->host_link_state == HLS_DN_DISABLE)
  9435. dc_start(dd);
  9436. /* allow any state to transition to offline */
  9437. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9438. if (!ret)
  9439. ppd->remote_link_down_reason = 0;
  9440. break;
  9441. case HLS_VERIFY_CAP:
  9442. if (ppd->host_link_state != HLS_DN_POLL)
  9443. goto unexpected;
  9444. ppd->host_link_state = HLS_VERIFY_CAP;
  9445. log_physical_state(ppd, PLS_CONFIGPHY_VERIFYCAP);
  9446. break;
  9447. case HLS_GOING_UP:
  9448. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9449. goto unexpected;
  9450. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9451. if (ret1 != HCMD_SUCCESS) {
  9452. dd_dev_err(dd,
  9453. "Failed to transition to link up state, return 0x%x\n",
  9454. ret1);
  9455. ret = -EINVAL;
  9456. break;
  9457. }
  9458. ppd->host_link_state = HLS_GOING_UP;
  9459. break;
  9460. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9461. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9462. default:
  9463. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9464. __func__, state);
  9465. ret = -EINVAL;
  9466. break;
  9467. }
  9468. goto done;
  9469. unexpected:
  9470. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9471. __func__, link_state_name(ppd->host_link_state),
  9472. link_state_name(state));
  9473. ret = -EINVAL;
  9474. done:
  9475. mutex_unlock(&ppd->hls_lock);
  9476. if (event.device)
  9477. ib_dispatch_event(&event);
  9478. return ret;
  9479. }
  9480. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9481. {
  9482. u64 reg;
  9483. int ret = 0;
  9484. switch (which) {
  9485. case HFI1_IB_CFG_LIDLMC:
  9486. set_lidlmc(ppd);
  9487. break;
  9488. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9489. /*
  9490. * The VL Arbitrator high limit is sent in units of 4k
  9491. * bytes, while HFI stores it in units of 64 bytes.
  9492. */
  9493. val *= 4096 / 64;
  9494. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9495. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9496. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9497. break;
  9498. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9499. /* HFI only supports POLL as the default link down state */
  9500. if (val != HLS_DN_POLL)
  9501. ret = -EINVAL;
  9502. break;
  9503. case HFI1_IB_CFG_OP_VLS:
  9504. if (ppd->vls_operational != val) {
  9505. ppd->vls_operational = val;
  9506. if (!ppd->port)
  9507. ret = -EINVAL;
  9508. }
  9509. break;
  9510. /*
  9511. * For link width, link width downgrade, and speed enable, always AND
  9512. * the setting with what is actually supported. This has two benefits.
  9513. * First, enabled can't have unsupported values, no matter what the
  9514. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9515. * "fill in with your supported value" have all the bits in the
  9516. * field set, so simply ANDing with supported has the desired result.
  9517. */
  9518. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9519. ppd->link_width_enabled = val & ppd->link_width_supported;
  9520. break;
  9521. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9522. ppd->link_width_downgrade_enabled =
  9523. val & ppd->link_width_downgrade_supported;
  9524. break;
  9525. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9526. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9527. break;
  9528. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9529. /*
  9530. * HFI does not follow IB specs, save this value
  9531. * so we can report it, if asked.
  9532. */
  9533. ppd->overrun_threshold = val;
  9534. break;
  9535. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9536. /*
  9537. * HFI does not follow IB specs, save this value
  9538. * so we can report it, if asked.
  9539. */
  9540. ppd->phy_error_threshold = val;
  9541. break;
  9542. case HFI1_IB_CFG_MTU:
  9543. set_send_length(ppd);
  9544. break;
  9545. case HFI1_IB_CFG_PKEYS:
  9546. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9547. set_partition_keys(ppd);
  9548. break;
  9549. default:
  9550. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9551. dd_dev_info(ppd->dd,
  9552. "%s: which %s, val 0x%x: not implemented\n",
  9553. __func__, ib_cfg_name(which), val);
  9554. break;
  9555. }
  9556. return ret;
  9557. }
  9558. /* begin functions related to vl arbitration table caching */
  9559. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9560. {
  9561. int i;
  9562. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9563. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9564. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9565. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9566. /*
  9567. * Note that we always return values directly from the
  9568. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9569. * 'Get(VLArbTable)'. This is obviously correct after a
  9570. * 'Set(VLArbTable)', since the cache will then be up to
  9571. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9572. * since then both the cache, and the relevant h/w registers
  9573. * will be zeroed.
  9574. */
  9575. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9576. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9577. }
  9578. /*
  9579. * vl_arb_lock_cache
  9580. *
  9581. * All other vl_arb_* functions should be called only after locking
  9582. * the cache.
  9583. */
  9584. static inline struct vl_arb_cache *
  9585. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9586. {
  9587. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9588. return NULL;
  9589. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9590. return &ppd->vl_arb_cache[idx];
  9591. }
  9592. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9593. {
  9594. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9595. }
  9596. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9597. struct ib_vl_weight_elem *vl)
  9598. {
  9599. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9600. }
  9601. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9602. struct ib_vl_weight_elem *vl)
  9603. {
  9604. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9605. }
  9606. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9607. struct ib_vl_weight_elem *vl)
  9608. {
  9609. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9610. }
  9611. /* end functions related to vl arbitration table caching */
  9612. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9613. u32 size, struct ib_vl_weight_elem *vl)
  9614. {
  9615. struct hfi1_devdata *dd = ppd->dd;
  9616. u64 reg;
  9617. unsigned int i, is_up = 0;
  9618. int drain, ret = 0;
  9619. mutex_lock(&ppd->hls_lock);
  9620. if (ppd->host_link_state & HLS_UP)
  9621. is_up = 1;
  9622. drain = !is_ax(dd) && is_up;
  9623. if (drain)
  9624. /*
  9625. * Before adjusting VL arbitration weights, empty per-VL
  9626. * FIFOs, otherwise a packet whose VL weight is being
  9627. * set to 0 could get stuck in a FIFO with no chance to
  9628. * egress.
  9629. */
  9630. ret = stop_drain_data_vls(dd);
  9631. if (ret) {
  9632. dd_dev_err(
  9633. dd,
  9634. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9635. __func__);
  9636. goto err;
  9637. }
  9638. for (i = 0; i < size; i++, vl++) {
  9639. /*
  9640. * NOTE: The low priority shift and mask are used here, but
  9641. * they are the same for both the low and high registers.
  9642. */
  9643. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9644. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9645. | (((u64)vl->weight
  9646. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9647. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9648. write_csr(dd, target + (i * 8), reg);
  9649. }
  9650. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9651. if (drain)
  9652. open_fill_data_vls(dd); /* reopen all VLs */
  9653. err:
  9654. mutex_unlock(&ppd->hls_lock);
  9655. return ret;
  9656. }
  9657. /*
  9658. * Read one credit merge VL register.
  9659. */
  9660. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9661. struct vl_limit *vll)
  9662. {
  9663. u64 reg = read_csr(dd, csr);
  9664. vll->dedicated = cpu_to_be16(
  9665. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9666. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9667. vll->shared = cpu_to_be16(
  9668. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9669. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9670. }
  9671. /*
  9672. * Read the current credit merge limits.
  9673. */
  9674. static int get_buffer_control(struct hfi1_devdata *dd,
  9675. struct buffer_control *bc, u16 *overall_limit)
  9676. {
  9677. u64 reg;
  9678. int i;
  9679. /* not all entries are filled in */
  9680. memset(bc, 0, sizeof(*bc));
  9681. /* OPA and HFI have a 1-1 mapping */
  9682. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9683. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9684. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9685. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9686. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9687. bc->overall_shared_limit = cpu_to_be16(
  9688. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9689. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9690. if (overall_limit)
  9691. *overall_limit = (reg
  9692. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9693. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9694. return sizeof(struct buffer_control);
  9695. }
  9696. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9697. {
  9698. u64 reg;
  9699. int i;
  9700. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9701. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9702. for (i = 0; i < sizeof(u64); i++) {
  9703. u8 byte = *(((u8 *)&reg) + i);
  9704. dp->vlnt[2 * i] = byte & 0xf;
  9705. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9706. }
  9707. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9708. for (i = 0; i < sizeof(u64); i++) {
  9709. u8 byte = *(((u8 *)&reg) + i);
  9710. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9711. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9712. }
  9713. return sizeof(struct sc2vlnt);
  9714. }
  9715. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9716. struct ib_vl_weight_elem *vl)
  9717. {
  9718. unsigned int i;
  9719. for (i = 0; i < nelems; i++, vl++) {
  9720. vl->vl = 0xf;
  9721. vl->weight = 0;
  9722. }
  9723. }
  9724. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9725. {
  9726. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9727. DC_SC_VL_VAL(15_0,
  9728. 0, dp->vlnt[0] & 0xf,
  9729. 1, dp->vlnt[1] & 0xf,
  9730. 2, dp->vlnt[2] & 0xf,
  9731. 3, dp->vlnt[3] & 0xf,
  9732. 4, dp->vlnt[4] & 0xf,
  9733. 5, dp->vlnt[5] & 0xf,
  9734. 6, dp->vlnt[6] & 0xf,
  9735. 7, dp->vlnt[7] & 0xf,
  9736. 8, dp->vlnt[8] & 0xf,
  9737. 9, dp->vlnt[9] & 0xf,
  9738. 10, dp->vlnt[10] & 0xf,
  9739. 11, dp->vlnt[11] & 0xf,
  9740. 12, dp->vlnt[12] & 0xf,
  9741. 13, dp->vlnt[13] & 0xf,
  9742. 14, dp->vlnt[14] & 0xf,
  9743. 15, dp->vlnt[15] & 0xf));
  9744. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9745. DC_SC_VL_VAL(31_16,
  9746. 16, dp->vlnt[16] & 0xf,
  9747. 17, dp->vlnt[17] & 0xf,
  9748. 18, dp->vlnt[18] & 0xf,
  9749. 19, dp->vlnt[19] & 0xf,
  9750. 20, dp->vlnt[20] & 0xf,
  9751. 21, dp->vlnt[21] & 0xf,
  9752. 22, dp->vlnt[22] & 0xf,
  9753. 23, dp->vlnt[23] & 0xf,
  9754. 24, dp->vlnt[24] & 0xf,
  9755. 25, dp->vlnt[25] & 0xf,
  9756. 26, dp->vlnt[26] & 0xf,
  9757. 27, dp->vlnt[27] & 0xf,
  9758. 28, dp->vlnt[28] & 0xf,
  9759. 29, dp->vlnt[29] & 0xf,
  9760. 30, dp->vlnt[30] & 0xf,
  9761. 31, dp->vlnt[31] & 0xf));
  9762. }
  9763. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9764. u16 limit)
  9765. {
  9766. if (limit != 0)
  9767. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9768. what, (int)limit, idx);
  9769. }
  9770. /* change only the shared limit portion of SendCmGLobalCredit */
  9771. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9772. {
  9773. u64 reg;
  9774. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9775. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9776. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9777. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9778. }
  9779. /* change only the total credit limit portion of SendCmGLobalCredit */
  9780. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9781. {
  9782. u64 reg;
  9783. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9784. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9785. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9786. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9787. }
  9788. /* set the given per-VL shared limit */
  9789. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9790. {
  9791. u64 reg;
  9792. u32 addr;
  9793. if (vl < TXE_NUM_DATA_VL)
  9794. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9795. else
  9796. addr = SEND_CM_CREDIT_VL15;
  9797. reg = read_csr(dd, addr);
  9798. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9799. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9800. write_csr(dd, addr, reg);
  9801. }
  9802. /* set the given per-VL dedicated limit */
  9803. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9804. {
  9805. u64 reg;
  9806. u32 addr;
  9807. if (vl < TXE_NUM_DATA_VL)
  9808. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9809. else
  9810. addr = SEND_CM_CREDIT_VL15;
  9811. reg = read_csr(dd, addr);
  9812. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9813. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9814. write_csr(dd, addr, reg);
  9815. }
  9816. /* spin until the given per-VL status mask bits clear */
  9817. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9818. const char *which)
  9819. {
  9820. unsigned long timeout;
  9821. u64 reg;
  9822. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9823. while (1) {
  9824. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9825. if (reg == 0)
  9826. return; /* success */
  9827. if (time_after(jiffies, timeout))
  9828. break; /* timed out */
  9829. udelay(1);
  9830. }
  9831. dd_dev_err(dd,
  9832. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9833. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9834. /*
  9835. * If this occurs, it is likely there was a credit loss on the link.
  9836. * The only recovery from that is a link bounce.
  9837. */
  9838. dd_dev_err(dd,
  9839. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9840. }
  9841. /*
  9842. * The number of credits on the VLs may be changed while everything
  9843. * is "live", but the following algorithm must be followed due to
  9844. * how the hardware is actually implemented. In particular,
  9845. * Return_Credit_Status[] is the only correct status check.
  9846. *
  9847. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9848. * set Global_Shared_Credit_Limit = 0
  9849. * use_all_vl = 1
  9850. * mask0 = all VLs that are changing either dedicated or shared limits
  9851. * set Shared_Limit[mask0] = 0
  9852. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9853. * if (changing any dedicated limit)
  9854. * mask1 = all VLs that are lowering dedicated limits
  9855. * lower Dedicated_Limit[mask1]
  9856. * spin until Return_Credit_Status[mask1] == 0
  9857. * raise Dedicated_Limits
  9858. * raise Shared_Limits
  9859. * raise Global_Shared_Credit_Limit
  9860. *
  9861. * lower = if the new limit is lower, set the limit to the new value
  9862. * raise = if the new limit is higher than the current value (may be changed
  9863. * earlier in the algorithm), set the new limit to the new value
  9864. */
  9865. int set_buffer_control(struct hfi1_pportdata *ppd,
  9866. struct buffer_control *new_bc)
  9867. {
  9868. struct hfi1_devdata *dd = ppd->dd;
  9869. u64 changing_mask, ld_mask, stat_mask;
  9870. int change_count;
  9871. int i, use_all_mask;
  9872. int this_shared_changing;
  9873. int vl_count = 0, ret;
  9874. /*
  9875. * A0: add the variable any_shared_limit_changing below and in the
  9876. * algorithm above. If removing A0 support, it can be removed.
  9877. */
  9878. int any_shared_limit_changing;
  9879. struct buffer_control cur_bc;
  9880. u8 changing[OPA_MAX_VLS];
  9881. u8 lowering_dedicated[OPA_MAX_VLS];
  9882. u16 cur_total;
  9883. u32 new_total = 0;
  9884. const u64 all_mask =
  9885. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9886. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9887. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9888. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9889. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9890. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9891. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9892. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9893. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9894. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9895. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9896. /* find the new total credits, do sanity check on unused VLs */
  9897. for (i = 0; i < OPA_MAX_VLS; i++) {
  9898. if (valid_vl(i)) {
  9899. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9900. continue;
  9901. }
  9902. nonzero_msg(dd, i, "dedicated",
  9903. be16_to_cpu(new_bc->vl[i].dedicated));
  9904. nonzero_msg(dd, i, "shared",
  9905. be16_to_cpu(new_bc->vl[i].shared));
  9906. new_bc->vl[i].dedicated = 0;
  9907. new_bc->vl[i].shared = 0;
  9908. }
  9909. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9910. /* fetch the current values */
  9911. get_buffer_control(dd, &cur_bc, &cur_total);
  9912. /*
  9913. * Create the masks we will use.
  9914. */
  9915. memset(changing, 0, sizeof(changing));
  9916. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9917. /*
  9918. * NOTE: Assumes that the individual VL bits are adjacent and in
  9919. * increasing order
  9920. */
  9921. stat_mask =
  9922. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9923. changing_mask = 0;
  9924. ld_mask = 0;
  9925. change_count = 0;
  9926. any_shared_limit_changing = 0;
  9927. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9928. if (!valid_vl(i))
  9929. continue;
  9930. this_shared_changing = new_bc->vl[i].shared
  9931. != cur_bc.vl[i].shared;
  9932. if (this_shared_changing)
  9933. any_shared_limit_changing = 1;
  9934. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9935. this_shared_changing) {
  9936. changing[i] = 1;
  9937. changing_mask |= stat_mask;
  9938. change_count++;
  9939. }
  9940. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9941. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9942. lowering_dedicated[i] = 1;
  9943. ld_mask |= stat_mask;
  9944. }
  9945. }
  9946. /* bracket the credit change with a total adjustment */
  9947. if (new_total > cur_total)
  9948. set_global_limit(dd, new_total);
  9949. /*
  9950. * Start the credit change algorithm.
  9951. */
  9952. use_all_mask = 0;
  9953. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  9954. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  9955. (is_ax(dd) && any_shared_limit_changing)) {
  9956. set_global_shared(dd, 0);
  9957. cur_bc.overall_shared_limit = 0;
  9958. use_all_mask = 1;
  9959. }
  9960. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9961. if (!valid_vl(i))
  9962. continue;
  9963. if (changing[i]) {
  9964. set_vl_shared(dd, i, 0);
  9965. cur_bc.vl[i].shared = 0;
  9966. }
  9967. }
  9968. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  9969. "shared");
  9970. if (change_count > 0) {
  9971. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9972. if (!valid_vl(i))
  9973. continue;
  9974. if (lowering_dedicated[i]) {
  9975. set_vl_dedicated(dd, i,
  9976. be16_to_cpu(new_bc->
  9977. vl[i].dedicated));
  9978. cur_bc.vl[i].dedicated =
  9979. new_bc->vl[i].dedicated;
  9980. }
  9981. }
  9982. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  9983. /* now raise all dedicated that are going up */
  9984. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9985. if (!valid_vl(i))
  9986. continue;
  9987. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  9988. be16_to_cpu(cur_bc.vl[i].dedicated))
  9989. set_vl_dedicated(dd, i,
  9990. be16_to_cpu(new_bc->
  9991. vl[i].dedicated));
  9992. }
  9993. }
  9994. /* next raise all shared that are going up */
  9995. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9996. if (!valid_vl(i))
  9997. continue;
  9998. if (be16_to_cpu(new_bc->vl[i].shared) >
  9999. be16_to_cpu(cur_bc.vl[i].shared))
  10000. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  10001. }
  10002. /* finally raise the global shared */
  10003. if (be16_to_cpu(new_bc->overall_shared_limit) >
  10004. be16_to_cpu(cur_bc.overall_shared_limit))
  10005. set_global_shared(dd,
  10006. be16_to_cpu(new_bc->overall_shared_limit));
  10007. /* bracket the credit change with a total adjustment */
  10008. if (new_total < cur_total)
  10009. set_global_limit(dd, new_total);
  10010. /*
  10011. * Determine the actual number of operational VLS using the number of
  10012. * dedicated and shared credits for each VL.
  10013. */
  10014. if (change_count > 0) {
  10015. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  10016. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  10017. be16_to_cpu(new_bc->vl[i].shared) > 0)
  10018. vl_count++;
  10019. ppd->actual_vls_operational = vl_count;
  10020. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  10021. ppd->actual_vls_operational :
  10022. ppd->vls_operational,
  10023. NULL);
  10024. if (ret == 0)
  10025. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  10026. ppd->actual_vls_operational :
  10027. ppd->vls_operational, NULL);
  10028. if (ret)
  10029. return ret;
  10030. }
  10031. return 0;
  10032. }
  10033. /*
  10034. * Read the given fabric manager table. Return the size of the
  10035. * table (in bytes) on success, and a negative error code on
  10036. * failure.
  10037. */
  10038. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  10039. {
  10040. int size;
  10041. struct vl_arb_cache *vlc;
  10042. switch (which) {
  10043. case FM_TBL_VL_HIGH_ARB:
  10044. size = 256;
  10045. /*
  10046. * OPA specifies 128 elements (of 2 bytes each), though
  10047. * HFI supports only 16 elements in h/w.
  10048. */
  10049. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10050. vl_arb_get_cache(vlc, t);
  10051. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10052. break;
  10053. case FM_TBL_VL_LOW_ARB:
  10054. size = 256;
  10055. /*
  10056. * OPA specifies 128 elements (of 2 bytes each), though
  10057. * HFI supports only 16 elements in h/w.
  10058. */
  10059. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10060. vl_arb_get_cache(vlc, t);
  10061. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10062. break;
  10063. case FM_TBL_BUFFER_CONTROL:
  10064. size = get_buffer_control(ppd->dd, t, NULL);
  10065. break;
  10066. case FM_TBL_SC2VLNT:
  10067. size = get_sc2vlnt(ppd->dd, t);
  10068. break;
  10069. case FM_TBL_VL_PREEMPT_ELEMS:
  10070. size = 256;
  10071. /* OPA specifies 128 elements, of 2 bytes each */
  10072. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  10073. break;
  10074. case FM_TBL_VL_PREEMPT_MATRIX:
  10075. size = 256;
  10076. /*
  10077. * OPA specifies that this is the same size as the VL
  10078. * arbitration tables (i.e., 256 bytes).
  10079. */
  10080. break;
  10081. default:
  10082. return -EINVAL;
  10083. }
  10084. return size;
  10085. }
  10086. /*
  10087. * Write the given fabric manager table.
  10088. */
  10089. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  10090. {
  10091. int ret = 0;
  10092. struct vl_arb_cache *vlc;
  10093. switch (which) {
  10094. case FM_TBL_VL_HIGH_ARB:
  10095. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10096. if (vl_arb_match_cache(vlc, t)) {
  10097. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10098. break;
  10099. }
  10100. vl_arb_set_cache(vlc, t);
  10101. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10102. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  10103. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  10104. break;
  10105. case FM_TBL_VL_LOW_ARB:
  10106. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10107. if (vl_arb_match_cache(vlc, t)) {
  10108. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10109. break;
  10110. }
  10111. vl_arb_set_cache(vlc, t);
  10112. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10113. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  10114. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  10115. break;
  10116. case FM_TBL_BUFFER_CONTROL:
  10117. ret = set_buffer_control(ppd, t);
  10118. break;
  10119. case FM_TBL_SC2VLNT:
  10120. set_sc2vlnt(ppd->dd, t);
  10121. break;
  10122. default:
  10123. ret = -EINVAL;
  10124. }
  10125. return ret;
  10126. }
  10127. /*
  10128. * Disable all data VLs.
  10129. *
  10130. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  10131. */
  10132. static int disable_data_vls(struct hfi1_devdata *dd)
  10133. {
  10134. if (is_ax(dd))
  10135. return 1;
  10136. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  10137. return 0;
  10138. }
  10139. /*
  10140. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  10141. * Just re-enables all data VLs (the "fill" part happens
  10142. * automatically - the name was chosen for symmetry with
  10143. * stop_drain_data_vls()).
  10144. *
  10145. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  10146. */
  10147. int open_fill_data_vls(struct hfi1_devdata *dd)
  10148. {
  10149. if (is_ax(dd))
  10150. return 1;
  10151. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  10152. return 0;
  10153. }
  10154. /*
  10155. * drain_data_vls() - assumes that disable_data_vls() has been called,
  10156. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  10157. * engines to drop to 0.
  10158. */
  10159. static void drain_data_vls(struct hfi1_devdata *dd)
  10160. {
  10161. sc_wait(dd);
  10162. sdma_wait(dd);
  10163. pause_for_credit_return(dd);
  10164. }
  10165. /*
  10166. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  10167. *
  10168. * Use open_fill_data_vls() to resume using data VLs. This pair is
  10169. * meant to be used like this:
  10170. *
  10171. * stop_drain_data_vls(dd);
  10172. * // do things with per-VL resources
  10173. * open_fill_data_vls(dd);
  10174. */
  10175. int stop_drain_data_vls(struct hfi1_devdata *dd)
  10176. {
  10177. int ret;
  10178. ret = disable_data_vls(dd);
  10179. if (ret == 0)
  10180. drain_data_vls(dd);
  10181. return ret;
  10182. }
  10183. /*
  10184. * Convert a nanosecond time to a cclock count. No matter how slow
  10185. * the cclock, a non-zero ns will always have a non-zero result.
  10186. */
  10187. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  10188. {
  10189. u32 cclocks;
  10190. if (dd->icode == ICODE_FPGA_EMULATION)
  10191. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  10192. else /* simulation pretends to be ASIC */
  10193. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  10194. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  10195. cclocks = 1;
  10196. return cclocks;
  10197. }
  10198. /*
  10199. * Convert a cclock count to nanoseconds. Not matter how slow
  10200. * the cclock, a non-zero cclocks will always have a non-zero result.
  10201. */
  10202. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  10203. {
  10204. u32 ns;
  10205. if (dd->icode == ICODE_FPGA_EMULATION)
  10206. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  10207. else /* simulation pretends to be ASIC */
  10208. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  10209. if (cclocks && !ns)
  10210. ns = 1;
  10211. return ns;
  10212. }
  10213. /*
  10214. * Dynamically adjust the receive interrupt timeout for a context based on
  10215. * incoming packet rate.
  10216. *
  10217. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  10218. */
  10219. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  10220. {
  10221. struct hfi1_devdata *dd = rcd->dd;
  10222. u32 timeout = rcd->rcvavail_timeout;
  10223. /*
  10224. * This algorithm doubles or halves the timeout depending on whether
  10225. * the number of packets received in this interrupt were less than or
  10226. * greater equal the interrupt count.
  10227. *
  10228. * The calculations below do not allow a steady state to be achieved.
  10229. * Only at the endpoints it is possible to have an unchanging
  10230. * timeout.
  10231. */
  10232. if (npkts < rcv_intr_count) {
  10233. /*
  10234. * Not enough packets arrived before the timeout, adjust
  10235. * timeout downward.
  10236. */
  10237. if (timeout < 2) /* already at minimum? */
  10238. return;
  10239. timeout >>= 1;
  10240. } else {
  10241. /*
  10242. * More than enough packets arrived before the timeout, adjust
  10243. * timeout upward.
  10244. */
  10245. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10246. return;
  10247. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10248. }
  10249. rcd->rcvavail_timeout = timeout;
  10250. /*
  10251. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10252. * been verified to be in range
  10253. */
  10254. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10255. (u64)timeout <<
  10256. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10257. }
  10258. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10259. u32 intr_adjust, u32 npkts)
  10260. {
  10261. struct hfi1_devdata *dd = rcd->dd;
  10262. u64 reg;
  10263. u32 ctxt = rcd->ctxt;
  10264. /*
  10265. * Need to write timeout register before updating RcvHdrHead to ensure
  10266. * that a new value is used when the HW decides to restart counting.
  10267. */
  10268. if (intr_adjust)
  10269. adjust_rcv_timeout(rcd, npkts);
  10270. if (updegr) {
  10271. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10272. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10273. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10274. }
  10275. mmiowb();
  10276. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10277. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10278. << RCV_HDR_HEAD_HEAD_SHIFT);
  10279. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10280. mmiowb();
  10281. }
  10282. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10283. {
  10284. u32 head, tail;
  10285. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10286. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10287. if (rcd->rcvhdrtail_kvaddr)
  10288. tail = get_rcvhdrtail(rcd);
  10289. else
  10290. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10291. return head == tail;
  10292. }
  10293. /*
  10294. * Context Control and Receive Array encoding for buffer size:
  10295. * 0x0 invalid
  10296. * 0x1 4 KB
  10297. * 0x2 8 KB
  10298. * 0x3 16 KB
  10299. * 0x4 32 KB
  10300. * 0x5 64 KB
  10301. * 0x6 128 KB
  10302. * 0x7 256 KB
  10303. * 0x8 512 KB (Receive Array only)
  10304. * 0x9 1 MB (Receive Array only)
  10305. * 0xa 2 MB (Receive Array only)
  10306. *
  10307. * 0xB-0xF - reserved (Receive Array only)
  10308. *
  10309. *
  10310. * This routine assumes that the value has already been sanity checked.
  10311. */
  10312. static u32 encoded_size(u32 size)
  10313. {
  10314. switch (size) {
  10315. case 4 * 1024: return 0x1;
  10316. case 8 * 1024: return 0x2;
  10317. case 16 * 1024: return 0x3;
  10318. case 32 * 1024: return 0x4;
  10319. case 64 * 1024: return 0x5;
  10320. case 128 * 1024: return 0x6;
  10321. case 256 * 1024: return 0x7;
  10322. case 512 * 1024: return 0x8;
  10323. case 1 * 1024 * 1024: return 0x9;
  10324. case 2 * 1024 * 1024: return 0xa;
  10325. }
  10326. return 0x1; /* if invalid, go with the minimum size */
  10327. }
  10328. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
  10329. struct hfi1_ctxtdata *rcd)
  10330. {
  10331. u64 rcvctrl, reg;
  10332. int did_enable = 0;
  10333. u16 ctxt;
  10334. if (!rcd)
  10335. return;
  10336. ctxt = rcd->ctxt;
  10337. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10338. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10339. /* if the context already enabled, don't do the extra steps */
  10340. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10341. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10342. /* reset the tail and hdr addresses, and sequence count */
  10343. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10344. rcd->rcvhdrq_dma);
  10345. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  10346. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10347. rcd->rcvhdrqtailaddr_dma);
  10348. rcd->seq_cnt = 1;
  10349. /* reset the cached receive header queue head value */
  10350. rcd->head = 0;
  10351. /*
  10352. * Zero the receive header queue so we don't get false
  10353. * positives when checking the sequence number. The
  10354. * sequence numbers could land exactly on the same spot.
  10355. * E.g. a rcd restart before the receive header wrapped.
  10356. */
  10357. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  10358. /* starting timeout */
  10359. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10360. /* enable the context */
  10361. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10362. /* clean the egr buffer size first */
  10363. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10364. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10365. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10366. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10367. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10368. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10369. did_enable = 1;
  10370. /* zero RcvEgrIndexHead */
  10371. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10372. /* set eager count and base index */
  10373. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10374. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10375. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10376. (((rcd->eager_base >> RCV_SHIFT)
  10377. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10378. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10379. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10380. /*
  10381. * Set TID (expected) count and base index.
  10382. * rcd->expected_count is set to individual RcvArray entries,
  10383. * not pairs, and the CSR takes a pair-count in groups of
  10384. * four, so divide by 8.
  10385. */
  10386. reg = (((rcd->expected_count >> RCV_SHIFT)
  10387. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10388. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10389. (((rcd->expected_base >> RCV_SHIFT)
  10390. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10391. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10392. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10393. if (ctxt == HFI1_CTRL_CTXT)
  10394. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10395. }
  10396. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10397. write_csr(dd, RCV_VL15, 0);
  10398. /*
  10399. * When receive context is being disabled turn on tail
  10400. * update with a dummy tail address and then disable
  10401. * receive context.
  10402. */
  10403. if (dd->rcvhdrtail_dummy_dma) {
  10404. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10405. dd->rcvhdrtail_dummy_dma);
  10406. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10407. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10408. }
  10409. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10410. }
  10411. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10412. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10413. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10414. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10415. if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
  10416. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10417. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10418. /* See comment on RcvCtxtCtrl.TailUpd above */
  10419. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10420. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10421. }
  10422. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10423. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10424. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10425. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10426. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10427. /*
  10428. * In one-packet-per-eager mode, the size comes from
  10429. * the RcvArray entry.
  10430. */
  10431. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10432. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10433. }
  10434. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10435. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10436. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10437. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10438. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10439. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10440. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10441. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10442. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10443. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10444. rcd->rcvctrl = rcvctrl;
  10445. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10446. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
  10447. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10448. if (did_enable &&
  10449. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10450. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10451. if (reg != 0) {
  10452. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10453. ctxt, reg);
  10454. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10455. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10456. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10457. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10458. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10459. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10460. ctxt, reg, reg == 0 ? "not" : "still");
  10461. }
  10462. }
  10463. if (did_enable) {
  10464. /*
  10465. * The interrupt timeout and count must be set after
  10466. * the context is enabled to take effect.
  10467. */
  10468. /* set interrupt timeout */
  10469. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10470. (u64)rcd->rcvavail_timeout <<
  10471. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10472. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10473. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10474. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10475. }
  10476. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10477. /*
  10478. * If the context has been disabled and the Tail Update has
  10479. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10480. * so it doesn't contain an address that is invalid.
  10481. */
  10482. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10483. dd->rcvhdrtail_dummy_dma);
  10484. }
  10485. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10486. {
  10487. int ret;
  10488. u64 val = 0;
  10489. if (namep) {
  10490. ret = dd->cntrnameslen;
  10491. *namep = dd->cntrnames;
  10492. } else {
  10493. const struct cntr_entry *entry;
  10494. int i, j;
  10495. ret = (dd->ndevcntrs) * sizeof(u64);
  10496. /* Get the start of the block of counters */
  10497. *cntrp = dd->cntrs;
  10498. /*
  10499. * Now go and fill in each counter in the block.
  10500. */
  10501. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10502. entry = &dev_cntrs[i];
  10503. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10504. if (entry->flags & CNTR_DISABLED) {
  10505. /* Nothing */
  10506. hfi1_cdbg(CNTR, "\tDisabled\n");
  10507. } else {
  10508. if (entry->flags & CNTR_VL) {
  10509. hfi1_cdbg(CNTR, "\tPer VL\n");
  10510. for (j = 0; j < C_VL_COUNT; j++) {
  10511. val = entry->rw_cntr(entry,
  10512. dd, j,
  10513. CNTR_MODE_R,
  10514. 0);
  10515. hfi1_cdbg(
  10516. CNTR,
  10517. "\t\tRead 0x%llx for %d\n",
  10518. val, j);
  10519. dd->cntrs[entry->offset + j] =
  10520. val;
  10521. }
  10522. } else if (entry->flags & CNTR_SDMA) {
  10523. hfi1_cdbg(CNTR,
  10524. "\t Per SDMA Engine\n");
  10525. for (j = 0; j < dd->chip_sdma_engines;
  10526. j++) {
  10527. val =
  10528. entry->rw_cntr(entry, dd, j,
  10529. CNTR_MODE_R, 0);
  10530. hfi1_cdbg(CNTR,
  10531. "\t\tRead 0x%llx for %d\n",
  10532. val, j);
  10533. dd->cntrs[entry->offset + j] =
  10534. val;
  10535. }
  10536. } else {
  10537. val = entry->rw_cntr(entry, dd,
  10538. CNTR_INVALID_VL,
  10539. CNTR_MODE_R, 0);
  10540. dd->cntrs[entry->offset] = val;
  10541. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10542. }
  10543. }
  10544. }
  10545. }
  10546. return ret;
  10547. }
  10548. /*
  10549. * Used by sysfs to create files for hfi stats to read
  10550. */
  10551. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10552. {
  10553. int ret;
  10554. u64 val = 0;
  10555. if (namep) {
  10556. ret = ppd->dd->portcntrnameslen;
  10557. *namep = ppd->dd->portcntrnames;
  10558. } else {
  10559. const struct cntr_entry *entry;
  10560. int i, j;
  10561. ret = ppd->dd->nportcntrs * sizeof(u64);
  10562. *cntrp = ppd->cntrs;
  10563. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10564. entry = &port_cntrs[i];
  10565. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10566. if (entry->flags & CNTR_DISABLED) {
  10567. /* Nothing */
  10568. hfi1_cdbg(CNTR, "\tDisabled\n");
  10569. continue;
  10570. }
  10571. if (entry->flags & CNTR_VL) {
  10572. hfi1_cdbg(CNTR, "\tPer VL");
  10573. for (j = 0; j < C_VL_COUNT; j++) {
  10574. val = entry->rw_cntr(entry, ppd, j,
  10575. CNTR_MODE_R,
  10576. 0);
  10577. hfi1_cdbg(
  10578. CNTR,
  10579. "\t\tRead 0x%llx for %d",
  10580. val, j);
  10581. ppd->cntrs[entry->offset + j] = val;
  10582. }
  10583. } else {
  10584. val = entry->rw_cntr(entry, ppd,
  10585. CNTR_INVALID_VL,
  10586. CNTR_MODE_R,
  10587. 0);
  10588. ppd->cntrs[entry->offset] = val;
  10589. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10590. }
  10591. }
  10592. }
  10593. return ret;
  10594. }
  10595. static void free_cntrs(struct hfi1_devdata *dd)
  10596. {
  10597. struct hfi1_pportdata *ppd;
  10598. int i;
  10599. if (dd->synth_stats_timer.data)
  10600. del_timer_sync(&dd->synth_stats_timer);
  10601. dd->synth_stats_timer.data = 0;
  10602. ppd = (struct hfi1_pportdata *)(dd + 1);
  10603. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10604. kfree(ppd->cntrs);
  10605. kfree(ppd->scntrs);
  10606. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10607. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10608. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10609. ppd->cntrs = NULL;
  10610. ppd->scntrs = NULL;
  10611. ppd->ibport_data.rvp.rc_acks = NULL;
  10612. ppd->ibport_data.rvp.rc_qacks = NULL;
  10613. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10614. }
  10615. kfree(dd->portcntrnames);
  10616. dd->portcntrnames = NULL;
  10617. kfree(dd->cntrs);
  10618. dd->cntrs = NULL;
  10619. kfree(dd->scntrs);
  10620. dd->scntrs = NULL;
  10621. kfree(dd->cntrnames);
  10622. dd->cntrnames = NULL;
  10623. if (dd->update_cntr_wq) {
  10624. destroy_workqueue(dd->update_cntr_wq);
  10625. dd->update_cntr_wq = NULL;
  10626. }
  10627. }
  10628. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10629. u64 *psval, void *context, int vl)
  10630. {
  10631. u64 val;
  10632. u64 sval = *psval;
  10633. if (entry->flags & CNTR_DISABLED) {
  10634. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10635. return 0;
  10636. }
  10637. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10638. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10639. /* If its a synthetic counter there is more work we need to do */
  10640. if (entry->flags & CNTR_SYNTH) {
  10641. if (sval == CNTR_MAX) {
  10642. /* No need to read already saturated */
  10643. return CNTR_MAX;
  10644. }
  10645. if (entry->flags & CNTR_32BIT) {
  10646. /* 32bit counters can wrap multiple times */
  10647. u64 upper = sval >> 32;
  10648. u64 lower = (sval << 32) >> 32;
  10649. if (lower > val) { /* hw wrapped */
  10650. if (upper == CNTR_32BIT_MAX)
  10651. val = CNTR_MAX;
  10652. else
  10653. upper++;
  10654. }
  10655. if (val != CNTR_MAX)
  10656. val = (upper << 32) | val;
  10657. } else {
  10658. /* If we rolled we are saturated */
  10659. if ((val < sval) || (val > CNTR_MAX))
  10660. val = CNTR_MAX;
  10661. }
  10662. }
  10663. *psval = val;
  10664. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10665. return val;
  10666. }
  10667. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10668. struct cntr_entry *entry,
  10669. u64 *psval, void *context, int vl, u64 data)
  10670. {
  10671. u64 val;
  10672. if (entry->flags & CNTR_DISABLED) {
  10673. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10674. return 0;
  10675. }
  10676. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10677. if (entry->flags & CNTR_SYNTH) {
  10678. *psval = data;
  10679. if (entry->flags & CNTR_32BIT) {
  10680. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10681. (data << 32) >> 32);
  10682. val = data; /* return the full 64bit value */
  10683. } else {
  10684. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10685. data);
  10686. }
  10687. } else {
  10688. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10689. }
  10690. *psval = val;
  10691. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10692. return val;
  10693. }
  10694. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10695. {
  10696. struct cntr_entry *entry;
  10697. u64 *sval;
  10698. entry = &dev_cntrs[index];
  10699. sval = dd->scntrs + entry->offset;
  10700. if (vl != CNTR_INVALID_VL)
  10701. sval += vl;
  10702. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10703. }
  10704. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10705. {
  10706. struct cntr_entry *entry;
  10707. u64 *sval;
  10708. entry = &dev_cntrs[index];
  10709. sval = dd->scntrs + entry->offset;
  10710. if (vl != CNTR_INVALID_VL)
  10711. sval += vl;
  10712. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10713. }
  10714. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10715. {
  10716. struct cntr_entry *entry;
  10717. u64 *sval;
  10718. entry = &port_cntrs[index];
  10719. sval = ppd->scntrs + entry->offset;
  10720. if (vl != CNTR_INVALID_VL)
  10721. sval += vl;
  10722. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10723. (index <= C_RCV_HDR_OVF_LAST)) {
  10724. /* We do not want to bother for disabled contexts */
  10725. return 0;
  10726. }
  10727. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10728. }
  10729. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10730. {
  10731. struct cntr_entry *entry;
  10732. u64 *sval;
  10733. entry = &port_cntrs[index];
  10734. sval = ppd->scntrs + entry->offset;
  10735. if (vl != CNTR_INVALID_VL)
  10736. sval += vl;
  10737. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10738. (index <= C_RCV_HDR_OVF_LAST)) {
  10739. /* We do not want to bother for disabled contexts */
  10740. return 0;
  10741. }
  10742. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10743. }
  10744. static void do_update_synth_timer(struct work_struct *work)
  10745. {
  10746. u64 cur_tx;
  10747. u64 cur_rx;
  10748. u64 total_flits;
  10749. u8 update = 0;
  10750. int i, j, vl;
  10751. struct hfi1_pportdata *ppd;
  10752. struct cntr_entry *entry;
  10753. struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
  10754. update_cntr_work);
  10755. /*
  10756. * Rather than keep beating on the CSRs pick a minimal set that we can
  10757. * check to watch for potential roll over. We can do this by looking at
  10758. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10759. * we have to iterate all the counters and update.
  10760. */
  10761. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10762. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10763. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10764. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10765. hfi1_cdbg(
  10766. CNTR,
  10767. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10768. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10769. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10770. /*
  10771. * May not be strictly necessary to update but it won't hurt and
  10772. * simplifies the logic here.
  10773. */
  10774. update = 1;
  10775. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10776. dd->unit);
  10777. } else {
  10778. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10779. hfi1_cdbg(CNTR,
  10780. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10781. total_flits, (u64)CNTR_32BIT_MAX);
  10782. if (total_flits >= CNTR_32BIT_MAX) {
  10783. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10784. dd->unit);
  10785. update = 1;
  10786. }
  10787. }
  10788. if (update) {
  10789. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10790. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10791. entry = &dev_cntrs[i];
  10792. if (entry->flags & CNTR_VL) {
  10793. for (vl = 0; vl < C_VL_COUNT; vl++)
  10794. read_dev_cntr(dd, i, vl);
  10795. } else {
  10796. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10797. }
  10798. }
  10799. ppd = (struct hfi1_pportdata *)(dd + 1);
  10800. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10801. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10802. entry = &port_cntrs[j];
  10803. if (entry->flags & CNTR_VL) {
  10804. for (vl = 0; vl < C_VL_COUNT; vl++)
  10805. read_port_cntr(ppd, j, vl);
  10806. } else {
  10807. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10808. }
  10809. }
  10810. }
  10811. /*
  10812. * We want the value in the register. The goal is to keep track
  10813. * of the number of "ticks" not the counter value. In other
  10814. * words if the register rolls we want to notice it and go ahead
  10815. * and force an update.
  10816. */
  10817. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10818. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10819. CNTR_MODE_R, 0);
  10820. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10821. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10822. CNTR_MODE_R, 0);
  10823. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10824. dd->unit, dd->last_tx, dd->last_rx);
  10825. } else {
  10826. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10827. }
  10828. }
  10829. static void update_synth_timer(unsigned long opaque)
  10830. {
  10831. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  10832. queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
  10833. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10834. }
  10835. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10836. static int init_cntrs(struct hfi1_devdata *dd)
  10837. {
  10838. int i, rcv_ctxts, j;
  10839. size_t sz;
  10840. char *p;
  10841. char name[C_MAX_NAME];
  10842. struct hfi1_pportdata *ppd;
  10843. const char *bit_type_32 = ",32";
  10844. const int bit_type_32_sz = strlen(bit_type_32);
  10845. /* set up the stats timer; the add_timer is done at the end */
  10846. setup_timer(&dd->synth_stats_timer, update_synth_timer,
  10847. (unsigned long)dd);
  10848. /***********************/
  10849. /* per device counters */
  10850. /***********************/
  10851. /* size names and determine how many we have*/
  10852. dd->ndevcntrs = 0;
  10853. sz = 0;
  10854. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10855. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10856. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10857. continue;
  10858. }
  10859. if (dev_cntrs[i].flags & CNTR_VL) {
  10860. dev_cntrs[i].offset = dd->ndevcntrs;
  10861. for (j = 0; j < C_VL_COUNT; j++) {
  10862. snprintf(name, C_MAX_NAME, "%s%d",
  10863. dev_cntrs[i].name, vl_from_idx(j));
  10864. sz += strlen(name);
  10865. /* Add ",32" for 32-bit counters */
  10866. if (dev_cntrs[i].flags & CNTR_32BIT)
  10867. sz += bit_type_32_sz;
  10868. sz++;
  10869. dd->ndevcntrs++;
  10870. }
  10871. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10872. dev_cntrs[i].offset = dd->ndevcntrs;
  10873. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10874. snprintf(name, C_MAX_NAME, "%s%d",
  10875. dev_cntrs[i].name, j);
  10876. sz += strlen(name);
  10877. /* Add ",32" for 32-bit counters */
  10878. if (dev_cntrs[i].flags & CNTR_32BIT)
  10879. sz += bit_type_32_sz;
  10880. sz++;
  10881. dd->ndevcntrs++;
  10882. }
  10883. } else {
  10884. /* +1 for newline. */
  10885. sz += strlen(dev_cntrs[i].name) + 1;
  10886. /* Add ",32" for 32-bit counters */
  10887. if (dev_cntrs[i].flags & CNTR_32BIT)
  10888. sz += bit_type_32_sz;
  10889. dev_cntrs[i].offset = dd->ndevcntrs;
  10890. dd->ndevcntrs++;
  10891. }
  10892. }
  10893. /* allocate space for the counter values */
  10894. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10895. if (!dd->cntrs)
  10896. goto bail;
  10897. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10898. if (!dd->scntrs)
  10899. goto bail;
  10900. /* allocate space for the counter names */
  10901. dd->cntrnameslen = sz;
  10902. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10903. if (!dd->cntrnames)
  10904. goto bail;
  10905. /* fill in the names */
  10906. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10907. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10908. /* Nothing */
  10909. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10910. for (j = 0; j < C_VL_COUNT; j++) {
  10911. snprintf(name, C_MAX_NAME, "%s%d",
  10912. dev_cntrs[i].name,
  10913. vl_from_idx(j));
  10914. memcpy(p, name, strlen(name));
  10915. p += strlen(name);
  10916. /* Counter is 32 bits */
  10917. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10918. memcpy(p, bit_type_32, bit_type_32_sz);
  10919. p += bit_type_32_sz;
  10920. }
  10921. *p++ = '\n';
  10922. }
  10923. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10924. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10925. snprintf(name, C_MAX_NAME, "%s%d",
  10926. dev_cntrs[i].name, j);
  10927. memcpy(p, name, strlen(name));
  10928. p += strlen(name);
  10929. /* Counter is 32 bits */
  10930. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10931. memcpy(p, bit_type_32, bit_type_32_sz);
  10932. p += bit_type_32_sz;
  10933. }
  10934. *p++ = '\n';
  10935. }
  10936. } else {
  10937. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10938. p += strlen(dev_cntrs[i].name);
  10939. /* Counter is 32 bits */
  10940. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10941. memcpy(p, bit_type_32, bit_type_32_sz);
  10942. p += bit_type_32_sz;
  10943. }
  10944. *p++ = '\n';
  10945. }
  10946. }
  10947. /*********************/
  10948. /* per port counters */
  10949. /*********************/
  10950. /*
  10951. * Go through the counters for the overflows and disable the ones we
  10952. * don't need. This varies based on platform so we need to do it
  10953. * dynamically here.
  10954. */
  10955. rcv_ctxts = dd->num_rcv_contexts;
  10956. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  10957. i <= C_RCV_HDR_OVF_LAST; i++) {
  10958. port_cntrs[i].flags |= CNTR_DISABLED;
  10959. }
  10960. /* size port counter names and determine how many we have*/
  10961. sz = 0;
  10962. dd->nportcntrs = 0;
  10963. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10964. if (port_cntrs[i].flags & CNTR_DISABLED) {
  10965. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  10966. continue;
  10967. }
  10968. if (port_cntrs[i].flags & CNTR_VL) {
  10969. port_cntrs[i].offset = dd->nportcntrs;
  10970. for (j = 0; j < C_VL_COUNT; j++) {
  10971. snprintf(name, C_MAX_NAME, "%s%d",
  10972. port_cntrs[i].name, vl_from_idx(j));
  10973. sz += strlen(name);
  10974. /* Add ",32" for 32-bit counters */
  10975. if (port_cntrs[i].flags & CNTR_32BIT)
  10976. sz += bit_type_32_sz;
  10977. sz++;
  10978. dd->nportcntrs++;
  10979. }
  10980. } else {
  10981. /* +1 for newline */
  10982. sz += strlen(port_cntrs[i].name) + 1;
  10983. /* Add ",32" for 32-bit counters */
  10984. if (port_cntrs[i].flags & CNTR_32BIT)
  10985. sz += bit_type_32_sz;
  10986. port_cntrs[i].offset = dd->nportcntrs;
  10987. dd->nportcntrs++;
  10988. }
  10989. }
  10990. /* allocate space for the counter names */
  10991. dd->portcntrnameslen = sz;
  10992. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  10993. if (!dd->portcntrnames)
  10994. goto bail;
  10995. /* fill in port cntr names */
  10996. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  10997. if (port_cntrs[i].flags & CNTR_DISABLED)
  10998. continue;
  10999. if (port_cntrs[i].flags & CNTR_VL) {
  11000. for (j = 0; j < C_VL_COUNT; j++) {
  11001. snprintf(name, C_MAX_NAME, "%s%d",
  11002. port_cntrs[i].name, vl_from_idx(j));
  11003. memcpy(p, name, strlen(name));
  11004. p += strlen(name);
  11005. /* Counter is 32 bits */
  11006. if (port_cntrs[i].flags & CNTR_32BIT) {
  11007. memcpy(p, bit_type_32, bit_type_32_sz);
  11008. p += bit_type_32_sz;
  11009. }
  11010. *p++ = '\n';
  11011. }
  11012. } else {
  11013. memcpy(p, port_cntrs[i].name,
  11014. strlen(port_cntrs[i].name));
  11015. p += strlen(port_cntrs[i].name);
  11016. /* Counter is 32 bits */
  11017. if (port_cntrs[i].flags & CNTR_32BIT) {
  11018. memcpy(p, bit_type_32, bit_type_32_sz);
  11019. p += bit_type_32_sz;
  11020. }
  11021. *p++ = '\n';
  11022. }
  11023. }
  11024. /* allocate per port storage for counter values */
  11025. ppd = (struct hfi1_pportdata *)(dd + 1);
  11026. for (i = 0; i < dd->num_pports; i++, ppd++) {
  11027. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11028. if (!ppd->cntrs)
  11029. goto bail;
  11030. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11031. if (!ppd->scntrs)
  11032. goto bail;
  11033. }
  11034. /* CPU counters need to be allocated and zeroed */
  11035. if (init_cpu_counters(dd))
  11036. goto bail;
  11037. dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
  11038. WQ_MEM_RECLAIM, dd->unit);
  11039. if (!dd->update_cntr_wq)
  11040. goto bail;
  11041. INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
  11042. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  11043. return 0;
  11044. bail:
  11045. free_cntrs(dd);
  11046. return -ENOMEM;
  11047. }
  11048. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  11049. {
  11050. switch (chip_lstate) {
  11051. default:
  11052. dd_dev_err(dd,
  11053. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  11054. chip_lstate);
  11055. /* fall through */
  11056. case LSTATE_DOWN:
  11057. return IB_PORT_DOWN;
  11058. case LSTATE_INIT:
  11059. return IB_PORT_INIT;
  11060. case LSTATE_ARMED:
  11061. return IB_PORT_ARMED;
  11062. case LSTATE_ACTIVE:
  11063. return IB_PORT_ACTIVE;
  11064. }
  11065. }
  11066. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  11067. {
  11068. /* look at the HFI meta-states only */
  11069. switch (chip_pstate & 0xf0) {
  11070. default:
  11071. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  11072. chip_pstate);
  11073. /* fall through */
  11074. case PLS_DISABLED:
  11075. return IB_PORTPHYSSTATE_DISABLED;
  11076. case PLS_OFFLINE:
  11077. return OPA_PORTPHYSSTATE_OFFLINE;
  11078. case PLS_POLLING:
  11079. return IB_PORTPHYSSTATE_POLLING;
  11080. case PLS_CONFIGPHY:
  11081. return IB_PORTPHYSSTATE_TRAINING;
  11082. case PLS_LINKUP:
  11083. return IB_PORTPHYSSTATE_LINKUP;
  11084. case PLS_PHYTEST:
  11085. return IB_PORTPHYSSTATE_PHY_TEST;
  11086. }
  11087. }
  11088. /* return the OPA port logical state name */
  11089. const char *opa_lstate_name(u32 lstate)
  11090. {
  11091. static const char * const port_logical_names[] = {
  11092. "PORT_NOP",
  11093. "PORT_DOWN",
  11094. "PORT_INIT",
  11095. "PORT_ARMED",
  11096. "PORT_ACTIVE",
  11097. "PORT_ACTIVE_DEFER",
  11098. };
  11099. if (lstate < ARRAY_SIZE(port_logical_names))
  11100. return port_logical_names[lstate];
  11101. return "unknown";
  11102. }
  11103. /* return the OPA port physical state name */
  11104. const char *opa_pstate_name(u32 pstate)
  11105. {
  11106. static const char * const port_physical_names[] = {
  11107. "PHYS_NOP",
  11108. "reserved1",
  11109. "PHYS_POLL",
  11110. "PHYS_DISABLED",
  11111. "PHYS_TRAINING",
  11112. "PHYS_LINKUP",
  11113. "PHYS_LINK_ERR_RECOVER",
  11114. "PHYS_PHY_TEST",
  11115. "reserved8",
  11116. "PHYS_OFFLINE",
  11117. "PHYS_GANGED",
  11118. "PHYS_TEST",
  11119. };
  11120. if (pstate < ARRAY_SIZE(port_physical_names))
  11121. return port_physical_names[pstate];
  11122. return "unknown";
  11123. }
  11124. static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
  11125. {
  11126. /*
  11127. * Set port status flags in the page mapped into userspace
  11128. * memory. Do it here to ensure a reliable state - this is
  11129. * the only function called by all state handling code.
  11130. * Always set the flags due to the fact that the cache value
  11131. * might have been changed explicitly outside of this
  11132. * function.
  11133. */
  11134. if (ppd->statusp) {
  11135. switch (state) {
  11136. case IB_PORT_DOWN:
  11137. case IB_PORT_INIT:
  11138. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  11139. HFI1_STATUS_IB_READY);
  11140. break;
  11141. case IB_PORT_ARMED:
  11142. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  11143. break;
  11144. case IB_PORT_ACTIVE:
  11145. *ppd->statusp |= HFI1_STATUS_IB_READY;
  11146. break;
  11147. }
  11148. }
  11149. }
  11150. /*
  11151. * wait_logical_linkstate - wait for an IB link state change to occur
  11152. * @ppd: port device
  11153. * @state: the state to wait for
  11154. * @msecs: the number of milliseconds to wait
  11155. *
  11156. * Wait up to msecs milliseconds for IB link state change to occur.
  11157. * For now, take the easy polling route.
  11158. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11159. */
  11160. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11161. int msecs)
  11162. {
  11163. unsigned long timeout;
  11164. u32 new_state;
  11165. timeout = jiffies + msecs_to_jiffies(msecs);
  11166. while (1) {
  11167. new_state = chip_to_opa_lstate(ppd->dd,
  11168. read_logical_state(ppd->dd));
  11169. if (new_state == state)
  11170. break;
  11171. if (time_after(jiffies, timeout)) {
  11172. dd_dev_err(ppd->dd,
  11173. "timeout waiting for link state 0x%x\n",
  11174. state);
  11175. return -ETIMEDOUT;
  11176. }
  11177. msleep(20);
  11178. }
  11179. update_statusp(ppd, state);
  11180. dd_dev_info(ppd->dd,
  11181. "logical state changed to %s (0x%x)\n",
  11182. opa_lstate_name(state),
  11183. state);
  11184. return 0;
  11185. }
  11186. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state)
  11187. {
  11188. u32 ib_pstate = chip_to_opa_pstate(ppd->dd, state);
  11189. dd_dev_info(ppd->dd,
  11190. "physical state changed to %s (0x%x), phy 0x%x\n",
  11191. opa_pstate_name(ib_pstate), ib_pstate, state);
  11192. }
  11193. /*
  11194. * Read the physical hardware link state and check if it matches host
  11195. * drivers anticipated state.
  11196. */
  11197. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state)
  11198. {
  11199. u32 read_state = read_physical_state(ppd->dd);
  11200. if (read_state == state) {
  11201. log_state_transition(ppd, state);
  11202. } else {
  11203. dd_dev_err(ppd->dd,
  11204. "anticipated phy link state 0x%x, read 0x%x\n",
  11205. state, read_state);
  11206. }
  11207. }
  11208. /*
  11209. * wait_physical_linkstate - wait for an physical 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 physical link state change to occur.
  11215. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11216. */
  11217. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11218. int msecs)
  11219. {
  11220. u32 read_state;
  11221. unsigned long timeout;
  11222. timeout = jiffies + msecs_to_jiffies(msecs);
  11223. while (1) {
  11224. read_state = read_physical_state(ppd->dd);
  11225. if (read_state == state)
  11226. break;
  11227. if (time_after(jiffies, timeout)) {
  11228. dd_dev_err(ppd->dd,
  11229. "timeout waiting for phy link state 0x%x\n",
  11230. state);
  11231. return -ETIMEDOUT;
  11232. }
  11233. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11234. }
  11235. log_state_transition(ppd, state);
  11236. return 0;
  11237. }
  11238. /*
  11239. * wait_phys_link_offline_quiet_substates - wait for any offline substate
  11240. * @ppd: port device
  11241. * @msecs: the number of milliseconds to wait
  11242. *
  11243. * Wait up to msecs milliseconds for any offline physical link
  11244. * state change to occur.
  11245. * Returns 0 if at least one state is reached, otherwise -ETIMEDOUT.
  11246. */
  11247. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  11248. int msecs)
  11249. {
  11250. u32 read_state;
  11251. unsigned long timeout;
  11252. timeout = jiffies + msecs_to_jiffies(msecs);
  11253. while (1) {
  11254. read_state = read_physical_state(ppd->dd);
  11255. if ((read_state & 0xF0) == PLS_OFFLINE)
  11256. break;
  11257. if (time_after(jiffies, timeout)) {
  11258. dd_dev_err(ppd->dd,
  11259. "timeout waiting for phy link offline.quiet substates. Read state 0x%x, %dms\n",
  11260. read_state, msecs);
  11261. return -ETIMEDOUT;
  11262. }
  11263. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11264. }
  11265. log_state_transition(ppd, read_state);
  11266. return read_state;
  11267. }
  11268. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  11269. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11270. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  11271. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11272. void hfi1_init_ctxt(struct send_context *sc)
  11273. {
  11274. if (sc) {
  11275. struct hfi1_devdata *dd = sc->dd;
  11276. u64 reg;
  11277. u8 set = (sc->type == SC_USER ?
  11278. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  11279. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  11280. reg = read_kctxt_csr(dd, sc->hw_context,
  11281. SEND_CTXT_CHECK_ENABLE);
  11282. if (set)
  11283. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  11284. else
  11285. SET_STATIC_RATE_CONTROL_SMASK(reg);
  11286. write_kctxt_csr(dd, sc->hw_context,
  11287. SEND_CTXT_CHECK_ENABLE, reg);
  11288. }
  11289. }
  11290. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  11291. {
  11292. int ret = 0;
  11293. u64 reg;
  11294. if (dd->icode != ICODE_RTL_SILICON) {
  11295. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  11296. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  11297. __func__);
  11298. return -EINVAL;
  11299. }
  11300. reg = read_csr(dd, ASIC_STS_THERM);
  11301. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  11302. ASIC_STS_THERM_CURR_TEMP_MASK);
  11303. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  11304. ASIC_STS_THERM_LO_TEMP_MASK);
  11305. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11306. ASIC_STS_THERM_HI_TEMP_MASK);
  11307. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11308. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11309. /* triggers is a 3-bit value - 1 bit per trigger. */
  11310. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11311. return ret;
  11312. }
  11313. /* ========================================================================= */
  11314. /*
  11315. * Enable/disable chip from delivering interrupts.
  11316. */
  11317. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11318. {
  11319. int i;
  11320. /*
  11321. * In HFI, the mask needs to be 1 to allow interrupts.
  11322. */
  11323. if (enable) {
  11324. /* enable all interrupts */
  11325. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11326. write_csr(dd, CCE_INT_MASK + (8 * i), ~(u64)0);
  11327. init_qsfp_int(dd);
  11328. } else {
  11329. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11330. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11331. }
  11332. }
  11333. /*
  11334. * Clear all interrupt sources on the chip.
  11335. */
  11336. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11337. {
  11338. int i;
  11339. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11340. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11341. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11342. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11343. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11344. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11345. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11346. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11347. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11348. for (i = 0; i < dd->chip_send_contexts; i++)
  11349. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11350. for (i = 0; i < dd->chip_sdma_engines; i++)
  11351. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11352. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11353. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11354. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11355. }
  11356. /* Move to pcie.c? */
  11357. static void disable_intx(struct pci_dev *pdev)
  11358. {
  11359. pci_intx(pdev, 0);
  11360. }
  11361. static void clean_up_interrupts(struct hfi1_devdata *dd)
  11362. {
  11363. int i;
  11364. /* remove irqs - must happen before disabling/turning off */
  11365. if (dd->num_msix_entries) {
  11366. /* MSI-X */
  11367. struct hfi1_msix_entry *me = dd->msix_entries;
  11368. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11369. if (!me->arg) /* => no irq, no affinity */
  11370. continue;
  11371. hfi1_put_irq_affinity(dd, me);
  11372. free_irq(me->irq, me->arg);
  11373. }
  11374. /* clean structures */
  11375. kfree(dd->msix_entries);
  11376. dd->msix_entries = NULL;
  11377. dd->num_msix_entries = 0;
  11378. } else {
  11379. /* INTx */
  11380. if (dd->requested_intx_irq) {
  11381. free_irq(dd->pcidev->irq, dd);
  11382. dd->requested_intx_irq = 0;
  11383. }
  11384. disable_intx(dd->pcidev);
  11385. }
  11386. pci_free_irq_vectors(dd->pcidev);
  11387. }
  11388. /*
  11389. * Remap the interrupt source from the general handler to the given MSI-X
  11390. * interrupt.
  11391. */
  11392. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11393. {
  11394. u64 reg;
  11395. int m, n;
  11396. /* clear from the handled mask of the general interrupt */
  11397. m = isrc / 64;
  11398. n = isrc % 64;
  11399. if (likely(m < CCE_NUM_INT_CSRS)) {
  11400. dd->gi_mask[m] &= ~((u64)1 << n);
  11401. } else {
  11402. dd_dev_err(dd, "remap interrupt err\n");
  11403. return;
  11404. }
  11405. /* direct the chip source to the given MSI-X interrupt */
  11406. m = isrc / 8;
  11407. n = isrc % 8;
  11408. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11409. reg &= ~((u64)0xff << (8 * n));
  11410. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11411. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11412. }
  11413. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11414. int engine, int msix_intr)
  11415. {
  11416. /*
  11417. * SDMA engine interrupt sources grouped by type, rather than
  11418. * engine. Per-engine interrupts are as follows:
  11419. * SDMA
  11420. * SDMAProgress
  11421. * SDMAIdle
  11422. */
  11423. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11424. msix_intr);
  11425. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11426. msix_intr);
  11427. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11428. msix_intr);
  11429. }
  11430. static int request_intx_irq(struct hfi1_devdata *dd)
  11431. {
  11432. int ret;
  11433. snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d",
  11434. dd->unit);
  11435. ret = request_irq(dd->pcidev->irq, general_interrupt,
  11436. IRQF_SHARED, dd->intx_name, dd);
  11437. if (ret)
  11438. dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
  11439. ret);
  11440. else
  11441. dd->requested_intx_irq = 1;
  11442. return ret;
  11443. }
  11444. static int request_msix_irqs(struct hfi1_devdata *dd)
  11445. {
  11446. int first_general, last_general;
  11447. int first_sdma, last_sdma;
  11448. int first_rx, last_rx;
  11449. int i, ret = 0;
  11450. /* calculate the ranges we are going to use */
  11451. first_general = 0;
  11452. last_general = first_general + 1;
  11453. first_sdma = last_general;
  11454. last_sdma = first_sdma + dd->num_sdma;
  11455. first_rx = last_sdma;
  11456. last_rx = first_rx + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
  11457. /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
  11458. dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
  11459. /*
  11460. * Sanity check - the code expects all SDMA chip source
  11461. * interrupts to be in the same CSR, starting at bit 0. Verify
  11462. * that this is true by checking the bit location of the start.
  11463. */
  11464. BUILD_BUG_ON(IS_SDMA_START % 64);
  11465. for (i = 0; i < dd->num_msix_entries; i++) {
  11466. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11467. const char *err_info;
  11468. irq_handler_t handler;
  11469. irq_handler_t thread = NULL;
  11470. void *arg = NULL;
  11471. int idx;
  11472. struct hfi1_ctxtdata *rcd = NULL;
  11473. struct sdma_engine *sde = NULL;
  11474. /* obtain the arguments to request_irq */
  11475. if (first_general <= i && i < last_general) {
  11476. idx = i - first_general;
  11477. handler = general_interrupt;
  11478. arg = dd;
  11479. snprintf(me->name, sizeof(me->name),
  11480. DRIVER_NAME "_%d", dd->unit);
  11481. err_info = "general";
  11482. me->type = IRQ_GENERAL;
  11483. } else if (first_sdma <= i && i < last_sdma) {
  11484. idx = i - first_sdma;
  11485. sde = &dd->per_sdma[idx];
  11486. handler = sdma_interrupt;
  11487. arg = sde;
  11488. snprintf(me->name, sizeof(me->name),
  11489. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11490. err_info = "sdma";
  11491. remap_sdma_interrupts(dd, idx, i);
  11492. me->type = IRQ_SDMA;
  11493. } else if (first_rx <= i && i < last_rx) {
  11494. idx = i - first_rx;
  11495. rcd = hfi1_rcd_get_by_index(dd, idx);
  11496. if (rcd) {
  11497. /*
  11498. * Set the interrupt register and mask for this
  11499. * context's interrupt.
  11500. */
  11501. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11502. rcd->imask = ((u64)1) <<
  11503. ((IS_RCVAVAIL_START + idx) % 64);
  11504. handler = receive_context_interrupt;
  11505. thread = receive_context_thread;
  11506. arg = rcd;
  11507. snprintf(me->name, sizeof(me->name),
  11508. DRIVER_NAME "_%d kctxt%d",
  11509. dd->unit, idx);
  11510. err_info = "receive context";
  11511. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11512. me->type = IRQ_RCVCTXT;
  11513. rcd->msix_intr = i;
  11514. hfi1_rcd_put(rcd);
  11515. }
  11516. } else {
  11517. /* not in our expected range - complain, then
  11518. * ignore it
  11519. */
  11520. dd_dev_err(dd,
  11521. "Unexpected extra MSI-X interrupt %d\n", i);
  11522. continue;
  11523. }
  11524. /* no argument, no interrupt */
  11525. if (!arg)
  11526. continue;
  11527. /* make sure the name is terminated */
  11528. me->name[sizeof(me->name) - 1] = 0;
  11529. me->irq = pci_irq_vector(dd->pcidev, i);
  11530. /*
  11531. * On err return me->irq. Don't need to clear this
  11532. * because 'arg' has not been set, and cleanup will
  11533. * do the right thing.
  11534. */
  11535. if (me->irq < 0)
  11536. return me->irq;
  11537. ret = request_threaded_irq(me->irq, handler, thread, 0,
  11538. me->name, arg);
  11539. if (ret) {
  11540. dd_dev_err(dd,
  11541. "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
  11542. err_info, me->irq, idx, ret);
  11543. return ret;
  11544. }
  11545. /*
  11546. * assign arg after request_irq call, so it will be
  11547. * cleaned up
  11548. */
  11549. me->arg = arg;
  11550. ret = hfi1_get_irq_affinity(dd, me);
  11551. if (ret)
  11552. dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
  11553. }
  11554. return ret;
  11555. }
  11556. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
  11557. {
  11558. int i;
  11559. if (!dd->num_msix_entries) {
  11560. synchronize_irq(dd->pcidev->irq);
  11561. return;
  11562. }
  11563. for (i = 0; i < dd->vnic.num_ctxt; i++) {
  11564. struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
  11565. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11566. synchronize_irq(me->irq);
  11567. }
  11568. }
  11569. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11570. {
  11571. struct hfi1_devdata *dd = rcd->dd;
  11572. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11573. if (!me->arg) /* => no irq, no affinity */
  11574. return;
  11575. hfi1_put_irq_affinity(dd, me);
  11576. free_irq(me->irq, me->arg);
  11577. me->arg = NULL;
  11578. }
  11579. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11580. {
  11581. struct hfi1_devdata *dd = rcd->dd;
  11582. struct hfi1_msix_entry *me;
  11583. int idx = rcd->ctxt;
  11584. void *arg = rcd;
  11585. int ret;
  11586. rcd->msix_intr = dd->vnic.msix_idx++;
  11587. me = &dd->msix_entries[rcd->msix_intr];
  11588. /*
  11589. * Set the interrupt register and mask for this
  11590. * context's interrupt.
  11591. */
  11592. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11593. rcd->imask = ((u64)1) <<
  11594. ((IS_RCVAVAIL_START + idx) % 64);
  11595. snprintf(me->name, sizeof(me->name),
  11596. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11597. me->name[sizeof(me->name) - 1] = 0;
  11598. me->type = IRQ_RCVCTXT;
  11599. me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
  11600. if (me->irq < 0) {
  11601. dd_dev_err(dd, "vnic irq vector request (idx %d) fail %d\n",
  11602. idx, me->irq);
  11603. return;
  11604. }
  11605. remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
  11606. ret = request_threaded_irq(me->irq, receive_context_interrupt,
  11607. receive_context_thread, 0, me->name, arg);
  11608. if (ret) {
  11609. dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
  11610. me->irq, idx, ret);
  11611. return;
  11612. }
  11613. /*
  11614. * assign arg after request_irq call, so it will be
  11615. * cleaned up
  11616. */
  11617. me->arg = arg;
  11618. ret = hfi1_get_irq_affinity(dd, me);
  11619. if (ret) {
  11620. dd_dev_err(dd,
  11621. "unable to pin IRQ %d\n", ret);
  11622. free_irq(me->irq, me->arg);
  11623. }
  11624. }
  11625. /*
  11626. * Set the general handler to accept all interrupts, remap all
  11627. * chip interrupts back to MSI-X 0.
  11628. */
  11629. static void reset_interrupts(struct hfi1_devdata *dd)
  11630. {
  11631. int i;
  11632. /* all interrupts handled by the general handler */
  11633. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11634. dd->gi_mask[i] = ~(u64)0;
  11635. /* all chip interrupts map to MSI-X 0 */
  11636. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11637. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11638. }
  11639. static int set_up_interrupts(struct hfi1_devdata *dd)
  11640. {
  11641. u32 total;
  11642. int ret, request;
  11643. int single_interrupt = 0; /* we expect to have all the interrupts */
  11644. /*
  11645. * Interrupt count:
  11646. * 1 general, "slow path" interrupt (includes the SDMA engines
  11647. * slow source, SDMACleanupDone)
  11648. * N interrupts - one per used SDMA engine
  11649. * M interrupt - one per kernel receive context
  11650. */
  11651. total = 1 + dd->num_sdma + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
  11652. /* ask for MSI-X interrupts */
  11653. request = request_msix(dd, total);
  11654. if (request < 0) {
  11655. ret = request;
  11656. goto fail;
  11657. } else if (request == 0) {
  11658. /* using INTx */
  11659. /* dd->num_msix_entries already zero */
  11660. single_interrupt = 1;
  11661. dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
  11662. } else if (request < total) {
  11663. /* using MSI-X, with reduced interrupts */
  11664. dd_dev_err(dd, "reduced interrupt found, wanted %u, got %u\n",
  11665. total, request);
  11666. ret = -EINVAL;
  11667. goto fail;
  11668. } else {
  11669. dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
  11670. GFP_KERNEL);
  11671. if (!dd->msix_entries) {
  11672. ret = -ENOMEM;
  11673. goto fail;
  11674. }
  11675. /* using MSI-X */
  11676. dd->num_msix_entries = total;
  11677. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11678. }
  11679. /* mask all interrupts */
  11680. set_intr_state(dd, 0);
  11681. /* clear all pending interrupts */
  11682. clear_all_interrupts(dd);
  11683. /* reset general handler mask, chip MSI-X mappings */
  11684. reset_interrupts(dd);
  11685. if (single_interrupt)
  11686. ret = request_intx_irq(dd);
  11687. else
  11688. ret = request_msix_irqs(dd);
  11689. if (ret)
  11690. goto fail;
  11691. return 0;
  11692. fail:
  11693. clean_up_interrupts(dd);
  11694. return ret;
  11695. }
  11696. /*
  11697. * Set up context values in dd. Sets:
  11698. *
  11699. * num_rcv_contexts - number of contexts being used
  11700. * n_krcv_queues - number of kernel contexts
  11701. * first_dyn_alloc_ctxt - first dynamically allocated context
  11702. * in array of contexts
  11703. * freectxts - number of free user contexts
  11704. * num_send_contexts - number of PIO send contexts being used
  11705. */
  11706. static int set_up_context_variables(struct hfi1_devdata *dd)
  11707. {
  11708. unsigned long num_kernel_contexts;
  11709. int total_contexts;
  11710. int ret;
  11711. unsigned ngroups;
  11712. int qos_rmt_count;
  11713. int user_rmt_reduced;
  11714. /*
  11715. * Kernel receive contexts:
  11716. * - Context 0 - control context (VL15/multicast/error)
  11717. * - Context 1 - first kernel context
  11718. * - Context 2 - second kernel context
  11719. * ...
  11720. */
  11721. if (n_krcvqs)
  11722. /*
  11723. * n_krcvqs is the sum of module parameter kernel receive
  11724. * contexts, krcvqs[]. It does not include the control
  11725. * context, so add that.
  11726. */
  11727. num_kernel_contexts = n_krcvqs + 1;
  11728. else
  11729. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11730. /*
  11731. * Every kernel receive context needs an ACK send context.
  11732. * one send context is allocated for each VL{0-7} and VL15
  11733. */
  11734. if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
  11735. dd_dev_err(dd,
  11736. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11737. (int)(dd->chip_send_contexts - num_vls - 1),
  11738. num_kernel_contexts);
  11739. num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
  11740. }
  11741. /*
  11742. * User contexts:
  11743. * - default to 1 user context per real (non-HT) CPU core if
  11744. * num_user_contexts is negative
  11745. */
  11746. if (num_user_contexts < 0)
  11747. num_user_contexts =
  11748. cpumask_weight(&node_affinity.real_cpu_mask);
  11749. total_contexts = num_kernel_contexts + num_user_contexts;
  11750. /*
  11751. * Adjust the counts given a global max.
  11752. */
  11753. if (total_contexts > dd->chip_rcv_contexts) {
  11754. dd_dev_err(dd,
  11755. "Reducing # user receive contexts to: %d, from %d\n",
  11756. (int)(dd->chip_rcv_contexts - num_kernel_contexts),
  11757. (int)num_user_contexts);
  11758. num_user_contexts = dd->chip_rcv_contexts - num_kernel_contexts;
  11759. /* recalculate */
  11760. total_contexts = num_kernel_contexts + num_user_contexts;
  11761. }
  11762. /* each user context requires an entry in the RMT */
  11763. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11764. if (qos_rmt_count + num_user_contexts > NUM_MAP_ENTRIES) {
  11765. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11766. dd_dev_err(dd,
  11767. "RMT size is reducing the number of user receive contexts from %d to %d\n",
  11768. (int)num_user_contexts,
  11769. user_rmt_reduced);
  11770. /* recalculate */
  11771. num_user_contexts = user_rmt_reduced;
  11772. total_contexts = num_kernel_contexts + num_user_contexts;
  11773. }
  11774. /* Accommodate VNIC contexts */
  11775. if ((total_contexts + HFI1_NUM_VNIC_CTXT) <= dd->chip_rcv_contexts)
  11776. total_contexts += HFI1_NUM_VNIC_CTXT;
  11777. /* the first N are kernel contexts, the rest are user/vnic contexts */
  11778. dd->num_rcv_contexts = total_contexts;
  11779. dd->n_krcv_queues = num_kernel_contexts;
  11780. dd->first_dyn_alloc_ctxt = num_kernel_contexts;
  11781. dd->num_user_contexts = num_user_contexts;
  11782. dd->freectxts = num_user_contexts;
  11783. dd_dev_info(dd,
  11784. "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
  11785. (int)dd->chip_rcv_contexts,
  11786. (int)dd->num_rcv_contexts,
  11787. (int)dd->n_krcv_queues,
  11788. (int)dd->num_rcv_contexts - dd->n_krcv_queues);
  11789. /*
  11790. * Receive array allocation:
  11791. * All RcvArray entries are divided into groups of 8. This
  11792. * is required by the hardware and will speed up writes to
  11793. * consecutive entries by using write-combining of the entire
  11794. * cacheline.
  11795. *
  11796. * The number of groups are evenly divided among all contexts.
  11797. * any left over groups will be given to the first N user
  11798. * contexts.
  11799. */
  11800. dd->rcv_entries.group_size = RCV_INCREMENT;
  11801. ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
  11802. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11803. dd->rcv_entries.nctxt_extra = ngroups -
  11804. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11805. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11806. dd->rcv_entries.ngroups,
  11807. dd->rcv_entries.nctxt_extra);
  11808. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11809. MAX_EAGER_ENTRIES * 2) {
  11810. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11811. dd->rcv_entries.group_size;
  11812. dd_dev_info(dd,
  11813. "RcvArray group count too high, change to %u\n",
  11814. dd->rcv_entries.ngroups);
  11815. dd->rcv_entries.nctxt_extra = 0;
  11816. }
  11817. /*
  11818. * PIO send contexts
  11819. */
  11820. ret = init_sc_pools_and_sizes(dd);
  11821. if (ret >= 0) { /* success */
  11822. dd->num_send_contexts = ret;
  11823. dd_dev_info(
  11824. dd,
  11825. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11826. dd->chip_send_contexts,
  11827. dd->num_send_contexts,
  11828. dd->sc_sizes[SC_KERNEL].count,
  11829. dd->sc_sizes[SC_ACK].count,
  11830. dd->sc_sizes[SC_USER].count,
  11831. dd->sc_sizes[SC_VL15].count);
  11832. ret = 0; /* success */
  11833. }
  11834. return ret;
  11835. }
  11836. /*
  11837. * Set the device/port partition key table. The MAD code
  11838. * will ensure that, at least, the partial management
  11839. * partition key is present in the table.
  11840. */
  11841. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11842. {
  11843. struct hfi1_devdata *dd = ppd->dd;
  11844. u64 reg = 0;
  11845. int i;
  11846. dd_dev_info(dd, "Setting partition keys\n");
  11847. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11848. reg |= (ppd->pkeys[i] &
  11849. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11850. ((i % 4) *
  11851. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11852. /* Each register holds 4 PKey values. */
  11853. if ((i % 4) == 3) {
  11854. write_csr(dd, RCV_PARTITION_KEY +
  11855. ((i - 3) * 2), reg);
  11856. reg = 0;
  11857. }
  11858. }
  11859. /* Always enable HW pkeys check when pkeys table is set */
  11860. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11861. }
  11862. /*
  11863. * These CSRs and memories are uninitialized on reset and must be
  11864. * written before reading to set the ECC/parity bits.
  11865. *
  11866. * NOTE: All user context CSRs that are not mmaped write-only
  11867. * (e.g. the TID flows) must be initialized even if the driver never
  11868. * reads them.
  11869. */
  11870. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11871. {
  11872. int i, j;
  11873. /* CceIntMap */
  11874. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11875. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11876. /* SendCtxtCreditReturnAddr */
  11877. for (i = 0; i < dd->chip_send_contexts; i++)
  11878. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11879. /* PIO Send buffers */
  11880. /* SDMA Send buffers */
  11881. /*
  11882. * These are not normally read, and (presently) have no method
  11883. * to be read, so are not pre-initialized
  11884. */
  11885. /* RcvHdrAddr */
  11886. /* RcvHdrTailAddr */
  11887. /* RcvTidFlowTable */
  11888. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11889. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11890. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11891. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11892. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11893. }
  11894. /* RcvArray */
  11895. for (i = 0; i < dd->chip_rcv_array_count; i++)
  11896. hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
  11897. /* RcvQPMapTable */
  11898. for (i = 0; i < 32; i++)
  11899. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11900. }
  11901. /*
  11902. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11903. */
  11904. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11905. u64 ctrl_bits)
  11906. {
  11907. unsigned long timeout;
  11908. u64 reg;
  11909. /* is the condition present? */
  11910. reg = read_csr(dd, CCE_STATUS);
  11911. if ((reg & status_bits) == 0)
  11912. return;
  11913. /* clear the condition */
  11914. write_csr(dd, CCE_CTRL, ctrl_bits);
  11915. /* wait for the condition to clear */
  11916. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11917. while (1) {
  11918. reg = read_csr(dd, CCE_STATUS);
  11919. if ((reg & status_bits) == 0)
  11920. return;
  11921. if (time_after(jiffies, timeout)) {
  11922. dd_dev_err(dd,
  11923. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11924. status_bits, reg & status_bits);
  11925. return;
  11926. }
  11927. udelay(1);
  11928. }
  11929. }
  11930. /* set CCE CSRs to chip reset defaults */
  11931. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11932. {
  11933. int i;
  11934. /* CCE_REVISION read-only */
  11935. /* CCE_REVISION2 read-only */
  11936. /* CCE_CTRL - bits clear automatically */
  11937. /* CCE_STATUS read-only, use CceCtrl to clear */
  11938. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11939. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  11940. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  11941. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  11942. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  11943. /* CCE_ERR_STATUS read-only */
  11944. write_csr(dd, CCE_ERR_MASK, 0);
  11945. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  11946. /* CCE_ERR_FORCE leave alone */
  11947. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  11948. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  11949. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  11950. /* CCE_PCIE_CTRL leave alone */
  11951. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  11952. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  11953. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  11954. CCE_MSIX_TABLE_UPPER_RESETCSR);
  11955. }
  11956. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  11957. /* CCE_MSIX_PBA read-only */
  11958. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  11959. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  11960. }
  11961. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11962. write_csr(dd, CCE_INT_MAP, 0);
  11963. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11964. /* CCE_INT_STATUS read-only */
  11965. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  11966. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  11967. /* CCE_INT_FORCE leave alone */
  11968. /* CCE_INT_BLOCKED read-only */
  11969. }
  11970. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  11971. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  11972. }
  11973. /* set MISC CSRs to chip reset defaults */
  11974. static void reset_misc_csrs(struct hfi1_devdata *dd)
  11975. {
  11976. int i;
  11977. for (i = 0; i < 32; i++) {
  11978. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  11979. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  11980. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  11981. }
  11982. /*
  11983. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  11984. * only be written 128-byte chunks
  11985. */
  11986. /* init RSA engine to clear lingering errors */
  11987. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  11988. write_csr(dd, MISC_CFG_RSA_MU, 0);
  11989. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  11990. /* MISC_STS_8051_DIGEST read-only */
  11991. /* MISC_STS_SBM_DIGEST read-only */
  11992. /* MISC_STS_PCIE_DIGEST read-only */
  11993. /* MISC_STS_FAB_DIGEST read-only */
  11994. /* MISC_ERR_STATUS read-only */
  11995. write_csr(dd, MISC_ERR_MASK, 0);
  11996. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  11997. /* MISC_ERR_FORCE leave alone */
  11998. }
  11999. /* set TXE CSRs to chip reset defaults */
  12000. static void reset_txe_csrs(struct hfi1_devdata *dd)
  12001. {
  12002. int i;
  12003. /*
  12004. * TXE Kernel CSRs
  12005. */
  12006. write_csr(dd, SEND_CTRL, 0);
  12007. __cm_reset(dd, 0); /* reset CM internal state */
  12008. /* SEND_CONTEXTS read-only */
  12009. /* SEND_DMA_ENGINES read-only */
  12010. /* SEND_PIO_MEM_SIZE read-only */
  12011. /* SEND_DMA_MEM_SIZE read-only */
  12012. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  12013. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  12014. /* SEND_PIO_ERR_STATUS read-only */
  12015. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  12016. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  12017. /* SEND_PIO_ERR_FORCE leave alone */
  12018. /* SEND_DMA_ERR_STATUS read-only */
  12019. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  12020. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  12021. /* SEND_DMA_ERR_FORCE leave alone */
  12022. /* SEND_EGRESS_ERR_STATUS read-only */
  12023. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  12024. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  12025. /* SEND_EGRESS_ERR_FORCE leave alone */
  12026. write_csr(dd, SEND_BTH_QP, 0);
  12027. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  12028. write_csr(dd, SEND_SC2VLT0, 0);
  12029. write_csr(dd, SEND_SC2VLT1, 0);
  12030. write_csr(dd, SEND_SC2VLT2, 0);
  12031. write_csr(dd, SEND_SC2VLT3, 0);
  12032. write_csr(dd, SEND_LEN_CHECK0, 0);
  12033. write_csr(dd, SEND_LEN_CHECK1, 0);
  12034. /* SEND_ERR_STATUS read-only */
  12035. write_csr(dd, SEND_ERR_MASK, 0);
  12036. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  12037. /* SEND_ERR_FORCE read-only */
  12038. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  12039. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  12040. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  12041. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  12042. for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
  12043. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  12044. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  12045. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  12046. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  12047. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  12048. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  12049. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  12050. /* SEND_CM_CREDIT_USED_STATUS read-only */
  12051. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  12052. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  12053. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  12054. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  12055. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  12056. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  12057. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  12058. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  12059. /* SEND_CM_CREDIT_USED_VL read-only */
  12060. /* SEND_CM_CREDIT_USED_VL15 read-only */
  12061. /* SEND_EGRESS_CTXT_STATUS read-only */
  12062. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  12063. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  12064. /* SEND_EGRESS_ERR_INFO read-only */
  12065. /* SEND_EGRESS_ERR_SOURCE read-only */
  12066. /*
  12067. * TXE Per-Context CSRs
  12068. */
  12069. for (i = 0; i < dd->chip_send_contexts; i++) {
  12070. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12071. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  12072. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  12073. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  12074. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  12075. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  12076. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  12077. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  12078. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  12079. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12080. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  12081. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  12082. }
  12083. /*
  12084. * TXE Per-SDMA CSRs
  12085. */
  12086. for (i = 0; i < dd->chip_sdma_engines; i++) {
  12087. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12088. /* SEND_DMA_STATUS read-only */
  12089. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  12090. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  12091. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  12092. /* SEND_DMA_HEAD read-only */
  12093. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  12094. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  12095. /* SEND_DMA_IDLE_CNT read-only */
  12096. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  12097. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  12098. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  12099. /* SEND_DMA_ENG_ERR_STATUS read-only */
  12100. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  12101. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  12102. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  12103. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  12104. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  12105. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  12106. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  12107. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  12108. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  12109. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  12110. }
  12111. }
  12112. /*
  12113. * Expect on entry:
  12114. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  12115. */
  12116. static void init_rbufs(struct hfi1_devdata *dd)
  12117. {
  12118. u64 reg;
  12119. int count;
  12120. /*
  12121. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  12122. * clear.
  12123. */
  12124. count = 0;
  12125. while (1) {
  12126. reg = read_csr(dd, RCV_STATUS);
  12127. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  12128. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  12129. break;
  12130. /*
  12131. * Give up after 1ms - maximum wait time.
  12132. *
  12133. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  12134. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  12135. * 136 KB / (66% * 250MB/s) = 844us
  12136. */
  12137. if (count++ > 500) {
  12138. dd_dev_err(dd,
  12139. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  12140. __func__, reg);
  12141. break;
  12142. }
  12143. udelay(2); /* do not busy-wait the CSR */
  12144. }
  12145. /* start the init - expect RcvCtrl to be 0 */
  12146. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  12147. /*
  12148. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  12149. * period after the write before RcvStatus.RxRbufInitDone is valid.
  12150. * The delay in the first run through the loop below is sufficient and
  12151. * required before the first read of RcvStatus.RxRbufInintDone.
  12152. */
  12153. read_csr(dd, RCV_CTRL);
  12154. /* wait for the init to finish */
  12155. count = 0;
  12156. while (1) {
  12157. /* delay is required first time through - see above */
  12158. udelay(2); /* do not busy-wait the CSR */
  12159. reg = read_csr(dd, RCV_STATUS);
  12160. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  12161. break;
  12162. /* give up after 100us - slowest possible at 33MHz is 73us */
  12163. if (count++ > 50) {
  12164. dd_dev_err(dd,
  12165. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  12166. __func__);
  12167. break;
  12168. }
  12169. }
  12170. }
  12171. /* set RXE CSRs to chip reset defaults */
  12172. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  12173. {
  12174. int i, j;
  12175. /*
  12176. * RXE Kernel CSRs
  12177. */
  12178. write_csr(dd, RCV_CTRL, 0);
  12179. init_rbufs(dd);
  12180. /* RCV_STATUS read-only */
  12181. /* RCV_CONTEXTS read-only */
  12182. /* RCV_ARRAY_CNT read-only */
  12183. /* RCV_BUF_SIZE read-only */
  12184. write_csr(dd, RCV_BTH_QP, 0);
  12185. write_csr(dd, RCV_MULTICAST, 0);
  12186. write_csr(dd, RCV_BYPASS, 0);
  12187. write_csr(dd, RCV_VL15, 0);
  12188. /* this is a clear-down */
  12189. write_csr(dd, RCV_ERR_INFO,
  12190. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  12191. /* RCV_ERR_STATUS read-only */
  12192. write_csr(dd, RCV_ERR_MASK, 0);
  12193. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  12194. /* RCV_ERR_FORCE leave alone */
  12195. for (i = 0; i < 32; i++)
  12196. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  12197. for (i = 0; i < 4; i++)
  12198. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  12199. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  12200. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  12201. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  12202. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  12203. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
  12204. clear_rsm_rule(dd, i);
  12205. for (i = 0; i < 32; i++)
  12206. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  12207. /*
  12208. * RXE Kernel and User Per-Context CSRs
  12209. */
  12210. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  12211. /* kernel */
  12212. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  12213. /* RCV_CTXT_STATUS read-only */
  12214. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  12215. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  12216. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  12217. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  12218. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  12219. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  12220. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  12221. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  12222. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  12223. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  12224. /* user */
  12225. /* RCV_HDR_TAIL read-only */
  12226. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  12227. /* RCV_EGR_INDEX_TAIL read-only */
  12228. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  12229. /* RCV_EGR_OFFSET_TAIL read-only */
  12230. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  12231. write_uctxt_csr(dd, i,
  12232. RCV_TID_FLOW_TABLE + (8 * j), 0);
  12233. }
  12234. }
  12235. }
  12236. /*
  12237. * Set sc2vl tables.
  12238. *
  12239. * They power on to zeros, so to avoid send context errors
  12240. * they need to be set:
  12241. *
  12242. * SC 0-7 -> VL 0-7 (respectively)
  12243. * SC 15 -> VL 15
  12244. * otherwise
  12245. * -> VL 0
  12246. */
  12247. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  12248. {
  12249. int i;
  12250. /* init per architecture spec, constrained by hardware capability */
  12251. /* HFI maps sent packets */
  12252. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  12253. 0,
  12254. 0, 0, 1, 1,
  12255. 2, 2, 3, 3,
  12256. 4, 4, 5, 5,
  12257. 6, 6, 7, 7));
  12258. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  12259. 1,
  12260. 8, 0, 9, 0,
  12261. 10, 0, 11, 0,
  12262. 12, 0, 13, 0,
  12263. 14, 0, 15, 15));
  12264. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  12265. 2,
  12266. 16, 0, 17, 0,
  12267. 18, 0, 19, 0,
  12268. 20, 0, 21, 0,
  12269. 22, 0, 23, 0));
  12270. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  12271. 3,
  12272. 24, 0, 25, 0,
  12273. 26, 0, 27, 0,
  12274. 28, 0, 29, 0,
  12275. 30, 0, 31, 0));
  12276. /* DC maps received packets */
  12277. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  12278. 15_0,
  12279. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  12280. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  12281. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  12282. 31_16,
  12283. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  12284. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  12285. /* initialize the cached sc2vl values consistently with h/w */
  12286. for (i = 0; i < 32; i++) {
  12287. if (i < 8 || i == 15)
  12288. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  12289. else
  12290. *((u8 *)(dd->sc2vl) + i) = 0;
  12291. }
  12292. }
  12293. /*
  12294. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  12295. * depend on the chip going through a power-on reset - a driver may be loaded
  12296. * and unloaded many times.
  12297. *
  12298. * Do not write any CSR values to the chip in this routine - there may be
  12299. * a reset following the (possible) FLR in this routine.
  12300. *
  12301. */
  12302. static int init_chip(struct hfi1_devdata *dd)
  12303. {
  12304. int i;
  12305. int ret = 0;
  12306. /*
  12307. * Put the HFI CSRs in a known state.
  12308. * Combine this with a DC reset.
  12309. *
  12310. * Stop the device from doing anything while we do a
  12311. * reset. We know there are no other active users of
  12312. * the device since we are now in charge. Turn off
  12313. * off all outbound and inbound traffic and make sure
  12314. * the device does not generate any interrupts.
  12315. */
  12316. /* disable send contexts and SDMA engines */
  12317. write_csr(dd, SEND_CTRL, 0);
  12318. for (i = 0; i < dd->chip_send_contexts; i++)
  12319. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12320. for (i = 0; i < dd->chip_sdma_engines; i++)
  12321. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12322. /* disable port (turn off RXE inbound traffic) and contexts */
  12323. write_csr(dd, RCV_CTRL, 0);
  12324. for (i = 0; i < dd->chip_rcv_contexts; i++)
  12325. write_csr(dd, RCV_CTXT_CTRL, 0);
  12326. /* mask all interrupt sources */
  12327. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  12328. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  12329. /*
  12330. * DC Reset: do a full DC reset before the register clear.
  12331. * A recommended length of time to hold is one CSR read,
  12332. * so reread the CceDcCtrl. Then, hold the DC in reset
  12333. * across the clear.
  12334. */
  12335. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  12336. (void)read_csr(dd, CCE_DC_CTRL);
  12337. if (use_flr) {
  12338. /*
  12339. * A FLR will reset the SPC core and part of the PCIe.
  12340. * The parts that need to be restored have already been
  12341. * saved.
  12342. */
  12343. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12344. /* do the FLR, the DC reset will remain */
  12345. pcie_flr(dd->pcidev);
  12346. /* restore command and BARs */
  12347. ret = restore_pci_variables(dd);
  12348. if (ret) {
  12349. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12350. __func__);
  12351. return ret;
  12352. }
  12353. if (is_ax(dd)) {
  12354. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12355. pcie_flr(dd->pcidev);
  12356. ret = restore_pci_variables(dd);
  12357. if (ret) {
  12358. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12359. __func__);
  12360. return ret;
  12361. }
  12362. }
  12363. } else {
  12364. dd_dev_info(dd, "Resetting CSRs with writes\n");
  12365. reset_cce_csrs(dd);
  12366. reset_txe_csrs(dd);
  12367. reset_rxe_csrs(dd);
  12368. reset_misc_csrs(dd);
  12369. }
  12370. /* clear the DC reset */
  12371. write_csr(dd, CCE_DC_CTRL, 0);
  12372. /* Set the LED off */
  12373. setextled(dd, 0);
  12374. /*
  12375. * Clear the QSFP reset.
  12376. * An FLR enforces a 0 on all out pins. The driver does not touch
  12377. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  12378. * anything plugged constantly in reset, if it pays attention
  12379. * to RESET_N.
  12380. * Prime examples of this are optical cables. Set all pins high.
  12381. * I2CCLK and I2CDAT will change per direction, and INT_N and
  12382. * MODPRS_N are input only and their value is ignored.
  12383. */
  12384. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  12385. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  12386. init_chip_resources(dd);
  12387. return ret;
  12388. }
  12389. static void init_early_variables(struct hfi1_devdata *dd)
  12390. {
  12391. int i;
  12392. /* assign link credit variables */
  12393. dd->vau = CM_VAU;
  12394. dd->link_credits = CM_GLOBAL_CREDITS;
  12395. if (is_ax(dd))
  12396. dd->link_credits--;
  12397. dd->vcu = cu_to_vcu(hfi1_cu);
  12398. /* enough room for 8 MAD packets plus header - 17K */
  12399. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12400. if (dd->vl15_init > dd->link_credits)
  12401. dd->vl15_init = dd->link_credits;
  12402. write_uninitialized_csrs_and_memories(dd);
  12403. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12404. for (i = 0; i < dd->num_pports; i++) {
  12405. struct hfi1_pportdata *ppd = &dd->pport[i];
  12406. set_partition_keys(ppd);
  12407. }
  12408. init_sc2vl_tables(dd);
  12409. }
  12410. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12411. {
  12412. /* user changed the KDETH_QP */
  12413. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12414. /* out of range or illegal value */
  12415. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12416. kdeth_qp = 0;
  12417. }
  12418. if (kdeth_qp == 0) /* not set, or failed range check */
  12419. kdeth_qp = DEFAULT_KDETH_QP;
  12420. write_csr(dd, SEND_BTH_QP,
  12421. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12422. SEND_BTH_QP_KDETH_QP_SHIFT);
  12423. write_csr(dd, RCV_BTH_QP,
  12424. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12425. RCV_BTH_QP_KDETH_QP_SHIFT);
  12426. }
  12427. /**
  12428. * init_qpmap_table
  12429. * @dd - device data
  12430. * @first_ctxt - first context
  12431. * @last_ctxt - first context
  12432. *
  12433. * This return sets the qpn mapping table that
  12434. * is indexed by qpn[8:1].
  12435. *
  12436. * The routine will round robin the 256 settings
  12437. * from first_ctxt to last_ctxt.
  12438. *
  12439. * The first/last looks ahead to having specialized
  12440. * receive contexts for mgmt and bypass. Normal
  12441. * verbs traffic will assumed to be on a range
  12442. * of receive contexts.
  12443. */
  12444. static void init_qpmap_table(struct hfi1_devdata *dd,
  12445. u32 first_ctxt,
  12446. u32 last_ctxt)
  12447. {
  12448. u64 reg = 0;
  12449. u64 regno = RCV_QP_MAP_TABLE;
  12450. int i;
  12451. u64 ctxt = first_ctxt;
  12452. for (i = 0; i < 256; i++) {
  12453. reg |= ctxt << (8 * (i % 8));
  12454. ctxt++;
  12455. if (ctxt > last_ctxt)
  12456. ctxt = first_ctxt;
  12457. if (i % 8 == 7) {
  12458. write_csr(dd, regno, reg);
  12459. reg = 0;
  12460. regno += 8;
  12461. }
  12462. }
  12463. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12464. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12465. }
  12466. struct rsm_map_table {
  12467. u64 map[NUM_MAP_REGS];
  12468. unsigned int used;
  12469. };
  12470. struct rsm_rule_data {
  12471. u8 offset;
  12472. u8 pkt_type;
  12473. u32 field1_off;
  12474. u32 field2_off;
  12475. u32 index1_off;
  12476. u32 index1_width;
  12477. u32 index2_off;
  12478. u32 index2_width;
  12479. u32 mask1;
  12480. u32 value1;
  12481. u32 mask2;
  12482. u32 value2;
  12483. };
  12484. /*
  12485. * Return an initialized RMT map table for users to fill in. OK if it
  12486. * returns NULL, indicating no table.
  12487. */
  12488. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12489. {
  12490. struct rsm_map_table *rmt;
  12491. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12492. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12493. if (rmt) {
  12494. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12495. rmt->used = 0;
  12496. }
  12497. return rmt;
  12498. }
  12499. /*
  12500. * Write the final RMT map table to the chip and free the table. OK if
  12501. * table is NULL.
  12502. */
  12503. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12504. struct rsm_map_table *rmt)
  12505. {
  12506. int i;
  12507. if (rmt) {
  12508. /* write table to chip */
  12509. for (i = 0; i < NUM_MAP_REGS; i++)
  12510. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12511. /* enable RSM */
  12512. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12513. }
  12514. }
  12515. /*
  12516. * Add a receive side mapping rule.
  12517. */
  12518. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12519. struct rsm_rule_data *rrd)
  12520. {
  12521. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12522. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12523. 1ull << rule_index | /* enable bit */
  12524. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12525. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12526. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12527. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12528. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12529. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12530. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12531. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12532. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12533. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12534. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12535. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12536. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12537. }
  12538. /*
  12539. * Clear a receive side mapping rule.
  12540. */
  12541. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
  12542. {
  12543. write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
  12544. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
  12545. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
  12546. }
  12547. /* return the number of RSM map table entries that will be used for QOS */
  12548. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12549. unsigned int *np)
  12550. {
  12551. int i;
  12552. unsigned int m, n;
  12553. u8 max_by_vl = 0;
  12554. /* is QOS active at all? */
  12555. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12556. num_vls == 1 ||
  12557. krcvqsset <= 1)
  12558. goto no_qos;
  12559. /* determine bits for qpn */
  12560. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12561. if (krcvqs[i] > max_by_vl)
  12562. max_by_vl = krcvqs[i];
  12563. if (max_by_vl > 32)
  12564. goto no_qos;
  12565. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12566. /* determine bits for vl */
  12567. n = ilog2(__roundup_pow_of_two(num_vls));
  12568. /* reject if too much is used */
  12569. if ((m + n) > 7)
  12570. goto no_qos;
  12571. if (mp)
  12572. *mp = m;
  12573. if (np)
  12574. *np = n;
  12575. return 1 << (m + n);
  12576. no_qos:
  12577. if (mp)
  12578. *mp = 0;
  12579. if (np)
  12580. *np = 0;
  12581. return 0;
  12582. }
  12583. /**
  12584. * init_qos - init RX qos
  12585. * @dd - device data
  12586. * @rmt - RSM map table
  12587. *
  12588. * This routine initializes Rule 0 and the RSM map table to implement
  12589. * quality of service (qos).
  12590. *
  12591. * If all of the limit tests succeed, qos is applied based on the array
  12592. * interpretation of krcvqs where entry 0 is VL0.
  12593. *
  12594. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12595. * feed both the RSM map table and the single rule.
  12596. */
  12597. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12598. {
  12599. struct rsm_rule_data rrd;
  12600. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12601. unsigned int rmt_entries;
  12602. u64 reg;
  12603. if (!rmt)
  12604. goto bail;
  12605. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12606. if (rmt_entries == 0)
  12607. goto bail;
  12608. qpns_per_vl = 1 << m;
  12609. /* enough room in the map table? */
  12610. rmt_entries = 1 << (m + n);
  12611. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12612. goto bail;
  12613. /* add qos entries to the the RSM map table */
  12614. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12615. unsigned tctxt;
  12616. for (qpn = 0, tctxt = ctxt;
  12617. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12618. unsigned idx, regoff, regidx;
  12619. /* generate the index the hardware will produce */
  12620. idx = rmt->used + ((qpn << n) ^ i);
  12621. regoff = (idx % 8) * 8;
  12622. regidx = idx / 8;
  12623. /* replace default with context number */
  12624. reg = rmt->map[regidx];
  12625. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12626. << regoff);
  12627. reg |= (u64)(tctxt++) << regoff;
  12628. rmt->map[regidx] = reg;
  12629. if (tctxt == ctxt + krcvqs[i])
  12630. tctxt = ctxt;
  12631. }
  12632. ctxt += krcvqs[i];
  12633. }
  12634. rrd.offset = rmt->used;
  12635. rrd.pkt_type = 2;
  12636. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12637. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12638. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12639. rrd.index1_width = n;
  12640. rrd.index2_off = QPN_SELECT_OFFSET;
  12641. rrd.index2_width = m + n;
  12642. rrd.mask1 = LRH_BTH_MASK;
  12643. rrd.value1 = LRH_BTH_VALUE;
  12644. rrd.mask2 = LRH_SC_MASK;
  12645. rrd.value2 = LRH_SC_VALUE;
  12646. /* add rule 0 */
  12647. add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
  12648. /* mark RSM map entries as used */
  12649. rmt->used += rmt_entries;
  12650. /* map everything else to the mcast/err/vl15 context */
  12651. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12652. dd->qos_shift = n + 1;
  12653. return;
  12654. bail:
  12655. dd->qos_shift = 1;
  12656. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12657. }
  12658. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12659. struct rsm_map_table *rmt)
  12660. {
  12661. struct rsm_rule_data rrd;
  12662. u64 reg;
  12663. int i, idx, regoff, regidx;
  12664. u8 offset;
  12665. /* there needs to be enough room in the map table */
  12666. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12667. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12668. return;
  12669. }
  12670. /*
  12671. * RSM will extract the destination context as an index into the
  12672. * map table. The destination contexts are a sequential block
  12673. * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
  12674. * Map entries are accessed as offset + extracted value. Adjust
  12675. * the added offset so this sequence can be placed anywhere in
  12676. * the table - as long as the entries themselves do not wrap.
  12677. * There are only enough bits in offset for the table size, so
  12678. * start with that to allow for a "negative" offset.
  12679. */
  12680. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12681. (int)dd->first_dyn_alloc_ctxt);
  12682. for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
  12683. i < dd->num_rcv_contexts; i++, idx++) {
  12684. /* replace with identity mapping */
  12685. regoff = (idx % 8) * 8;
  12686. regidx = idx / 8;
  12687. reg = rmt->map[regidx];
  12688. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12689. reg |= (u64)i << regoff;
  12690. rmt->map[regidx] = reg;
  12691. }
  12692. /*
  12693. * For RSM intercept of Expected FECN packets:
  12694. * o packet type 0 - expected
  12695. * o match on F (bit 95), using select/match 1, and
  12696. * o match on SH (bit 133), using select/match 2.
  12697. *
  12698. * Use index 1 to extract the 8-bit receive context from DestQP
  12699. * (start at bit 64). Use that as the RSM map table index.
  12700. */
  12701. rrd.offset = offset;
  12702. rrd.pkt_type = 0;
  12703. rrd.field1_off = 95;
  12704. rrd.field2_off = 133;
  12705. rrd.index1_off = 64;
  12706. rrd.index1_width = 8;
  12707. rrd.index2_off = 0;
  12708. rrd.index2_width = 0;
  12709. rrd.mask1 = 1;
  12710. rrd.value1 = 1;
  12711. rrd.mask2 = 1;
  12712. rrd.value2 = 1;
  12713. /* add rule 1 */
  12714. add_rsm_rule(dd, RSM_INS_FECN, &rrd);
  12715. rmt->used += dd->num_user_contexts;
  12716. }
  12717. /* Initialize RSM for VNIC */
  12718. void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
  12719. {
  12720. u8 i, j;
  12721. u8 ctx_id = 0;
  12722. u64 reg;
  12723. u32 regoff;
  12724. struct rsm_rule_data rrd;
  12725. if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
  12726. dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
  12727. dd->vnic.rmt_start);
  12728. return;
  12729. }
  12730. dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
  12731. dd->vnic.rmt_start,
  12732. dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
  12733. /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
  12734. regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
  12735. reg = read_csr(dd, regoff);
  12736. for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
  12737. /* Update map register with vnic context */
  12738. j = (dd->vnic.rmt_start + i) % 8;
  12739. reg &= ~(0xffllu << (j * 8));
  12740. reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
  12741. /* Wrap up vnic ctx index */
  12742. ctx_id %= dd->vnic.num_ctxt;
  12743. /* Write back map register */
  12744. if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
  12745. dev_dbg(&(dd)->pcidev->dev,
  12746. "Vnic rsm map reg[%d] =0x%llx\n",
  12747. regoff - RCV_RSM_MAP_TABLE, reg);
  12748. write_csr(dd, regoff, reg);
  12749. regoff += 8;
  12750. if (i < (NUM_VNIC_MAP_ENTRIES - 1))
  12751. reg = read_csr(dd, regoff);
  12752. }
  12753. }
  12754. /* Add rule for vnic */
  12755. rrd.offset = dd->vnic.rmt_start;
  12756. rrd.pkt_type = 4;
  12757. /* Match 16B packets */
  12758. rrd.field1_off = L2_TYPE_MATCH_OFFSET;
  12759. rrd.mask1 = L2_TYPE_MASK;
  12760. rrd.value1 = L2_16B_VALUE;
  12761. /* Match ETH L4 packets */
  12762. rrd.field2_off = L4_TYPE_MATCH_OFFSET;
  12763. rrd.mask2 = L4_16B_TYPE_MASK;
  12764. rrd.value2 = L4_16B_ETH_VALUE;
  12765. /* Calc context from veswid and entropy */
  12766. rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
  12767. rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12768. rrd.index2_off = L2_16B_ENTROPY_OFFSET;
  12769. rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12770. add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
  12771. /* Enable RSM if not already enabled */
  12772. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12773. }
  12774. void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
  12775. {
  12776. clear_rsm_rule(dd, RSM_INS_VNIC);
  12777. /* Disable RSM if used only by vnic */
  12778. if (dd->vnic.rmt_start == 0)
  12779. clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12780. }
  12781. static void init_rxe(struct hfi1_devdata *dd)
  12782. {
  12783. struct rsm_map_table *rmt;
  12784. u64 val;
  12785. /* enable all receive errors */
  12786. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12787. rmt = alloc_rsm_map_table(dd);
  12788. /* set up QOS, including the QPN map table */
  12789. init_qos(dd, rmt);
  12790. init_user_fecn_handling(dd, rmt);
  12791. complete_rsm_map_table(dd, rmt);
  12792. /* record number of used rsm map entries for vnic */
  12793. dd->vnic.rmt_start = rmt->used;
  12794. kfree(rmt);
  12795. /*
  12796. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12797. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12798. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12799. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12800. * Max_PayLoad_Size set to its minimum of 128.
  12801. *
  12802. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12803. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12804. * tune_pcie_caps() which is called after this routine.
  12805. */
  12806. /* Have 16 bytes (4DW) of bypass header available in header queue */
  12807. val = read_csr(dd, RCV_BYPASS);
  12808. val |= (4ull << 16);
  12809. write_csr(dd, RCV_BYPASS, val);
  12810. }
  12811. static void init_other(struct hfi1_devdata *dd)
  12812. {
  12813. /* enable all CCE errors */
  12814. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12815. /* enable *some* Misc errors */
  12816. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12817. /* enable all DC errors, except LCB */
  12818. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12819. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12820. }
  12821. /*
  12822. * Fill out the given AU table using the given CU. A CU is defined in terms
  12823. * AUs. The table is a an encoding: given the index, how many AUs does that
  12824. * represent?
  12825. *
  12826. * NOTE: Assumes that the register layout is the same for the
  12827. * local and remote tables.
  12828. */
  12829. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12830. u32 csr0to3, u32 csr4to7)
  12831. {
  12832. write_csr(dd, csr0to3,
  12833. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12834. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12835. 2ull * cu <<
  12836. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12837. 4ull * cu <<
  12838. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12839. write_csr(dd, csr4to7,
  12840. 8ull * cu <<
  12841. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12842. 16ull * cu <<
  12843. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12844. 32ull * cu <<
  12845. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12846. 64ull * cu <<
  12847. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12848. }
  12849. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12850. {
  12851. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12852. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12853. }
  12854. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12855. {
  12856. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12857. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12858. }
  12859. static void init_txe(struct hfi1_devdata *dd)
  12860. {
  12861. int i;
  12862. /* enable all PIO, SDMA, general, and Egress errors */
  12863. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12864. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12865. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12866. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12867. /* enable all per-context and per-SDMA engine errors */
  12868. for (i = 0; i < dd->chip_send_contexts; i++)
  12869. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12870. for (i = 0; i < dd->chip_sdma_engines; i++)
  12871. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12872. /* set the local CU to AU mapping */
  12873. assign_local_cm_au_table(dd, dd->vcu);
  12874. /*
  12875. * Set reasonable default for Credit Return Timer
  12876. * Don't set on Simulator - causes it to choke.
  12877. */
  12878. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12879. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12880. }
  12881. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12882. u16 jkey)
  12883. {
  12884. u8 hw_ctxt;
  12885. u64 reg;
  12886. if (!rcd || !rcd->sc)
  12887. return -EINVAL;
  12888. hw_ctxt = rcd->sc->hw_context;
  12889. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12890. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12891. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12892. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12893. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12894. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12895. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12896. /*
  12897. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12898. */
  12899. if (!is_ax(dd)) {
  12900. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12901. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12902. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12903. }
  12904. /* Enable J_KEY check on receive context. */
  12905. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12906. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12907. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12908. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
  12909. return 0;
  12910. }
  12911. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
  12912. {
  12913. u8 hw_ctxt;
  12914. u64 reg;
  12915. if (!rcd || !rcd->sc)
  12916. return -EINVAL;
  12917. hw_ctxt = rcd->sc->hw_context;
  12918. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12919. /*
  12920. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12921. * This check would not have been enabled for A0 h/w, see
  12922. * set_ctxt_jkey().
  12923. */
  12924. if (!is_ax(dd)) {
  12925. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12926. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12927. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12928. }
  12929. /* Turn off the J_KEY on the receive side */
  12930. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
  12931. return 0;
  12932. }
  12933. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12934. u16 pkey)
  12935. {
  12936. u8 hw_ctxt;
  12937. u64 reg;
  12938. if (!rcd || !rcd->sc)
  12939. return -EINVAL;
  12940. hw_ctxt = rcd->sc->hw_context;
  12941. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  12942. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  12943. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  12944. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12945. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12946. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  12947. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12948. return 0;
  12949. }
  12950. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
  12951. {
  12952. u8 hw_ctxt;
  12953. u64 reg;
  12954. if (!ctxt || !ctxt->sc)
  12955. return -EINVAL;
  12956. hw_ctxt = ctxt->sc->hw_context;
  12957. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12958. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12959. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12960. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12961. return 0;
  12962. }
  12963. /*
  12964. * Start doing the clean up the the chip. Our clean up happens in multiple
  12965. * stages and this is just the first.
  12966. */
  12967. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  12968. {
  12969. aspm_exit(dd);
  12970. free_cntrs(dd);
  12971. free_rcverr(dd);
  12972. clean_up_interrupts(dd);
  12973. finish_chip_resources(dd);
  12974. }
  12975. #define HFI_BASE_GUID(dev) \
  12976. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  12977. /*
  12978. * Information can be shared between the two HFIs on the same ASIC
  12979. * in the same OS. This function finds the peer device and sets
  12980. * up a shared structure.
  12981. */
  12982. static int init_asic_data(struct hfi1_devdata *dd)
  12983. {
  12984. unsigned long flags;
  12985. struct hfi1_devdata *tmp, *peer = NULL;
  12986. struct hfi1_asic_data *asic_data;
  12987. int ret = 0;
  12988. /* pre-allocate the asic structure in case we are the first device */
  12989. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  12990. if (!asic_data)
  12991. return -ENOMEM;
  12992. spin_lock_irqsave(&hfi1_devs_lock, flags);
  12993. /* Find our peer device */
  12994. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  12995. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  12996. dd->unit != tmp->unit) {
  12997. peer = tmp;
  12998. break;
  12999. }
  13000. }
  13001. if (peer) {
  13002. /* use already allocated structure */
  13003. dd->asic_data = peer->asic_data;
  13004. kfree(asic_data);
  13005. } else {
  13006. dd->asic_data = asic_data;
  13007. mutex_init(&dd->asic_data->asic_resource_mutex);
  13008. }
  13009. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  13010. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  13011. /* first one through - set up i2c devices */
  13012. if (!peer)
  13013. ret = set_up_i2c(dd, dd->asic_data);
  13014. return ret;
  13015. }
  13016. /*
  13017. * Set dd->boardname. Use a generic name if a name is not returned from
  13018. * EFI variable space.
  13019. *
  13020. * Return 0 on success, -ENOMEM if space could not be allocated.
  13021. */
  13022. static int obtain_boardname(struct hfi1_devdata *dd)
  13023. {
  13024. /* generic board description */
  13025. const char generic[] =
  13026. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  13027. unsigned long size;
  13028. int ret;
  13029. ret = read_hfi1_efi_var(dd, "description", &size,
  13030. (void **)&dd->boardname);
  13031. if (ret) {
  13032. dd_dev_info(dd, "Board description not found\n");
  13033. /* use generic description */
  13034. dd->boardname = kstrdup(generic, GFP_KERNEL);
  13035. if (!dd->boardname)
  13036. return -ENOMEM;
  13037. }
  13038. return 0;
  13039. }
  13040. /*
  13041. * Check the interrupt registers to make sure that they are mapped correctly.
  13042. * It is intended to help user identify any mismapping by VMM when the driver
  13043. * is running in a VM. This function should only be called before interrupt
  13044. * is set up properly.
  13045. *
  13046. * Return 0 on success, -EINVAL on failure.
  13047. */
  13048. static int check_int_registers(struct hfi1_devdata *dd)
  13049. {
  13050. u64 reg;
  13051. u64 all_bits = ~(u64)0;
  13052. u64 mask;
  13053. /* Clear CceIntMask[0] to avoid raising any interrupts */
  13054. mask = read_csr(dd, CCE_INT_MASK);
  13055. write_csr(dd, CCE_INT_MASK, 0ull);
  13056. reg = read_csr(dd, CCE_INT_MASK);
  13057. if (reg)
  13058. goto err_exit;
  13059. /* Clear all interrupt status bits */
  13060. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13061. reg = read_csr(dd, CCE_INT_STATUS);
  13062. if (reg)
  13063. goto err_exit;
  13064. /* Set all interrupt status bits */
  13065. write_csr(dd, CCE_INT_FORCE, all_bits);
  13066. reg = read_csr(dd, CCE_INT_STATUS);
  13067. if (reg != all_bits)
  13068. goto err_exit;
  13069. /* Restore the interrupt mask */
  13070. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13071. write_csr(dd, CCE_INT_MASK, mask);
  13072. return 0;
  13073. err_exit:
  13074. write_csr(dd, CCE_INT_MASK, mask);
  13075. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  13076. return -EINVAL;
  13077. }
  13078. /**
  13079. * Allocate and initialize the device structure for the hfi.
  13080. * @dev: the pci_dev for hfi1_ib device
  13081. * @ent: pci_device_id struct for this dev
  13082. *
  13083. * Also allocates, initializes, and returns the devdata struct for this
  13084. * device instance
  13085. *
  13086. * This is global, and is called directly at init to set up the
  13087. * chip-specific function pointers for later use.
  13088. */
  13089. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  13090. const struct pci_device_id *ent)
  13091. {
  13092. struct hfi1_devdata *dd;
  13093. struct hfi1_pportdata *ppd;
  13094. u64 reg;
  13095. int i, ret;
  13096. static const char * const inames[] = { /* implementation names */
  13097. "RTL silicon",
  13098. "RTL VCS simulation",
  13099. "RTL FPGA emulation",
  13100. "Functional simulator"
  13101. };
  13102. struct pci_dev *parent = pdev->bus->self;
  13103. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  13104. sizeof(struct hfi1_pportdata));
  13105. if (IS_ERR(dd))
  13106. goto bail;
  13107. ppd = dd->pport;
  13108. for (i = 0; i < dd->num_pports; i++, ppd++) {
  13109. int vl;
  13110. /* init common fields */
  13111. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  13112. /* DC supports 4 link widths */
  13113. ppd->link_width_supported =
  13114. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  13115. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  13116. ppd->link_width_downgrade_supported =
  13117. ppd->link_width_supported;
  13118. /* start out enabling only 4X */
  13119. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  13120. ppd->link_width_downgrade_enabled =
  13121. ppd->link_width_downgrade_supported;
  13122. /* link width active is 0 when link is down */
  13123. /* link width downgrade active is 0 when link is down */
  13124. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  13125. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  13126. hfi1_early_err(&pdev->dev,
  13127. "Invalid num_vls %u, using %u VLs\n",
  13128. num_vls, HFI1_MAX_VLS_SUPPORTED);
  13129. num_vls = HFI1_MAX_VLS_SUPPORTED;
  13130. }
  13131. ppd->vls_supported = num_vls;
  13132. ppd->vls_operational = ppd->vls_supported;
  13133. /* Set the default MTU. */
  13134. for (vl = 0; vl < num_vls; vl++)
  13135. dd->vld[vl].mtu = hfi1_max_mtu;
  13136. dd->vld[15].mtu = MAX_MAD_PACKET;
  13137. /*
  13138. * Set the initial values to reasonable default, will be set
  13139. * for real when link is up.
  13140. */
  13141. ppd->overrun_threshold = 0x4;
  13142. ppd->phy_error_threshold = 0xf;
  13143. ppd->port_crc_mode_enabled = link_crc_mask;
  13144. /* initialize supported LTP CRC mode */
  13145. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  13146. /* initialize enabled LTP CRC mode */
  13147. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  13148. /* start in offline */
  13149. ppd->host_link_state = HLS_DN_OFFLINE;
  13150. init_vl_arb_caches(ppd);
  13151. }
  13152. dd->link_default = HLS_DN_POLL;
  13153. /*
  13154. * Do remaining PCIe setup and save PCIe values in dd.
  13155. * Any error printing is already done by the init code.
  13156. * On return, we have the chip mapped.
  13157. */
  13158. ret = hfi1_pcie_ddinit(dd, pdev);
  13159. if (ret < 0)
  13160. goto bail_free;
  13161. /* Save PCI space registers to rewrite after device reset */
  13162. ret = save_pci_variables(dd);
  13163. if (ret < 0)
  13164. goto bail_cleanup;
  13165. /* verify that reads actually work, save revision for reset check */
  13166. dd->revision = read_csr(dd, CCE_REVISION);
  13167. if (dd->revision == ~(u64)0) {
  13168. dd_dev_err(dd, "cannot read chip CSRs\n");
  13169. ret = -EINVAL;
  13170. goto bail_cleanup;
  13171. }
  13172. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  13173. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  13174. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  13175. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  13176. /*
  13177. * Check interrupt registers mapping if the driver has no access to
  13178. * the upstream component. In this case, it is likely that the driver
  13179. * is running in a VM.
  13180. */
  13181. if (!parent) {
  13182. ret = check_int_registers(dd);
  13183. if (ret)
  13184. goto bail_cleanup;
  13185. }
  13186. /*
  13187. * obtain the hardware ID - NOT related to unit, which is a
  13188. * software enumeration
  13189. */
  13190. reg = read_csr(dd, CCE_REVISION2);
  13191. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  13192. & CCE_REVISION2_HFI_ID_MASK;
  13193. /* the variable size will remove unwanted bits */
  13194. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  13195. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  13196. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  13197. dd->icode < ARRAY_SIZE(inames) ?
  13198. inames[dd->icode] : "unknown", (int)dd->irev);
  13199. /* speeds the hardware can support */
  13200. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  13201. /* speeds allowed to run at */
  13202. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  13203. /* give a reasonable active value, will be set on link up */
  13204. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  13205. dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
  13206. dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
  13207. dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
  13208. dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
  13209. dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
  13210. /* fix up link widths for emulation _p */
  13211. ppd = dd->pport;
  13212. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  13213. ppd->link_width_supported =
  13214. ppd->link_width_enabled =
  13215. ppd->link_width_downgrade_supported =
  13216. ppd->link_width_downgrade_enabled =
  13217. OPA_LINK_WIDTH_1X;
  13218. }
  13219. /* insure num_vls isn't larger than number of sdma engines */
  13220. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
  13221. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  13222. num_vls, dd->chip_sdma_engines);
  13223. num_vls = dd->chip_sdma_engines;
  13224. ppd->vls_supported = dd->chip_sdma_engines;
  13225. ppd->vls_operational = ppd->vls_supported;
  13226. }
  13227. /*
  13228. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  13229. * Limit the max if larger than the field holds. If timeout is
  13230. * non-zero, then the calculated field will be at least 1.
  13231. *
  13232. * Must be after icode is set up - the cclock rate depends
  13233. * on knowing the hardware being used.
  13234. */
  13235. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  13236. if (dd->rcv_intr_timeout_csr >
  13237. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  13238. dd->rcv_intr_timeout_csr =
  13239. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  13240. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  13241. dd->rcv_intr_timeout_csr = 1;
  13242. /* needs to be done before we look for the peer device */
  13243. read_guid(dd);
  13244. /* set up shared ASIC data with peer device */
  13245. ret = init_asic_data(dd);
  13246. if (ret)
  13247. goto bail_cleanup;
  13248. /* obtain chip sizes, reset chip CSRs */
  13249. ret = init_chip(dd);
  13250. if (ret)
  13251. goto bail_cleanup;
  13252. /* read in the PCIe link speed information */
  13253. ret = pcie_speeds(dd);
  13254. if (ret)
  13255. goto bail_cleanup;
  13256. /* call before get_platform_config(), after init_chip_resources() */
  13257. ret = eprom_init(dd);
  13258. if (ret)
  13259. goto bail_free_rcverr;
  13260. /* Needs to be called before hfi1_firmware_init */
  13261. get_platform_config(dd);
  13262. /* read in firmware */
  13263. ret = hfi1_firmware_init(dd);
  13264. if (ret)
  13265. goto bail_cleanup;
  13266. /*
  13267. * In general, the PCIe Gen3 transition must occur after the
  13268. * chip has been idled (so it won't initiate any PCIe transactions
  13269. * e.g. an interrupt) and before the driver changes any registers
  13270. * (the transition will reset the registers).
  13271. *
  13272. * In particular, place this call after:
  13273. * - init_chip() - the chip will not initiate any PCIe transactions
  13274. * - pcie_speeds() - reads the current link speed
  13275. * - hfi1_firmware_init() - the needed firmware is ready to be
  13276. * downloaded
  13277. */
  13278. ret = do_pcie_gen3_transition(dd);
  13279. if (ret)
  13280. goto bail_cleanup;
  13281. /* start setting dd values and adjusting CSRs */
  13282. init_early_variables(dd);
  13283. parse_platform_config(dd);
  13284. ret = obtain_boardname(dd);
  13285. if (ret)
  13286. goto bail_cleanup;
  13287. snprintf(dd->boardversion, BOARD_VERS_MAX,
  13288. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  13289. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  13290. (u32)dd->majrev,
  13291. (u32)dd->minrev,
  13292. (dd->revision >> CCE_REVISION_SW_SHIFT)
  13293. & CCE_REVISION_SW_MASK);
  13294. ret = set_up_context_variables(dd);
  13295. if (ret)
  13296. goto bail_cleanup;
  13297. /* set initial RXE CSRs */
  13298. init_rxe(dd);
  13299. /* set initial TXE CSRs */
  13300. init_txe(dd);
  13301. /* set initial non-RXE, non-TXE CSRs */
  13302. init_other(dd);
  13303. /* set up KDETH QP prefix in both RX and TX CSRs */
  13304. init_kdeth_qp(dd);
  13305. ret = hfi1_dev_affinity_init(dd);
  13306. if (ret)
  13307. goto bail_cleanup;
  13308. /* send contexts must be set up before receive contexts */
  13309. ret = init_send_contexts(dd);
  13310. if (ret)
  13311. goto bail_cleanup;
  13312. ret = hfi1_create_kctxts(dd);
  13313. if (ret)
  13314. goto bail_cleanup;
  13315. /*
  13316. * Initialize aspm, to be done after gen3 transition and setting up
  13317. * contexts and before enabling interrupts
  13318. */
  13319. aspm_init(dd);
  13320. dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
  13321. /*
  13322. * rcd[0] is guaranteed to be valid by this point. Also, all
  13323. * context are using the same value, as per the module parameter.
  13324. */
  13325. dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
  13326. ret = init_pervl_scs(dd);
  13327. if (ret)
  13328. goto bail_cleanup;
  13329. /* sdma init */
  13330. for (i = 0; i < dd->num_pports; ++i) {
  13331. ret = sdma_init(dd, i);
  13332. if (ret)
  13333. goto bail_cleanup;
  13334. }
  13335. /* use contexts created by hfi1_create_kctxts */
  13336. ret = set_up_interrupts(dd);
  13337. if (ret)
  13338. goto bail_cleanup;
  13339. /* set up LCB access - must be after set_up_interrupts() */
  13340. init_lcb_access(dd);
  13341. /*
  13342. * Serial number is created from the base guid:
  13343. * [27:24] = base guid [38:35]
  13344. * [23: 0] = base guid [23: 0]
  13345. */
  13346. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  13347. (dd->base_guid & 0xFFFFFF) |
  13348. ((dd->base_guid >> 11) & 0xF000000));
  13349. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  13350. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  13351. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  13352. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  13353. if (ret)
  13354. goto bail_clear_intr;
  13355. thermal_init(dd);
  13356. ret = init_cntrs(dd);
  13357. if (ret)
  13358. goto bail_clear_intr;
  13359. ret = init_rcverr(dd);
  13360. if (ret)
  13361. goto bail_free_cntrs;
  13362. init_completion(&dd->user_comp);
  13363. /* The user refcount starts with one to inidicate an active device */
  13364. atomic_set(&dd->user_refcount, 1);
  13365. goto bail;
  13366. bail_free_rcverr:
  13367. free_rcverr(dd);
  13368. bail_free_cntrs:
  13369. free_cntrs(dd);
  13370. bail_clear_intr:
  13371. clean_up_interrupts(dd);
  13372. bail_cleanup:
  13373. hfi1_pcie_ddcleanup(dd);
  13374. bail_free:
  13375. hfi1_free_devdata(dd);
  13376. dd = ERR_PTR(ret);
  13377. bail:
  13378. return dd;
  13379. }
  13380. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  13381. u32 dw_len)
  13382. {
  13383. u32 delta_cycles;
  13384. u32 current_egress_rate = ppd->current_egress_rate;
  13385. /* rates here are in units of 10^6 bits/sec */
  13386. if (desired_egress_rate == -1)
  13387. return 0; /* shouldn't happen */
  13388. if (desired_egress_rate >= current_egress_rate)
  13389. return 0; /* we can't help go faster, only slower */
  13390. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  13391. egress_cycles(dw_len * 4, current_egress_rate);
  13392. return (u16)delta_cycles;
  13393. }
  13394. /**
  13395. * create_pbc - build a pbc for transmission
  13396. * @flags: special case flags or-ed in built pbc
  13397. * @srate: static rate
  13398. * @vl: vl
  13399. * @dwlen: dword length (header words + data words + pbc words)
  13400. *
  13401. * Create a PBC with the given flags, rate, VL, and length.
  13402. *
  13403. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  13404. * for verbs, which does not use this PSM feature. The lone other caller
  13405. * is for the diagnostic interface which calls this if the user does not
  13406. * supply their own PBC.
  13407. */
  13408. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  13409. u32 dw_len)
  13410. {
  13411. u64 pbc, delay = 0;
  13412. if (unlikely(srate_mbs))
  13413. delay = delay_cycles(ppd, srate_mbs, dw_len);
  13414. pbc = flags
  13415. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  13416. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  13417. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  13418. | (dw_len & PBC_LENGTH_DWS_MASK)
  13419. << PBC_LENGTH_DWS_SHIFT;
  13420. return pbc;
  13421. }
  13422. #define SBUS_THERMAL 0x4f
  13423. #define SBUS_THERM_MONITOR_MODE 0x1
  13424. #define THERM_FAILURE(dev, ret, reason) \
  13425. dd_dev_err((dd), \
  13426. "Thermal sensor initialization failed: %s (%d)\n", \
  13427. (reason), (ret))
  13428. /*
  13429. * Initialize the thermal sensor.
  13430. *
  13431. * After initialization, enable polling of thermal sensor through
  13432. * SBus interface. In order for this to work, the SBus Master
  13433. * firmware has to be loaded due to the fact that the HW polling
  13434. * logic uses SBus interrupts, which are not supported with
  13435. * default firmware. Otherwise, no data will be returned through
  13436. * the ASIC_STS_THERM CSR.
  13437. */
  13438. static int thermal_init(struct hfi1_devdata *dd)
  13439. {
  13440. int ret = 0;
  13441. if (dd->icode != ICODE_RTL_SILICON ||
  13442. check_chip_resource(dd, CR_THERM_INIT, NULL))
  13443. return ret;
  13444. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  13445. if (ret) {
  13446. THERM_FAILURE(dd, ret, "Acquire SBus");
  13447. return ret;
  13448. }
  13449. dd_dev_info(dd, "Initializing thermal sensor\n");
  13450. /* Disable polling of thermal readings */
  13451. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13452. msleep(100);
  13453. /* Thermal Sensor Initialization */
  13454. /* Step 1: Reset the Thermal SBus Receiver */
  13455. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13456. RESET_SBUS_RECEIVER, 0);
  13457. if (ret) {
  13458. THERM_FAILURE(dd, ret, "Bus Reset");
  13459. goto done;
  13460. }
  13461. /* Step 2: Set Reset bit in Thermal block */
  13462. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13463. WRITE_SBUS_RECEIVER, 0x1);
  13464. if (ret) {
  13465. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13466. goto done;
  13467. }
  13468. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13469. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13470. WRITE_SBUS_RECEIVER, 0x32);
  13471. if (ret) {
  13472. THERM_FAILURE(dd, ret, "Write Clock Div");
  13473. goto done;
  13474. }
  13475. /* Step 4: Select temperature mode */
  13476. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13477. WRITE_SBUS_RECEIVER,
  13478. SBUS_THERM_MONITOR_MODE);
  13479. if (ret) {
  13480. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13481. goto done;
  13482. }
  13483. /* Step 5: De-assert block reset and start conversion */
  13484. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13485. WRITE_SBUS_RECEIVER, 0x2);
  13486. if (ret) {
  13487. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13488. goto done;
  13489. }
  13490. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13491. msleep(22);
  13492. /* Enable polling of thermal readings */
  13493. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13494. /* Set initialized flag */
  13495. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13496. if (ret)
  13497. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13498. done:
  13499. release_chip_resource(dd, CR_SBUS);
  13500. return ret;
  13501. }
  13502. static void handle_temp_err(struct hfi1_devdata *dd)
  13503. {
  13504. struct hfi1_pportdata *ppd = &dd->pport[0];
  13505. /*
  13506. * Thermal Critical Interrupt
  13507. * Put the device into forced freeze mode, take link down to
  13508. * offline, and put DC into reset.
  13509. */
  13510. dd_dev_emerg(dd,
  13511. "Critical temperature reached! Forcing device into freeze mode!\n");
  13512. dd->flags |= HFI1_FORCED_FREEZE;
  13513. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13514. /*
  13515. * Shut DC down as much and as quickly as possible.
  13516. *
  13517. * Step 1: Take the link down to OFFLINE. This will cause the
  13518. * 8051 to put the Serdes in reset. However, we don't want to
  13519. * go through the entire link state machine since we want to
  13520. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13521. * but rather an attempt to save the chip.
  13522. * Code below is almost the same as quiet_serdes() but avoids
  13523. * all the extra work and the sleeps.
  13524. */
  13525. ppd->driver_link_ready = 0;
  13526. ppd->link_enabled = 0;
  13527. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13528. PLS_OFFLINE);
  13529. /*
  13530. * Step 2: Shutdown LCB and 8051
  13531. * After shutdown, do not restore DC_CFG_RESET value.
  13532. */
  13533. dc_shutdown(dd);
  13534. }