chip.c 451 KB

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