chip.c 447 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332
  1. /*
  2. * Copyright(c) 2015 - 2017 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. /*
  48. * This file contains all of the code that is specific to the HFI chip
  49. */
  50. #include <linux/pci.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/module.h>
  54. #include "hfi.h"
  55. #include "trace.h"
  56. #include "mad.h"
  57. #include "pio.h"
  58. #include "sdma.h"
  59. #include "eprom.h"
  60. #include "efivar.h"
  61. #include "platform.h"
  62. #include "aspm.h"
  63. #include "affinity.h"
  64. #include "debugfs.h"
  65. #define NUM_IB_PORTS 1
  66. uint kdeth_qp;
  67. module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
  68. MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
  69. uint num_vls = HFI1_MAX_VLS_SUPPORTED;
  70. module_param(num_vls, uint, S_IRUGO);
  71. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  72. /*
  73. * Default time to aggregate two 10K packets from the idle state
  74. * (timer not running). The timer starts at the end of the first packet,
  75. * so only the time for one 10K packet and header plus a bit extra is needed.
  76. * 10 * 1024 + 64 header byte = 10304 byte
  77. * 10304 byte / 12.5 GB/s = 824.32ns
  78. */
  79. uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
  80. module_param(rcv_intr_timeout, uint, S_IRUGO);
  81. MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
  82. uint rcv_intr_count = 16; /* same as qib */
  83. module_param(rcv_intr_count, uint, S_IRUGO);
  84. MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
  85. ushort link_crc_mask = SUPPORTED_CRCS;
  86. module_param(link_crc_mask, ushort, S_IRUGO);
  87. MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
  88. uint loopback;
  89. module_param_named(loopback, loopback, uint, S_IRUGO);
  90. MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
  91. /* Other driver tunables */
  92. uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
  93. static ushort crc_14b_sideband = 1;
  94. static uint use_flr = 1;
  95. uint quick_linkup; /* skip LNI */
  96. struct flag_table {
  97. u64 flag; /* the flag */
  98. char *str; /* description string */
  99. u16 extra; /* extra information */
  100. u16 unused0;
  101. u32 unused1;
  102. };
  103. /* str must be a string constant */
  104. #define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
  105. #define FLAG_ENTRY0(str, flag) {flag, str, 0}
  106. /* Send Error Consequences */
  107. #define SEC_WRITE_DROPPED 0x1
  108. #define SEC_PACKET_DROPPED 0x2
  109. #define SEC_SC_HALTED 0x4 /* per-context only */
  110. #define SEC_SPC_FREEZE 0x8 /* per-HFI only */
  111. #define DEFAULT_KRCVQS 2
  112. #define MIN_KERNEL_KCTXTS 2
  113. #define FIRST_KERNEL_KCTXT 1
  114. /*
  115. * RSM instance allocation
  116. * 0 - Verbs
  117. * 1 - User Fecn Handling
  118. * 2 - Vnic
  119. */
  120. #define RSM_INS_VERBS 0
  121. #define RSM_INS_FECN 1
  122. #define RSM_INS_VNIC 2
  123. /* Bit offset into the GUID which carries HFI id information */
  124. #define GUID_HFI_INDEX_SHIFT 39
  125. /* extract the emulation revision */
  126. #define emulator_rev(dd) ((dd)->irev >> 8)
  127. /* parallel and serial emulation versions are 3 and 4 respectively */
  128. #define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
  129. #define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
  130. /* RSM fields for Verbs */
  131. /* packet type */
  132. #define IB_PACKET_TYPE 2ull
  133. #define QW_SHIFT 6ull
  134. /* QPN[7..1] */
  135. #define QPN_WIDTH 7ull
  136. /* LRH.BTH: QW 0, OFFSET 48 - for match */
  137. #define LRH_BTH_QW 0ull
  138. #define LRH_BTH_BIT_OFFSET 48ull
  139. #define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
  140. #define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
  141. #define LRH_BTH_SELECT
  142. #define LRH_BTH_MASK 3ull
  143. #define LRH_BTH_VALUE 2ull
  144. /* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
  145. #define LRH_SC_QW 0ull
  146. #define LRH_SC_BIT_OFFSET 56ull
  147. #define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
  148. #define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
  149. #define LRH_SC_MASK 128ull
  150. #define LRH_SC_VALUE 0ull
  151. /* SC[n..0] QW 0, OFFSET 60 - for select */
  152. #define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
  153. /* QPN[m+n:1] QW 1, OFFSET 1 */
  154. #define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
  155. /* RSM fields for Vnic */
  156. /* L2_TYPE: QW 0, OFFSET 61 - for match */
  157. #define L2_TYPE_QW 0ull
  158. #define L2_TYPE_BIT_OFFSET 61ull
  159. #define L2_TYPE_OFFSET(off) ((L2_TYPE_QW << QW_SHIFT) | (off))
  160. #define L2_TYPE_MATCH_OFFSET L2_TYPE_OFFSET(L2_TYPE_BIT_OFFSET)
  161. #define L2_TYPE_MASK 3ull
  162. #define L2_16B_VALUE 2ull
  163. /* L4_TYPE QW 1, OFFSET 0 - for match */
  164. #define L4_TYPE_QW 1ull
  165. #define L4_TYPE_BIT_OFFSET 0ull
  166. #define L4_TYPE_OFFSET(off) ((L4_TYPE_QW << QW_SHIFT) | (off))
  167. #define L4_TYPE_MATCH_OFFSET L4_TYPE_OFFSET(L4_TYPE_BIT_OFFSET)
  168. #define L4_16B_TYPE_MASK 0xFFull
  169. #define L4_16B_ETH_VALUE 0x78ull
  170. /* 16B VESWID - for select */
  171. #define L4_16B_HDR_VESWID_OFFSET ((2 << QW_SHIFT) | (16ull))
  172. /* 16B ENTROPY - for select */
  173. #define L2_16B_ENTROPY_OFFSET ((1 << QW_SHIFT) | (32ull))
  174. /* defines to build power on SC2VL table */
  175. #define SC2VL_VAL( \
  176. num, \
  177. sc0, sc0val, \
  178. sc1, sc1val, \
  179. sc2, sc2val, \
  180. sc3, sc3val, \
  181. sc4, sc4val, \
  182. sc5, sc5val, \
  183. sc6, sc6val, \
  184. sc7, sc7val) \
  185. ( \
  186. ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
  187. ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
  188. ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
  189. ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
  190. ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
  191. ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
  192. ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
  193. ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
  194. )
  195. #define DC_SC_VL_VAL( \
  196. range, \
  197. e0, e0val, \
  198. e1, e1val, \
  199. e2, e2val, \
  200. e3, e3val, \
  201. e4, e4val, \
  202. e5, e5val, \
  203. e6, e6val, \
  204. e7, e7val, \
  205. e8, e8val, \
  206. e9, e9val, \
  207. e10, e10val, \
  208. e11, e11val, \
  209. e12, e12val, \
  210. e13, e13val, \
  211. e14, e14val, \
  212. e15, e15val) \
  213. ( \
  214. ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
  215. ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
  216. ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
  217. ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
  218. ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
  219. ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
  220. ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
  221. ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
  222. ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
  223. ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
  224. ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
  225. ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
  226. ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
  227. ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
  228. ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
  229. ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
  230. )
  231. /* all CceStatus sub-block freeze bits */
  232. #define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
  233. | CCE_STATUS_RXE_FROZE_SMASK \
  234. | CCE_STATUS_TXE_FROZE_SMASK \
  235. | CCE_STATUS_TXE_PIO_FROZE_SMASK)
  236. /* all CceStatus sub-block TXE pause bits */
  237. #define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
  238. | CCE_STATUS_TXE_PAUSED_SMASK \
  239. | CCE_STATUS_SDMA_PAUSED_SMASK)
  240. /* all CceStatus sub-block RXE pause bits */
  241. #define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
  242. #define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
  243. #define CNTR_32BIT_MAX 0x00000000FFFFFFFF
  244. /*
  245. * CCE Error flags.
  246. */
  247. static struct flag_table cce_err_status_flags[] = {
  248. /* 0*/ FLAG_ENTRY0("CceCsrParityErr",
  249. CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
  250. /* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
  251. CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
  252. /* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
  253. CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
  254. /* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
  255. CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
  256. /* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
  257. CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
  258. /* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
  259. CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
  260. /* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
  261. CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
  262. /* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
  263. CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
  264. /* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
  265. CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
  266. /* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  267. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
  268. /*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  269. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
  270. /*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
  271. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
  272. /*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
  273. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
  274. /*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  275. CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
  276. /*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  277. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
  278. /*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  279. CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
  280. /*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  281. CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
  282. /*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  283. CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
  284. /*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
  285. CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
  286. /*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
  287. CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
  288. /*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
  289. CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
  290. /*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
  291. CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
  292. /*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
  293. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
  294. /*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
  295. CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
  296. /*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
  297. CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
  298. /*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
  299. CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
  300. /*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
  301. CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
  302. /*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
  303. CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
  304. /*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
  305. CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
  306. /*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
  307. CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
  308. /*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
  309. CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
  310. /*31*/ FLAG_ENTRY0("LATriggered",
  311. CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
  312. /*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
  313. CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
  314. /*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
  315. CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
  316. /*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
  317. CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
  318. /*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
  319. CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
  320. /*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
  321. CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
  322. /*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
  323. CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
  324. /*38*/ FLAG_ENTRY0("CceIntMapCorErr",
  325. CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
  326. /*39*/ FLAG_ENTRY0("CceIntMapUncErr",
  327. CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
  328. /*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
  329. CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
  330. /*41-63 reserved*/
  331. };
  332. /*
  333. * Misc Error flags
  334. */
  335. #define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
  336. static struct flag_table misc_err_status_flags[] = {
  337. /* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
  338. /* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
  339. /* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
  340. /* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
  341. /* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
  342. /* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
  343. /* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
  344. /* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
  345. /* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
  346. /* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
  347. /*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
  348. /*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
  349. /*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
  350. };
  351. /*
  352. * TXE PIO Error flags and consequences
  353. */
  354. static struct flag_table pio_err_status_flags[] = {
  355. /* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
  356. SEC_WRITE_DROPPED,
  357. SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
  358. /* 1*/ FLAG_ENTRY("PioWriteAddrParity",
  359. SEC_SPC_FREEZE,
  360. SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
  361. /* 2*/ FLAG_ENTRY("PioCsrParity",
  362. SEC_SPC_FREEZE,
  363. SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
  364. /* 3*/ FLAG_ENTRY("PioSbMemFifo0",
  365. SEC_SPC_FREEZE,
  366. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
  367. /* 4*/ FLAG_ENTRY("PioSbMemFifo1",
  368. SEC_SPC_FREEZE,
  369. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
  370. /* 5*/ FLAG_ENTRY("PioPccFifoParity",
  371. SEC_SPC_FREEZE,
  372. SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
  373. /* 6*/ FLAG_ENTRY("PioPecFifoParity",
  374. SEC_SPC_FREEZE,
  375. SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
  376. /* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
  377. SEC_SPC_FREEZE,
  378. SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
  379. /* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
  380. SEC_SPC_FREEZE,
  381. SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
  382. /* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
  383. SEC_SPC_FREEZE,
  384. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
  385. /*10*/ FLAG_ENTRY("PioSmPktResetParity",
  386. SEC_SPC_FREEZE,
  387. SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
  388. /*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
  389. SEC_SPC_FREEZE,
  390. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
  391. /*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
  392. SEC_SPC_FREEZE,
  393. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
  394. /*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
  395. 0,
  396. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
  397. /*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
  398. 0,
  399. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
  400. /*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
  401. SEC_SPC_FREEZE,
  402. SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
  403. /*16*/ FLAG_ENTRY("PioPpmcPblFifo",
  404. SEC_SPC_FREEZE,
  405. SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
  406. /*17*/ FLAG_ENTRY("PioInitSmIn",
  407. 0,
  408. SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
  409. /*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
  410. SEC_SPC_FREEZE,
  411. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
  412. /*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
  413. SEC_SPC_FREEZE,
  414. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
  415. /*20*/ FLAG_ENTRY("PioHostAddrMemCor",
  416. 0,
  417. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
  418. /*21*/ FLAG_ENTRY("PioWriteDataParity",
  419. SEC_SPC_FREEZE,
  420. SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
  421. /*22*/ FLAG_ENTRY("PioStateMachine",
  422. SEC_SPC_FREEZE,
  423. SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
  424. /*23*/ FLAG_ENTRY("PioWriteQwValidParity",
  425. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  426. SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
  427. /*24*/ FLAG_ENTRY("PioBlockQwCountParity",
  428. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  429. SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
  430. /*25*/ FLAG_ENTRY("PioVlfVlLenParity",
  431. SEC_SPC_FREEZE,
  432. SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
  433. /*26*/ FLAG_ENTRY("PioVlfSopParity",
  434. SEC_SPC_FREEZE,
  435. SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
  436. /*27*/ FLAG_ENTRY("PioVlFifoParity",
  437. SEC_SPC_FREEZE,
  438. SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
  439. /*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
  440. SEC_SPC_FREEZE,
  441. SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
  442. /*29*/ FLAG_ENTRY("PioPpmcSopLen",
  443. SEC_SPC_FREEZE,
  444. SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
  445. /*30-31 reserved*/
  446. /*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
  447. SEC_SPC_FREEZE,
  448. SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
  449. /*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
  450. SEC_SPC_FREEZE,
  451. SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
  452. /*34*/ FLAG_ENTRY("PioPccSopHeadParity",
  453. SEC_SPC_FREEZE,
  454. SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
  455. /*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
  456. SEC_SPC_FREEZE,
  457. SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
  458. /*36-63 reserved*/
  459. };
  460. /* TXE PIO errors that cause an SPC freeze */
  461. #define ALL_PIO_FREEZE_ERR \
  462. (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
  463. | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
  464. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
  465. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
  466. | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
  467. | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
  468. | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
  469. | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
  470. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
  471. | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
  472. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
  473. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
  474. | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
  475. | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
  476. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
  477. | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
  478. | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
  479. | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
  480. | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
  481. | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
  482. | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
  483. | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
  484. | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
  485. | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
  486. | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
  487. | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
  488. | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
  489. | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
  490. | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
  491. /*
  492. * TXE SDMA Error flags
  493. */
  494. static struct flag_table sdma_err_status_flags[] = {
  495. /* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
  496. SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
  497. /* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
  498. SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
  499. /* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
  500. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
  501. /* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
  502. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
  503. /*04-63 reserved*/
  504. };
  505. /* TXE SDMA errors that cause an SPC freeze */
  506. #define ALL_SDMA_FREEZE_ERR \
  507. (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
  508. | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
  509. | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
  510. /* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
  511. #define PORT_DISCARD_EGRESS_ERRS \
  512. (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
  513. | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
  514. | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
  515. /*
  516. * TXE Egress Error flags
  517. */
  518. #define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
  519. static struct flag_table egress_err_status_flags[] = {
  520. /* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
  521. /* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
  522. /* 2 reserved */
  523. /* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
  524. SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
  525. /* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
  526. /* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
  527. /* 6 reserved */
  528. /* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
  529. SEES(TX_PIO_LAUNCH_INTF_PARITY)),
  530. /* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
  531. SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
  532. /* 9-10 reserved */
  533. /*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
  534. SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
  535. /*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
  536. /*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
  537. /*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
  538. /*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
  539. /*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
  540. SEES(TX_SDMA0_DISALLOWED_PACKET)),
  541. /*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
  542. SEES(TX_SDMA1_DISALLOWED_PACKET)),
  543. /*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
  544. SEES(TX_SDMA2_DISALLOWED_PACKET)),
  545. /*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
  546. SEES(TX_SDMA3_DISALLOWED_PACKET)),
  547. /*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
  548. SEES(TX_SDMA4_DISALLOWED_PACKET)),
  549. /*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
  550. SEES(TX_SDMA5_DISALLOWED_PACKET)),
  551. /*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
  552. SEES(TX_SDMA6_DISALLOWED_PACKET)),
  553. /*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
  554. SEES(TX_SDMA7_DISALLOWED_PACKET)),
  555. /*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
  556. SEES(TX_SDMA8_DISALLOWED_PACKET)),
  557. /*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
  558. SEES(TX_SDMA9_DISALLOWED_PACKET)),
  559. /*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
  560. SEES(TX_SDMA10_DISALLOWED_PACKET)),
  561. /*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
  562. SEES(TX_SDMA11_DISALLOWED_PACKET)),
  563. /*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
  564. SEES(TX_SDMA12_DISALLOWED_PACKET)),
  565. /*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
  566. SEES(TX_SDMA13_DISALLOWED_PACKET)),
  567. /*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
  568. SEES(TX_SDMA14_DISALLOWED_PACKET)),
  569. /*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
  570. SEES(TX_SDMA15_DISALLOWED_PACKET)),
  571. /*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
  572. SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
  573. /*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
  574. SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
  575. /*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
  576. SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
  577. /*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
  578. SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
  579. /*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
  580. SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
  581. /*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
  582. SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
  583. /*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
  584. SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
  585. /*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
  586. SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
  587. /*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
  588. SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
  589. /*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
  590. /*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
  591. /*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
  592. /*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
  593. /*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
  594. /*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
  595. /*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
  596. /*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
  597. /*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
  598. /*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
  599. /*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
  600. /*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
  601. /*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
  602. /*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
  603. /*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
  604. /*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
  605. /*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
  606. /*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
  607. /*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
  608. /*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
  609. /*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
  610. /*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
  611. SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
  612. /*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
  613. SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
  614. };
  615. /*
  616. * TXE Egress Error Info flags
  617. */
  618. #define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
  619. static struct flag_table egress_err_info_flags[] = {
  620. /* 0*/ FLAG_ENTRY0("Reserved", 0ull),
  621. /* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
  622. /* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  623. /* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  624. /* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
  625. /* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
  626. /* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
  627. /* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
  628. /* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
  629. /* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
  630. /*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
  631. /*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
  632. /*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
  633. /*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
  634. /*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
  635. /*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
  636. /*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
  637. /*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
  638. /*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
  639. /*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
  640. /*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
  641. /*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
  642. };
  643. /* TXE Egress errors that cause an SPC freeze */
  644. #define ALL_TXE_EGRESS_FREEZE_ERR \
  645. (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
  646. | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
  647. | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
  648. | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
  649. | SEES(TX_LAUNCH_CSR_PARITY) \
  650. | SEES(TX_SBRD_CTL_CSR_PARITY) \
  651. | SEES(TX_CONFIG_PARITY) \
  652. | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
  653. | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
  654. | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
  655. | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
  656. | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
  657. | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
  658. | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
  659. | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
  660. | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
  661. | SEES(TX_CREDIT_RETURN_PARITY))
  662. /*
  663. * TXE Send error flags
  664. */
  665. #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
  666. static struct flag_table send_err_status_flags[] = {
  667. /* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
  668. /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
  669. /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
  670. };
  671. /*
  672. * TXE Send Context Error flags and consequences
  673. */
  674. static struct flag_table sc_err_status_flags[] = {
  675. /* 0*/ FLAG_ENTRY("InconsistentSop",
  676. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  677. SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
  678. /* 1*/ FLAG_ENTRY("DisallowedPacket",
  679. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  680. SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
  681. /* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
  682. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  683. SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
  684. /* 3*/ FLAG_ENTRY("WriteOverflow",
  685. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  686. SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
  687. /* 4*/ FLAG_ENTRY("WriteOutOfBounds",
  688. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  689. SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
  690. /* 5-63 reserved*/
  691. };
  692. /*
  693. * RXE Receive Error flags
  694. */
  695. #define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
  696. static struct flag_table rxe_err_status_flags[] = {
  697. /* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
  698. /* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
  699. /* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
  700. /* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
  701. /* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
  702. /* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
  703. /* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
  704. /* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
  705. /* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
  706. /* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
  707. /*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
  708. /*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
  709. /*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
  710. /*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
  711. /*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
  712. /*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
  713. /*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
  714. RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
  715. /*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
  716. /*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
  717. /*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
  718. RXES(RBUF_BLOCK_LIST_READ_UNC)),
  719. /*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
  720. RXES(RBUF_BLOCK_LIST_READ_COR)),
  721. /*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
  722. RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
  723. /*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
  724. RXES(RBUF_CSR_QENT_CNT_PARITY)),
  725. /*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
  726. RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
  727. /*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
  728. RXES(RBUF_CSR_QVLD_BIT_PARITY)),
  729. /*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
  730. /*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
  731. /*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
  732. RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
  733. /*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
  734. /*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
  735. /*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
  736. /*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
  737. /*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
  738. /*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
  739. /*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
  740. /*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
  741. RXES(RBUF_FL_INITDONE_PARITY)),
  742. /*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
  743. RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
  744. /*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
  745. /*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
  746. /*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
  747. /*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
  748. RXES(LOOKUP_DES_PART1_UNC_COR)),
  749. /*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
  750. RXES(LOOKUP_DES_PART2_PARITY)),
  751. /*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
  752. /*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
  753. /*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
  754. /*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
  755. /*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
  756. /*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
  757. /*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
  758. /*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
  759. /*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
  760. /*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
  761. /*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
  762. /*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
  763. /*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
  764. /*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
  765. /*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
  766. /*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
  767. /*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
  768. /*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
  769. /*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
  770. /*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
  771. /*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
  772. /*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
  773. };
  774. /* RXE errors that will trigger an SPC freeze */
  775. #define ALL_RXE_FREEZE_ERR \
  776. (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
  777. | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
  778. | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
  779. | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
  780. | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
  781. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
  782. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
  783. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
  784. | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
  785. | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
  786. | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
  787. | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
  788. | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
  789. | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
  790. | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
  791. | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
  792. | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
  793. | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
  794. | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
  795. | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
  796. | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
  797. | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
  798. | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
  799. | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
  800. | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
  801. | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
  802. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
  803. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
  804. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
  805. | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
  806. | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
  807. | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
  808. | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
  809. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
  810. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
  811. | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
  812. | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
  813. | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
  814. | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
  815. | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
  816. | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
  817. | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
  818. | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
  819. | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
  820. #define RXE_FREEZE_ABORT_MASK \
  821. (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
  822. RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
  823. RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
  824. /*
  825. * DCC Error Flags
  826. */
  827. #define DCCE(name) DCC_ERR_FLG_##name##_SMASK
  828. static struct flag_table dcc_err_flags[] = {
  829. FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
  830. FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
  831. FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
  832. FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
  833. FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
  834. FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
  835. FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
  836. FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
  837. FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
  838. FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
  839. FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
  840. FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
  841. FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
  842. FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
  843. FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
  844. FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
  845. FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
  846. FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
  847. FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
  848. FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
  849. FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
  850. FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
  851. FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
  852. FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
  853. FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
  854. FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
  855. FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
  856. FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
  857. FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
  858. FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
  859. FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
  860. FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
  861. FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
  862. FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
  863. FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
  864. FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
  865. FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
  866. FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
  867. FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
  868. FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
  869. FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
  870. FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
  871. FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
  872. FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
  873. FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
  874. FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
  875. };
  876. /*
  877. * LCB error flags
  878. */
  879. #define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
  880. static struct flag_table lcb_err_flags[] = {
  881. /* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
  882. /* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
  883. /* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
  884. /* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
  885. LCBE(ALL_LNS_FAILED_REINIT_TEST)),
  886. /* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
  887. /* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
  888. /* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
  889. /* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
  890. /* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
  891. /* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
  892. /*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
  893. /*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
  894. /*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
  895. /*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
  896. LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
  897. /*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
  898. /*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
  899. /*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
  900. /*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
  901. /*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
  902. /*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
  903. LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
  904. /*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
  905. /*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
  906. /*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
  907. /*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
  908. /*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
  909. /*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
  910. /*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
  911. LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
  912. /*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
  913. /*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
  914. LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
  915. /*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
  916. LCBE(REDUNDANT_FLIT_PARITY_ERR))
  917. };
  918. /*
  919. * DC8051 Error Flags
  920. */
  921. #define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
  922. static struct flag_table dc8051_err_flags[] = {
  923. FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
  924. FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
  925. FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
  926. FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
  927. FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
  928. FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
  929. FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
  930. FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
  931. FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
  932. D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
  933. FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
  934. };
  935. /*
  936. * DC8051 Information Error flags
  937. *
  938. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
  939. */
  940. static struct flag_table dc8051_info_err_flags[] = {
  941. FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
  942. FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
  943. FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
  944. FLAG_ENTRY0("Serdes internal loopback failure",
  945. FAILED_SERDES_INTERNAL_LOOPBACK),
  946. FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
  947. FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
  948. FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
  949. FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
  950. FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
  951. FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
  952. FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
  953. FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
  954. FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
  955. FLAG_ENTRY0("External Device Request Timeout",
  956. EXTERNAL_DEVICE_REQ_TIMEOUT),
  957. };
  958. /*
  959. * DC8051 Information Host Information flags
  960. *
  961. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
  962. */
  963. static struct flag_table dc8051_info_host_msg_flags[] = {
  964. FLAG_ENTRY0("Host request done", 0x0001),
  965. FLAG_ENTRY0("BC PWR_MGM message", 0x0002),
  966. FLAG_ENTRY0("BC SMA message", 0x0004),
  967. FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
  968. FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
  969. FLAG_ENTRY0("External device config request", 0x0020),
  970. FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
  971. FLAG_ENTRY0("LinkUp achieved", 0x0080),
  972. FLAG_ENTRY0("Link going down", 0x0100),
  973. FLAG_ENTRY0("Link width downgraded", 0x0200),
  974. };
  975. static u32 encoded_size(u32 size);
  976. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
  977. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
  978. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  979. u8 *continuous);
  980. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  981. u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
  982. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  983. u8 *remote_tx_rate, u16 *link_widths);
  984. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  985. u8 *flag_bits, u16 *link_widths);
  986. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  987. u8 *device_rev);
  988. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed);
  989. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
  990. static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
  991. u8 *tx_polarity_inversion,
  992. u8 *rx_polarity_inversion, u8 *max_rate);
  993. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  994. unsigned int context, u64 err_status);
  995. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
  996. static void handle_dcc_err(struct hfi1_devdata *dd,
  997. unsigned int context, u64 err_status);
  998. static void handle_lcb_err(struct hfi1_devdata *dd,
  999. unsigned int context, u64 err_status);
  1000. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1001. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1002. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1003. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1004. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1005. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1006. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1007. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1008. static void set_partition_keys(struct hfi1_pportdata *ppd);
  1009. static const char *link_state_name(u32 state);
  1010. static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
  1011. u32 state);
  1012. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  1013. u64 *out_data);
  1014. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
  1015. static int thermal_init(struct hfi1_devdata *dd);
  1016. static void update_statusp(struct hfi1_pportdata *ppd, u32 state);
  1017. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1018. int msecs);
  1019. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1020. int msecs);
  1021. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
  1022. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
  1023. static void handle_temp_err(struct hfi1_devdata *dd);
  1024. static void dc_shutdown(struct hfi1_devdata *dd);
  1025. static void dc_start(struct hfi1_devdata *dd);
  1026. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  1027. unsigned int *np);
  1028. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
  1029. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
  1030. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index);
  1031. /*
  1032. * Error interrupt table entry. This is used as input to the interrupt
  1033. * "clear down" routine used for all second tier error interrupt register.
  1034. * Second tier interrupt registers have a single bit representing them
  1035. * in the top-level CceIntStatus.
  1036. */
  1037. struct err_reg_info {
  1038. u32 status; /* status CSR offset */
  1039. u32 clear; /* clear CSR offset */
  1040. u32 mask; /* mask CSR offset */
  1041. void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
  1042. const char *desc;
  1043. };
  1044. #define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
  1045. #define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
  1046. #define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
  1047. /*
  1048. * Helpers for building HFI and DC error interrupt table entries. Different
  1049. * helpers are needed because of inconsistent register names.
  1050. */
  1051. #define EE(reg, handler, desc) \
  1052. { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
  1053. handler, desc }
  1054. #define DC_EE1(reg, handler, desc) \
  1055. { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
  1056. #define DC_EE2(reg, handler, desc) \
  1057. { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
  1058. /*
  1059. * Table of the "misc" grouping of error interrupts. Each entry refers to
  1060. * another register containing more information.
  1061. */
  1062. static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
  1063. /* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
  1064. /* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
  1065. /* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
  1066. /* 3*/ { 0, 0, 0, NULL }, /* reserved */
  1067. /* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
  1068. /* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
  1069. /* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
  1070. /* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
  1071. /* the rest are reserved */
  1072. };
  1073. /*
  1074. * Index into the Various section of the interrupt sources
  1075. * corresponding to the Critical Temperature interrupt.
  1076. */
  1077. #define TCRIT_INT_SOURCE 4
  1078. /*
  1079. * SDMA error interrupt entry - refers to another register containing more
  1080. * information.
  1081. */
  1082. static const struct err_reg_info sdma_eng_err =
  1083. EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
  1084. static const struct err_reg_info various_err[NUM_VARIOUS] = {
  1085. /* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
  1086. /* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
  1087. /* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
  1088. /* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
  1089. /* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
  1090. /* rest are reserved */
  1091. };
  1092. /*
  1093. * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
  1094. * register can not be derived from the MTU value because 10K is not
  1095. * a power of 2. Therefore, we need a constant. Everything else can
  1096. * be calculated.
  1097. */
  1098. #define DCC_CFG_PORT_MTU_CAP_10240 7
  1099. /*
  1100. * Table of the DC grouping of error interrupts. Each entry refers to
  1101. * another register containing more information.
  1102. */
  1103. static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
  1104. /* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
  1105. /* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
  1106. /* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
  1107. /* 3*/ /* dc_lbm_int - special, see is_dc_int() */
  1108. /* the rest are reserved */
  1109. };
  1110. struct cntr_entry {
  1111. /*
  1112. * counter name
  1113. */
  1114. char *name;
  1115. /*
  1116. * csr to read for name (if applicable)
  1117. */
  1118. u64 csr;
  1119. /*
  1120. * offset into dd or ppd to store the counter's value
  1121. */
  1122. int offset;
  1123. /*
  1124. * flags
  1125. */
  1126. u8 flags;
  1127. /*
  1128. * accessor for stat element, context either dd or ppd
  1129. */
  1130. u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
  1131. int mode, u64 data);
  1132. };
  1133. #define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
  1134. #define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
  1135. #define CNTR_ELEM(name, csr, offset, flags, accessor) \
  1136. { \
  1137. name, \
  1138. csr, \
  1139. offset, \
  1140. flags, \
  1141. accessor \
  1142. }
  1143. /* 32bit RXE */
  1144. #define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1145. CNTR_ELEM(#name, \
  1146. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1147. 0, flags | CNTR_32BIT, \
  1148. port_access_u32_csr)
  1149. #define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
  1150. CNTR_ELEM(#name, \
  1151. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1152. 0, flags | CNTR_32BIT, \
  1153. dev_access_u32_csr)
  1154. /* 64bit RXE */
  1155. #define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1156. CNTR_ELEM(#name, \
  1157. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1158. 0, flags, \
  1159. port_access_u64_csr)
  1160. #define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
  1161. CNTR_ELEM(#name, \
  1162. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1163. 0, flags, \
  1164. dev_access_u64_csr)
  1165. #define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
  1166. #define OVR_ELM(ctx) \
  1167. CNTR_ELEM("RcvHdrOvr" #ctx, \
  1168. (RCV_HDR_OVFL_CNT + ctx * 0x100), \
  1169. 0, CNTR_NORMAL, port_access_u64_csr)
  1170. /* 32bit TXE */
  1171. #define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1172. CNTR_ELEM(#name, \
  1173. (counter * 8 + SEND_COUNTER_ARRAY32), \
  1174. 0, flags | CNTR_32BIT, \
  1175. port_access_u32_csr)
  1176. /* 64bit TXE */
  1177. #define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1178. CNTR_ELEM(#name, \
  1179. (counter * 8 + SEND_COUNTER_ARRAY64), \
  1180. 0, flags, \
  1181. port_access_u64_csr)
  1182. # define TX64_DEV_CNTR_ELEM(name, counter, flags) \
  1183. CNTR_ELEM(#name,\
  1184. counter * 8 + SEND_COUNTER_ARRAY64, \
  1185. 0, \
  1186. flags, \
  1187. dev_access_u64_csr)
  1188. /* CCE */
  1189. #define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
  1190. CNTR_ELEM(#name, \
  1191. (counter * 8 + CCE_COUNTER_ARRAY32), \
  1192. 0, flags | CNTR_32BIT, \
  1193. dev_access_u32_csr)
  1194. #define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
  1195. CNTR_ELEM(#name, \
  1196. (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
  1197. 0, flags | CNTR_32BIT, \
  1198. dev_access_u32_csr)
  1199. /* DC */
  1200. #define DC_PERF_CNTR(name, counter, flags) \
  1201. CNTR_ELEM(#name, \
  1202. counter, \
  1203. 0, \
  1204. flags, \
  1205. dev_access_u64_csr)
  1206. #define DC_PERF_CNTR_LCB(name, counter, flags) \
  1207. CNTR_ELEM(#name, \
  1208. counter, \
  1209. 0, \
  1210. flags, \
  1211. dc_access_lcb_cntr)
  1212. /* ibp counters */
  1213. #define SW_IBP_CNTR(name, cntr) \
  1214. CNTR_ELEM(#name, \
  1215. 0, \
  1216. 0, \
  1217. CNTR_SYNTH, \
  1218. access_ibp_##cntr)
  1219. /**
  1220. * hfi_addr_from_offset - return addr for readq/writeq
  1221. * @dd - the dd device
  1222. * @offset - the offset of the CSR within bar0
  1223. *
  1224. * This routine selects the appropriate base address
  1225. * based on the indicated offset.
  1226. */
  1227. static inline void __iomem *hfi1_addr_from_offset(
  1228. const struct hfi1_devdata *dd,
  1229. u32 offset)
  1230. {
  1231. if (offset >= dd->base2_start)
  1232. return dd->kregbase2 + (offset - dd->base2_start);
  1233. return dd->kregbase1 + offset;
  1234. }
  1235. /**
  1236. * read_csr - read CSR at the indicated offset
  1237. * @dd - the dd device
  1238. * @offset - the offset of the CSR within bar0
  1239. *
  1240. * Return: the value read or all FF's if there
  1241. * is no mapping
  1242. */
  1243. u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
  1244. {
  1245. if (dd->flags & HFI1_PRESENT)
  1246. return readq(hfi1_addr_from_offset(dd, offset));
  1247. return -1;
  1248. }
  1249. /**
  1250. * write_csr - write CSR at the indicated offset
  1251. * @dd - the dd device
  1252. * @offset - the offset of the CSR within bar0
  1253. * @value - value to write
  1254. */
  1255. void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
  1256. {
  1257. if (dd->flags & HFI1_PRESENT) {
  1258. void __iomem *base = hfi1_addr_from_offset(dd, offset);
  1259. /* avoid write to RcvArray */
  1260. if (WARN_ON(offset >= RCV_ARRAY && offset < dd->base2_start))
  1261. return;
  1262. writeq(value, base);
  1263. }
  1264. }
  1265. /**
  1266. * get_csr_addr - return te iomem address for offset
  1267. * @dd - the dd device
  1268. * @offset - the offset of the CSR within bar0
  1269. *
  1270. * Return: The iomem address to use in subsequent
  1271. * writeq/readq operations.
  1272. */
  1273. void __iomem *get_csr_addr(
  1274. const struct hfi1_devdata *dd,
  1275. u32 offset)
  1276. {
  1277. if (dd->flags & HFI1_PRESENT)
  1278. return hfi1_addr_from_offset(dd, offset);
  1279. return NULL;
  1280. }
  1281. static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
  1282. int mode, u64 value)
  1283. {
  1284. u64 ret;
  1285. if (mode == CNTR_MODE_R) {
  1286. ret = read_csr(dd, csr);
  1287. } else if (mode == CNTR_MODE_W) {
  1288. write_csr(dd, csr, value);
  1289. ret = value;
  1290. } else {
  1291. dd_dev_err(dd, "Invalid cntr register access mode");
  1292. return 0;
  1293. }
  1294. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
  1295. return ret;
  1296. }
  1297. /* Dev Access */
  1298. static u64 dev_access_u32_csr(const struct cntr_entry *entry,
  1299. void *context, int vl, int mode, u64 data)
  1300. {
  1301. struct hfi1_devdata *dd = context;
  1302. u64 csr = entry->csr;
  1303. if (entry->flags & CNTR_SDMA) {
  1304. if (vl == CNTR_INVALID_VL)
  1305. return 0;
  1306. csr += 0x100 * vl;
  1307. } else {
  1308. if (vl != CNTR_INVALID_VL)
  1309. return 0;
  1310. }
  1311. return read_write_csr(dd, csr, mode, data);
  1312. }
  1313. static u64 access_sde_err_cnt(const struct cntr_entry *entry,
  1314. void *context, int idx, int mode, u64 data)
  1315. {
  1316. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1317. if (dd->per_sdma && idx < dd->num_sdma)
  1318. return dd->per_sdma[idx].err_cnt;
  1319. return 0;
  1320. }
  1321. static u64 access_sde_int_cnt(const struct cntr_entry *entry,
  1322. void *context, int idx, int mode, u64 data)
  1323. {
  1324. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1325. if (dd->per_sdma && idx < dd->num_sdma)
  1326. return dd->per_sdma[idx].sdma_int_cnt;
  1327. return 0;
  1328. }
  1329. static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
  1330. void *context, int idx, int mode, u64 data)
  1331. {
  1332. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1333. if (dd->per_sdma && idx < dd->num_sdma)
  1334. return dd->per_sdma[idx].idle_int_cnt;
  1335. return 0;
  1336. }
  1337. static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
  1338. void *context, int idx, int mode,
  1339. u64 data)
  1340. {
  1341. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1342. if (dd->per_sdma && idx < dd->num_sdma)
  1343. return dd->per_sdma[idx].progress_int_cnt;
  1344. return 0;
  1345. }
  1346. static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
  1347. int vl, int mode, u64 data)
  1348. {
  1349. struct hfi1_devdata *dd = context;
  1350. u64 val = 0;
  1351. u64 csr = entry->csr;
  1352. if (entry->flags & CNTR_VL) {
  1353. if (vl == CNTR_INVALID_VL)
  1354. return 0;
  1355. csr += 8 * vl;
  1356. } else {
  1357. if (vl != CNTR_INVALID_VL)
  1358. return 0;
  1359. }
  1360. val = read_write_csr(dd, csr, mode, data);
  1361. return val;
  1362. }
  1363. static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
  1364. int vl, int mode, u64 data)
  1365. {
  1366. struct hfi1_devdata *dd = context;
  1367. u32 csr = entry->csr;
  1368. int ret = 0;
  1369. if (vl != CNTR_INVALID_VL)
  1370. return 0;
  1371. if (mode == CNTR_MODE_R)
  1372. ret = read_lcb_csr(dd, csr, &data);
  1373. else if (mode == CNTR_MODE_W)
  1374. ret = write_lcb_csr(dd, csr, data);
  1375. if (ret) {
  1376. dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
  1377. return 0;
  1378. }
  1379. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
  1380. return data;
  1381. }
  1382. /* Port Access */
  1383. static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
  1384. int vl, int mode, u64 data)
  1385. {
  1386. struct hfi1_pportdata *ppd = context;
  1387. if (vl != CNTR_INVALID_VL)
  1388. return 0;
  1389. return read_write_csr(ppd->dd, entry->csr, mode, data);
  1390. }
  1391. static u64 port_access_u64_csr(const struct cntr_entry *entry,
  1392. void *context, int vl, int mode, u64 data)
  1393. {
  1394. struct hfi1_pportdata *ppd = context;
  1395. u64 val;
  1396. u64 csr = entry->csr;
  1397. if (entry->flags & CNTR_VL) {
  1398. if (vl == CNTR_INVALID_VL)
  1399. return 0;
  1400. csr += 8 * vl;
  1401. } else {
  1402. if (vl != CNTR_INVALID_VL)
  1403. return 0;
  1404. }
  1405. val = read_write_csr(ppd->dd, csr, mode, data);
  1406. return val;
  1407. }
  1408. /* Software defined */
  1409. static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
  1410. u64 data)
  1411. {
  1412. u64 ret;
  1413. if (mode == CNTR_MODE_R) {
  1414. ret = *cntr;
  1415. } else if (mode == CNTR_MODE_W) {
  1416. *cntr = data;
  1417. ret = data;
  1418. } else {
  1419. dd_dev_err(dd, "Invalid cntr sw access mode");
  1420. return 0;
  1421. }
  1422. hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
  1423. return ret;
  1424. }
  1425. static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
  1426. int vl, int mode, u64 data)
  1427. {
  1428. struct hfi1_pportdata *ppd = context;
  1429. if (vl != CNTR_INVALID_VL)
  1430. return 0;
  1431. return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
  1432. }
  1433. static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
  1434. int vl, int mode, u64 data)
  1435. {
  1436. struct hfi1_pportdata *ppd = context;
  1437. if (vl != CNTR_INVALID_VL)
  1438. return 0;
  1439. return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
  1440. }
  1441. static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
  1442. void *context, int vl, int mode,
  1443. u64 data)
  1444. {
  1445. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1446. if (vl != CNTR_INVALID_VL)
  1447. return 0;
  1448. return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
  1449. }
  1450. static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
  1451. void *context, int vl, int mode, u64 data)
  1452. {
  1453. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1454. u64 zero = 0;
  1455. u64 *counter;
  1456. if (vl == CNTR_INVALID_VL)
  1457. counter = &ppd->port_xmit_discards;
  1458. else if (vl >= 0 && vl < C_VL_COUNT)
  1459. counter = &ppd->port_xmit_discards_vl[vl];
  1460. else
  1461. counter = &zero;
  1462. return read_write_sw(ppd->dd, counter, mode, data);
  1463. }
  1464. static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
  1465. void *context, int vl, int mode,
  1466. u64 data)
  1467. {
  1468. struct hfi1_pportdata *ppd = context;
  1469. if (vl != CNTR_INVALID_VL)
  1470. return 0;
  1471. return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
  1472. mode, data);
  1473. }
  1474. static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
  1475. void *context, int vl, int mode, u64 data)
  1476. {
  1477. struct hfi1_pportdata *ppd = context;
  1478. if (vl != CNTR_INVALID_VL)
  1479. return 0;
  1480. return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
  1481. mode, data);
  1482. }
  1483. u64 get_all_cpu_total(u64 __percpu *cntr)
  1484. {
  1485. int cpu;
  1486. u64 counter = 0;
  1487. for_each_possible_cpu(cpu)
  1488. counter += *per_cpu_ptr(cntr, cpu);
  1489. return counter;
  1490. }
  1491. static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
  1492. u64 __percpu *cntr,
  1493. int vl, int mode, u64 data)
  1494. {
  1495. u64 ret = 0;
  1496. if (vl != CNTR_INVALID_VL)
  1497. return 0;
  1498. if (mode == CNTR_MODE_R) {
  1499. ret = get_all_cpu_total(cntr) - *z_val;
  1500. } else if (mode == CNTR_MODE_W) {
  1501. /* A write can only zero the counter */
  1502. if (data == 0)
  1503. *z_val = get_all_cpu_total(cntr);
  1504. else
  1505. dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
  1506. } else {
  1507. dd_dev_err(dd, "Invalid cntr sw cpu access mode");
  1508. return 0;
  1509. }
  1510. return ret;
  1511. }
  1512. static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
  1513. void *context, int vl, int mode, u64 data)
  1514. {
  1515. struct hfi1_devdata *dd = context;
  1516. return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
  1517. mode, data);
  1518. }
  1519. static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
  1520. void *context, int vl, int mode, u64 data)
  1521. {
  1522. struct hfi1_devdata *dd = context;
  1523. return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
  1524. mode, data);
  1525. }
  1526. static u64 access_sw_pio_wait(const struct cntr_entry *entry,
  1527. void *context, int vl, int mode, u64 data)
  1528. {
  1529. struct hfi1_devdata *dd = context;
  1530. return dd->verbs_dev.n_piowait;
  1531. }
  1532. static u64 access_sw_pio_drain(const struct cntr_entry *entry,
  1533. void *context, int vl, int mode, u64 data)
  1534. {
  1535. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1536. return dd->verbs_dev.n_piodrain;
  1537. }
  1538. static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
  1539. void *context, int vl, int mode, u64 data)
  1540. {
  1541. struct hfi1_devdata *dd = context;
  1542. return dd->verbs_dev.n_txwait;
  1543. }
  1544. static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
  1545. void *context, int vl, int mode, u64 data)
  1546. {
  1547. struct hfi1_devdata *dd = context;
  1548. return dd->verbs_dev.n_kmem_wait;
  1549. }
  1550. static u64 access_sw_send_schedule(const struct cntr_entry *entry,
  1551. void *context, int vl, int mode, u64 data)
  1552. {
  1553. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1554. return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
  1555. mode, data);
  1556. }
  1557. /* Software counters for the error status bits within MISC_ERR_STATUS */
  1558. static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
  1559. void *context, int vl, int mode,
  1560. u64 data)
  1561. {
  1562. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1563. return dd->misc_err_status_cnt[12];
  1564. }
  1565. static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
  1566. void *context, int vl, int mode,
  1567. u64 data)
  1568. {
  1569. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1570. return dd->misc_err_status_cnt[11];
  1571. }
  1572. static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
  1573. void *context, int vl, int mode,
  1574. u64 data)
  1575. {
  1576. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1577. return dd->misc_err_status_cnt[10];
  1578. }
  1579. static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
  1580. void *context, int vl,
  1581. int mode, u64 data)
  1582. {
  1583. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1584. return dd->misc_err_status_cnt[9];
  1585. }
  1586. static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
  1587. void *context, int vl, int mode,
  1588. u64 data)
  1589. {
  1590. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1591. return dd->misc_err_status_cnt[8];
  1592. }
  1593. static u64 access_misc_efuse_read_bad_addr_err_cnt(
  1594. const struct cntr_entry *entry,
  1595. void *context, int vl, int mode, u64 data)
  1596. {
  1597. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1598. return dd->misc_err_status_cnt[7];
  1599. }
  1600. static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
  1601. void *context, int vl,
  1602. int mode, u64 data)
  1603. {
  1604. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1605. return dd->misc_err_status_cnt[6];
  1606. }
  1607. static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
  1608. void *context, int vl, int mode,
  1609. u64 data)
  1610. {
  1611. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1612. return dd->misc_err_status_cnt[5];
  1613. }
  1614. static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
  1615. void *context, int vl, int mode,
  1616. u64 data)
  1617. {
  1618. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1619. return dd->misc_err_status_cnt[4];
  1620. }
  1621. static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
  1622. void *context, int vl,
  1623. int mode, u64 data)
  1624. {
  1625. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1626. return dd->misc_err_status_cnt[3];
  1627. }
  1628. static u64 access_misc_csr_write_bad_addr_err_cnt(
  1629. const struct cntr_entry *entry,
  1630. void *context, int vl, int mode, u64 data)
  1631. {
  1632. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1633. return dd->misc_err_status_cnt[2];
  1634. }
  1635. static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1636. void *context, int vl,
  1637. int mode, u64 data)
  1638. {
  1639. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1640. return dd->misc_err_status_cnt[1];
  1641. }
  1642. static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
  1643. void *context, int vl, int mode,
  1644. u64 data)
  1645. {
  1646. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1647. return dd->misc_err_status_cnt[0];
  1648. }
  1649. /*
  1650. * Software counter for the aggregate of
  1651. * individual CceErrStatus counters
  1652. */
  1653. static u64 access_sw_cce_err_status_aggregated_cnt(
  1654. const struct cntr_entry *entry,
  1655. void *context, int vl, int mode, u64 data)
  1656. {
  1657. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1658. return dd->sw_cce_err_status_aggregate;
  1659. }
  1660. /*
  1661. * Software counters corresponding to each of the
  1662. * error status bits within CceErrStatus
  1663. */
  1664. static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
  1665. void *context, int vl, int mode,
  1666. u64 data)
  1667. {
  1668. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1669. return dd->cce_err_status_cnt[40];
  1670. }
  1671. static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
  1672. void *context, int vl, int mode,
  1673. u64 data)
  1674. {
  1675. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1676. return dd->cce_err_status_cnt[39];
  1677. }
  1678. static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
  1679. void *context, int vl, int mode,
  1680. u64 data)
  1681. {
  1682. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1683. return dd->cce_err_status_cnt[38];
  1684. }
  1685. static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
  1686. void *context, int vl, int mode,
  1687. u64 data)
  1688. {
  1689. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1690. return dd->cce_err_status_cnt[37];
  1691. }
  1692. static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
  1693. void *context, int vl, int mode,
  1694. u64 data)
  1695. {
  1696. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1697. return dd->cce_err_status_cnt[36];
  1698. }
  1699. static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
  1700. const struct cntr_entry *entry,
  1701. void *context, int vl, int mode, u64 data)
  1702. {
  1703. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1704. return dd->cce_err_status_cnt[35];
  1705. }
  1706. static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
  1707. const struct cntr_entry *entry,
  1708. void *context, int vl, int mode, u64 data)
  1709. {
  1710. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1711. return dd->cce_err_status_cnt[34];
  1712. }
  1713. static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1714. void *context, int vl,
  1715. int mode, u64 data)
  1716. {
  1717. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1718. return dd->cce_err_status_cnt[33];
  1719. }
  1720. static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1721. void *context, int vl, int mode,
  1722. u64 data)
  1723. {
  1724. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1725. return dd->cce_err_status_cnt[32];
  1726. }
  1727. static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
  1728. void *context, int vl, int mode, u64 data)
  1729. {
  1730. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1731. return dd->cce_err_status_cnt[31];
  1732. }
  1733. static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
  1734. void *context, int vl, int mode,
  1735. u64 data)
  1736. {
  1737. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1738. return dd->cce_err_status_cnt[30];
  1739. }
  1740. static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
  1741. void *context, int vl, int mode,
  1742. u64 data)
  1743. {
  1744. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1745. return dd->cce_err_status_cnt[29];
  1746. }
  1747. static u64 access_pcic_transmit_back_parity_err_cnt(
  1748. const struct cntr_entry *entry,
  1749. void *context, int vl, int mode, u64 data)
  1750. {
  1751. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1752. return dd->cce_err_status_cnt[28];
  1753. }
  1754. static u64 access_pcic_transmit_front_parity_err_cnt(
  1755. const struct cntr_entry *entry,
  1756. void *context, int vl, int mode, u64 data)
  1757. {
  1758. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1759. return dd->cce_err_status_cnt[27];
  1760. }
  1761. static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1762. void *context, int vl, int mode,
  1763. u64 data)
  1764. {
  1765. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1766. return dd->cce_err_status_cnt[26];
  1767. }
  1768. static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1769. void *context, int vl, int mode,
  1770. u64 data)
  1771. {
  1772. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1773. return dd->cce_err_status_cnt[25];
  1774. }
  1775. static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1776. void *context, int vl, int mode,
  1777. u64 data)
  1778. {
  1779. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1780. return dd->cce_err_status_cnt[24];
  1781. }
  1782. static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1783. void *context, int vl, int mode,
  1784. u64 data)
  1785. {
  1786. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1787. return dd->cce_err_status_cnt[23];
  1788. }
  1789. static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
  1790. void *context, int vl,
  1791. int mode, u64 data)
  1792. {
  1793. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1794. return dd->cce_err_status_cnt[22];
  1795. }
  1796. static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
  1797. void *context, int vl, int mode,
  1798. u64 data)
  1799. {
  1800. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1801. return dd->cce_err_status_cnt[21];
  1802. }
  1803. static u64 access_pcic_n_post_dat_q_parity_err_cnt(
  1804. const struct cntr_entry *entry,
  1805. void *context, int vl, int mode, u64 data)
  1806. {
  1807. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1808. return dd->cce_err_status_cnt[20];
  1809. }
  1810. static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
  1811. void *context, int vl,
  1812. int mode, u64 data)
  1813. {
  1814. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1815. return dd->cce_err_status_cnt[19];
  1816. }
  1817. static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1818. void *context, int vl, int mode,
  1819. u64 data)
  1820. {
  1821. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1822. return dd->cce_err_status_cnt[18];
  1823. }
  1824. static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1825. void *context, int vl, int mode,
  1826. u64 data)
  1827. {
  1828. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1829. return dd->cce_err_status_cnt[17];
  1830. }
  1831. static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1832. void *context, int vl, int mode,
  1833. u64 data)
  1834. {
  1835. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1836. return dd->cce_err_status_cnt[16];
  1837. }
  1838. static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1839. void *context, int vl, int mode,
  1840. u64 data)
  1841. {
  1842. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1843. return dd->cce_err_status_cnt[15];
  1844. }
  1845. static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
  1846. void *context, int vl,
  1847. int mode, u64 data)
  1848. {
  1849. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1850. return dd->cce_err_status_cnt[14];
  1851. }
  1852. static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
  1853. void *context, int vl, int mode,
  1854. u64 data)
  1855. {
  1856. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1857. return dd->cce_err_status_cnt[13];
  1858. }
  1859. static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
  1860. const struct cntr_entry *entry,
  1861. void *context, int vl, int mode, u64 data)
  1862. {
  1863. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1864. return dd->cce_err_status_cnt[12];
  1865. }
  1866. static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
  1867. const struct cntr_entry *entry,
  1868. void *context, int vl, int mode, u64 data)
  1869. {
  1870. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1871. return dd->cce_err_status_cnt[11];
  1872. }
  1873. static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
  1874. const struct cntr_entry *entry,
  1875. void *context, int vl, int mode, u64 data)
  1876. {
  1877. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1878. return dd->cce_err_status_cnt[10];
  1879. }
  1880. static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
  1881. const struct cntr_entry *entry,
  1882. void *context, int vl, int mode, u64 data)
  1883. {
  1884. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1885. return dd->cce_err_status_cnt[9];
  1886. }
  1887. static u64 access_cce_cli2_async_fifo_parity_err_cnt(
  1888. const struct cntr_entry *entry,
  1889. void *context, int vl, int mode, u64 data)
  1890. {
  1891. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1892. return dd->cce_err_status_cnt[8];
  1893. }
  1894. static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
  1895. void *context, int vl,
  1896. int mode, u64 data)
  1897. {
  1898. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1899. return dd->cce_err_status_cnt[7];
  1900. }
  1901. static u64 access_cce_cli0_async_fifo_parity_err_cnt(
  1902. const struct cntr_entry *entry,
  1903. void *context, int vl, int mode, u64 data)
  1904. {
  1905. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1906. return dd->cce_err_status_cnt[6];
  1907. }
  1908. static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
  1909. void *context, int vl, int mode,
  1910. u64 data)
  1911. {
  1912. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1913. return dd->cce_err_status_cnt[5];
  1914. }
  1915. static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry,
  1916. void *context, int vl, int mode,
  1917. u64 data)
  1918. {
  1919. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1920. return dd->cce_err_status_cnt[4];
  1921. }
  1922. static u64 access_cce_trgt_async_fifo_parity_err_cnt(
  1923. const struct cntr_entry *entry,
  1924. void *context, int vl, int mode, u64 data)
  1925. {
  1926. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1927. return dd->cce_err_status_cnt[3];
  1928. }
  1929. static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1930. void *context, int vl,
  1931. int mode, u64 data)
  1932. {
  1933. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1934. return dd->cce_err_status_cnt[2];
  1935. }
  1936. static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1937. void *context, int vl,
  1938. int mode, u64 data)
  1939. {
  1940. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1941. return dd->cce_err_status_cnt[1];
  1942. }
  1943. static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
  1944. void *context, int vl, int mode,
  1945. u64 data)
  1946. {
  1947. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1948. return dd->cce_err_status_cnt[0];
  1949. }
  1950. /*
  1951. * Software counters corresponding to each of the
  1952. * error status bits within RcvErrStatus
  1953. */
  1954. static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
  1955. void *context, int vl, int mode,
  1956. u64 data)
  1957. {
  1958. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1959. return dd->rcv_err_status_cnt[63];
  1960. }
  1961. static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1962. void *context, int vl,
  1963. int mode, u64 data)
  1964. {
  1965. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1966. return dd->rcv_err_status_cnt[62];
  1967. }
  1968. static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1969. void *context, int vl, int mode,
  1970. u64 data)
  1971. {
  1972. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1973. return dd->rcv_err_status_cnt[61];
  1974. }
  1975. static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
  1976. void *context, int vl, int mode,
  1977. u64 data)
  1978. {
  1979. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1980. return dd->rcv_err_status_cnt[60];
  1981. }
  1982. static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1983. void *context, int vl,
  1984. int mode, u64 data)
  1985. {
  1986. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1987. return dd->rcv_err_status_cnt[59];
  1988. }
  1989. static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1990. void *context, int vl,
  1991. int mode, u64 data)
  1992. {
  1993. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1994. return dd->rcv_err_status_cnt[58];
  1995. }
  1996. static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
  1997. void *context, int vl, int mode,
  1998. u64 data)
  1999. {
  2000. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2001. return dd->rcv_err_status_cnt[57];
  2002. }
  2003. static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
  2004. void *context, int vl, int mode,
  2005. u64 data)
  2006. {
  2007. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2008. return dd->rcv_err_status_cnt[56];
  2009. }
  2010. static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
  2011. void *context, int vl, int mode,
  2012. u64 data)
  2013. {
  2014. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2015. return dd->rcv_err_status_cnt[55];
  2016. }
  2017. static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
  2018. const struct cntr_entry *entry,
  2019. void *context, int vl, int mode, u64 data)
  2020. {
  2021. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2022. return dd->rcv_err_status_cnt[54];
  2023. }
  2024. static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
  2025. const struct cntr_entry *entry,
  2026. void *context, int vl, int mode, u64 data)
  2027. {
  2028. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2029. return dd->rcv_err_status_cnt[53];
  2030. }
  2031. static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
  2032. void *context, int vl,
  2033. int mode, u64 data)
  2034. {
  2035. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2036. return dd->rcv_err_status_cnt[52];
  2037. }
  2038. static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
  2039. void *context, int vl,
  2040. int mode, u64 data)
  2041. {
  2042. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2043. return dd->rcv_err_status_cnt[51];
  2044. }
  2045. static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
  2046. void *context, int vl,
  2047. int mode, u64 data)
  2048. {
  2049. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2050. return dd->rcv_err_status_cnt[50];
  2051. }
  2052. static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
  2053. void *context, int vl,
  2054. int mode, u64 data)
  2055. {
  2056. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2057. return dd->rcv_err_status_cnt[49];
  2058. }
  2059. static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
  2060. void *context, int vl,
  2061. int mode, u64 data)
  2062. {
  2063. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2064. return dd->rcv_err_status_cnt[48];
  2065. }
  2066. static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
  2067. void *context, int vl,
  2068. int mode, u64 data)
  2069. {
  2070. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2071. return dd->rcv_err_status_cnt[47];
  2072. }
  2073. static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
  2074. void *context, int vl, int mode,
  2075. u64 data)
  2076. {
  2077. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2078. return dd->rcv_err_status_cnt[46];
  2079. }
  2080. static u64 access_rx_hq_intr_csr_parity_err_cnt(
  2081. const struct cntr_entry *entry,
  2082. void *context, int vl, int mode, u64 data)
  2083. {
  2084. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2085. return dd->rcv_err_status_cnt[45];
  2086. }
  2087. static u64 access_rx_lookup_csr_parity_err_cnt(
  2088. const struct cntr_entry *entry,
  2089. void *context, int vl, int mode, u64 data)
  2090. {
  2091. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2092. return dd->rcv_err_status_cnt[44];
  2093. }
  2094. static u64 access_rx_lookup_rcv_array_cor_err_cnt(
  2095. const struct cntr_entry *entry,
  2096. void *context, int vl, int mode, u64 data)
  2097. {
  2098. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2099. return dd->rcv_err_status_cnt[43];
  2100. }
  2101. static u64 access_rx_lookup_rcv_array_unc_err_cnt(
  2102. const struct cntr_entry *entry,
  2103. void *context, int vl, int mode, u64 data)
  2104. {
  2105. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2106. return dd->rcv_err_status_cnt[42];
  2107. }
  2108. static u64 access_rx_lookup_des_part2_parity_err_cnt(
  2109. const struct cntr_entry *entry,
  2110. void *context, int vl, int mode, u64 data)
  2111. {
  2112. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2113. return dd->rcv_err_status_cnt[41];
  2114. }
  2115. static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
  2116. const struct cntr_entry *entry,
  2117. void *context, int vl, int mode, u64 data)
  2118. {
  2119. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2120. return dd->rcv_err_status_cnt[40];
  2121. }
  2122. static u64 access_rx_lookup_des_part1_unc_err_cnt(
  2123. const struct cntr_entry *entry,
  2124. void *context, int vl, int mode, u64 data)
  2125. {
  2126. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2127. return dd->rcv_err_status_cnt[39];
  2128. }
  2129. static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
  2130. const struct cntr_entry *entry,
  2131. void *context, int vl, int mode, u64 data)
  2132. {
  2133. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2134. return dd->rcv_err_status_cnt[38];
  2135. }
  2136. static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
  2137. const struct cntr_entry *entry,
  2138. void *context, int vl, int mode, u64 data)
  2139. {
  2140. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2141. return dd->rcv_err_status_cnt[37];
  2142. }
  2143. static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
  2144. const struct cntr_entry *entry,
  2145. void *context, int vl, int mode, u64 data)
  2146. {
  2147. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2148. return dd->rcv_err_status_cnt[36];
  2149. }
  2150. static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
  2151. const struct cntr_entry *entry,
  2152. void *context, int vl, int mode, u64 data)
  2153. {
  2154. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2155. return dd->rcv_err_status_cnt[35];
  2156. }
  2157. static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
  2158. const struct cntr_entry *entry,
  2159. void *context, int vl, int mode, u64 data)
  2160. {
  2161. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2162. return dd->rcv_err_status_cnt[34];
  2163. }
  2164. static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
  2165. const struct cntr_entry *entry,
  2166. void *context, int vl, int mode, u64 data)
  2167. {
  2168. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2169. return dd->rcv_err_status_cnt[33];
  2170. }
  2171. static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
  2172. void *context, int vl, int mode,
  2173. u64 data)
  2174. {
  2175. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2176. return dd->rcv_err_status_cnt[32];
  2177. }
  2178. static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
  2179. void *context, int vl, int mode,
  2180. u64 data)
  2181. {
  2182. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2183. return dd->rcv_err_status_cnt[31];
  2184. }
  2185. static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
  2186. void *context, int vl, int mode,
  2187. u64 data)
  2188. {
  2189. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2190. return dd->rcv_err_status_cnt[30];
  2191. }
  2192. static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
  2193. void *context, int vl, int mode,
  2194. u64 data)
  2195. {
  2196. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2197. return dd->rcv_err_status_cnt[29];
  2198. }
  2199. static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
  2200. void *context, int vl,
  2201. int mode, u64 data)
  2202. {
  2203. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2204. return dd->rcv_err_status_cnt[28];
  2205. }
  2206. static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
  2207. const struct cntr_entry *entry,
  2208. void *context, int vl, int mode, u64 data)
  2209. {
  2210. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2211. return dd->rcv_err_status_cnt[27];
  2212. }
  2213. static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
  2214. const struct cntr_entry *entry,
  2215. void *context, int vl, int mode, u64 data)
  2216. {
  2217. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2218. return dd->rcv_err_status_cnt[26];
  2219. }
  2220. static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
  2221. const struct cntr_entry *entry,
  2222. void *context, int vl, int mode, u64 data)
  2223. {
  2224. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2225. return dd->rcv_err_status_cnt[25];
  2226. }
  2227. static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
  2228. const struct cntr_entry *entry,
  2229. void *context, int vl, int mode, u64 data)
  2230. {
  2231. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2232. return dd->rcv_err_status_cnt[24];
  2233. }
  2234. static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
  2235. const struct cntr_entry *entry,
  2236. void *context, int vl, int mode, u64 data)
  2237. {
  2238. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2239. return dd->rcv_err_status_cnt[23];
  2240. }
  2241. static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
  2242. const struct cntr_entry *entry,
  2243. void *context, int vl, int mode, u64 data)
  2244. {
  2245. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2246. return dd->rcv_err_status_cnt[22];
  2247. }
  2248. static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
  2249. const struct cntr_entry *entry,
  2250. void *context, int vl, int mode, u64 data)
  2251. {
  2252. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2253. return dd->rcv_err_status_cnt[21];
  2254. }
  2255. static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
  2256. const struct cntr_entry *entry,
  2257. void *context, int vl, int mode, u64 data)
  2258. {
  2259. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2260. return dd->rcv_err_status_cnt[20];
  2261. }
  2262. static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
  2263. const struct cntr_entry *entry,
  2264. void *context, int vl, int mode, u64 data)
  2265. {
  2266. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2267. return dd->rcv_err_status_cnt[19];
  2268. }
  2269. static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
  2270. void *context, int vl,
  2271. int mode, u64 data)
  2272. {
  2273. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2274. return dd->rcv_err_status_cnt[18];
  2275. }
  2276. static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
  2277. void *context, int vl,
  2278. int mode, u64 data)
  2279. {
  2280. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2281. return dd->rcv_err_status_cnt[17];
  2282. }
  2283. static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
  2284. const struct cntr_entry *entry,
  2285. void *context, int vl, int mode, u64 data)
  2286. {
  2287. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2288. return dd->rcv_err_status_cnt[16];
  2289. }
  2290. static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
  2291. const struct cntr_entry *entry,
  2292. void *context, int vl, int mode, u64 data)
  2293. {
  2294. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2295. return dd->rcv_err_status_cnt[15];
  2296. }
  2297. static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
  2298. void *context, int vl,
  2299. int mode, u64 data)
  2300. {
  2301. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2302. return dd->rcv_err_status_cnt[14];
  2303. }
  2304. static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
  2305. void *context, int vl,
  2306. int mode, u64 data)
  2307. {
  2308. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2309. return dd->rcv_err_status_cnt[13];
  2310. }
  2311. static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  2312. void *context, int vl, int mode,
  2313. u64 data)
  2314. {
  2315. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2316. return dd->rcv_err_status_cnt[12];
  2317. }
  2318. static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
  2319. void *context, int vl, int mode,
  2320. u64 data)
  2321. {
  2322. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2323. return dd->rcv_err_status_cnt[11];
  2324. }
  2325. static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
  2326. void *context, int vl, int mode,
  2327. u64 data)
  2328. {
  2329. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2330. return dd->rcv_err_status_cnt[10];
  2331. }
  2332. static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
  2333. void *context, int vl, int mode,
  2334. u64 data)
  2335. {
  2336. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2337. return dd->rcv_err_status_cnt[9];
  2338. }
  2339. static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
  2340. void *context, int vl, int mode,
  2341. u64 data)
  2342. {
  2343. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2344. return dd->rcv_err_status_cnt[8];
  2345. }
  2346. static u64 access_rx_rcv_qp_map_table_cor_err_cnt(
  2347. const struct cntr_entry *entry,
  2348. void *context, int vl, int mode, u64 data)
  2349. {
  2350. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2351. return dd->rcv_err_status_cnt[7];
  2352. }
  2353. static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
  2354. const struct cntr_entry *entry,
  2355. void *context, int vl, int mode, u64 data)
  2356. {
  2357. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2358. return dd->rcv_err_status_cnt[6];
  2359. }
  2360. static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry,
  2361. void *context, int vl, int mode,
  2362. u64 data)
  2363. {
  2364. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2365. return dd->rcv_err_status_cnt[5];
  2366. }
  2367. static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry,
  2368. void *context, int vl, int mode,
  2369. u64 data)
  2370. {
  2371. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2372. return dd->rcv_err_status_cnt[4];
  2373. }
  2374. static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2375. void *context, int vl, int mode,
  2376. u64 data)
  2377. {
  2378. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2379. return dd->rcv_err_status_cnt[3];
  2380. }
  2381. static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2382. void *context, int vl, int mode,
  2383. u64 data)
  2384. {
  2385. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2386. return dd->rcv_err_status_cnt[2];
  2387. }
  2388. static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry,
  2389. void *context, int vl, int mode,
  2390. u64 data)
  2391. {
  2392. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2393. return dd->rcv_err_status_cnt[1];
  2394. }
  2395. static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
  2396. void *context, int vl, int mode,
  2397. u64 data)
  2398. {
  2399. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2400. return dd->rcv_err_status_cnt[0];
  2401. }
  2402. /*
  2403. * Software counters corresponding to each of the
  2404. * error status bits within SendPioErrStatus
  2405. */
  2406. static u64 access_pio_pec_sop_head_parity_err_cnt(
  2407. const struct cntr_entry *entry,
  2408. void *context, int vl, int mode, u64 data)
  2409. {
  2410. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2411. return dd->send_pio_err_status_cnt[35];
  2412. }
  2413. static u64 access_pio_pcc_sop_head_parity_err_cnt(
  2414. const struct cntr_entry *entry,
  2415. void *context, int vl, int mode, u64 data)
  2416. {
  2417. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2418. return dd->send_pio_err_status_cnt[34];
  2419. }
  2420. static u64 access_pio_last_returned_cnt_parity_err_cnt(
  2421. const struct cntr_entry *entry,
  2422. void *context, int vl, int mode, u64 data)
  2423. {
  2424. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2425. return dd->send_pio_err_status_cnt[33];
  2426. }
  2427. static u64 access_pio_current_free_cnt_parity_err_cnt(
  2428. const struct cntr_entry *entry,
  2429. void *context, int vl, int mode, u64 data)
  2430. {
  2431. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2432. return dd->send_pio_err_status_cnt[32];
  2433. }
  2434. static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
  2435. void *context, int vl, int mode,
  2436. u64 data)
  2437. {
  2438. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2439. return dd->send_pio_err_status_cnt[31];
  2440. }
  2441. static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
  2442. void *context, int vl, int mode,
  2443. u64 data)
  2444. {
  2445. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2446. return dd->send_pio_err_status_cnt[30];
  2447. }
  2448. static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
  2449. void *context, int vl, int mode,
  2450. u64 data)
  2451. {
  2452. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2453. return dd->send_pio_err_status_cnt[29];
  2454. }
  2455. static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
  2456. const struct cntr_entry *entry,
  2457. void *context, int vl, int mode, u64 data)
  2458. {
  2459. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2460. return dd->send_pio_err_status_cnt[28];
  2461. }
  2462. static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2463. void *context, int vl, int mode,
  2464. u64 data)
  2465. {
  2466. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2467. return dd->send_pio_err_status_cnt[27];
  2468. }
  2469. static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
  2470. void *context, int vl, int mode,
  2471. u64 data)
  2472. {
  2473. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2474. return dd->send_pio_err_status_cnt[26];
  2475. }
  2476. static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
  2477. void *context, int vl,
  2478. int mode, u64 data)
  2479. {
  2480. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2481. return dd->send_pio_err_status_cnt[25];
  2482. }
  2483. static u64 access_pio_block_qw_count_parity_err_cnt(
  2484. const struct cntr_entry *entry,
  2485. void *context, int vl, int mode, u64 data)
  2486. {
  2487. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2488. return dd->send_pio_err_status_cnt[24];
  2489. }
  2490. static u64 access_pio_write_qw_valid_parity_err_cnt(
  2491. const struct cntr_entry *entry,
  2492. void *context, int vl, int mode, u64 data)
  2493. {
  2494. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2495. return dd->send_pio_err_status_cnt[23];
  2496. }
  2497. static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
  2498. void *context, int vl, int mode,
  2499. u64 data)
  2500. {
  2501. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2502. return dd->send_pio_err_status_cnt[22];
  2503. }
  2504. static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
  2505. void *context, int vl,
  2506. int mode, u64 data)
  2507. {
  2508. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2509. return dd->send_pio_err_status_cnt[21];
  2510. }
  2511. static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
  2512. void *context, int vl,
  2513. int mode, u64 data)
  2514. {
  2515. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2516. return dd->send_pio_err_status_cnt[20];
  2517. }
  2518. static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
  2519. void *context, int vl,
  2520. int mode, u64 data)
  2521. {
  2522. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2523. return dd->send_pio_err_status_cnt[19];
  2524. }
  2525. static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
  2526. const struct cntr_entry *entry,
  2527. void *context, int vl, int mode, u64 data)
  2528. {
  2529. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2530. return dd->send_pio_err_status_cnt[18];
  2531. }
  2532. static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
  2533. void *context, int vl, int mode,
  2534. u64 data)
  2535. {
  2536. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2537. return dd->send_pio_err_status_cnt[17];
  2538. }
  2539. static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
  2540. void *context, int vl, int mode,
  2541. u64 data)
  2542. {
  2543. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2544. return dd->send_pio_err_status_cnt[16];
  2545. }
  2546. static u64 access_pio_credit_ret_fifo_parity_err_cnt(
  2547. const struct cntr_entry *entry,
  2548. void *context, int vl, int mode, u64 data)
  2549. {
  2550. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2551. return dd->send_pio_err_status_cnt[15];
  2552. }
  2553. static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
  2554. const struct cntr_entry *entry,
  2555. void *context, int vl, int mode, u64 data)
  2556. {
  2557. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2558. return dd->send_pio_err_status_cnt[14];
  2559. }
  2560. static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
  2561. const struct cntr_entry *entry,
  2562. void *context, int vl, int mode, u64 data)
  2563. {
  2564. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2565. return dd->send_pio_err_status_cnt[13];
  2566. }
  2567. static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
  2568. const struct cntr_entry *entry,
  2569. void *context, int vl, int mode, u64 data)
  2570. {
  2571. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2572. return dd->send_pio_err_status_cnt[12];
  2573. }
  2574. static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
  2575. const struct cntr_entry *entry,
  2576. void *context, int vl, int mode, u64 data)
  2577. {
  2578. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2579. return dd->send_pio_err_status_cnt[11];
  2580. }
  2581. static u64 access_pio_sm_pkt_reset_parity_err_cnt(
  2582. const struct cntr_entry *entry,
  2583. void *context, int vl, int mode, u64 data)
  2584. {
  2585. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2586. return dd->send_pio_err_status_cnt[10];
  2587. }
  2588. static u64 access_pio_pkt_evict_fifo_parity_err_cnt(
  2589. const struct cntr_entry *entry,
  2590. void *context, int vl, int mode, u64 data)
  2591. {
  2592. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2593. return dd->send_pio_err_status_cnt[9];
  2594. }
  2595. static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
  2596. const struct cntr_entry *entry,
  2597. void *context, int vl, int mode, u64 data)
  2598. {
  2599. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2600. return dd->send_pio_err_status_cnt[8];
  2601. }
  2602. static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
  2603. const struct cntr_entry *entry,
  2604. void *context, int vl, int mode, u64 data)
  2605. {
  2606. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2607. return dd->send_pio_err_status_cnt[7];
  2608. }
  2609. static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2610. void *context, int vl, int mode,
  2611. u64 data)
  2612. {
  2613. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2614. return dd->send_pio_err_status_cnt[6];
  2615. }
  2616. static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2617. void *context, int vl, int mode,
  2618. u64 data)
  2619. {
  2620. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2621. return dd->send_pio_err_status_cnt[5];
  2622. }
  2623. static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
  2624. void *context, int vl, int mode,
  2625. u64 data)
  2626. {
  2627. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2628. return dd->send_pio_err_status_cnt[4];
  2629. }
  2630. static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
  2631. void *context, int vl, int mode,
  2632. u64 data)
  2633. {
  2634. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2635. return dd->send_pio_err_status_cnt[3];
  2636. }
  2637. static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
  2638. void *context, int vl, int mode,
  2639. u64 data)
  2640. {
  2641. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2642. return dd->send_pio_err_status_cnt[2];
  2643. }
  2644. static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
  2645. void *context, int vl,
  2646. int mode, u64 data)
  2647. {
  2648. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2649. return dd->send_pio_err_status_cnt[1];
  2650. }
  2651. static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
  2652. void *context, int vl, int mode,
  2653. u64 data)
  2654. {
  2655. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2656. return dd->send_pio_err_status_cnt[0];
  2657. }
  2658. /*
  2659. * Software counters corresponding to each of the
  2660. * error status bits within SendDmaErrStatus
  2661. */
  2662. static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
  2663. const struct cntr_entry *entry,
  2664. void *context, int vl, int mode, u64 data)
  2665. {
  2666. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2667. return dd->send_dma_err_status_cnt[3];
  2668. }
  2669. static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
  2670. const struct cntr_entry *entry,
  2671. void *context, int vl, int mode, u64 data)
  2672. {
  2673. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2674. return dd->send_dma_err_status_cnt[2];
  2675. }
  2676. static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2677. void *context, int vl, int mode,
  2678. u64 data)
  2679. {
  2680. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2681. return dd->send_dma_err_status_cnt[1];
  2682. }
  2683. static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry,
  2684. void *context, int vl, int mode,
  2685. u64 data)
  2686. {
  2687. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2688. return dd->send_dma_err_status_cnt[0];
  2689. }
  2690. /*
  2691. * Software counters corresponding to each of the
  2692. * error status bits within SendEgressErrStatus
  2693. */
  2694. static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
  2695. const struct cntr_entry *entry,
  2696. void *context, int vl, int mode, u64 data)
  2697. {
  2698. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2699. return dd->send_egress_err_status_cnt[63];
  2700. }
  2701. static u64 access_tx_read_sdma_memory_csr_err_cnt(
  2702. const struct cntr_entry *entry,
  2703. void *context, int vl, int mode, u64 data)
  2704. {
  2705. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2706. return dd->send_egress_err_status_cnt[62];
  2707. }
  2708. static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
  2709. void *context, int vl, int mode,
  2710. u64 data)
  2711. {
  2712. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2713. return dd->send_egress_err_status_cnt[61];
  2714. }
  2715. static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
  2716. void *context, int vl,
  2717. int mode, u64 data)
  2718. {
  2719. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2720. return dd->send_egress_err_status_cnt[60];
  2721. }
  2722. static u64 access_tx_read_sdma_memory_cor_err_cnt(
  2723. const struct cntr_entry *entry,
  2724. void *context, int vl, int mode, u64 data)
  2725. {
  2726. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2727. return dd->send_egress_err_status_cnt[59];
  2728. }
  2729. static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2730. void *context, int vl, int mode,
  2731. u64 data)
  2732. {
  2733. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2734. return dd->send_egress_err_status_cnt[58];
  2735. }
  2736. static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
  2737. void *context, int vl, int mode,
  2738. u64 data)
  2739. {
  2740. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2741. return dd->send_egress_err_status_cnt[57];
  2742. }
  2743. static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
  2744. void *context, int vl, int mode,
  2745. u64 data)
  2746. {
  2747. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2748. return dd->send_egress_err_status_cnt[56];
  2749. }
  2750. static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
  2751. void *context, int vl, int mode,
  2752. u64 data)
  2753. {
  2754. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2755. return dd->send_egress_err_status_cnt[55];
  2756. }
  2757. static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
  2758. void *context, int vl, int mode,
  2759. u64 data)
  2760. {
  2761. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2762. return dd->send_egress_err_status_cnt[54];
  2763. }
  2764. static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
  2765. void *context, int vl, int mode,
  2766. u64 data)
  2767. {
  2768. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2769. return dd->send_egress_err_status_cnt[53];
  2770. }
  2771. static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
  2772. void *context, int vl, int mode,
  2773. u64 data)
  2774. {
  2775. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2776. return dd->send_egress_err_status_cnt[52];
  2777. }
  2778. static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
  2779. void *context, int vl, int mode,
  2780. u64 data)
  2781. {
  2782. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2783. return dd->send_egress_err_status_cnt[51];
  2784. }
  2785. static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
  2786. void *context, int vl, int mode,
  2787. u64 data)
  2788. {
  2789. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2790. return dd->send_egress_err_status_cnt[50];
  2791. }
  2792. static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
  2793. void *context, int vl, int mode,
  2794. u64 data)
  2795. {
  2796. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2797. return dd->send_egress_err_status_cnt[49];
  2798. }
  2799. static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
  2800. void *context, int vl, int mode,
  2801. u64 data)
  2802. {
  2803. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2804. return dd->send_egress_err_status_cnt[48];
  2805. }
  2806. static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
  2807. void *context, int vl, int mode,
  2808. u64 data)
  2809. {
  2810. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2811. return dd->send_egress_err_status_cnt[47];
  2812. }
  2813. static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
  2814. void *context, int vl, int mode,
  2815. u64 data)
  2816. {
  2817. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2818. return dd->send_egress_err_status_cnt[46];
  2819. }
  2820. static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
  2821. void *context, int vl, int mode,
  2822. u64 data)
  2823. {
  2824. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2825. return dd->send_egress_err_status_cnt[45];
  2826. }
  2827. static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
  2828. void *context, int vl,
  2829. int mode, u64 data)
  2830. {
  2831. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2832. return dd->send_egress_err_status_cnt[44];
  2833. }
  2834. static u64 access_tx_read_sdma_memory_unc_err_cnt(
  2835. const struct cntr_entry *entry,
  2836. void *context, int vl, int mode, u64 data)
  2837. {
  2838. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2839. return dd->send_egress_err_status_cnt[43];
  2840. }
  2841. static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2842. void *context, int vl, int mode,
  2843. u64 data)
  2844. {
  2845. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2846. return dd->send_egress_err_status_cnt[42];
  2847. }
  2848. static u64 access_tx_credit_return_partiy_err_cnt(
  2849. const struct cntr_entry *entry,
  2850. void *context, int vl, int mode, u64 data)
  2851. {
  2852. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2853. return dd->send_egress_err_status_cnt[41];
  2854. }
  2855. static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
  2856. const struct cntr_entry *entry,
  2857. void *context, int vl, int mode, u64 data)
  2858. {
  2859. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2860. return dd->send_egress_err_status_cnt[40];
  2861. }
  2862. static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
  2863. const struct cntr_entry *entry,
  2864. void *context, int vl, int mode, u64 data)
  2865. {
  2866. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2867. return dd->send_egress_err_status_cnt[39];
  2868. }
  2869. static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
  2870. const struct cntr_entry *entry,
  2871. void *context, int vl, int mode, u64 data)
  2872. {
  2873. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2874. return dd->send_egress_err_status_cnt[38];
  2875. }
  2876. static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
  2877. const struct cntr_entry *entry,
  2878. void *context, int vl, int mode, u64 data)
  2879. {
  2880. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2881. return dd->send_egress_err_status_cnt[37];
  2882. }
  2883. static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
  2884. const struct cntr_entry *entry,
  2885. void *context, int vl, int mode, u64 data)
  2886. {
  2887. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2888. return dd->send_egress_err_status_cnt[36];
  2889. }
  2890. static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
  2891. const struct cntr_entry *entry,
  2892. void *context, int vl, int mode, u64 data)
  2893. {
  2894. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2895. return dd->send_egress_err_status_cnt[35];
  2896. }
  2897. static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
  2898. const struct cntr_entry *entry,
  2899. void *context, int vl, int mode, u64 data)
  2900. {
  2901. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2902. return dd->send_egress_err_status_cnt[34];
  2903. }
  2904. static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
  2905. const struct cntr_entry *entry,
  2906. void *context, int vl, int mode, u64 data)
  2907. {
  2908. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2909. return dd->send_egress_err_status_cnt[33];
  2910. }
  2911. static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
  2912. const struct cntr_entry *entry,
  2913. void *context, int vl, int mode, u64 data)
  2914. {
  2915. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2916. return dd->send_egress_err_status_cnt[32];
  2917. }
  2918. static u64 access_tx_sdma15_disallowed_packet_err_cnt(
  2919. const struct cntr_entry *entry,
  2920. void *context, int vl, int mode, u64 data)
  2921. {
  2922. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2923. return dd->send_egress_err_status_cnt[31];
  2924. }
  2925. static u64 access_tx_sdma14_disallowed_packet_err_cnt(
  2926. const struct cntr_entry *entry,
  2927. void *context, int vl, int mode, u64 data)
  2928. {
  2929. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2930. return dd->send_egress_err_status_cnt[30];
  2931. }
  2932. static u64 access_tx_sdma13_disallowed_packet_err_cnt(
  2933. const struct cntr_entry *entry,
  2934. void *context, int vl, int mode, u64 data)
  2935. {
  2936. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2937. return dd->send_egress_err_status_cnt[29];
  2938. }
  2939. static u64 access_tx_sdma12_disallowed_packet_err_cnt(
  2940. const struct cntr_entry *entry,
  2941. void *context, int vl, int mode, u64 data)
  2942. {
  2943. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2944. return dd->send_egress_err_status_cnt[28];
  2945. }
  2946. static u64 access_tx_sdma11_disallowed_packet_err_cnt(
  2947. const struct cntr_entry *entry,
  2948. void *context, int vl, int mode, u64 data)
  2949. {
  2950. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2951. return dd->send_egress_err_status_cnt[27];
  2952. }
  2953. static u64 access_tx_sdma10_disallowed_packet_err_cnt(
  2954. const struct cntr_entry *entry,
  2955. void *context, int vl, int mode, u64 data)
  2956. {
  2957. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2958. return dd->send_egress_err_status_cnt[26];
  2959. }
  2960. static u64 access_tx_sdma9_disallowed_packet_err_cnt(
  2961. const struct cntr_entry *entry,
  2962. void *context, int vl, int mode, u64 data)
  2963. {
  2964. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2965. return dd->send_egress_err_status_cnt[25];
  2966. }
  2967. static u64 access_tx_sdma8_disallowed_packet_err_cnt(
  2968. const struct cntr_entry *entry,
  2969. void *context, int vl, int mode, u64 data)
  2970. {
  2971. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2972. return dd->send_egress_err_status_cnt[24];
  2973. }
  2974. static u64 access_tx_sdma7_disallowed_packet_err_cnt(
  2975. const struct cntr_entry *entry,
  2976. void *context, int vl, int mode, u64 data)
  2977. {
  2978. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2979. return dd->send_egress_err_status_cnt[23];
  2980. }
  2981. static u64 access_tx_sdma6_disallowed_packet_err_cnt(
  2982. const struct cntr_entry *entry,
  2983. void *context, int vl, int mode, u64 data)
  2984. {
  2985. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2986. return dd->send_egress_err_status_cnt[22];
  2987. }
  2988. static u64 access_tx_sdma5_disallowed_packet_err_cnt(
  2989. const struct cntr_entry *entry,
  2990. void *context, int vl, int mode, u64 data)
  2991. {
  2992. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2993. return dd->send_egress_err_status_cnt[21];
  2994. }
  2995. static u64 access_tx_sdma4_disallowed_packet_err_cnt(
  2996. const struct cntr_entry *entry,
  2997. void *context, int vl, int mode, u64 data)
  2998. {
  2999. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3000. return dd->send_egress_err_status_cnt[20];
  3001. }
  3002. static u64 access_tx_sdma3_disallowed_packet_err_cnt(
  3003. const struct cntr_entry *entry,
  3004. void *context, int vl, int mode, u64 data)
  3005. {
  3006. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3007. return dd->send_egress_err_status_cnt[19];
  3008. }
  3009. static u64 access_tx_sdma2_disallowed_packet_err_cnt(
  3010. const struct cntr_entry *entry,
  3011. void *context, int vl, int mode, u64 data)
  3012. {
  3013. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3014. return dd->send_egress_err_status_cnt[18];
  3015. }
  3016. static u64 access_tx_sdma1_disallowed_packet_err_cnt(
  3017. const struct cntr_entry *entry,
  3018. void *context, int vl, int mode, u64 data)
  3019. {
  3020. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3021. return dd->send_egress_err_status_cnt[17];
  3022. }
  3023. static u64 access_tx_sdma0_disallowed_packet_err_cnt(
  3024. const struct cntr_entry *entry,
  3025. void *context, int vl, int mode, u64 data)
  3026. {
  3027. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3028. return dd->send_egress_err_status_cnt[16];
  3029. }
  3030. static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
  3031. void *context, int vl, int mode,
  3032. u64 data)
  3033. {
  3034. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3035. return dd->send_egress_err_status_cnt[15];
  3036. }
  3037. static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
  3038. void *context, int vl,
  3039. int mode, u64 data)
  3040. {
  3041. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3042. return dd->send_egress_err_status_cnt[14];
  3043. }
  3044. static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
  3045. void *context, int vl, int mode,
  3046. u64 data)
  3047. {
  3048. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3049. return dd->send_egress_err_status_cnt[13];
  3050. }
  3051. static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
  3052. void *context, int vl, int mode,
  3053. u64 data)
  3054. {
  3055. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3056. return dd->send_egress_err_status_cnt[12];
  3057. }
  3058. static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
  3059. const struct cntr_entry *entry,
  3060. void *context, int vl, int mode, u64 data)
  3061. {
  3062. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3063. return dd->send_egress_err_status_cnt[11];
  3064. }
  3065. static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
  3066. void *context, int vl, int mode,
  3067. u64 data)
  3068. {
  3069. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3070. return dd->send_egress_err_status_cnt[10];
  3071. }
  3072. static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
  3073. void *context, int vl, int mode,
  3074. u64 data)
  3075. {
  3076. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3077. return dd->send_egress_err_status_cnt[9];
  3078. }
  3079. static u64 access_tx_sdma_launch_intf_parity_err_cnt(
  3080. const struct cntr_entry *entry,
  3081. void *context, int vl, int mode, u64 data)
  3082. {
  3083. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3084. return dd->send_egress_err_status_cnt[8];
  3085. }
  3086. static u64 access_tx_pio_launch_intf_parity_err_cnt(
  3087. const struct cntr_entry *entry,
  3088. void *context, int vl, int mode, u64 data)
  3089. {
  3090. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3091. return dd->send_egress_err_status_cnt[7];
  3092. }
  3093. static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
  3094. void *context, int vl, int mode,
  3095. u64 data)
  3096. {
  3097. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3098. return dd->send_egress_err_status_cnt[6];
  3099. }
  3100. static u64 access_tx_incorrect_link_state_err_cnt(
  3101. const struct cntr_entry *entry,
  3102. void *context, int vl, int mode, u64 data)
  3103. {
  3104. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3105. return dd->send_egress_err_status_cnt[5];
  3106. }
  3107. static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
  3108. void *context, int vl, int mode,
  3109. u64 data)
  3110. {
  3111. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3112. return dd->send_egress_err_status_cnt[4];
  3113. }
  3114. static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
  3115. const struct cntr_entry *entry,
  3116. void *context, int vl, int mode, u64 data)
  3117. {
  3118. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3119. return dd->send_egress_err_status_cnt[3];
  3120. }
  3121. static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
  3122. void *context, int vl, int mode,
  3123. u64 data)
  3124. {
  3125. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3126. return dd->send_egress_err_status_cnt[2];
  3127. }
  3128. static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
  3129. const struct cntr_entry *entry,
  3130. void *context, int vl, int mode, u64 data)
  3131. {
  3132. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3133. return dd->send_egress_err_status_cnt[1];
  3134. }
  3135. static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
  3136. const struct cntr_entry *entry,
  3137. void *context, int vl, int mode, u64 data)
  3138. {
  3139. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3140. return dd->send_egress_err_status_cnt[0];
  3141. }
  3142. /*
  3143. * Software counters corresponding to each of the
  3144. * error status bits within SendErrStatus
  3145. */
  3146. static u64 access_send_csr_write_bad_addr_err_cnt(
  3147. const struct cntr_entry *entry,
  3148. void *context, int vl, int mode, u64 data)
  3149. {
  3150. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3151. return dd->send_err_status_cnt[2];
  3152. }
  3153. static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  3154. void *context, int vl,
  3155. int mode, u64 data)
  3156. {
  3157. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3158. return dd->send_err_status_cnt[1];
  3159. }
  3160. static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
  3161. void *context, int vl, int mode,
  3162. u64 data)
  3163. {
  3164. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3165. return dd->send_err_status_cnt[0];
  3166. }
  3167. /*
  3168. * Software counters corresponding to each of the
  3169. * error status bits within SendCtxtErrStatus
  3170. */
  3171. static u64 access_pio_write_out_of_bounds_err_cnt(
  3172. const struct cntr_entry *entry,
  3173. void *context, int vl, int mode, u64 data)
  3174. {
  3175. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3176. return dd->sw_ctxt_err_status_cnt[4];
  3177. }
  3178. static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
  3179. void *context, int vl, int mode,
  3180. u64 data)
  3181. {
  3182. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3183. return dd->sw_ctxt_err_status_cnt[3];
  3184. }
  3185. static u64 access_pio_write_crosses_boundary_err_cnt(
  3186. const struct cntr_entry *entry,
  3187. void *context, int vl, int mode, u64 data)
  3188. {
  3189. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3190. return dd->sw_ctxt_err_status_cnt[2];
  3191. }
  3192. static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
  3193. void *context, int vl,
  3194. int mode, u64 data)
  3195. {
  3196. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3197. return dd->sw_ctxt_err_status_cnt[1];
  3198. }
  3199. static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry,
  3200. void *context, int vl, int mode,
  3201. u64 data)
  3202. {
  3203. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3204. return dd->sw_ctxt_err_status_cnt[0];
  3205. }
  3206. /*
  3207. * Software counters corresponding to each of the
  3208. * error status bits within SendDmaEngErrStatus
  3209. */
  3210. static u64 access_sdma_header_request_fifo_cor_err_cnt(
  3211. const struct cntr_entry *entry,
  3212. void *context, int vl, int mode, u64 data)
  3213. {
  3214. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3215. return dd->sw_send_dma_eng_err_status_cnt[23];
  3216. }
  3217. static u64 access_sdma_header_storage_cor_err_cnt(
  3218. const struct cntr_entry *entry,
  3219. void *context, int vl, int mode, u64 data)
  3220. {
  3221. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3222. return dd->sw_send_dma_eng_err_status_cnt[22];
  3223. }
  3224. static u64 access_sdma_packet_tracking_cor_err_cnt(
  3225. const struct cntr_entry *entry,
  3226. void *context, int vl, int mode, u64 data)
  3227. {
  3228. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3229. return dd->sw_send_dma_eng_err_status_cnt[21];
  3230. }
  3231. static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
  3232. void *context, int vl, int mode,
  3233. u64 data)
  3234. {
  3235. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3236. return dd->sw_send_dma_eng_err_status_cnt[20];
  3237. }
  3238. static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
  3239. void *context, int vl, int mode,
  3240. u64 data)
  3241. {
  3242. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3243. return dd->sw_send_dma_eng_err_status_cnt[19];
  3244. }
  3245. static u64 access_sdma_header_request_fifo_unc_err_cnt(
  3246. const struct cntr_entry *entry,
  3247. void *context, int vl, int mode, u64 data)
  3248. {
  3249. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3250. return dd->sw_send_dma_eng_err_status_cnt[18];
  3251. }
  3252. static u64 access_sdma_header_storage_unc_err_cnt(
  3253. const struct cntr_entry *entry,
  3254. void *context, int vl, int mode, u64 data)
  3255. {
  3256. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3257. return dd->sw_send_dma_eng_err_status_cnt[17];
  3258. }
  3259. static u64 access_sdma_packet_tracking_unc_err_cnt(
  3260. const struct cntr_entry *entry,
  3261. void *context, int vl, int mode, u64 data)
  3262. {
  3263. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3264. return dd->sw_send_dma_eng_err_status_cnt[16];
  3265. }
  3266. static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
  3267. void *context, int vl, int mode,
  3268. u64 data)
  3269. {
  3270. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3271. return dd->sw_send_dma_eng_err_status_cnt[15];
  3272. }
  3273. static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
  3274. void *context, int vl, int mode,
  3275. u64 data)
  3276. {
  3277. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3278. return dd->sw_send_dma_eng_err_status_cnt[14];
  3279. }
  3280. static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
  3281. void *context, int vl, int mode,
  3282. u64 data)
  3283. {
  3284. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3285. return dd->sw_send_dma_eng_err_status_cnt[13];
  3286. }
  3287. static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
  3288. void *context, int vl, int mode,
  3289. u64 data)
  3290. {
  3291. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3292. return dd->sw_send_dma_eng_err_status_cnt[12];
  3293. }
  3294. static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
  3295. void *context, int vl, int mode,
  3296. u64 data)
  3297. {
  3298. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3299. return dd->sw_send_dma_eng_err_status_cnt[11];
  3300. }
  3301. static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
  3302. void *context, int vl, int mode,
  3303. u64 data)
  3304. {
  3305. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3306. return dd->sw_send_dma_eng_err_status_cnt[10];
  3307. }
  3308. static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
  3309. void *context, int vl, int mode,
  3310. u64 data)
  3311. {
  3312. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3313. return dd->sw_send_dma_eng_err_status_cnt[9];
  3314. }
  3315. static u64 access_sdma_packet_desc_overflow_err_cnt(
  3316. const struct cntr_entry *entry,
  3317. void *context, int vl, int mode, u64 data)
  3318. {
  3319. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3320. return dd->sw_send_dma_eng_err_status_cnt[8];
  3321. }
  3322. static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
  3323. void *context, int vl,
  3324. int mode, u64 data)
  3325. {
  3326. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3327. return dd->sw_send_dma_eng_err_status_cnt[7];
  3328. }
  3329. static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
  3330. void *context, int vl, int mode, u64 data)
  3331. {
  3332. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3333. return dd->sw_send_dma_eng_err_status_cnt[6];
  3334. }
  3335. static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
  3336. void *context, int vl, int mode,
  3337. u64 data)
  3338. {
  3339. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3340. return dd->sw_send_dma_eng_err_status_cnt[5];
  3341. }
  3342. static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
  3343. void *context, int vl, int mode,
  3344. u64 data)
  3345. {
  3346. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3347. return dd->sw_send_dma_eng_err_status_cnt[4];
  3348. }
  3349. static u64 access_sdma_tail_out_of_bounds_err_cnt(
  3350. const struct cntr_entry *entry,
  3351. void *context, int vl, int mode, u64 data)
  3352. {
  3353. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3354. return dd->sw_send_dma_eng_err_status_cnt[3];
  3355. }
  3356. static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
  3357. void *context, int vl, int mode,
  3358. u64 data)
  3359. {
  3360. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3361. return dd->sw_send_dma_eng_err_status_cnt[2];
  3362. }
  3363. static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
  3364. void *context, int vl, int mode,
  3365. u64 data)
  3366. {
  3367. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3368. return dd->sw_send_dma_eng_err_status_cnt[1];
  3369. }
  3370. static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
  3371. void *context, int vl, int mode,
  3372. u64 data)
  3373. {
  3374. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3375. return dd->sw_send_dma_eng_err_status_cnt[0];
  3376. }
  3377. static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
  3378. void *context, int vl, int mode,
  3379. u64 data)
  3380. {
  3381. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3382. u64 val = 0;
  3383. u64 csr = entry->csr;
  3384. val = read_write_csr(dd, csr, mode, data);
  3385. if (mode == CNTR_MODE_R) {
  3386. val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
  3387. CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
  3388. } else if (mode == CNTR_MODE_W) {
  3389. dd->sw_rcv_bypass_packet_errors = 0;
  3390. } else {
  3391. dd_dev_err(dd, "Invalid cntr register access mode");
  3392. return 0;
  3393. }
  3394. return val;
  3395. }
  3396. #define def_access_sw_cpu(cntr) \
  3397. static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
  3398. void *context, int vl, int mode, u64 data) \
  3399. { \
  3400. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3401. return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
  3402. ppd->ibport_data.rvp.cntr, vl, \
  3403. mode, data); \
  3404. }
  3405. def_access_sw_cpu(rc_acks);
  3406. def_access_sw_cpu(rc_qacks);
  3407. def_access_sw_cpu(rc_delayed_comp);
  3408. #define def_access_ibp_counter(cntr) \
  3409. static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
  3410. void *context, int vl, int mode, u64 data) \
  3411. { \
  3412. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3413. \
  3414. if (vl != CNTR_INVALID_VL) \
  3415. return 0; \
  3416. \
  3417. return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
  3418. mode, data); \
  3419. }
  3420. def_access_ibp_counter(loop_pkts);
  3421. def_access_ibp_counter(rc_resends);
  3422. def_access_ibp_counter(rnr_naks);
  3423. def_access_ibp_counter(other_naks);
  3424. def_access_ibp_counter(rc_timeouts);
  3425. def_access_ibp_counter(pkt_drops);
  3426. def_access_ibp_counter(dmawait);
  3427. def_access_ibp_counter(rc_seqnak);
  3428. def_access_ibp_counter(rc_dupreq);
  3429. def_access_ibp_counter(rdma_seq);
  3430. def_access_ibp_counter(unaligned);
  3431. def_access_ibp_counter(seq_naks);
  3432. static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
  3433. [C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
  3434. [C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
  3435. CNTR_NORMAL),
  3436. [C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
  3437. CNTR_NORMAL),
  3438. [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
  3439. RCV_TID_FLOW_GEN_MISMATCH_CNT,
  3440. CNTR_NORMAL),
  3441. [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
  3442. CNTR_NORMAL),
  3443. [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
  3444. RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
  3445. [C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
  3446. CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
  3447. [C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
  3448. CNTR_NORMAL),
  3449. [C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
  3450. CNTR_NORMAL),
  3451. [C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
  3452. CNTR_NORMAL),
  3453. [C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
  3454. CNTR_NORMAL),
  3455. [C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
  3456. CNTR_NORMAL),
  3457. [C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
  3458. CNTR_NORMAL),
  3459. [C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
  3460. CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
  3461. [C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
  3462. CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
  3463. [C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
  3464. CNTR_SYNTH),
  3465. [C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
  3466. access_dc_rcv_err_cnt),
  3467. [C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
  3468. CNTR_SYNTH),
  3469. [C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
  3470. CNTR_SYNTH),
  3471. [C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
  3472. CNTR_SYNTH),
  3473. [C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
  3474. DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
  3475. [C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
  3476. DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
  3477. CNTR_SYNTH),
  3478. [C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
  3479. DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
  3480. [C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
  3481. CNTR_SYNTH),
  3482. [C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
  3483. CNTR_SYNTH),
  3484. [C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
  3485. CNTR_SYNTH),
  3486. [C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
  3487. CNTR_SYNTH),
  3488. [C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
  3489. CNTR_SYNTH),
  3490. [C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
  3491. CNTR_SYNTH),
  3492. [C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
  3493. CNTR_SYNTH),
  3494. [C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
  3495. CNTR_SYNTH | CNTR_VL),
  3496. [C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
  3497. CNTR_SYNTH | CNTR_VL),
  3498. [C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
  3499. [C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
  3500. CNTR_SYNTH | CNTR_VL),
  3501. [C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
  3502. [C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
  3503. CNTR_SYNTH | CNTR_VL),
  3504. [C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
  3505. CNTR_SYNTH),
  3506. [C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
  3507. CNTR_SYNTH | CNTR_VL),
  3508. [C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
  3509. CNTR_SYNTH),
  3510. [C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
  3511. CNTR_SYNTH | CNTR_VL),
  3512. [C_DC_TOTAL_CRC] =
  3513. DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
  3514. CNTR_SYNTH),
  3515. [C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
  3516. CNTR_SYNTH),
  3517. [C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
  3518. CNTR_SYNTH),
  3519. [C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
  3520. CNTR_SYNTH),
  3521. [C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
  3522. CNTR_SYNTH),
  3523. [C_DC_CRC_MULT_LN] =
  3524. DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
  3525. CNTR_SYNTH),
  3526. [C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
  3527. CNTR_SYNTH),
  3528. [C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
  3529. CNTR_SYNTH),
  3530. [C_DC_SEQ_CRC_CNT] =
  3531. DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
  3532. CNTR_SYNTH),
  3533. [C_DC_ESC0_ONLY_CNT] =
  3534. DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
  3535. CNTR_SYNTH),
  3536. [C_DC_ESC0_PLUS1_CNT] =
  3537. DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
  3538. CNTR_SYNTH),
  3539. [C_DC_ESC0_PLUS2_CNT] =
  3540. DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
  3541. CNTR_SYNTH),
  3542. [C_DC_REINIT_FROM_PEER_CNT] =
  3543. DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
  3544. CNTR_SYNTH),
  3545. [C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
  3546. CNTR_SYNTH),
  3547. [C_DC_MISC_FLG_CNT] =
  3548. DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
  3549. CNTR_SYNTH),
  3550. [C_DC_PRF_GOOD_LTP_CNT] =
  3551. DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
  3552. [C_DC_PRF_ACCEPTED_LTP_CNT] =
  3553. DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
  3554. CNTR_SYNTH),
  3555. [C_DC_PRF_RX_FLIT_CNT] =
  3556. DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
  3557. [C_DC_PRF_TX_FLIT_CNT] =
  3558. DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
  3559. [C_DC_PRF_CLK_CNTR] =
  3560. DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
  3561. [C_DC_PG_DBG_FLIT_CRDTS_CNT] =
  3562. DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
  3563. [C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
  3564. DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
  3565. CNTR_SYNTH),
  3566. [C_DC_PG_STS_TX_SBE_CNT] =
  3567. DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
  3568. [C_DC_PG_STS_TX_MBE_CNT] =
  3569. DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
  3570. CNTR_SYNTH),
  3571. [C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
  3572. access_sw_cpu_intr),
  3573. [C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
  3574. access_sw_cpu_rcv_limit),
  3575. [C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
  3576. access_sw_vtx_wait),
  3577. [C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
  3578. access_sw_pio_wait),
  3579. [C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
  3580. access_sw_pio_drain),
  3581. [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
  3582. access_sw_kmem_wait),
  3583. [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
  3584. access_sw_send_schedule),
  3585. [C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
  3586. SEND_DMA_DESC_FETCHED_CNT, 0,
  3587. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3588. dev_access_u32_csr),
  3589. [C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
  3590. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3591. access_sde_int_cnt),
  3592. [C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
  3593. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3594. access_sde_err_cnt),
  3595. [C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
  3596. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3597. access_sde_idle_int_cnt),
  3598. [C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
  3599. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3600. access_sde_progress_int_cnt),
  3601. /* MISC_ERR_STATUS */
  3602. [C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
  3603. CNTR_NORMAL,
  3604. access_misc_pll_lock_fail_err_cnt),
  3605. [C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
  3606. CNTR_NORMAL,
  3607. access_misc_mbist_fail_err_cnt),
  3608. [C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
  3609. CNTR_NORMAL,
  3610. access_misc_invalid_eep_cmd_err_cnt),
  3611. [C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
  3612. CNTR_NORMAL,
  3613. access_misc_efuse_done_parity_err_cnt),
  3614. [C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
  3615. CNTR_NORMAL,
  3616. access_misc_efuse_write_err_cnt),
  3617. [C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
  3618. 0, CNTR_NORMAL,
  3619. access_misc_efuse_read_bad_addr_err_cnt),
  3620. [C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
  3621. CNTR_NORMAL,
  3622. access_misc_efuse_csr_parity_err_cnt),
  3623. [C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
  3624. CNTR_NORMAL,
  3625. access_misc_fw_auth_failed_err_cnt),
  3626. [C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
  3627. CNTR_NORMAL,
  3628. access_misc_key_mismatch_err_cnt),
  3629. [C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
  3630. CNTR_NORMAL,
  3631. access_misc_sbus_write_failed_err_cnt),
  3632. [C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
  3633. CNTR_NORMAL,
  3634. access_misc_csr_write_bad_addr_err_cnt),
  3635. [C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
  3636. CNTR_NORMAL,
  3637. access_misc_csr_read_bad_addr_err_cnt),
  3638. [C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
  3639. CNTR_NORMAL,
  3640. access_misc_csr_parity_err_cnt),
  3641. /* CceErrStatus */
  3642. [C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
  3643. CNTR_NORMAL,
  3644. access_sw_cce_err_status_aggregated_cnt),
  3645. [C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
  3646. CNTR_NORMAL,
  3647. access_cce_msix_csr_parity_err_cnt),
  3648. [C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
  3649. CNTR_NORMAL,
  3650. access_cce_int_map_unc_err_cnt),
  3651. [C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
  3652. CNTR_NORMAL,
  3653. access_cce_int_map_cor_err_cnt),
  3654. [C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
  3655. CNTR_NORMAL,
  3656. access_cce_msix_table_unc_err_cnt),
  3657. [C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
  3658. CNTR_NORMAL,
  3659. access_cce_msix_table_cor_err_cnt),
  3660. [C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
  3661. 0, CNTR_NORMAL,
  3662. access_cce_rxdma_conv_fifo_parity_err_cnt),
  3663. [C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
  3664. 0, CNTR_NORMAL,
  3665. access_cce_rcpl_async_fifo_parity_err_cnt),
  3666. [C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
  3667. CNTR_NORMAL,
  3668. access_cce_seg_write_bad_addr_err_cnt),
  3669. [C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
  3670. CNTR_NORMAL,
  3671. access_cce_seg_read_bad_addr_err_cnt),
  3672. [C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
  3673. CNTR_NORMAL,
  3674. access_la_triggered_cnt),
  3675. [C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
  3676. CNTR_NORMAL,
  3677. access_cce_trgt_cpl_timeout_err_cnt),
  3678. [C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
  3679. CNTR_NORMAL,
  3680. access_pcic_receive_parity_err_cnt),
  3681. [C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
  3682. CNTR_NORMAL,
  3683. access_pcic_transmit_back_parity_err_cnt),
  3684. [C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
  3685. 0, CNTR_NORMAL,
  3686. access_pcic_transmit_front_parity_err_cnt),
  3687. [C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
  3688. CNTR_NORMAL,
  3689. access_pcic_cpl_dat_q_unc_err_cnt),
  3690. [C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
  3691. CNTR_NORMAL,
  3692. access_pcic_cpl_hd_q_unc_err_cnt),
  3693. [C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
  3694. CNTR_NORMAL,
  3695. access_pcic_post_dat_q_unc_err_cnt),
  3696. [C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
  3697. CNTR_NORMAL,
  3698. access_pcic_post_hd_q_unc_err_cnt),
  3699. [C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
  3700. CNTR_NORMAL,
  3701. access_pcic_retry_sot_mem_unc_err_cnt),
  3702. [C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
  3703. CNTR_NORMAL,
  3704. access_pcic_retry_mem_unc_err),
  3705. [C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
  3706. CNTR_NORMAL,
  3707. access_pcic_n_post_dat_q_parity_err_cnt),
  3708. [C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
  3709. CNTR_NORMAL,
  3710. access_pcic_n_post_h_q_parity_err_cnt),
  3711. [C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
  3712. CNTR_NORMAL,
  3713. access_pcic_cpl_dat_q_cor_err_cnt),
  3714. [C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
  3715. CNTR_NORMAL,
  3716. access_pcic_cpl_hd_q_cor_err_cnt),
  3717. [C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
  3718. CNTR_NORMAL,
  3719. access_pcic_post_dat_q_cor_err_cnt),
  3720. [C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
  3721. CNTR_NORMAL,
  3722. access_pcic_post_hd_q_cor_err_cnt),
  3723. [C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
  3724. CNTR_NORMAL,
  3725. access_pcic_retry_sot_mem_cor_err_cnt),
  3726. [C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
  3727. CNTR_NORMAL,
  3728. access_pcic_retry_mem_cor_err_cnt),
  3729. [C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
  3730. "CceCli1AsyncFifoDbgParityError", 0, 0,
  3731. CNTR_NORMAL,
  3732. access_cce_cli1_async_fifo_dbg_parity_err_cnt),
  3733. [C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
  3734. "CceCli1AsyncFifoRxdmaParityError", 0, 0,
  3735. CNTR_NORMAL,
  3736. access_cce_cli1_async_fifo_rxdma_parity_err_cnt
  3737. ),
  3738. [C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
  3739. "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
  3740. CNTR_NORMAL,
  3741. access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
  3742. [C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
  3743. "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
  3744. CNTR_NORMAL,
  3745. access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
  3746. [C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
  3747. 0, CNTR_NORMAL,
  3748. access_cce_cli2_async_fifo_parity_err_cnt),
  3749. [C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
  3750. CNTR_NORMAL,
  3751. access_cce_csr_cfg_bus_parity_err_cnt),
  3752. [C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
  3753. 0, CNTR_NORMAL,
  3754. access_cce_cli0_async_fifo_parity_err_cnt),
  3755. [C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
  3756. CNTR_NORMAL,
  3757. access_cce_rspd_data_parity_err_cnt),
  3758. [C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
  3759. CNTR_NORMAL,
  3760. access_cce_trgt_access_err_cnt),
  3761. [C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
  3762. 0, CNTR_NORMAL,
  3763. access_cce_trgt_async_fifo_parity_err_cnt),
  3764. [C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
  3765. CNTR_NORMAL,
  3766. access_cce_csr_write_bad_addr_err_cnt),
  3767. [C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
  3768. CNTR_NORMAL,
  3769. access_cce_csr_read_bad_addr_err_cnt),
  3770. [C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
  3771. CNTR_NORMAL,
  3772. access_ccs_csr_parity_err_cnt),
  3773. /* RcvErrStatus */
  3774. [C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
  3775. CNTR_NORMAL,
  3776. access_rx_csr_parity_err_cnt),
  3777. [C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
  3778. CNTR_NORMAL,
  3779. access_rx_csr_write_bad_addr_err_cnt),
  3780. [C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
  3781. CNTR_NORMAL,
  3782. access_rx_csr_read_bad_addr_err_cnt),
  3783. [C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
  3784. CNTR_NORMAL,
  3785. access_rx_dma_csr_unc_err_cnt),
  3786. [C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
  3787. CNTR_NORMAL,
  3788. access_rx_dma_dq_fsm_encoding_err_cnt),
  3789. [C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
  3790. CNTR_NORMAL,
  3791. access_rx_dma_eq_fsm_encoding_err_cnt),
  3792. [C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
  3793. CNTR_NORMAL,
  3794. access_rx_dma_csr_parity_err_cnt),
  3795. [C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
  3796. CNTR_NORMAL,
  3797. access_rx_rbuf_data_cor_err_cnt),
  3798. [C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
  3799. CNTR_NORMAL,
  3800. access_rx_rbuf_data_unc_err_cnt),
  3801. [C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
  3802. CNTR_NORMAL,
  3803. access_rx_dma_data_fifo_rd_cor_err_cnt),
  3804. [C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
  3805. CNTR_NORMAL,
  3806. access_rx_dma_data_fifo_rd_unc_err_cnt),
  3807. [C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
  3808. CNTR_NORMAL,
  3809. access_rx_dma_hdr_fifo_rd_cor_err_cnt),
  3810. [C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
  3811. CNTR_NORMAL,
  3812. access_rx_dma_hdr_fifo_rd_unc_err_cnt),
  3813. [C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
  3814. CNTR_NORMAL,
  3815. access_rx_rbuf_desc_part2_cor_err_cnt),
  3816. [C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
  3817. CNTR_NORMAL,
  3818. access_rx_rbuf_desc_part2_unc_err_cnt),
  3819. [C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
  3820. CNTR_NORMAL,
  3821. access_rx_rbuf_desc_part1_cor_err_cnt),
  3822. [C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
  3823. CNTR_NORMAL,
  3824. access_rx_rbuf_desc_part1_unc_err_cnt),
  3825. [C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
  3826. CNTR_NORMAL,
  3827. access_rx_hq_intr_fsm_err_cnt),
  3828. [C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
  3829. CNTR_NORMAL,
  3830. access_rx_hq_intr_csr_parity_err_cnt),
  3831. [C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
  3832. CNTR_NORMAL,
  3833. access_rx_lookup_csr_parity_err_cnt),
  3834. [C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
  3835. CNTR_NORMAL,
  3836. access_rx_lookup_rcv_array_cor_err_cnt),
  3837. [C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
  3838. CNTR_NORMAL,
  3839. access_rx_lookup_rcv_array_unc_err_cnt),
  3840. [C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
  3841. 0, CNTR_NORMAL,
  3842. access_rx_lookup_des_part2_parity_err_cnt),
  3843. [C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
  3844. 0, CNTR_NORMAL,
  3845. access_rx_lookup_des_part1_unc_cor_err_cnt),
  3846. [C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
  3847. CNTR_NORMAL,
  3848. access_rx_lookup_des_part1_unc_err_cnt),
  3849. [C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
  3850. CNTR_NORMAL,
  3851. access_rx_rbuf_next_free_buf_cor_err_cnt),
  3852. [C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
  3853. CNTR_NORMAL,
  3854. access_rx_rbuf_next_free_buf_unc_err_cnt),
  3855. [C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
  3856. "RxRbufFlInitWrAddrParityErr", 0, 0,
  3857. CNTR_NORMAL,
  3858. access_rbuf_fl_init_wr_addr_parity_err_cnt),
  3859. [C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
  3860. 0, CNTR_NORMAL,
  3861. access_rx_rbuf_fl_initdone_parity_err_cnt),
  3862. [C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
  3863. 0, CNTR_NORMAL,
  3864. access_rx_rbuf_fl_write_addr_parity_err_cnt),
  3865. [C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
  3866. CNTR_NORMAL,
  3867. access_rx_rbuf_fl_rd_addr_parity_err_cnt),
  3868. [C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
  3869. CNTR_NORMAL,
  3870. access_rx_rbuf_empty_err_cnt),
  3871. [C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
  3872. CNTR_NORMAL,
  3873. access_rx_rbuf_full_err_cnt),
  3874. [C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
  3875. CNTR_NORMAL,
  3876. access_rbuf_bad_lookup_err_cnt),
  3877. [C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
  3878. CNTR_NORMAL,
  3879. access_rbuf_ctx_id_parity_err_cnt),
  3880. [C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
  3881. CNTR_NORMAL,
  3882. access_rbuf_csr_qeopdw_parity_err_cnt),
  3883. [C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
  3884. "RxRbufCsrQNumOfPktParityErr", 0, 0,
  3885. CNTR_NORMAL,
  3886. access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
  3887. [C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
  3888. "RxRbufCsrQTlPtrParityErr", 0, 0,
  3889. CNTR_NORMAL,
  3890. access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
  3891. [C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
  3892. 0, CNTR_NORMAL,
  3893. access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
  3894. [C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
  3895. 0, CNTR_NORMAL,
  3896. access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
  3897. [C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
  3898. 0, 0, CNTR_NORMAL,
  3899. access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
  3900. [C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
  3901. 0, CNTR_NORMAL,
  3902. access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
  3903. [C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
  3904. "RxRbufCsrQHeadBufNumParityErr", 0, 0,
  3905. CNTR_NORMAL,
  3906. access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
  3907. [C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
  3908. 0, CNTR_NORMAL,
  3909. access_rx_rbuf_block_list_read_cor_err_cnt),
  3910. [C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
  3911. 0, CNTR_NORMAL,
  3912. access_rx_rbuf_block_list_read_unc_err_cnt),
  3913. [C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
  3914. CNTR_NORMAL,
  3915. access_rx_rbuf_lookup_des_cor_err_cnt),
  3916. [C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
  3917. CNTR_NORMAL,
  3918. access_rx_rbuf_lookup_des_unc_err_cnt),
  3919. [C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
  3920. "RxRbufLookupDesRegUncCorErr", 0, 0,
  3921. CNTR_NORMAL,
  3922. access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
  3923. [C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
  3924. CNTR_NORMAL,
  3925. access_rx_rbuf_lookup_des_reg_unc_err_cnt),
  3926. [C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
  3927. CNTR_NORMAL,
  3928. access_rx_rbuf_free_list_cor_err_cnt),
  3929. [C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
  3930. CNTR_NORMAL,
  3931. access_rx_rbuf_free_list_unc_err_cnt),
  3932. [C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
  3933. CNTR_NORMAL,
  3934. access_rx_rcv_fsm_encoding_err_cnt),
  3935. [C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
  3936. CNTR_NORMAL,
  3937. access_rx_dma_flag_cor_err_cnt),
  3938. [C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
  3939. CNTR_NORMAL,
  3940. access_rx_dma_flag_unc_err_cnt),
  3941. [C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
  3942. CNTR_NORMAL,
  3943. access_rx_dc_sop_eop_parity_err_cnt),
  3944. [C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
  3945. CNTR_NORMAL,
  3946. access_rx_rcv_csr_parity_err_cnt),
  3947. [C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
  3948. CNTR_NORMAL,
  3949. access_rx_rcv_qp_map_table_cor_err_cnt),
  3950. [C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
  3951. CNTR_NORMAL,
  3952. access_rx_rcv_qp_map_table_unc_err_cnt),
  3953. [C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
  3954. CNTR_NORMAL,
  3955. access_rx_rcv_data_cor_err_cnt),
  3956. [C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
  3957. CNTR_NORMAL,
  3958. access_rx_rcv_data_unc_err_cnt),
  3959. [C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
  3960. CNTR_NORMAL,
  3961. access_rx_rcv_hdr_cor_err_cnt),
  3962. [C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
  3963. CNTR_NORMAL,
  3964. access_rx_rcv_hdr_unc_err_cnt),
  3965. [C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
  3966. CNTR_NORMAL,
  3967. access_rx_dc_intf_parity_err_cnt),
  3968. [C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
  3969. CNTR_NORMAL,
  3970. access_rx_dma_csr_cor_err_cnt),
  3971. /* SendPioErrStatus */
  3972. [C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
  3973. CNTR_NORMAL,
  3974. access_pio_pec_sop_head_parity_err_cnt),
  3975. [C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
  3976. CNTR_NORMAL,
  3977. access_pio_pcc_sop_head_parity_err_cnt),
  3978. [C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
  3979. 0, 0, CNTR_NORMAL,
  3980. access_pio_last_returned_cnt_parity_err_cnt),
  3981. [C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
  3982. 0, CNTR_NORMAL,
  3983. access_pio_current_free_cnt_parity_err_cnt),
  3984. [C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
  3985. CNTR_NORMAL,
  3986. access_pio_reserved_31_err_cnt),
  3987. [C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
  3988. CNTR_NORMAL,
  3989. access_pio_reserved_30_err_cnt),
  3990. [C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
  3991. CNTR_NORMAL,
  3992. access_pio_ppmc_sop_len_err_cnt),
  3993. [C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
  3994. CNTR_NORMAL,
  3995. access_pio_ppmc_bqc_mem_parity_err_cnt),
  3996. [C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
  3997. CNTR_NORMAL,
  3998. access_pio_vl_fifo_parity_err_cnt),
  3999. [C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
  4000. CNTR_NORMAL,
  4001. access_pio_vlf_sop_parity_err_cnt),
  4002. [C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
  4003. CNTR_NORMAL,
  4004. access_pio_vlf_v1_len_parity_err_cnt),
  4005. [C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
  4006. CNTR_NORMAL,
  4007. access_pio_block_qw_count_parity_err_cnt),
  4008. [C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
  4009. CNTR_NORMAL,
  4010. access_pio_write_qw_valid_parity_err_cnt),
  4011. [C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
  4012. CNTR_NORMAL,
  4013. access_pio_state_machine_err_cnt),
  4014. [C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
  4015. CNTR_NORMAL,
  4016. access_pio_write_data_parity_err_cnt),
  4017. [C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
  4018. CNTR_NORMAL,
  4019. access_pio_host_addr_mem_cor_err_cnt),
  4020. [C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
  4021. CNTR_NORMAL,
  4022. access_pio_host_addr_mem_unc_err_cnt),
  4023. [C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
  4024. CNTR_NORMAL,
  4025. access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
  4026. [C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
  4027. CNTR_NORMAL,
  4028. access_pio_init_sm_in_err_cnt),
  4029. [C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
  4030. CNTR_NORMAL,
  4031. access_pio_ppmc_pbl_fifo_err_cnt),
  4032. [C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
  4033. 0, CNTR_NORMAL,
  4034. access_pio_credit_ret_fifo_parity_err_cnt),
  4035. [C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
  4036. CNTR_NORMAL,
  4037. access_pio_v1_len_mem_bank1_cor_err_cnt),
  4038. [C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
  4039. CNTR_NORMAL,
  4040. access_pio_v1_len_mem_bank0_cor_err_cnt),
  4041. [C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
  4042. CNTR_NORMAL,
  4043. access_pio_v1_len_mem_bank1_unc_err_cnt),
  4044. [C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
  4045. CNTR_NORMAL,
  4046. access_pio_v1_len_mem_bank0_unc_err_cnt),
  4047. [C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
  4048. CNTR_NORMAL,
  4049. access_pio_sm_pkt_reset_parity_err_cnt),
  4050. [C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
  4051. CNTR_NORMAL,
  4052. access_pio_pkt_evict_fifo_parity_err_cnt),
  4053. [C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
  4054. "PioSbrdctrlCrrelFifoParityErr", 0, 0,
  4055. CNTR_NORMAL,
  4056. access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
  4057. [C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
  4058. CNTR_NORMAL,
  4059. access_pio_sbrdctl_crrel_parity_err_cnt),
  4060. [C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
  4061. CNTR_NORMAL,
  4062. access_pio_pec_fifo_parity_err_cnt),
  4063. [C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
  4064. CNTR_NORMAL,
  4065. access_pio_pcc_fifo_parity_err_cnt),
  4066. [C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
  4067. CNTR_NORMAL,
  4068. access_pio_sb_mem_fifo1_err_cnt),
  4069. [C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
  4070. CNTR_NORMAL,
  4071. access_pio_sb_mem_fifo0_err_cnt),
  4072. [C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
  4073. CNTR_NORMAL,
  4074. access_pio_csr_parity_err_cnt),
  4075. [C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
  4076. CNTR_NORMAL,
  4077. access_pio_write_addr_parity_err_cnt),
  4078. [C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
  4079. CNTR_NORMAL,
  4080. access_pio_write_bad_ctxt_err_cnt),
  4081. /* SendDmaErrStatus */
  4082. [C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
  4083. 0, CNTR_NORMAL,
  4084. access_sdma_pcie_req_tracking_cor_err_cnt),
  4085. [C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
  4086. 0, CNTR_NORMAL,
  4087. access_sdma_pcie_req_tracking_unc_err_cnt),
  4088. [C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
  4089. CNTR_NORMAL,
  4090. access_sdma_csr_parity_err_cnt),
  4091. [C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
  4092. CNTR_NORMAL,
  4093. access_sdma_rpy_tag_err_cnt),
  4094. /* SendEgressErrStatus */
  4095. [C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
  4096. CNTR_NORMAL,
  4097. access_tx_read_pio_memory_csr_unc_err_cnt),
  4098. [C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
  4099. 0, CNTR_NORMAL,
  4100. access_tx_read_sdma_memory_csr_err_cnt),
  4101. [C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
  4102. CNTR_NORMAL,
  4103. access_tx_egress_fifo_cor_err_cnt),
  4104. [C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
  4105. CNTR_NORMAL,
  4106. access_tx_read_pio_memory_cor_err_cnt),
  4107. [C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
  4108. CNTR_NORMAL,
  4109. access_tx_read_sdma_memory_cor_err_cnt),
  4110. [C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
  4111. CNTR_NORMAL,
  4112. access_tx_sb_hdr_cor_err_cnt),
  4113. [C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
  4114. CNTR_NORMAL,
  4115. access_tx_credit_overrun_err_cnt),
  4116. [C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
  4117. CNTR_NORMAL,
  4118. access_tx_launch_fifo8_cor_err_cnt),
  4119. [C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
  4120. CNTR_NORMAL,
  4121. access_tx_launch_fifo7_cor_err_cnt),
  4122. [C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
  4123. CNTR_NORMAL,
  4124. access_tx_launch_fifo6_cor_err_cnt),
  4125. [C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
  4126. CNTR_NORMAL,
  4127. access_tx_launch_fifo5_cor_err_cnt),
  4128. [C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
  4129. CNTR_NORMAL,
  4130. access_tx_launch_fifo4_cor_err_cnt),
  4131. [C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
  4132. CNTR_NORMAL,
  4133. access_tx_launch_fifo3_cor_err_cnt),
  4134. [C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
  4135. CNTR_NORMAL,
  4136. access_tx_launch_fifo2_cor_err_cnt),
  4137. [C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
  4138. CNTR_NORMAL,
  4139. access_tx_launch_fifo1_cor_err_cnt),
  4140. [C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
  4141. CNTR_NORMAL,
  4142. access_tx_launch_fifo0_cor_err_cnt),
  4143. [C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
  4144. CNTR_NORMAL,
  4145. access_tx_credit_return_vl_err_cnt),
  4146. [C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
  4147. CNTR_NORMAL,
  4148. access_tx_hcrc_insertion_err_cnt),
  4149. [C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
  4150. CNTR_NORMAL,
  4151. access_tx_egress_fifo_unc_err_cnt),
  4152. [C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
  4153. CNTR_NORMAL,
  4154. access_tx_read_pio_memory_unc_err_cnt),
  4155. [C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
  4156. CNTR_NORMAL,
  4157. access_tx_read_sdma_memory_unc_err_cnt),
  4158. [C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
  4159. CNTR_NORMAL,
  4160. access_tx_sb_hdr_unc_err_cnt),
  4161. [C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
  4162. CNTR_NORMAL,
  4163. access_tx_credit_return_partiy_err_cnt),
  4164. [C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
  4165. 0, 0, CNTR_NORMAL,
  4166. access_tx_launch_fifo8_unc_or_parity_err_cnt),
  4167. [C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
  4168. 0, 0, CNTR_NORMAL,
  4169. access_tx_launch_fifo7_unc_or_parity_err_cnt),
  4170. [C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
  4171. 0, 0, CNTR_NORMAL,
  4172. access_tx_launch_fifo6_unc_or_parity_err_cnt),
  4173. [C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
  4174. 0, 0, CNTR_NORMAL,
  4175. access_tx_launch_fifo5_unc_or_parity_err_cnt),
  4176. [C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
  4177. 0, 0, CNTR_NORMAL,
  4178. access_tx_launch_fifo4_unc_or_parity_err_cnt),
  4179. [C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
  4180. 0, 0, CNTR_NORMAL,
  4181. access_tx_launch_fifo3_unc_or_parity_err_cnt),
  4182. [C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
  4183. 0, 0, CNTR_NORMAL,
  4184. access_tx_launch_fifo2_unc_or_parity_err_cnt),
  4185. [C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
  4186. 0, 0, CNTR_NORMAL,
  4187. access_tx_launch_fifo1_unc_or_parity_err_cnt),
  4188. [C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
  4189. 0, 0, CNTR_NORMAL,
  4190. access_tx_launch_fifo0_unc_or_parity_err_cnt),
  4191. [C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
  4192. 0, 0, CNTR_NORMAL,
  4193. access_tx_sdma15_disallowed_packet_err_cnt),
  4194. [C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
  4195. 0, 0, CNTR_NORMAL,
  4196. access_tx_sdma14_disallowed_packet_err_cnt),
  4197. [C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
  4198. 0, 0, CNTR_NORMAL,
  4199. access_tx_sdma13_disallowed_packet_err_cnt),
  4200. [C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
  4201. 0, 0, CNTR_NORMAL,
  4202. access_tx_sdma12_disallowed_packet_err_cnt),
  4203. [C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
  4204. 0, 0, CNTR_NORMAL,
  4205. access_tx_sdma11_disallowed_packet_err_cnt),
  4206. [C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
  4207. 0, 0, CNTR_NORMAL,
  4208. access_tx_sdma10_disallowed_packet_err_cnt),
  4209. [C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
  4210. 0, 0, CNTR_NORMAL,
  4211. access_tx_sdma9_disallowed_packet_err_cnt),
  4212. [C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
  4213. 0, 0, CNTR_NORMAL,
  4214. access_tx_sdma8_disallowed_packet_err_cnt),
  4215. [C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
  4216. 0, 0, CNTR_NORMAL,
  4217. access_tx_sdma7_disallowed_packet_err_cnt),
  4218. [C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
  4219. 0, 0, CNTR_NORMAL,
  4220. access_tx_sdma6_disallowed_packet_err_cnt),
  4221. [C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
  4222. 0, 0, CNTR_NORMAL,
  4223. access_tx_sdma5_disallowed_packet_err_cnt),
  4224. [C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
  4225. 0, 0, CNTR_NORMAL,
  4226. access_tx_sdma4_disallowed_packet_err_cnt),
  4227. [C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
  4228. 0, 0, CNTR_NORMAL,
  4229. access_tx_sdma3_disallowed_packet_err_cnt),
  4230. [C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
  4231. 0, 0, CNTR_NORMAL,
  4232. access_tx_sdma2_disallowed_packet_err_cnt),
  4233. [C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
  4234. 0, 0, CNTR_NORMAL,
  4235. access_tx_sdma1_disallowed_packet_err_cnt),
  4236. [C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
  4237. 0, 0, CNTR_NORMAL,
  4238. access_tx_sdma0_disallowed_packet_err_cnt),
  4239. [C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
  4240. CNTR_NORMAL,
  4241. access_tx_config_parity_err_cnt),
  4242. [C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
  4243. CNTR_NORMAL,
  4244. access_tx_sbrd_ctl_csr_parity_err_cnt),
  4245. [C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
  4246. CNTR_NORMAL,
  4247. access_tx_launch_csr_parity_err_cnt),
  4248. [C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
  4249. CNTR_NORMAL,
  4250. access_tx_illegal_vl_err_cnt),
  4251. [C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
  4252. "TxSbrdCtlStateMachineParityErr", 0, 0,
  4253. CNTR_NORMAL,
  4254. access_tx_sbrd_ctl_state_machine_parity_err_cnt),
  4255. [C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
  4256. CNTR_NORMAL,
  4257. access_egress_reserved_10_err_cnt),
  4258. [C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
  4259. CNTR_NORMAL,
  4260. access_egress_reserved_9_err_cnt),
  4261. [C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
  4262. 0, 0, CNTR_NORMAL,
  4263. access_tx_sdma_launch_intf_parity_err_cnt),
  4264. [C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
  4265. CNTR_NORMAL,
  4266. access_tx_pio_launch_intf_parity_err_cnt),
  4267. [C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
  4268. CNTR_NORMAL,
  4269. access_egress_reserved_6_err_cnt),
  4270. [C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
  4271. CNTR_NORMAL,
  4272. access_tx_incorrect_link_state_err_cnt),
  4273. [C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
  4274. CNTR_NORMAL,
  4275. access_tx_linkdown_err_cnt),
  4276. [C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
  4277. "EgressFifoUnderrunOrParityErr", 0, 0,
  4278. CNTR_NORMAL,
  4279. access_tx_egress_fifi_underrun_or_parity_err_cnt),
  4280. [C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
  4281. CNTR_NORMAL,
  4282. access_egress_reserved_2_err_cnt),
  4283. [C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
  4284. CNTR_NORMAL,
  4285. access_tx_pkt_integrity_mem_unc_err_cnt),
  4286. [C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
  4287. CNTR_NORMAL,
  4288. access_tx_pkt_integrity_mem_cor_err_cnt),
  4289. /* SendErrStatus */
  4290. [C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
  4291. CNTR_NORMAL,
  4292. access_send_csr_write_bad_addr_err_cnt),
  4293. [C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
  4294. CNTR_NORMAL,
  4295. access_send_csr_read_bad_addr_err_cnt),
  4296. [C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
  4297. CNTR_NORMAL,
  4298. access_send_csr_parity_cnt),
  4299. /* SendCtxtErrStatus */
  4300. [C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
  4301. CNTR_NORMAL,
  4302. access_pio_write_out_of_bounds_err_cnt),
  4303. [C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
  4304. CNTR_NORMAL,
  4305. access_pio_write_overflow_err_cnt),
  4306. [C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
  4307. 0, 0, CNTR_NORMAL,
  4308. access_pio_write_crosses_boundary_err_cnt),
  4309. [C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
  4310. CNTR_NORMAL,
  4311. access_pio_disallowed_packet_err_cnt),
  4312. [C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
  4313. CNTR_NORMAL,
  4314. access_pio_inconsistent_sop_err_cnt),
  4315. /* SendDmaEngErrStatus */
  4316. [C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
  4317. 0, 0, CNTR_NORMAL,
  4318. access_sdma_header_request_fifo_cor_err_cnt),
  4319. [C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
  4320. CNTR_NORMAL,
  4321. access_sdma_header_storage_cor_err_cnt),
  4322. [C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
  4323. CNTR_NORMAL,
  4324. access_sdma_packet_tracking_cor_err_cnt),
  4325. [C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
  4326. CNTR_NORMAL,
  4327. access_sdma_assembly_cor_err_cnt),
  4328. [C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
  4329. CNTR_NORMAL,
  4330. access_sdma_desc_table_cor_err_cnt),
  4331. [C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
  4332. 0, 0, CNTR_NORMAL,
  4333. access_sdma_header_request_fifo_unc_err_cnt),
  4334. [C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
  4335. CNTR_NORMAL,
  4336. access_sdma_header_storage_unc_err_cnt),
  4337. [C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
  4338. CNTR_NORMAL,
  4339. access_sdma_packet_tracking_unc_err_cnt),
  4340. [C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
  4341. CNTR_NORMAL,
  4342. access_sdma_assembly_unc_err_cnt),
  4343. [C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
  4344. CNTR_NORMAL,
  4345. access_sdma_desc_table_unc_err_cnt),
  4346. [C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
  4347. CNTR_NORMAL,
  4348. access_sdma_timeout_err_cnt),
  4349. [C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
  4350. CNTR_NORMAL,
  4351. access_sdma_header_length_err_cnt),
  4352. [C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
  4353. CNTR_NORMAL,
  4354. access_sdma_header_address_err_cnt),
  4355. [C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
  4356. CNTR_NORMAL,
  4357. access_sdma_header_select_err_cnt),
  4358. [C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
  4359. CNTR_NORMAL,
  4360. access_sdma_reserved_9_err_cnt),
  4361. [C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
  4362. CNTR_NORMAL,
  4363. access_sdma_packet_desc_overflow_err_cnt),
  4364. [C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
  4365. CNTR_NORMAL,
  4366. access_sdma_length_mismatch_err_cnt),
  4367. [C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
  4368. CNTR_NORMAL,
  4369. access_sdma_halt_err_cnt),
  4370. [C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
  4371. CNTR_NORMAL,
  4372. access_sdma_mem_read_err_cnt),
  4373. [C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
  4374. CNTR_NORMAL,
  4375. access_sdma_first_desc_err_cnt),
  4376. [C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
  4377. CNTR_NORMAL,
  4378. access_sdma_tail_out_of_bounds_err_cnt),
  4379. [C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
  4380. CNTR_NORMAL,
  4381. access_sdma_too_long_err_cnt),
  4382. [C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
  4383. CNTR_NORMAL,
  4384. access_sdma_gen_mismatch_err_cnt),
  4385. [C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
  4386. CNTR_NORMAL,
  4387. access_sdma_wrong_dw_err_cnt),
  4388. };
  4389. static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
  4390. [C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
  4391. CNTR_NORMAL),
  4392. [C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
  4393. CNTR_NORMAL),
  4394. [C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
  4395. CNTR_NORMAL),
  4396. [C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
  4397. CNTR_NORMAL),
  4398. [C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
  4399. CNTR_NORMAL),
  4400. [C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
  4401. CNTR_NORMAL),
  4402. [C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
  4403. CNTR_NORMAL),
  4404. [C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
  4405. [C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
  4406. [C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
  4407. [C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
  4408. CNTR_SYNTH | CNTR_VL),
  4409. [C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
  4410. CNTR_SYNTH | CNTR_VL),
  4411. [C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
  4412. CNTR_SYNTH | CNTR_VL),
  4413. [C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
  4414. [C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
  4415. [C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4416. access_sw_link_dn_cnt),
  4417. [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4418. access_sw_link_up_cnt),
  4419. [C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
  4420. access_sw_unknown_frame_cnt),
  4421. [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4422. access_sw_xmit_discards),
  4423. [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
  4424. CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
  4425. access_sw_xmit_discards),
  4426. [C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
  4427. access_xmit_constraint_errs),
  4428. [C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
  4429. access_rcv_constraint_errs),
  4430. [C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
  4431. [C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
  4432. [C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
  4433. [C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
  4434. [C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
  4435. [C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
  4436. [C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
  4437. [C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
  4438. [C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
  4439. [C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
  4440. [C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
  4441. [C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
  4442. [C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
  4443. access_sw_cpu_rc_acks),
  4444. [C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
  4445. access_sw_cpu_rc_qacks),
  4446. [C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
  4447. access_sw_cpu_rc_delayed_comp),
  4448. [OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
  4449. [OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
  4450. [OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
  4451. [OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
  4452. [OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
  4453. [OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
  4454. [OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
  4455. [OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
  4456. [OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
  4457. [OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
  4458. [OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
  4459. [OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
  4460. [OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
  4461. [OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
  4462. [OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
  4463. [OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
  4464. [OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
  4465. [OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
  4466. [OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
  4467. [OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
  4468. [OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
  4469. [OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
  4470. [OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
  4471. [OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
  4472. [OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
  4473. [OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
  4474. [OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
  4475. [OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
  4476. [OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
  4477. [OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
  4478. [OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
  4479. [OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
  4480. [OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
  4481. [OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
  4482. [OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
  4483. [OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
  4484. [OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
  4485. [OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
  4486. [OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
  4487. [OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
  4488. [OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
  4489. [OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
  4490. [OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
  4491. [OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
  4492. [OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
  4493. [OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
  4494. [OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
  4495. [OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
  4496. [OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
  4497. [OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
  4498. [OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
  4499. [OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
  4500. [OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
  4501. [OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
  4502. [OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
  4503. [OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
  4504. [OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
  4505. [OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
  4506. [OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
  4507. [OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
  4508. [OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
  4509. [OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
  4510. [OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
  4511. [OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
  4512. [OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
  4513. [OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
  4514. [OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
  4515. [OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
  4516. [OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
  4517. [OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
  4518. [OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
  4519. [OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
  4520. [OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
  4521. [OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
  4522. [OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
  4523. [OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
  4524. [OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
  4525. [OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
  4526. [OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
  4527. [OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
  4528. };
  4529. /* ======================================================================== */
  4530. /* return true if this is chip revision revision a */
  4531. int is_ax(struct hfi1_devdata *dd)
  4532. {
  4533. u8 chip_rev_minor =
  4534. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4535. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4536. return (chip_rev_minor & 0xf0) == 0;
  4537. }
  4538. /* return true if this is chip revision revision b */
  4539. int is_bx(struct hfi1_devdata *dd)
  4540. {
  4541. u8 chip_rev_minor =
  4542. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4543. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4544. return (chip_rev_minor & 0xF0) == 0x10;
  4545. }
  4546. /*
  4547. * Append string s to buffer buf. Arguments curp and len are the current
  4548. * position and remaining length, respectively.
  4549. *
  4550. * return 0 on success, 1 on out of room
  4551. */
  4552. static int append_str(char *buf, char **curp, int *lenp, const char *s)
  4553. {
  4554. char *p = *curp;
  4555. int len = *lenp;
  4556. int result = 0; /* success */
  4557. char c;
  4558. /* add a comma, if first in the buffer */
  4559. if (p != buf) {
  4560. if (len == 0) {
  4561. result = 1; /* out of room */
  4562. goto done;
  4563. }
  4564. *p++ = ',';
  4565. len--;
  4566. }
  4567. /* copy the string */
  4568. while ((c = *s++) != 0) {
  4569. if (len == 0) {
  4570. result = 1; /* out of room */
  4571. goto done;
  4572. }
  4573. *p++ = c;
  4574. len--;
  4575. }
  4576. done:
  4577. /* write return values */
  4578. *curp = p;
  4579. *lenp = len;
  4580. return result;
  4581. }
  4582. /*
  4583. * Using the given flag table, print a comma separated string into
  4584. * the buffer. End in '*' if the buffer is too short.
  4585. */
  4586. static char *flag_string(char *buf, int buf_len, u64 flags,
  4587. struct flag_table *table, int table_size)
  4588. {
  4589. char extra[32];
  4590. char *p = buf;
  4591. int len = buf_len;
  4592. int no_room = 0;
  4593. int i;
  4594. /* make sure there is at least 2 so we can form "*" */
  4595. if (len < 2)
  4596. return "";
  4597. len--; /* leave room for a nul */
  4598. for (i = 0; i < table_size; i++) {
  4599. if (flags & table[i].flag) {
  4600. no_room = append_str(buf, &p, &len, table[i].str);
  4601. if (no_room)
  4602. break;
  4603. flags &= ~table[i].flag;
  4604. }
  4605. }
  4606. /* any undocumented bits left? */
  4607. if (!no_room && flags) {
  4608. snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
  4609. no_room = append_str(buf, &p, &len, extra);
  4610. }
  4611. /* add * if ran out of room */
  4612. if (no_room) {
  4613. /* may need to back up to add space for a '*' */
  4614. if (len == 0)
  4615. --p;
  4616. *p++ = '*';
  4617. }
  4618. /* add final nul - space already allocated above */
  4619. *p = 0;
  4620. return buf;
  4621. }
  4622. /* first 8 CCE error interrupt source names */
  4623. static const char * const cce_misc_names[] = {
  4624. "CceErrInt", /* 0 */
  4625. "RxeErrInt", /* 1 */
  4626. "MiscErrInt", /* 2 */
  4627. "Reserved3", /* 3 */
  4628. "PioErrInt", /* 4 */
  4629. "SDmaErrInt", /* 5 */
  4630. "EgressErrInt", /* 6 */
  4631. "TxeErrInt" /* 7 */
  4632. };
  4633. /*
  4634. * Return the miscellaneous error interrupt name.
  4635. */
  4636. static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
  4637. {
  4638. if (source < ARRAY_SIZE(cce_misc_names))
  4639. strncpy(buf, cce_misc_names[source], bsize);
  4640. else
  4641. snprintf(buf, bsize, "Reserved%u",
  4642. source + IS_GENERAL_ERR_START);
  4643. return buf;
  4644. }
  4645. /*
  4646. * Return the SDMA engine error interrupt name.
  4647. */
  4648. static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
  4649. {
  4650. snprintf(buf, bsize, "SDmaEngErrInt%u", source);
  4651. return buf;
  4652. }
  4653. /*
  4654. * Return the send context error interrupt name.
  4655. */
  4656. static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
  4657. {
  4658. snprintf(buf, bsize, "SendCtxtErrInt%u", source);
  4659. return buf;
  4660. }
  4661. static const char * const various_names[] = {
  4662. "PbcInt",
  4663. "GpioAssertInt",
  4664. "Qsfp1Int",
  4665. "Qsfp2Int",
  4666. "TCritInt"
  4667. };
  4668. /*
  4669. * Return the various interrupt name.
  4670. */
  4671. static char *is_various_name(char *buf, size_t bsize, unsigned int source)
  4672. {
  4673. if (source < ARRAY_SIZE(various_names))
  4674. strncpy(buf, various_names[source], bsize);
  4675. else
  4676. snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
  4677. return buf;
  4678. }
  4679. /*
  4680. * Return the DC interrupt name.
  4681. */
  4682. static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
  4683. {
  4684. static const char * const dc_int_names[] = {
  4685. "common",
  4686. "lcb",
  4687. "8051",
  4688. "lbm" /* local block merge */
  4689. };
  4690. if (source < ARRAY_SIZE(dc_int_names))
  4691. snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
  4692. else
  4693. snprintf(buf, bsize, "DCInt%u", source);
  4694. return buf;
  4695. }
  4696. static const char * const sdma_int_names[] = {
  4697. "SDmaInt",
  4698. "SdmaIdleInt",
  4699. "SdmaProgressInt",
  4700. };
  4701. /*
  4702. * Return the SDMA engine interrupt name.
  4703. */
  4704. static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
  4705. {
  4706. /* what interrupt */
  4707. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  4708. /* which engine */
  4709. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  4710. if (likely(what < 3))
  4711. snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
  4712. else
  4713. snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
  4714. return buf;
  4715. }
  4716. /*
  4717. * Return the receive available interrupt name.
  4718. */
  4719. static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
  4720. {
  4721. snprintf(buf, bsize, "RcvAvailInt%u", source);
  4722. return buf;
  4723. }
  4724. /*
  4725. * Return the receive urgent interrupt name.
  4726. */
  4727. static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
  4728. {
  4729. snprintf(buf, bsize, "RcvUrgentInt%u", source);
  4730. return buf;
  4731. }
  4732. /*
  4733. * Return the send credit interrupt name.
  4734. */
  4735. static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
  4736. {
  4737. snprintf(buf, bsize, "SendCreditInt%u", source);
  4738. return buf;
  4739. }
  4740. /*
  4741. * Return the reserved interrupt name.
  4742. */
  4743. static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
  4744. {
  4745. snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
  4746. return buf;
  4747. }
  4748. static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
  4749. {
  4750. return flag_string(buf, buf_len, flags,
  4751. cce_err_status_flags,
  4752. ARRAY_SIZE(cce_err_status_flags));
  4753. }
  4754. static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
  4755. {
  4756. return flag_string(buf, buf_len, flags,
  4757. rxe_err_status_flags,
  4758. ARRAY_SIZE(rxe_err_status_flags));
  4759. }
  4760. static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
  4761. {
  4762. return flag_string(buf, buf_len, flags, misc_err_status_flags,
  4763. ARRAY_SIZE(misc_err_status_flags));
  4764. }
  4765. static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
  4766. {
  4767. return flag_string(buf, buf_len, flags,
  4768. pio_err_status_flags,
  4769. ARRAY_SIZE(pio_err_status_flags));
  4770. }
  4771. static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
  4772. {
  4773. return flag_string(buf, buf_len, flags,
  4774. sdma_err_status_flags,
  4775. ARRAY_SIZE(sdma_err_status_flags));
  4776. }
  4777. static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
  4778. {
  4779. return flag_string(buf, buf_len, flags,
  4780. egress_err_status_flags,
  4781. ARRAY_SIZE(egress_err_status_flags));
  4782. }
  4783. static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
  4784. {
  4785. return flag_string(buf, buf_len, flags,
  4786. egress_err_info_flags,
  4787. ARRAY_SIZE(egress_err_info_flags));
  4788. }
  4789. static char *send_err_status_string(char *buf, int buf_len, u64 flags)
  4790. {
  4791. return flag_string(buf, buf_len, flags,
  4792. send_err_status_flags,
  4793. ARRAY_SIZE(send_err_status_flags));
  4794. }
  4795. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4796. {
  4797. char buf[96];
  4798. int i = 0;
  4799. /*
  4800. * For most these errors, there is nothing that can be done except
  4801. * report or record it.
  4802. */
  4803. dd_dev_info(dd, "CCE Error: %s\n",
  4804. cce_err_status_string(buf, sizeof(buf), reg));
  4805. if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
  4806. is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
  4807. /* this error requires a manual drop into SPC freeze mode */
  4808. /* then a fix up */
  4809. start_freeze_handling(dd->pport, FREEZE_SELF);
  4810. }
  4811. for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
  4812. if (reg & (1ull << i)) {
  4813. incr_cntr64(&dd->cce_err_status_cnt[i]);
  4814. /* maintain a counter over all cce_err_status errors */
  4815. incr_cntr64(&dd->sw_cce_err_status_aggregate);
  4816. }
  4817. }
  4818. }
  4819. /*
  4820. * Check counters for receive errors that do not have an interrupt
  4821. * associated with them.
  4822. */
  4823. #define RCVERR_CHECK_TIME 10
  4824. static void update_rcverr_timer(unsigned long opaque)
  4825. {
  4826. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  4827. struct hfi1_pportdata *ppd = dd->pport;
  4828. u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  4829. if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
  4830. ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
  4831. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  4832. set_link_down_reason(
  4833. ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
  4834. OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
  4835. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  4836. }
  4837. dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
  4838. mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4839. }
  4840. static int init_rcverr(struct hfi1_devdata *dd)
  4841. {
  4842. setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
  4843. /* Assume the hardware counter has been reset */
  4844. dd->rcv_ovfl_cnt = 0;
  4845. return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4846. }
  4847. static void free_rcverr(struct hfi1_devdata *dd)
  4848. {
  4849. if (dd->rcverr_timer.data)
  4850. del_timer_sync(&dd->rcverr_timer);
  4851. dd->rcverr_timer.data = 0;
  4852. }
  4853. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4854. {
  4855. char buf[96];
  4856. int i = 0;
  4857. dd_dev_info(dd, "Receive Error: %s\n",
  4858. rxe_err_status_string(buf, sizeof(buf), reg));
  4859. if (reg & ALL_RXE_FREEZE_ERR) {
  4860. int flags = 0;
  4861. /*
  4862. * Freeze mode recovery is disabled for the errors
  4863. * in RXE_FREEZE_ABORT_MASK
  4864. */
  4865. if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
  4866. flags = FREEZE_ABORT;
  4867. start_freeze_handling(dd->pport, flags);
  4868. }
  4869. for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
  4870. if (reg & (1ull << i))
  4871. incr_cntr64(&dd->rcv_err_status_cnt[i]);
  4872. }
  4873. }
  4874. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4875. {
  4876. char buf[96];
  4877. int i = 0;
  4878. dd_dev_info(dd, "Misc Error: %s",
  4879. misc_err_status_string(buf, sizeof(buf), reg));
  4880. for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
  4881. if (reg & (1ull << i))
  4882. incr_cntr64(&dd->misc_err_status_cnt[i]);
  4883. }
  4884. }
  4885. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4886. {
  4887. char buf[96];
  4888. int i = 0;
  4889. dd_dev_info(dd, "PIO Error: %s\n",
  4890. pio_err_status_string(buf, sizeof(buf), reg));
  4891. if (reg & ALL_PIO_FREEZE_ERR)
  4892. start_freeze_handling(dd->pport, 0);
  4893. for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
  4894. if (reg & (1ull << i))
  4895. incr_cntr64(&dd->send_pio_err_status_cnt[i]);
  4896. }
  4897. }
  4898. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4899. {
  4900. char buf[96];
  4901. int i = 0;
  4902. dd_dev_info(dd, "SDMA Error: %s\n",
  4903. sdma_err_status_string(buf, sizeof(buf), reg));
  4904. if (reg & ALL_SDMA_FREEZE_ERR)
  4905. start_freeze_handling(dd->pport, 0);
  4906. for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
  4907. if (reg & (1ull << i))
  4908. incr_cntr64(&dd->send_dma_err_status_cnt[i]);
  4909. }
  4910. }
  4911. static inline void __count_port_discards(struct hfi1_pportdata *ppd)
  4912. {
  4913. incr_cntr64(&ppd->port_xmit_discards);
  4914. }
  4915. static void count_port_inactive(struct hfi1_devdata *dd)
  4916. {
  4917. __count_port_discards(dd->pport);
  4918. }
  4919. /*
  4920. * We have had a "disallowed packet" error during egress. Determine the
  4921. * integrity check which failed, and update relevant error counter, etc.
  4922. *
  4923. * Note that the SEND_EGRESS_ERR_INFO register has only a single
  4924. * bit of state per integrity check, and so we can miss the reason for an
  4925. * egress error if more than one packet fails the same integrity check
  4926. * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
  4927. */
  4928. static void handle_send_egress_err_info(struct hfi1_devdata *dd,
  4929. int vl)
  4930. {
  4931. struct hfi1_pportdata *ppd = dd->pport;
  4932. u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
  4933. u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
  4934. char buf[96];
  4935. /* clear down all observed info as quickly as possible after read */
  4936. write_csr(dd, SEND_EGRESS_ERR_INFO, info);
  4937. dd_dev_info(dd,
  4938. "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
  4939. info, egress_err_info_string(buf, sizeof(buf), info), src);
  4940. /* Eventually add other counters for each bit */
  4941. if (info & PORT_DISCARD_EGRESS_ERRS) {
  4942. int weight, i;
  4943. /*
  4944. * Count all applicable bits as individual errors and
  4945. * attribute them to the packet that triggered this handler.
  4946. * This may not be completely accurate due to limitations
  4947. * on the available hardware error information. There is
  4948. * a single information register and any number of error
  4949. * packets may have occurred and contributed to it before
  4950. * this routine is called. This means that:
  4951. * a) If multiple packets with the same error occur before
  4952. * this routine is called, earlier packets are missed.
  4953. * There is only a single bit for each error type.
  4954. * b) Errors may not be attributed to the correct VL.
  4955. * The driver is attributing all bits in the info register
  4956. * to the packet that triggered this call, but bits
  4957. * could be an accumulation of different packets with
  4958. * different VLs.
  4959. * c) A single error packet may have multiple counts attached
  4960. * to it. There is no way for the driver to know if
  4961. * multiple bits set in the info register are due to a
  4962. * single packet or multiple packets. The driver assumes
  4963. * multiple packets.
  4964. */
  4965. weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
  4966. for (i = 0; i < weight; i++) {
  4967. __count_port_discards(ppd);
  4968. if (vl >= 0 && vl < TXE_NUM_DATA_VL)
  4969. incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
  4970. else if (vl == 15)
  4971. incr_cntr64(&ppd->port_xmit_discards_vl
  4972. [C_VL_15]);
  4973. }
  4974. }
  4975. }
  4976. /*
  4977. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4978. * register. Does it represent a 'port inactive' error?
  4979. */
  4980. static inline int port_inactive_err(u64 posn)
  4981. {
  4982. return (posn >= SEES(TX_LINKDOWN) &&
  4983. posn <= SEES(TX_INCORRECT_LINK_STATE));
  4984. }
  4985. /*
  4986. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4987. * register. Does it represent a 'disallowed packet' error?
  4988. */
  4989. static inline int disallowed_pkt_err(int posn)
  4990. {
  4991. return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
  4992. posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
  4993. }
  4994. /*
  4995. * Input value is a bit position of one of the SDMA engine disallowed
  4996. * packet errors. Return which engine. Use of this must be guarded by
  4997. * disallowed_pkt_err().
  4998. */
  4999. static inline int disallowed_pkt_engine(int posn)
  5000. {
  5001. return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
  5002. }
  5003. /*
  5004. * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
  5005. * be done.
  5006. */
  5007. static int engine_to_vl(struct hfi1_devdata *dd, int engine)
  5008. {
  5009. struct sdma_vl_map *m;
  5010. int vl;
  5011. /* range check */
  5012. if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
  5013. return -1;
  5014. rcu_read_lock();
  5015. m = rcu_dereference(dd->sdma_map);
  5016. vl = m->engine_to_vl[engine];
  5017. rcu_read_unlock();
  5018. return vl;
  5019. }
  5020. /*
  5021. * Translate the send context (sofware index) into a VL. Return -1 if the
  5022. * translation cannot be done.
  5023. */
  5024. static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
  5025. {
  5026. struct send_context_info *sci;
  5027. struct send_context *sc;
  5028. int i;
  5029. sci = &dd->send_contexts[sw_index];
  5030. /* there is no information for user (PSM) and ack contexts */
  5031. if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
  5032. return -1;
  5033. sc = sci->sc;
  5034. if (!sc)
  5035. return -1;
  5036. if (dd->vld[15].sc == sc)
  5037. return 15;
  5038. for (i = 0; i < num_vls; i++)
  5039. if (dd->vld[i].sc == sc)
  5040. return i;
  5041. return -1;
  5042. }
  5043. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5044. {
  5045. u64 reg_copy = reg, handled = 0;
  5046. char buf[96];
  5047. int i = 0;
  5048. if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
  5049. start_freeze_handling(dd->pport, 0);
  5050. else if (is_ax(dd) &&
  5051. (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
  5052. (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
  5053. start_freeze_handling(dd->pport, 0);
  5054. while (reg_copy) {
  5055. int posn = fls64(reg_copy);
  5056. /* fls64() returns a 1-based offset, we want it zero based */
  5057. int shift = posn - 1;
  5058. u64 mask = 1ULL << shift;
  5059. if (port_inactive_err(shift)) {
  5060. count_port_inactive(dd);
  5061. handled |= mask;
  5062. } else if (disallowed_pkt_err(shift)) {
  5063. int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
  5064. handle_send_egress_err_info(dd, vl);
  5065. handled |= mask;
  5066. }
  5067. reg_copy &= ~mask;
  5068. }
  5069. reg &= ~handled;
  5070. if (reg)
  5071. dd_dev_info(dd, "Egress Error: %s\n",
  5072. egress_err_status_string(buf, sizeof(buf), reg));
  5073. for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
  5074. if (reg & (1ull << i))
  5075. incr_cntr64(&dd->send_egress_err_status_cnt[i]);
  5076. }
  5077. }
  5078. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5079. {
  5080. char buf[96];
  5081. int i = 0;
  5082. dd_dev_info(dd, "Send Error: %s\n",
  5083. send_err_status_string(buf, sizeof(buf), reg));
  5084. for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
  5085. if (reg & (1ull << i))
  5086. incr_cntr64(&dd->send_err_status_cnt[i]);
  5087. }
  5088. }
  5089. /*
  5090. * The maximum number of times the error clear down will loop before
  5091. * blocking a repeating error. This value is arbitrary.
  5092. */
  5093. #define MAX_CLEAR_COUNT 20
  5094. /*
  5095. * Clear and handle an error register. All error interrupts are funneled
  5096. * through here to have a central location to correctly handle single-
  5097. * or multi-shot errors.
  5098. *
  5099. * For non per-context registers, call this routine with a context value
  5100. * of 0 so the per-context offset is zero.
  5101. *
  5102. * If the handler loops too many times, assume that something is wrong
  5103. * and can't be fixed, so mask the error bits.
  5104. */
  5105. static void interrupt_clear_down(struct hfi1_devdata *dd,
  5106. u32 context,
  5107. const struct err_reg_info *eri)
  5108. {
  5109. u64 reg;
  5110. u32 count;
  5111. /* read in a loop until no more errors are seen */
  5112. count = 0;
  5113. while (1) {
  5114. reg = read_kctxt_csr(dd, context, eri->status);
  5115. if (reg == 0)
  5116. break;
  5117. write_kctxt_csr(dd, context, eri->clear, reg);
  5118. if (likely(eri->handler))
  5119. eri->handler(dd, context, reg);
  5120. count++;
  5121. if (count > MAX_CLEAR_COUNT) {
  5122. u64 mask;
  5123. dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
  5124. eri->desc, reg);
  5125. /*
  5126. * Read-modify-write so any other masked bits
  5127. * remain masked.
  5128. */
  5129. mask = read_kctxt_csr(dd, context, eri->mask);
  5130. mask &= ~reg;
  5131. write_kctxt_csr(dd, context, eri->mask, mask);
  5132. break;
  5133. }
  5134. }
  5135. }
  5136. /*
  5137. * CCE block "misc" interrupt. Source is < 16.
  5138. */
  5139. static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
  5140. {
  5141. const struct err_reg_info *eri = &misc_errs[source];
  5142. if (eri->handler) {
  5143. interrupt_clear_down(dd, 0, eri);
  5144. } else {
  5145. dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
  5146. source);
  5147. }
  5148. }
  5149. static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
  5150. {
  5151. return flag_string(buf, buf_len, flags,
  5152. sc_err_status_flags,
  5153. ARRAY_SIZE(sc_err_status_flags));
  5154. }
  5155. /*
  5156. * Send context error interrupt. Source (hw_context) is < 160.
  5157. *
  5158. * All send context errors cause the send context to halt. The normal
  5159. * clear-down mechanism cannot be used because we cannot clear the
  5160. * error bits until several other long-running items are done first.
  5161. * This is OK because with the context halted, nothing else is going
  5162. * to happen on it anyway.
  5163. */
  5164. static void is_sendctxt_err_int(struct hfi1_devdata *dd,
  5165. unsigned int hw_context)
  5166. {
  5167. struct send_context_info *sci;
  5168. struct send_context *sc;
  5169. char flags[96];
  5170. u64 status;
  5171. u32 sw_index;
  5172. int i = 0;
  5173. sw_index = dd->hw_to_sw[hw_context];
  5174. if (sw_index >= dd->num_send_contexts) {
  5175. dd_dev_err(dd,
  5176. "out of range sw index %u for send context %u\n",
  5177. sw_index, hw_context);
  5178. return;
  5179. }
  5180. sci = &dd->send_contexts[sw_index];
  5181. sc = sci->sc;
  5182. if (!sc) {
  5183. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5184. sw_index, hw_context);
  5185. return;
  5186. }
  5187. /* tell the software that a halt has begun */
  5188. sc_stop(sc, SCF_HALTED);
  5189. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5190. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5191. send_context_err_status_string(flags, sizeof(flags),
  5192. status));
  5193. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5194. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5195. /*
  5196. * Automatically restart halted kernel contexts out of interrupt
  5197. * context. User contexts must ask the driver to restart the context.
  5198. */
  5199. if (sc->type != SC_USER)
  5200. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5201. /*
  5202. * Update the counters for the corresponding status bits.
  5203. * Note that these particular counters are aggregated over all
  5204. * 160 contexts.
  5205. */
  5206. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5207. if (status & (1ull << i))
  5208. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5209. }
  5210. }
  5211. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5212. unsigned int source, u64 status)
  5213. {
  5214. struct sdma_engine *sde;
  5215. int i = 0;
  5216. sde = &dd->per_sdma[source];
  5217. #ifdef CONFIG_SDMA_VERBOSITY
  5218. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5219. slashstrip(__FILE__), __LINE__, __func__);
  5220. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5221. sde->this_idx, source, (unsigned long long)status);
  5222. #endif
  5223. sde->err_cnt++;
  5224. sdma_engine_error(sde, status);
  5225. /*
  5226. * Update the counters for the corresponding status bits.
  5227. * Note that these particular counters are aggregated over
  5228. * all 16 DMA engines.
  5229. */
  5230. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5231. if (status & (1ull << i))
  5232. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5233. }
  5234. }
  5235. /*
  5236. * CCE block SDMA error interrupt. Source is < 16.
  5237. */
  5238. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5239. {
  5240. #ifdef CONFIG_SDMA_VERBOSITY
  5241. struct sdma_engine *sde = &dd->per_sdma[source];
  5242. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5243. slashstrip(__FILE__), __LINE__, __func__);
  5244. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5245. source);
  5246. sdma_dumpstate(sde);
  5247. #endif
  5248. interrupt_clear_down(dd, source, &sdma_eng_err);
  5249. }
  5250. /*
  5251. * CCE block "various" interrupt. Source is < 8.
  5252. */
  5253. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5254. {
  5255. const struct err_reg_info *eri = &various_err[source];
  5256. /*
  5257. * TCritInt cannot go through interrupt_clear_down()
  5258. * because it is not a second tier interrupt. The handler
  5259. * should be called directly.
  5260. */
  5261. if (source == TCRIT_INT_SOURCE)
  5262. handle_temp_err(dd);
  5263. else if (eri->handler)
  5264. interrupt_clear_down(dd, 0, eri);
  5265. else
  5266. dd_dev_info(dd,
  5267. "%s: Unimplemented/reserved interrupt %d\n",
  5268. __func__, source);
  5269. }
  5270. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5271. {
  5272. /* src_ctx is always zero */
  5273. struct hfi1_pportdata *ppd = dd->pport;
  5274. unsigned long flags;
  5275. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5276. if (reg & QSFP_HFI0_MODPRST_N) {
  5277. if (!qsfp_mod_present(ppd)) {
  5278. dd_dev_info(dd, "%s: QSFP module removed\n",
  5279. __func__);
  5280. ppd->driver_link_ready = 0;
  5281. /*
  5282. * Cable removed, reset all our information about the
  5283. * cache and cable capabilities
  5284. */
  5285. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5286. /*
  5287. * We don't set cache_refresh_required here as we expect
  5288. * an interrupt when a cable is inserted
  5289. */
  5290. ppd->qsfp_info.cache_valid = 0;
  5291. ppd->qsfp_info.reset_needed = 0;
  5292. ppd->qsfp_info.limiting_active = 0;
  5293. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5294. flags);
  5295. /* Invert the ModPresent pin now to detect plug-in */
  5296. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5297. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5298. if ((ppd->offline_disabled_reason >
  5299. HFI1_ODR_MASK(
  5300. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5301. (ppd->offline_disabled_reason ==
  5302. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5303. ppd->offline_disabled_reason =
  5304. HFI1_ODR_MASK(
  5305. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5306. if (ppd->host_link_state == HLS_DN_POLL) {
  5307. /*
  5308. * The link is still in POLL. This means
  5309. * that the normal link down processing
  5310. * will not happen. We have to do it here
  5311. * before turning the DC off.
  5312. */
  5313. queue_work(ppd->link_wq, &ppd->link_down_work);
  5314. }
  5315. } else {
  5316. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5317. __func__);
  5318. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5319. ppd->qsfp_info.cache_valid = 0;
  5320. ppd->qsfp_info.cache_refresh_required = 1;
  5321. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5322. flags);
  5323. /*
  5324. * Stop inversion of ModPresent pin to detect
  5325. * removal of the cable
  5326. */
  5327. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5328. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5329. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5330. ppd->offline_disabled_reason =
  5331. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5332. }
  5333. }
  5334. if (reg & QSFP_HFI0_INT_N) {
  5335. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5336. __func__);
  5337. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5338. ppd->qsfp_info.check_interrupt_flags = 1;
  5339. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5340. }
  5341. /* Schedule the QSFP work only if there is a cable attached. */
  5342. if (qsfp_mod_present(ppd))
  5343. queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
  5344. }
  5345. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5346. {
  5347. int ret;
  5348. ret = do_8051_command(dd, HCMD_MISC,
  5349. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5350. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5351. if (ret != HCMD_SUCCESS) {
  5352. dd_dev_err(dd, "%s: command failed with error %d\n",
  5353. __func__, ret);
  5354. }
  5355. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5356. }
  5357. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5358. {
  5359. int ret;
  5360. ret = do_8051_command(dd, HCMD_MISC,
  5361. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5362. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5363. if (ret != HCMD_SUCCESS) {
  5364. dd_dev_err(dd, "%s: command failed with error %d\n",
  5365. __func__, ret);
  5366. }
  5367. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5368. }
  5369. /*
  5370. * Set the LCB selector - allow host access. The DCC selector always
  5371. * points to the host.
  5372. */
  5373. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5374. {
  5375. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5376. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5377. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5378. }
  5379. /*
  5380. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5381. * points to the host.
  5382. */
  5383. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5384. {
  5385. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5386. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5387. }
  5388. /*
  5389. * Acquire LCB access from the 8051. If the host already has access,
  5390. * just increment a counter. Otherwise, inform the 8051 that the
  5391. * host is taking access.
  5392. *
  5393. * Returns:
  5394. * 0 on success
  5395. * -EBUSY if the 8051 has control and cannot be disturbed
  5396. * -errno if unable to acquire access from the 8051
  5397. */
  5398. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5399. {
  5400. struct hfi1_pportdata *ppd = dd->pport;
  5401. int ret = 0;
  5402. /*
  5403. * Use the host link state lock so the operation of this routine
  5404. * { link state check, selector change, count increment } can occur
  5405. * as a unit against a link state change. Otherwise there is a
  5406. * race between the state change and the count increment.
  5407. */
  5408. if (sleep_ok) {
  5409. mutex_lock(&ppd->hls_lock);
  5410. } else {
  5411. while (!mutex_trylock(&ppd->hls_lock))
  5412. udelay(1);
  5413. }
  5414. /* this access is valid only when the link is up */
  5415. if (ppd->host_link_state & HLS_DOWN) {
  5416. dd_dev_info(dd, "%s: link state %s not up\n",
  5417. __func__, link_state_name(ppd->host_link_state));
  5418. ret = -EBUSY;
  5419. goto done;
  5420. }
  5421. if (dd->lcb_access_count == 0) {
  5422. ret = request_host_lcb_access(dd);
  5423. if (ret) {
  5424. dd_dev_err(dd,
  5425. "%s: unable to acquire LCB access, err %d\n",
  5426. __func__, ret);
  5427. goto done;
  5428. }
  5429. set_host_lcb_access(dd);
  5430. }
  5431. dd->lcb_access_count++;
  5432. done:
  5433. mutex_unlock(&ppd->hls_lock);
  5434. return ret;
  5435. }
  5436. /*
  5437. * Release LCB access by decrementing the use count. If the count is moving
  5438. * from 1 to 0, inform 8051 that it has control back.
  5439. *
  5440. * Returns:
  5441. * 0 on success
  5442. * -errno if unable to release access to the 8051
  5443. */
  5444. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5445. {
  5446. int ret = 0;
  5447. /*
  5448. * Use the host link state lock because the acquire needed it.
  5449. * Here, we only need to keep { selector change, count decrement }
  5450. * as a unit.
  5451. */
  5452. if (sleep_ok) {
  5453. mutex_lock(&dd->pport->hls_lock);
  5454. } else {
  5455. while (!mutex_trylock(&dd->pport->hls_lock))
  5456. udelay(1);
  5457. }
  5458. if (dd->lcb_access_count == 0) {
  5459. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5460. __func__);
  5461. goto done;
  5462. }
  5463. if (dd->lcb_access_count == 1) {
  5464. set_8051_lcb_access(dd);
  5465. ret = request_8051_lcb_access(dd);
  5466. if (ret) {
  5467. dd_dev_err(dd,
  5468. "%s: unable to release LCB access, err %d\n",
  5469. __func__, ret);
  5470. /* restore host access if the grant didn't work */
  5471. set_host_lcb_access(dd);
  5472. goto done;
  5473. }
  5474. }
  5475. dd->lcb_access_count--;
  5476. done:
  5477. mutex_unlock(&dd->pport->hls_lock);
  5478. return ret;
  5479. }
  5480. /*
  5481. * Initialize LCB access variables and state. Called during driver load,
  5482. * after most of the initialization is finished.
  5483. *
  5484. * The DC default is LCB access on for the host. The driver defaults to
  5485. * leaving access to the 8051. Assign access now - this constrains the call
  5486. * to this routine to be after all LCB set-up is done. In particular, after
  5487. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5488. */
  5489. static void init_lcb_access(struct hfi1_devdata *dd)
  5490. {
  5491. dd->lcb_access_count = 0;
  5492. }
  5493. /*
  5494. * Write a response back to a 8051 request.
  5495. */
  5496. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5497. {
  5498. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5499. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5500. (u64)return_code <<
  5501. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5502. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5503. }
  5504. /*
  5505. * Handle host requests from the 8051.
  5506. */
  5507. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5508. {
  5509. struct hfi1_devdata *dd = ppd->dd;
  5510. u64 reg;
  5511. u16 data = 0;
  5512. u8 type;
  5513. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5514. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5515. return; /* no request */
  5516. /* zero out COMPLETED so the response is seen */
  5517. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5518. /* extract request details */
  5519. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5520. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5521. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5522. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5523. switch (type) {
  5524. case HREQ_LOAD_CONFIG:
  5525. case HREQ_SAVE_CONFIG:
  5526. case HREQ_READ_CONFIG:
  5527. case HREQ_SET_TX_EQ_ABS:
  5528. case HREQ_SET_TX_EQ_REL:
  5529. case HREQ_ENABLE:
  5530. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5531. type);
  5532. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5533. break;
  5534. case HREQ_CONFIG_DONE:
  5535. hreq_response(dd, HREQ_SUCCESS, 0);
  5536. break;
  5537. case HREQ_INTERFACE_TEST:
  5538. hreq_response(dd, HREQ_SUCCESS, data);
  5539. break;
  5540. default:
  5541. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5542. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5543. break;
  5544. }
  5545. }
  5546. /*
  5547. * Set up allocation unit vaulue.
  5548. */
  5549. void set_up_vau(struct hfi1_devdata *dd, u8 vau)
  5550. {
  5551. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5552. /* do not modify other values in the register */
  5553. reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
  5554. reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
  5555. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5556. }
  5557. /*
  5558. * Set up initial VL15 credits of the remote. Assumes the rest of
  5559. * the CM credit registers are zero from a previous global or credit reset.
  5560. * Shared limit for VL15 will always be 0.
  5561. */
  5562. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
  5563. {
  5564. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5565. /* set initial values for total and shared credit limit */
  5566. reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
  5567. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
  5568. /*
  5569. * Set total limit to be equal to VL15 credits.
  5570. * Leave shared limit at 0.
  5571. */
  5572. reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  5573. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5574. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5575. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5576. }
  5577. /*
  5578. * Zero all credit details from the previous connection and
  5579. * reset the CM manager's internal counters.
  5580. */
  5581. void reset_link_credits(struct hfi1_devdata *dd)
  5582. {
  5583. int i;
  5584. /* remove all previous VL credit limits */
  5585. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5586. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5587. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5588. write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
  5589. /* reset the CM block */
  5590. pio_send_control(dd, PSC_CM_RESET);
  5591. /* reset cached value */
  5592. dd->vl15buf_cached = 0;
  5593. }
  5594. /* convert a vCU to a CU */
  5595. static u32 vcu_to_cu(u8 vcu)
  5596. {
  5597. return 1 << vcu;
  5598. }
  5599. /* convert a CU to a vCU */
  5600. static u8 cu_to_vcu(u32 cu)
  5601. {
  5602. return ilog2(cu);
  5603. }
  5604. /* convert a vAU to an AU */
  5605. static u32 vau_to_au(u8 vau)
  5606. {
  5607. return 8 * (1 << vau);
  5608. }
  5609. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5610. {
  5611. ppd->sm_trap_qp = 0x0;
  5612. ppd->sa_qp = 0x1;
  5613. }
  5614. /*
  5615. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5616. */
  5617. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5618. {
  5619. u64 reg;
  5620. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5621. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5622. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5623. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5624. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5625. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5626. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5627. reg = read_csr(dd, DCC_CFG_RESET);
  5628. write_csr(dd, DCC_CFG_RESET, reg |
  5629. (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
  5630. (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
  5631. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5632. if (!abort) {
  5633. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5634. write_csr(dd, DCC_CFG_RESET, reg);
  5635. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5636. }
  5637. }
  5638. /*
  5639. * This routine should be called after the link has been transitioned to
  5640. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5641. * reset).
  5642. *
  5643. * The expectation is that the caller of this routine would have taken
  5644. * care of properly transitioning the link into the correct state.
  5645. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5646. * before calling this function.
  5647. */
  5648. static void _dc_shutdown(struct hfi1_devdata *dd)
  5649. {
  5650. lockdep_assert_held(&dd->dc8051_lock);
  5651. if (dd->dc_shutdown)
  5652. return;
  5653. dd->dc_shutdown = 1;
  5654. /* Shutdown the LCB */
  5655. lcb_shutdown(dd, 1);
  5656. /*
  5657. * Going to OFFLINE would have causes the 8051 to put the
  5658. * SerDes into reset already. Just need to shut down the 8051,
  5659. * itself.
  5660. */
  5661. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5662. }
  5663. static void dc_shutdown(struct hfi1_devdata *dd)
  5664. {
  5665. mutex_lock(&dd->dc8051_lock);
  5666. _dc_shutdown(dd);
  5667. mutex_unlock(&dd->dc8051_lock);
  5668. }
  5669. /*
  5670. * Calling this after the DC has been brought out of reset should not
  5671. * do any damage.
  5672. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5673. * before calling this function.
  5674. */
  5675. static void _dc_start(struct hfi1_devdata *dd)
  5676. {
  5677. lockdep_assert_held(&dd->dc8051_lock);
  5678. if (!dd->dc_shutdown)
  5679. return;
  5680. /* Take the 8051 out of reset */
  5681. write_csr(dd, DC_DC8051_CFG_RST, 0ull);
  5682. /* Wait until 8051 is ready */
  5683. if (wait_fm_ready(dd, TIMEOUT_8051_START))
  5684. dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
  5685. __func__);
  5686. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5687. write_csr(dd, DCC_CFG_RESET, 0x10);
  5688. /* lcb_shutdown() with abort=1 does not restore these */
  5689. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5690. dd->dc_shutdown = 0;
  5691. }
  5692. static void dc_start(struct hfi1_devdata *dd)
  5693. {
  5694. mutex_lock(&dd->dc8051_lock);
  5695. _dc_start(dd);
  5696. mutex_unlock(&dd->dc8051_lock);
  5697. }
  5698. /*
  5699. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5700. */
  5701. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5702. {
  5703. u64 rx_radr, tx_radr;
  5704. u32 version;
  5705. if (dd->icode != ICODE_FPGA_EMULATION)
  5706. return;
  5707. /*
  5708. * These LCB defaults on emulator _s are good, nothing to do here:
  5709. * LCB_CFG_TX_FIFOS_RADR
  5710. * LCB_CFG_RX_FIFOS_RADR
  5711. * LCB_CFG_LN_DCLK
  5712. * LCB_CFG_IGNORE_LOST_RCLK
  5713. */
  5714. if (is_emulator_s(dd))
  5715. return;
  5716. /* else this is _p */
  5717. version = emulator_rev(dd);
  5718. if (!is_ax(dd))
  5719. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5720. if (version <= 0x12) {
  5721. /* release 0x12 and below */
  5722. /*
  5723. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5724. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5725. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5726. */
  5727. rx_radr =
  5728. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5729. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5730. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5731. /*
  5732. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5733. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5734. */
  5735. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5736. } else if (version <= 0x18) {
  5737. /* release 0x13 up to 0x18 */
  5738. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5739. rx_radr =
  5740. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5741. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5742. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5743. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5744. } else if (version == 0x19) {
  5745. /* release 0x19 */
  5746. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5747. rx_radr =
  5748. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5749. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5750. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5751. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5752. } else if (version == 0x1a) {
  5753. /* release 0x1a */
  5754. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5755. rx_radr =
  5756. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5757. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5758. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5759. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5760. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5761. } else {
  5762. /* release 0x1b and higher */
  5763. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5764. rx_radr =
  5765. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5766. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5767. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5768. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5769. }
  5770. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5771. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5772. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5773. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5774. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5775. }
  5776. /*
  5777. * Handle a SMA idle message
  5778. *
  5779. * This is a work-queue function outside of the interrupt.
  5780. */
  5781. void handle_sma_message(struct work_struct *work)
  5782. {
  5783. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5784. sma_message_work);
  5785. struct hfi1_devdata *dd = ppd->dd;
  5786. u64 msg;
  5787. int ret;
  5788. /*
  5789. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5790. * is stripped off
  5791. */
  5792. ret = read_idle_sma(dd, &msg);
  5793. if (ret)
  5794. return;
  5795. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5796. /*
  5797. * React to the SMA message. Byte[1] (0 for us) is the command.
  5798. */
  5799. switch (msg & 0xff) {
  5800. case SMA_IDLE_ARM:
  5801. /*
  5802. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5803. * State Transitions
  5804. *
  5805. * Only expected in INIT or ARMED, discard otherwise.
  5806. */
  5807. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5808. ppd->neighbor_normal = 1;
  5809. break;
  5810. case SMA_IDLE_ACTIVE:
  5811. /*
  5812. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5813. * State Transitions
  5814. *
  5815. * Can activate the node. Discard otherwise.
  5816. */
  5817. if (ppd->host_link_state == HLS_UP_ARMED &&
  5818. ppd->is_active_optimize_enabled) {
  5819. ppd->neighbor_normal = 1;
  5820. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5821. if (ret)
  5822. dd_dev_err(
  5823. dd,
  5824. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5825. __func__);
  5826. }
  5827. break;
  5828. default:
  5829. dd_dev_err(dd,
  5830. "%s: received unexpected SMA idle message 0x%llx\n",
  5831. __func__, msg);
  5832. break;
  5833. }
  5834. }
  5835. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5836. {
  5837. u64 rcvctrl;
  5838. unsigned long flags;
  5839. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5840. rcvctrl = read_csr(dd, RCV_CTRL);
  5841. rcvctrl |= add;
  5842. rcvctrl &= ~clear;
  5843. write_csr(dd, RCV_CTRL, rcvctrl);
  5844. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5845. }
  5846. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5847. {
  5848. adjust_rcvctrl(dd, add, 0);
  5849. }
  5850. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5851. {
  5852. adjust_rcvctrl(dd, 0, clear);
  5853. }
  5854. /*
  5855. * Called from all interrupt handlers to start handling an SPC freeze.
  5856. */
  5857. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5858. {
  5859. struct hfi1_devdata *dd = ppd->dd;
  5860. struct send_context *sc;
  5861. int i;
  5862. if (flags & FREEZE_SELF)
  5863. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5864. /* enter frozen mode */
  5865. dd->flags |= HFI1_FROZEN;
  5866. /* notify all SDMA engines that they are going into a freeze */
  5867. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5868. /* do halt pre-handling on all enabled send contexts */
  5869. for (i = 0; i < dd->num_send_contexts; i++) {
  5870. sc = dd->send_contexts[i].sc;
  5871. if (sc && (sc->flags & SCF_ENABLED))
  5872. sc_stop(sc, SCF_FROZEN | SCF_HALTED);
  5873. }
  5874. /* Send context are frozen. Notify user space */
  5875. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5876. if (flags & FREEZE_ABORT) {
  5877. dd_dev_err(dd,
  5878. "Aborted freeze recovery. Please REBOOT system\n");
  5879. return;
  5880. }
  5881. /* queue non-interrupt handler */
  5882. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5883. }
  5884. /*
  5885. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5886. * depending on the "freeze" parameter.
  5887. *
  5888. * No need to return an error if it times out, our only option
  5889. * is to proceed anyway.
  5890. */
  5891. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5892. {
  5893. unsigned long timeout;
  5894. u64 reg;
  5895. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5896. while (1) {
  5897. reg = read_csr(dd, CCE_STATUS);
  5898. if (freeze) {
  5899. /* waiting until all indicators are set */
  5900. if ((reg & ALL_FROZE) == ALL_FROZE)
  5901. return; /* all done */
  5902. } else {
  5903. /* waiting until all indicators are clear */
  5904. if ((reg & ALL_FROZE) == 0)
  5905. return; /* all done */
  5906. }
  5907. if (time_after(jiffies, timeout)) {
  5908. dd_dev_err(dd,
  5909. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5910. freeze ? "" : "un", reg & ALL_FROZE,
  5911. freeze ? ALL_FROZE : 0ull);
  5912. return;
  5913. }
  5914. usleep_range(80, 120);
  5915. }
  5916. }
  5917. /*
  5918. * Do all freeze handling for the RXE block.
  5919. */
  5920. static void rxe_freeze(struct hfi1_devdata *dd)
  5921. {
  5922. int i;
  5923. struct hfi1_ctxtdata *rcd;
  5924. /* disable port */
  5925. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5926. /* disable all receive contexts */
  5927. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5928. rcd = hfi1_rcd_get_by_index(dd, i);
  5929. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
  5930. hfi1_rcd_put(rcd);
  5931. }
  5932. }
  5933. /*
  5934. * Unfreeze handling for the RXE block - kernel contexts only.
  5935. * This will also enable the port. User contexts will do unfreeze
  5936. * handling on a per-context basis as they call into the driver.
  5937. *
  5938. */
  5939. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5940. {
  5941. u32 rcvmask;
  5942. u16 i;
  5943. struct hfi1_ctxtdata *rcd;
  5944. /* enable all kernel contexts */
  5945. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5946. rcd = hfi1_rcd_get_by_index(dd, i);
  5947. /* Ensure all non-user contexts(including vnic) are enabled */
  5948. if (!rcd || !rcd->sc || (rcd->sc->type == SC_USER)) {
  5949. hfi1_rcd_put(rcd);
  5950. continue;
  5951. }
  5952. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5953. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5954. rcvmask |= HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
  5955. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5956. hfi1_rcvctrl(dd, rcvmask, rcd);
  5957. hfi1_rcd_put(rcd);
  5958. }
  5959. /* enable port */
  5960. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5961. }
  5962. /*
  5963. * Non-interrupt SPC freeze handling.
  5964. *
  5965. * This is a work-queue function outside of the triggering interrupt.
  5966. */
  5967. void handle_freeze(struct work_struct *work)
  5968. {
  5969. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5970. freeze_work);
  5971. struct hfi1_devdata *dd = ppd->dd;
  5972. /* wait for freeze indicators on all affected blocks */
  5973. wait_for_freeze_status(dd, 1);
  5974. /* SPC is now frozen */
  5975. /* do send PIO freeze steps */
  5976. pio_freeze(dd);
  5977. /* do send DMA freeze steps */
  5978. sdma_freeze(dd);
  5979. /* do send egress freeze steps - nothing to do */
  5980. /* do receive freeze steps */
  5981. rxe_freeze(dd);
  5982. /*
  5983. * Unfreeze the hardware - clear the freeze, wait for each
  5984. * block's frozen bit to clear, then clear the frozen flag.
  5985. */
  5986. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5987. wait_for_freeze_status(dd, 0);
  5988. if (is_ax(dd)) {
  5989. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5990. wait_for_freeze_status(dd, 1);
  5991. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5992. wait_for_freeze_status(dd, 0);
  5993. }
  5994. /* do send PIO unfreeze steps for kernel contexts */
  5995. pio_kernel_unfreeze(dd);
  5996. /* do send DMA unfreeze steps */
  5997. sdma_unfreeze(dd);
  5998. /* do send egress unfreeze steps - nothing to do */
  5999. /* do receive unfreeze steps for kernel contexts */
  6000. rxe_kernel_unfreeze(dd);
  6001. /*
  6002. * The unfreeze procedure touches global device registers when
  6003. * it disables and re-enables RXE. Mark the device unfrozen
  6004. * after all that is done so other parts of the driver waiting
  6005. * for the device to unfreeze don't do things out of order.
  6006. *
  6007. * The above implies that the meaning of HFI1_FROZEN flag is
  6008. * "Device has gone into freeze mode and freeze mode handling
  6009. * is still in progress."
  6010. *
  6011. * The flag will be removed when freeze mode processing has
  6012. * completed.
  6013. */
  6014. dd->flags &= ~HFI1_FROZEN;
  6015. wake_up(&dd->event_queue);
  6016. /* no longer frozen */
  6017. }
  6018. /*
  6019. * Handle a link up interrupt from the 8051.
  6020. *
  6021. * This is a work-queue function outside of the interrupt.
  6022. */
  6023. void handle_link_up(struct work_struct *work)
  6024. {
  6025. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6026. link_up_work);
  6027. struct hfi1_devdata *dd = ppd->dd;
  6028. set_link_state(ppd, HLS_UP_INIT);
  6029. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  6030. read_ltp_rtt(dd);
  6031. /*
  6032. * OPA specifies that certain counters are cleared on a transition
  6033. * to link up, so do that.
  6034. */
  6035. clear_linkup_counters(dd);
  6036. /*
  6037. * And (re)set link up default values.
  6038. */
  6039. set_linkup_defaults(ppd);
  6040. /*
  6041. * Set VL15 credits. Use cached value from verify cap interrupt.
  6042. * In case of quick linkup or simulator, vl15 value will be set by
  6043. * handle_linkup_change. VerifyCap interrupt handler will not be
  6044. * called in those scenarios.
  6045. */
  6046. if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
  6047. set_up_vl15(dd, dd->vl15buf_cached);
  6048. /* enforce link speed enabled */
  6049. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  6050. /* oops - current speed is not enabled, bounce */
  6051. dd_dev_err(dd,
  6052. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  6053. ppd->link_speed_active, ppd->link_speed_enabled);
  6054. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  6055. OPA_LINKDOWN_REASON_SPEED_POLICY);
  6056. set_link_state(ppd, HLS_DN_OFFLINE);
  6057. start_link(ppd);
  6058. }
  6059. }
  6060. /*
  6061. * Several pieces of LNI information were cached for SMA in ppd.
  6062. * Reset these on link down
  6063. */
  6064. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  6065. {
  6066. ppd->neighbor_guid = 0;
  6067. ppd->neighbor_port_number = 0;
  6068. ppd->neighbor_type = 0;
  6069. ppd->neighbor_fm_security = 0;
  6070. }
  6071. static const char * const link_down_reason_strs[] = {
  6072. [OPA_LINKDOWN_REASON_NONE] = "None",
  6073. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
  6074. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  6075. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  6076. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  6077. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  6078. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  6079. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  6080. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  6081. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  6082. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  6083. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  6084. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  6085. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  6086. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  6087. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  6088. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  6089. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  6090. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  6091. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  6092. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  6093. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  6094. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  6095. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  6096. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  6097. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  6098. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  6099. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  6100. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  6101. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  6102. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  6103. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  6104. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  6105. "Excessive buffer overrun",
  6106. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  6107. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  6108. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  6109. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  6110. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  6111. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  6112. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6113. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6114. "Local media not installed",
  6115. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6116. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6117. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6118. "End to end not installed",
  6119. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6120. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6121. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6122. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6123. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6124. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6125. };
  6126. /* return the neighbor link down reason string */
  6127. static const char *link_down_reason_str(u8 reason)
  6128. {
  6129. const char *str = NULL;
  6130. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6131. str = link_down_reason_strs[reason];
  6132. if (!str)
  6133. str = "(invalid)";
  6134. return str;
  6135. }
  6136. /*
  6137. * Handle a link down interrupt from the 8051.
  6138. *
  6139. * This is a work-queue function outside of the interrupt.
  6140. */
  6141. void handle_link_down(struct work_struct *work)
  6142. {
  6143. u8 lcl_reason, neigh_reason = 0;
  6144. u8 link_down_reason;
  6145. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6146. link_down_work);
  6147. int was_up;
  6148. static const char ldr_str[] = "Link down reason: ";
  6149. if ((ppd->host_link_state &
  6150. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6151. ppd->port_type == PORT_TYPE_FIXED)
  6152. ppd->offline_disabled_reason =
  6153. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6154. /* Go offline first, then deal with reading/writing through 8051 */
  6155. was_up = !!(ppd->host_link_state & HLS_UP);
  6156. set_link_state(ppd, HLS_DN_OFFLINE);
  6157. xchg(&ppd->is_link_down_queued, 0);
  6158. if (was_up) {
  6159. lcl_reason = 0;
  6160. /* link down reason is only valid if the link was up */
  6161. read_link_down_reason(ppd->dd, &link_down_reason);
  6162. switch (link_down_reason) {
  6163. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6164. /* the link went down, no idle message reason */
  6165. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6166. ldr_str);
  6167. break;
  6168. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6169. /*
  6170. * The neighbor reason is only valid if an idle message
  6171. * was received for it.
  6172. */
  6173. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6174. dd_dev_info(ppd->dd,
  6175. "%sNeighbor link down message %d, %s\n",
  6176. ldr_str, neigh_reason,
  6177. link_down_reason_str(neigh_reason));
  6178. break;
  6179. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6180. dd_dev_info(ppd->dd,
  6181. "%sHost requested link to go offline\n",
  6182. ldr_str);
  6183. break;
  6184. default:
  6185. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6186. ldr_str, link_down_reason);
  6187. break;
  6188. }
  6189. /*
  6190. * If no reason, assume peer-initiated but missed
  6191. * LinkGoingDown idle flits.
  6192. */
  6193. if (neigh_reason == 0)
  6194. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6195. } else {
  6196. /* went down while polling or going up */
  6197. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6198. }
  6199. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6200. /* inform the SMA when the link transitions from up to down */
  6201. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6202. ppd->neigh_link_down_reason.sma == 0) {
  6203. ppd->local_link_down_reason.sma =
  6204. ppd->local_link_down_reason.latest;
  6205. ppd->neigh_link_down_reason.sma =
  6206. ppd->neigh_link_down_reason.latest;
  6207. }
  6208. reset_neighbor_info(ppd);
  6209. /* disable the port */
  6210. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6211. /*
  6212. * If there is no cable attached, turn the DC off. Otherwise,
  6213. * start the link bring up.
  6214. */
  6215. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6216. dc_shutdown(ppd->dd);
  6217. else
  6218. start_link(ppd);
  6219. }
  6220. void handle_link_bounce(struct work_struct *work)
  6221. {
  6222. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6223. link_bounce_work);
  6224. /*
  6225. * Only do something if the link is currently up.
  6226. */
  6227. if (ppd->host_link_state & HLS_UP) {
  6228. set_link_state(ppd, HLS_DN_OFFLINE);
  6229. start_link(ppd);
  6230. } else {
  6231. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6232. __func__, link_state_name(ppd->host_link_state));
  6233. }
  6234. }
  6235. /*
  6236. * Mask conversion: Capability exchange to Port LTP. The capability
  6237. * exchange has an implicit 16b CRC that is mandatory.
  6238. */
  6239. static int cap_to_port_ltp(int cap)
  6240. {
  6241. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6242. if (cap & CAP_CRC_14B)
  6243. port_ltp |= PORT_LTP_CRC_MODE_14;
  6244. if (cap & CAP_CRC_48B)
  6245. port_ltp |= PORT_LTP_CRC_MODE_48;
  6246. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6247. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6248. return port_ltp;
  6249. }
  6250. /*
  6251. * Convert an OPA Port LTP mask to capability mask
  6252. */
  6253. int port_ltp_to_cap(int port_ltp)
  6254. {
  6255. int cap_mask = 0;
  6256. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6257. cap_mask |= CAP_CRC_14B;
  6258. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6259. cap_mask |= CAP_CRC_48B;
  6260. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6261. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6262. return cap_mask;
  6263. }
  6264. /*
  6265. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6266. */
  6267. static int lcb_to_port_ltp(int lcb_crc)
  6268. {
  6269. int port_ltp = 0;
  6270. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6271. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6272. else if (lcb_crc == LCB_CRC_48B)
  6273. port_ltp = PORT_LTP_CRC_MODE_48;
  6274. else if (lcb_crc == LCB_CRC_14B)
  6275. port_ltp = PORT_LTP_CRC_MODE_14;
  6276. else
  6277. port_ltp = PORT_LTP_CRC_MODE_16;
  6278. return port_ltp;
  6279. }
  6280. /*
  6281. * Our neighbor has indicated that we are allowed to act as a fabric
  6282. * manager, so place the full management partition key in the second
  6283. * (0-based) pkey array position (see OPAv1, section 20.2.2.6.8). Note
  6284. * that we should already have the limited management partition key in
  6285. * array element 1, and also that the port is not yet up when
  6286. * add_full_mgmt_pkey() is invoked.
  6287. */
  6288. static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6289. {
  6290. struct hfi1_devdata *dd = ppd->dd;
  6291. /* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
  6292. if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
  6293. dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
  6294. __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
  6295. ppd->pkeys[2] = FULL_MGMT_P_KEY;
  6296. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6297. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6298. }
  6299. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6300. {
  6301. if (ppd->pkeys[2] != 0) {
  6302. ppd->pkeys[2] = 0;
  6303. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6304. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6305. }
  6306. }
  6307. /*
  6308. * Convert the given link width to the OPA link width bitmask.
  6309. */
  6310. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6311. {
  6312. switch (width) {
  6313. case 0:
  6314. /*
  6315. * Simulator and quick linkup do not set the width.
  6316. * Just set it to 4x without complaint.
  6317. */
  6318. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6319. return OPA_LINK_WIDTH_4X;
  6320. return 0; /* no lanes up */
  6321. case 1: return OPA_LINK_WIDTH_1X;
  6322. case 2: return OPA_LINK_WIDTH_2X;
  6323. case 3: return OPA_LINK_WIDTH_3X;
  6324. default:
  6325. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6326. __func__, width);
  6327. /* fall through */
  6328. case 4: return OPA_LINK_WIDTH_4X;
  6329. }
  6330. }
  6331. /*
  6332. * Do a population count on the bottom nibble.
  6333. */
  6334. static const u8 bit_counts[16] = {
  6335. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6336. };
  6337. static inline u8 nibble_to_count(u8 nibble)
  6338. {
  6339. return bit_counts[nibble & 0xf];
  6340. }
  6341. /*
  6342. * Read the active lane information from the 8051 registers and return
  6343. * their widths.
  6344. *
  6345. * Active lane information is found in these 8051 registers:
  6346. * enable_lane_tx
  6347. * enable_lane_rx
  6348. */
  6349. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6350. u16 *rx_width)
  6351. {
  6352. u16 tx, rx;
  6353. u8 enable_lane_rx;
  6354. u8 enable_lane_tx;
  6355. u8 tx_polarity_inversion;
  6356. u8 rx_polarity_inversion;
  6357. u8 max_rate;
  6358. /* read the active lanes */
  6359. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6360. &rx_polarity_inversion, &max_rate);
  6361. read_local_lni(dd, &enable_lane_rx);
  6362. /* convert to counts */
  6363. tx = nibble_to_count(enable_lane_tx);
  6364. rx = nibble_to_count(enable_lane_rx);
  6365. /*
  6366. * Set link_speed_active here, overriding what was set in
  6367. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6368. * set the max_rate field in handle_verify_cap until v0.19.
  6369. */
  6370. if ((dd->icode == ICODE_RTL_SILICON) &&
  6371. (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
  6372. /* max_rate: 0 = 12.5G, 1 = 25G */
  6373. switch (max_rate) {
  6374. case 0:
  6375. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6376. break;
  6377. default:
  6378. dd_dev_err(dd,
  6379. "%s: unexpected max rate %d, using 25Gb\n",
  6380. __func__, (int)max_rate);
  6381. /* fall through */
  6382. case 1:
  6383. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6384. break;
  6385. }
  6386. }
  6387. dd_dev_info(dd,
  6388. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6389. enable_lane_tx, tx, enable_lane_rx, rx);
  6390. *tx_width = link_width_to_bits(dd, tx);
  6391. *rx_width = link_width_to_bits(dd, rx);
  6392. }
  6393. /*
  6394. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6395. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6396. * after link up. I.e. look elsewhere for downgrade information.
  6397. *
  6398. * Bits are:
  6399. * + bits [7:4] contain the number of active transmitters
  6400. * + bits [3:0] contain the number of active receivers
  6401. * These are numbers 1 through 4 and can be different values if the
  6402. * link is asymmetric.
  6403. *
  6404. * verify_cap_local_fm_link_width[0] retains its original value.
  6405. */
  6406. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6407. u16 *rx_width)
  6408. {
  6409. u16 widths, tx, rx;
  6410. u8 misc_bits, local_flags;
  6411. u16 active_tx, active_rx;
  6412. read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
  6413. tx = widths >> 12;
  6414. rx = (widths >> 8) & 0xf;
  6415. *tx_width = link_width_to_bits(dd, tx);
  6416. *rx_width = link_width_to_bits(dd, rx);
  6417. /* print the active widths */
  6418. get_link_widths(dd, &active_tx, &active_rx);
  6419. }
  6420. /*
  6421. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6422. * hardware information when the link first comes up.
  6423. *
  6424. * The link width is not available until after VerifyCap.AllFramesReceived
  6425. * (the trigger for handle_verify_cap), so this is outside that routine
  6426. * and should be called when the 8051 signals linkup.
  6427. */
  6428. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6429. {
  6430. u16 tx_width, rx_width;
  6431. /* get end-of-LNI link widths */
  6432. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6433. /* use tx_width as the link is supposed to be symmetric on link up */
  6434. ppd->link_width_active = tx_width;
  6435. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6436. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6437. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6438. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6439. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6440. /* cache the active egress rate (units {10^6 bits/sec]) */
  6441. ppd->current_egress_rate = active_egress_rate(ppd);
  6442. }
  6443. /*
  6444. * Handle a verify capabilities interrupt from the 8051.
  6445. *
  6446. * This is a work-queue function outside of the interrupt.
  6447. */
  6448. void handle_verify_cap(struct work_struct *work)
  6449. {
  6450. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6451. link_vc_work);
  6452. struct hfi1_devdata *dd = ppd->dd;
  6453. u64 reg;
  6454. u8 power_management;
  6455. u8 continuous;
  6456. u8 vcu;
  6457. u8 vau;
  6458. u8 z;
  6459. u16 vl15buf;
  6460. u16 link_widths;
  6461. u16 crc_mask;
  6462. u16 crc_val;
  6463. u16 device_id;
  6464. u16 active_tx, active_rx;
  6465. u8 partner_supported_crc;
  6466. u8 remote_tx_rate;
  6467. u8 device_rev;
  6468. set_link_state(ppd, HLS_VERIFY_CAP);
  6469. lcb_shutdown(dd, 0);
  6470. adjust_lcb_for_fpga_serdes(dd);
  6471. read_vc_remote_phy(dd, &power_management, &continuous);
  6472. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6473. &partner_supported_crc);
  6474. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6475. read_remote_device_id(dd, &device_id, &device_rev);
  6476. /*
  6477. * And the 'MgmtAllowed' information, which is exchanged during
  6478. * LNI, is also be available at this point.
  6479. */
  6480. read_mgmt_allowed(dd, &ppd->mgmt_allowed);
  6481. /* print the active widths */
  6482. get_link_widths(dd, &active_tx, &active_rx);
  6483. dd_dev_info(dd,
  6484. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6485. (int)power_management, (int)continuous);
  6486. dd_dev_info(dd,
  6487. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6488. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6489. (int)partner_supported_crc);
  6490. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6491. (u32)remote_tx_rate, (u32)link_widths);
  6492. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6493. (u32)device_id, (u32)device_rev);
  6494. /*
  6495. * The peer vAU value just read is the peer receiver value. HFI does
  6496. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6497. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6498. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6499. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6500. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6501. * subject to the Z value exception.
  6502. */
  6503. if (vau == 0)
  6504. vau = 1;
  6505. set_up_vau(dd, vau);
  6506. /*
  6507. * Set VL15 credits to 0 in global credit register. Cache remote VL15
  6508. * credits value and wait for link-up interrupt ot set it.
  6509. */
  6510. set_up_vl15(dd, 0);
  6511. dd->vl15buf_cached = vl15buf;
  6512. /* set up the LCB CRC mode */
  6513. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6514. /* order is important: use the lowest bit in common */
  6515. if (crc_mask & CAP_CRC_14B)
  6516. crc_val = LCB_CRC_14B;
  6517. else if (crc_mask & CAP_CRC_48B)
  6518. crc_val = LCB_CRC_48B;
  6519. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6520. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6521. else
  6522. crc_val = LCB_CRC_16B;
  6523. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6524. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6525. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6526. /* set (14b only) or clear sideband credit */
  6527. reg = read_csr(dd, SEND_CM_CTRL);
  6528. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6529. write_csr(dd, SEND_CM_CTRL,
  6530. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6531. } else {
  6532. write_csr(dd, SEND_CM_CTRL,
  6533. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6534. }
  6535. ppd->link_speed_active = 0; /* invalid value */
  6536. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  6537. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6538. switch (remote_tx_rate) {
  6539. case 0:
  6540. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6541. break;
  6542. case 1:
  6543. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6544. break;
  6545. }
  6546. } else {
  6547. /* actual rate is highest bit of the ANDed rates */
  6548. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6549. if (rate & 2)
  6550. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6551. else if (rate & 1)
  6552. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6553. }
  6554. if (ppd->link_speed_active == 0) {
  6555. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6556. __func__, (int)remote_tx_rate);
  6557. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6558. }
  6559. /*
  6560. * Cache the values of the supported, enabled, and active
  6561. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6562. * flags that are returned in the portinfo query differ from
  6563. * what's in the link_crc_mask, crc_sizes, and crc_val
  6564. * variables. Convert these here.
  6565. */
  6566. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6567. /* supported crc modes */
  6568. ppd->port_ltp_crc_mode |=
  6569. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6570. /* enabled crc modes */
  6571. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6572. /* active crc mode */
  6573. /* set up the remote credit return table */
  6574. assign_remote_cm_au_table(dd, vcu);
  6575. /*
  6576. * The LCB is reset on entry to handle_verify_cap(), so this must
  6577. * be applied on every link up.
  6578. *
  6579. * Adjust LCB error kill enable to kill the link if
  6580. * these RBUF errors are seen:
  6581. * REPLAY_BUF_MBE_SMASK
  6582. * FLIT_INPUT_BUF_MBE_SMASK
  6583. */
  6584. if (is_ax(dd)) { /* fixed in B0 */
  6585. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6586. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6587. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6588. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6589. }
  6590. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6591. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6592. /* give 8051 access to the LCB CSRs */
  6593. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6594. set_8051_lcb_access(dd);
  6595. if (ppd->mgmt_allowed)
  6596. add_full_mgmt_pkey(ppd);
  6597. /* tell the 8051 to go to LinkUp */
  6598. set_link_state(ppd, HLS_GOING_UP);
  6599. }
  6600. /*
  6601. * Apply the link width downgrade enabled policy against the current active
  6602. * link widths.
  6603. *
  6604. * Called when the enabled policy changes or the active link widths change.
  6605. */
  6606. void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
  6607. {
  6608. int do_bounce = 0;
  6609. int tries;
  6610. u16 lwde;
  6611. u16 tx, rx;
  6612. /* use the hls lock to avoid a race with actual link up */
  6613. tries = 0;
  6614. retry:
  6615. mutex_lock(&ppd->hls_lock);
  6616. /* only apply if the link is up */
  6617. if (ppd->host_link_state & HLS_DOWN) {
  6618. /* still going up..wait and retry */
  6619. if (ppd->host_link_state & HLS_GOING_UP) {
  6620. if (++tries < 1000) {
  6621. mutex_unlock(&ppd->hls_lock);
  6622. usleep_range(100, 120); /* arbitrary */
  6623. goto retry;
  6624. }
  6625. dd_dev_err(ppd->dd,
  6626. "%s: giving up waiting for link state change\n",
  6627. __func__);
  6628. }
  6629. goto done;
  6630. }
  6631. lwde = ppd->link_width_downgrade_enabled;
  6632. if (refresh_widths) {
  6633. get_link_widths(ppd->dd, &tx, &rx);
  6634. ppd->link_width_downgrade_tx_active = tx;
  6635. ppd->link_width_downgrade_rx_active = rx;
  6636. }
  6637. if (ppd->link_width_downgrade_tx_active == 0 ||
  6638. ppd->link_width_downgrade_rx_active == 0) {
  6639. /* the 8051 reported a dead link as a downgrade */
  6640. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6641. } else if (lwde == 0) {
  6642. /* downgrade is disabled */
  6643. /* bounce if not at starting active width */
  6644. if ((ppd->link_width_active !=
  6645. ppd->link_width_downgrade_tx_active) ||
  6646. (ppd->link_width_active !=
  6647. ppd->link_width_downgrade_rx_active)) {
  6648. dd_dev_err(ppd->dd,
  6649. "Link downgrade is disabled and link has downgraded, downing link\n");
  6650. dd_dev_err(ppd->dd,
  6651. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6652. ppd->link_width_active,
  6653. ppd->link_width_downgrade_tx_active,
  6654. ppd->link_width_downgrade_rx_active);
  6655. do_bounce = 1;
  6656. }
  6657. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6658. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6659. /* Tx or Rx is outside the enabled policy */
  6660. dd_dev_err(ppd->dd,
  6661. "Link is outside of downgrade allowed, downing link\n");
  6662. dd_dev_err(ppd->dd,
  6663. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6664. lwde, ppd->link_width_downgrade_tx_active,
  6665. ppd->link_width_downgrade_rx_active);
  6666. do_bounce = 1;
  6667. }
  6668. done:
  6669. mutex_unlock(&ppd->hls_lock);
  6670. if (do_bounce) {
  6671. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6672. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6673. set_link_state(ppd, HLS_DN_OFFLINE);
  6674. start_link(ppd);
  6675. }
  6676. }
  6677. /*
  6678. * Handle a link downgrade interrupt from the 8051.
  6679. *
  6680. * This is a work-queue function outside of the interrupt.
  6681. */
  6682. void handle_link_downgrade(struct work_struct *work)
  6683. {
  6684. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6685. link_downgrade_work);
  6686. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6687. apply_link_downgrade_policy(ppd, 1);
  6688. }
  6689. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6690. {
  6691. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6692. ARRAY_SIZE(dcc_err_flags));
  6693. }
  6694. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6695. {
  6696. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6697. ARRAY_SIZE(lcb_err_flags));
  6698. }
  6699. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6700. {
  6701. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6702. ARRAY_SIZE(dc8051_err_flags));
  6703. }
  6704. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6705. {
  6706. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6707. ARRAY_SIZE(dc8051_info_err_flags));
  6708. }
  6709. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6710. {
  6711. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6712. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6713. }
  6714. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6715. {
  6716. struct hfi1_pportdata *ppd = dd->pport;
  6717. u64 info, err, host_msg;
  6718. int queue_link_down = 0;
  6719. char buf[96];
  6720. /* look at the flags */
  6721. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6722. /* 8051 information set by firmware */
  6723. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6724. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6725. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6726. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6727. host_msg = (info >>
  6728. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6729. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6730. /*
  6731. * Handle error flags.
  6732. */
  6733. if (err & FAILED_LNI) {
  6734. /*
  6735. * LNI error indications are cleared by the 8051
  6736. * only when starting polling. Only pay attention
  6737. * to them when in the states that occur during
  6738. * LNI.
  6739. */
  6740. if (ppd->host_link_state
  6741. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6742. queue_link_down = 1;
  6743. dd_dev_info(dd, "Link error: %s\n",
  6744. dc8051_info_err_string(buf,
  6745. sizeof(buf),
  6746. err &
  6747. FAILED_LNI));
  6748. }
  6749. err &= ~(u64)FAILED_LNI;
  6750. }
  6751. /* unknown frames can happen durning LNI, just count */
  6752. if (err & UNKNOWN_FRAME) {
  6753. ppd->unknown_frame_count++;
  6754. err &= ~(u64)UNKNOWN_FRAME;
  6755. }
  6756. if (err) {
  6757. /* report remaining errors, but do not do anything */
  6758. dd_dev_err(dd, "8051 info error: %s\n",
  6759. dc8051_info_err_string(buf, sizeof(buf),
  6760. err));
  6761. }
  6762. /*
  6763. * Handle host message flags.
  6764. */
  6765. if (host_msg & HOST_REQ_DONE) {
  6766. /*
  6767. * Presently, the driver does a busy wait for
  6768. * host requests to complete. This is only an
  6769. * informational message.
  6770. * NOTE: The 8051 clears the host message
  6771. * information *on the next 8051 command*.
  6772. * Therefore, when linkup is achieved,
  6773. * this flag will still be set.
  6774. */
  6775. host_msg &= ~(u64)HOST_REQ_DONE;
  6776. }
  6777. if (host_msg & BC_SMA_MSG) {
  6778. queue_work(ppd->link_wq, &ppd->sma_message_work);
  6779. host_msg &= ~(u64)BC_SMA_MSG;
  6780. }
  6781. if (host_msg & LINKUP_ACHIEVED) {
  6782. dd_dev_info(dd, "8051: Link up\n");
  6783. queue_work(ppd->link_wq, &ppd->link_up_work);
  6784. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6785. }
  6786. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6787. handle_8051_request(ppd);
  6788. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6789. }
  6790. if (host_msg & VERIFY_CAP_FRAME) {
  6791. queue_work(ppd->link_wq, &ppd->link_vc_work);
  6792. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6793. }
  6794. if (host_msg & LINK_GOING_DOWN) {
  6795. const char *extra = "";
  6796. /* no downgrade action needed if going down */
  6797. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6798. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6799. extra = " (ignoring downgrade)";
  6800. }
  6801. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6802. queue_link_down = 1;
  6803. host_msg &= ~(u64)LINK_GOING_DOWN;
  6804. }
  6805. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6806. queue_work(ppd->link_wq, &ppd->link_downgrade_work);
  6807. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6808. }
  6809. if (host_msg) {
  6810. /* report remaining messages, but do not do anything */
  6811. dd_dev_info(dd, "8051 info host message: %s\n",
  6812. dc8051_info_host_msg_string(buf,
  6813. sizeof(buf),
  6814. host_msg));
  6815. }
  6816. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6817. }
  6818. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6819. /*
  6820. * Lost the 8051 heartbeat. If this happens, we
  6821. * receive constant interrupts about it. Disable
  6822. * the interrupt after the first.
  6823. */
  6824. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6825. write_csr(dd, DC_DC8051_ERR_EN,
  6826. read_csr(dd, DC_DC8051_ERR_EN) &
  6827. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6828. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6829. }
  6830. if (reg) {
  6831. /* report the error, but do not do anything */
  6832. dd_dev_err(dd, "8051 error: %s\n",
  6833. dc8051_err_string(buf, sizeof(buf), reg));
  6834. }
  6835. if (queue_link_down) {
  6836. /*
  6837. * if the link is already going down or disabled, do not
  6838. * queue another
  6839. */
  6840. if ((ppd->host_link_state &
  6841. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6842. ppd->link_enabled == 0 || ppd->is_link_down_queued) {
  6843. dd_dev_info(dd, "%s: not queuing link down\n",
  6844. __func__);
  6845. } else {
  6846. xchg(&ppd->is_link_down_queued, 1);
  6847. queue_work(ppd->link_wq, &ppd->link_down_work);
  6848. }
  6849. }
  6850. }
  6851. static const char * const fm_config_txt[] = {
  6852. [0] =
  6853. "BadHeadDist: Distance violation between two head flits",
  6854. [1] =
  6855. "BadTailDist: Distance violation between two tail flits",
  6856. [2] =
  6857. "BadCtrlDist: Distance violation between two credit control flits",
  6858. [3] =
  6859. "BadCrdAck: Credits return for unsupported VL",
  6860. [4] =
  6861. "UnsupportedVLMarker: Received VL Marker",
  6862. [5] =
  6863. "BadPreempt: Exceeded the preemption nesting level",
  6864. [6] =
  6865. "BadControlFlit: Received unsupported control flit",
  6866. /* no 7 */
  6867. [8] =
  6868. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6869. };
  6870. static const char * const port_rcv_txt[] = {
  6871. [1] =
  6872. "BadPktLen: Illegal PktLen",
  6873. [2] =
  6874. "PktLenTooLong: Packet longer than PktLen",
  6875. [3] =
  6876. "PktLenTooShort: Packet shorter than PktLen",
  6877. [4] =
  6878. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6879. [5] =
  6880. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6881. [6] =
  6882. "BadL2: Illegal L2 opcode",
  6883. [7] =
  6884. "BadSC: Unsupported SC",
  6885. [9] =
  6886. "BadRC: Illegal RC",
  6887. [11] =
  6888. "PreemptError: Preempting with same VL",
  6889. [12] =
  6890. "PreemptVL15: Preempting a VL15 packet",
  6891. };
  6892. #define OPA_LDR_FMCONFIG_OFFSET 16
  6893. #define OPA_LDR_PORTRCV_OFFSET 0
  6894. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6895. {
  6896. u64 info, hdr0, hdr1;
  6897. const char *extra;
  6898. char buf[96];
  6899. struct hfi1_pportdata *ppd = dd->pport;
  6900. u8 lcl_reason = 0;
  6901. int do_bounce = 0;
  6902. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6903. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6904. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6905. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6906. /* set status bit */
  6907. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6908. }
  6909. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6910. }
  6911. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6912. struct hfi1_pportdata *ppd = dd->pport;
  6913. /* this counter saturates at (2^32) - 1 */
  6914. if (ppd->link_downed < (u32)UINT_MAX)
  6915. ppd->link_downed++;
  6916. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6917. }
  6918. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6919. u8 reason_valid = 1;
  6920. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6921. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6922. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6923. /* set status bit */
  6924. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6925. }
  6926. switch (info) {
  6927. case 0:
  6928. case 1:
  6929. case 2:
  6930. case 3:
  6931. case 4:
  6932. case 5:
  6933. case 6:
  6934. extra = fm_config_txt[info];
  6935. break;
  6936. case 8:
  6937. extra = fm_config_txt[info];
  6938. if (ppd->port_error_action &
  6939. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6940. do_bounce = 1;
  6941. /*
  6942. * lcl_reason cannot be derived from info
  6943. * for this error
  6944. */
  6945. lcl_reason =
  6946. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6947. }
  6948. break;
  6949. default:
  6950. reason_valid = 0;
  6951. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6952. extra = buf;
  6953. break;
  6954. }
  6955. if (reason_valid && !do_bounce) {
  6956. do_bounce = ppd->port_error_action &
  6957. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6958. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  6959. }
  6960. /* just report this */
  6961. dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
  6962. extra);
  6963. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  6964. }
  6965. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  6966. u8 reason_valid = 1;
  6967. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  6968. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  6969. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  6970. if (!(dd->err_info_rcvport.status_and_code &
  6971. OPA_EI_STATUS_SMASK)) {
  6972. dd->err_info_rcvport.status_and_code =
  6973. info & OPA_EI_CODE_SMASK;
  6974. /* set status bit */
  6975. dd->err_info_rcvport.status_and_code |=
  6976. OPA_EI_STATUS_SMASK;
  6977. /*
  6978. * save first 2 flits in the packet that caused
  6979. * the error
  6980. */
  6981. dd->err_info_rcvport.packet_flit1 = hdr0;
  6982. dd->err_info_rcvport.packet_flit2 = hdr1;
  6983. }
  6984. switch (info) {
  6985. case 1:
  6986. case 2:
  6987. case 3:
  6988. case 4:
  6989. case 5:
  6990. case 6:
  6991. case 7:
  6992. case 9:
  6993. case 11:
  6994. case 12:
  6995. extra = port_rcv_txt[info];
  6996. break;
  6997. default:
  6998. reason_valid = 0;
  6999. snprintf(buf, sizeof(buf), "reserved%lld", info);
  7000. extra = buf;
  7001. break;
  7002. }
  7003. if (reason_valid && !do_bounce) {
  7004. do_bounce = ppd->port_error_action &
  7005. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  7006. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  7007. }
  7008. /* just report this */
  7009. dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
  7010. " hdr0 0x%llx, hdr1 0x%llx\n",
  7011. extra, hdr0, hdr1);
  7012. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  7013. }
  7014. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  7015. /* informative only */
  7016. dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
  7017. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  7018. }
  7019. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  7020. /* informative only */
  7021. dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
  7022. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  7023. }
  7024. if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
  7025. reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
  7026. /* report any remaining errors */
  7027. if (reg)
  7028. dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
  7029. dcc_err_string(buf, sizeof(buf), reg));
  7030. if (lcl_reason == 0)
  7031. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  7032. if (do_bounce) {
  7033. dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
  7034. __func__);
  7035. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  7036. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  7037. }
  7038. }
  7039. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  7040. {
  7041. char buf[96];
  7042. dd_dev_info(dd, "LCB Error: %s\n",
  7043. lcb_err_string(buf, sizeof(buf), reg));
  7044. }
  7045. /*
  7046. * CCE block DC interrupt. Source is < 8.
  7047. */
  7048. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  7049. {
  7050. const struct err_reg_info *eri = &dc_errs[source];
  7051. if (eri->handler) {
  7052. interrupt_clear_down(dd, 0, eri);
  7053. } else if (source == 3 /* dc_lbm_int */) {
  7054. /*
  7055. * This indicates that a parity error has occurred on the
  7056. * address/control lines presented to the LBM. The error
  7057. * is a single pulse, there is no associated error flag,
  7058. * and it is non-maskable. This is because if a parity
  7059. * error occurs on the request the request is dropped.
  7060. * This should never occur, but it is nice to know if it
  7061. * ever does.
  7062. */
  7063. dd_dev_err(dd, "Parity error in DC LBM block\n");
  7064. } else {
  7065. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  7066. }
  7067. }
  7068. /*
  7069. * TX block send credit interrupt. Source is < 160.
  7070. */
  7071. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  7072. {
  7073. sc_group_release_update(dd, source);
  7074. }
  7075. /*
  7076. * TX block SDMA interrupt. Source is < 48.
  7077. *
  7078. * SDMA interrupts are grouped by type:
  7079. *
  7080. * 0 - N-1 = SDma
  7081. * N - 2N-1 = SDmaProgress
  7082. * 2N - 3N-1 = SDmaIdle
  7083. */
  7084. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  7085. {
  7086. /* what interrupt */
  7087. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  7088. /* which engine */
  7089. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  7090. #ifdef CONFIG_SDMA_VERBOSITY
  7091. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  7092. slashstrip(__FILE__), __LINE__, __func__);
  7093. sdma_dumpstate(&dd->per_sdma[which]);
  7094. #endif
  7095. if (likely(what < 3 && which < dd->num_sdma)) {
  7096. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  7097. } else {
  7098. /* should not happen */
  7099. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  7100. }
  7101. }
  7102. /*
  7103. * RX block receive available interrupt. Source is < 160.
  7104. */
  7105. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7106. {
  7107. struct hfi1_ctxtdata *rcd;
  7108. char *err_detail;
  7109. if (likely(source < dd->num_rcv_contexts)) {
  7110. rcd = hfi1_rcd_get_by_index(dd, source);
  7111. if (rcd) {
  7112. /* Check for non-user contexts, including vnic */
  7113. if ((source < dd->first_dyn_alloc_ctxt) ||
  7114. (rcd->sc && (rcd->sc->type == SC_KERNEL)))
  7115. rcd->do_interrupt(rcd, 0);
  7116. else
  7117. handle_user_interrupt(rcd);
  7118. hfi1_rcd_put(rcd);
  7119. return; /* OK */
  7120. }
  7121. /* received an interrupt, but no rcd */
  7122. err_detail = "dataless";
  7123. } else {
  7124. /* received an interrupt, but are not using that context */
  7125. err_detail = "out of range";
  7126. }
  7127. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7128. err_detail, source);
  7129. }
  7130. /*
  7131. * RX block receive urgent interrupt. Source is < 160.
  7132. */
  7133. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7134. {
  7135. struct hfi1_ctxtdata *rcd;
  7136. char *err_detail;
  7137. if (likely(source < dd->num_rcv_contexts)) {
  7138. rcd = hfi1_rcd_get_by_index(dd, source);
  7139. if (rcd) {
  7140. /* only pay attention to user urgent interrupts */
  7141. if ((source >= dd->first_dyn_alloc_ctxt) &&
  7142. (!rcd->sc || (rcd->sc->type == SC_USER)))
  7143. handle_user_interrupt(rcd);
  7144. hfi1_rcd_put(rcd);
  7145. return; /* OK */
  7146. }
  7147. /* received an interrupt, but no rcd */
  7148. err_detail = "dataless";
  7149. } else {
  7150. /* received an interrupt, but are not using that context */
  7151. err_detail = "out of range";
  7152. }
  7153. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7154. err_detail, source);
  7155. }
  7156. /*
  7157. * Reserved range interrupt. Should not be called in normal operation.
  7158. */
  7159. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7160. {
  7161. char name[64];
  7162. dd_dev_err(dd, "unexpected %s interrupt\n",
  7163. is_reserved_name(name, sizeof(name), source));
  7164. }
  7165. static const struct is_table is_table[] = {
  7166. /*
  7167. * start end
  7168. * name func interrupt func
  7169. */
  7170. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7171. is_misc_err_name, is_misc_err_int },
  7172. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7173. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7174. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7175. is_sendctxt_err_name, is_sendctxt_err_int },
  7176. { IS_SDMA_START, IS_SDMA_END,
  7177. is_sdma_eng_name, is_sdma_eng_int },
  7178. { IS_VARIOUS_START, IS_VARIOUS_END,
  7179. is_various_name, is_various_int },
  7180. { IS_DC_START, IS_DC_END,
  7181. is_dc_name, is_dc_int },
  7182. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7183. is_rcv_avail_name, is_rcv_avail_int },
  7184. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7185. is_rcv_urgent_name, is_rcv_urgent_int },
  7186. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7187. is_send_credit_name, is_send_credit_int},
  7188. { IS_RESERVED_START, IS_RESERVED_END,
  7189. is_reserved_name, is_reserved_int},
  7190. };
  7191. /*
  7192. * Interrupt source interrupt - called when the given source has an interrupt.
  7193. * Source is a bit index into an array of 64-bit integers.
  7194. */
  7195. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7196. {
  7197. const struct is_table *entry;
  7198. /* avoids a double compare by walking the table in-order */
  7199. for (entry = &is_table[0]; entry->is_name; entry++) {
  7200. if (source < entry->end) {
  7201. trace_hfi1_interrupt(dd, entry, source);
  7202. entry->is_int(dd, source - entry->start);
  7203. return;
  7204. }
  7205. }
  7206. /* fell off the end */
  7207. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7208. }
  7209. /*
  7210. * General interrupt handler. This is able to correctly handle
  7211. * all interrupts in case INTx is used.
  7212. */
  7213. static irqreturn_t general_interrupt(int irq, void *data)
  7214. {
  7215. struct hfi1_devdata *dd = data;
  7216. u64 regs[CCE_NUM_INT_CSRS];
  7217. u32 bit;
  7218. int i;
  7219. this_cpu_inc(*dd->int_counter);
  7220. /* phase 1: scan and clear all handled interrupts */
  7221. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7222. if (dd->gi_mask[i] == 0) {
  7223. regs[i] = 0; /* used later */
  7224. continue;
  7225. }
  7226. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7227. dd->gi_mask[i];
  7228. /* only clear if anything is set */
  7229. if (regs[i])
  7230. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7231. }
  7232. /* phase 2: call the appropriate handler */
  7233. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7234. CCE_NUM_INT_CSRS * 64) {
  7235. is_interrupt(dd, bit);
  7236. }
  7237. return IRQ_HANDLED;
  7238. }
  7239. static irqreturn_t sdma_interrupt(int irq, void *data)
  7240. {
  7241. struct sdma_engine *sde = data;
  7242. struct hfi1_devdata *dd = sde->dd;
  7243. u64 status;
  7244. #ifdef CONFIG_SDMA_VERBOSITY
  7245. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7246. slashstrip(__FILE__), __LINE__, __func__);
  7247. sdma_dumpstate(sde);
  7248. #endif
  7249. this_cpu_inc(*dd->int_counter);
  7250. /* This read_csr is really bad in the hot path */
  7251. status = read_csr(dd,
  7252. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7253. & sde->imask;
  7254. if (likely(status)) {
  7255. /* clear the interrupt(s) */
  7256. write_csr(dd,
  7257. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7258. status);
  7259. /* handle the interrupt(s) */
  7260. sdma_engine_interrupt(sde, status);
  7261. } else {
  7262. dd_dev_err(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7263. sde->this_idx);
  7264. }
  7265. return IRQ_HANDLED;
  7266. }
  7267. /*
  7268. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7269. * to insure that the write completed. This does NOT guarantee that
  7270. * queued DMA writes to memory from the chip are pushed.
  7271. */
  7272. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7273. {
  7274. struct hfi1_devdata *dd = rcd->dd;
  7275. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7276. mmiowb(); /* make sure everything before is written */
  7277. write_csr(dd, addr, rcd->imask);
  7278. /* force the above write on the chip and get a value back */
  7279. (void)read_csr(dd, addr);
  7280. }
  7281. /* force the receive interrupt */
  7282. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7283. {
  7284. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7285. }
  7286. /*
  7287. * Return non-zero if a packet is present.
  7288. *
  7289. * This routine is called when rechecking for packets after the RcvAvail
  7290. * interrupt has been cleared down. First, do a quick check of memory for
  7291. * a packet present. If not found, use an expensive CSR read of the context
  7292. * tail to determine the actual tail. The CSR read is necessary because there
  7293. * is no method to push pending DMAs to memory other than an interrupt and we
  7294. * are trying to determine if we need to force an interrupt.
  7295. */
  7296. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7297. {
  7298. u32 tail;
  7299. int present;
  7300. if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
  7301. present = (rcd->seq_cnt ==
  7302. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7303. else /* is RDMA rtail */
  7304. present = (rcd->head != get_rcvhdrtail(rcd));
  7305. if (present)
  7306. return 1;
  7307. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7308. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7309. return rcd->head != tail;
  7310. }
  7311. /*
  7312. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7313. * This routine will try to handle packets immediately (latency), but if
  7314. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7315. * chip receive interrupt is *not* cleared down until this or the thread (if
  7316. * invoked) is finished. The intent is to avoid extra interrupts while we
  7317. * are processing packets anyway.
  7318. */
  7319. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7320. {
  7321. struct hfi1_ctxtdata *rcd = data;
  7322. struct hfi1_devdata *dd = rcd->dd;
  7323. int disposition;
  7324. int present;
  7325. trace_hfi1_receive_interrupt(dd, rcd);
  7326. this_cpu_inc(*dd->int_counter);
  7327. aspm_ctx_disable(rcd);
  7328. /* receive interrupt remains blocked while processing packets */
  7329. disposition = rcd->do_interrupt(rcd, 0);
  7330. /*
  7331. * Too many packets were seen while processing packets in this
  7332. * IRQ handler. Invoke the handler thread. The receive interrupt
  7333. * remains blocked.
  7334. */
  7335. if (disposition == RCV_PKT_LIMIT)
  7336. return IRQ_WAKE_THREAD;
  7337. /*
  7338. * The packet processor detected no more packets. Clear the receive
  7339. * interrupt and recheck for a packet packet that may have arrived
  7340. * after the previous check and interrupt clear. If a packet arrived,
  7341. * force another interrupt.
  7342. */
  7343. clear_recv_intr(rcd);
  7344. present = check_packet_present(rcd);
  7345. if (present)
  7346. force_recv_intr(rcd);
  7347. return IRQ_HANDLED;
  7348. }
  7349. /*
  7350. * Receive packet thread handler. This expects to be invoked with the
  7351. * receive interrupt still blocked.
  7352. */
  7353. static irqreturn_t receive_context_thread(int irq, void *data)
  7354. {
  7355. struct hfi1_ctxtdata *rcd = data;
  7356. int present;
  7357. /* receive interrupt is still blocked from the IRQ handler */
  7358. (void)rcd->do_interrupt(rcd, 1);
  7359. /*
  7360. * The packet processor will only return if it detected no more
  7361. * packets. Hold IRQs here so we can safely clear the interrupt and
  7362. * recheck for a packet that may have arrived after the previous
  7363. * check and the interrupt clear. If a packet arrived, force another
  7364. * interrupt.
  7365. */
  7366. local_irq_disable();
  7367. clear_recv_intr(rcd);
  7368. present = check_packet_present(rcd);
  7369. if (present)
  7370. force_recv_intr(rcd);
  7371. local_irq_enable();
  7372. return IRQ_HANDLED;
  7373. }
  7374. /* ========================================================================= */
  7375. u32 read_physical_state(struct hfi1_devdata *dd)
  7376. {
  7377. u64 reg;
  7378. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7379. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7380. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7381. }
  7382. u32 read_logical_state(struct hfi1_devdata *dd)
  7383. {
  7384. u64 reg;
  7385. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7386. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7387. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7388. }
  7389. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7390. {
  7391. u64 reg;
  7392. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7393. /* clear current state, set new state */
  7394. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7395. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7396. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7397. }
  7398. /*
  7399. * Use the 8051 to read a LCB CSR.
  7400. */
  7401. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7402. {
  7403. u32 regno;
  7404. int ret;
  7405. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7406. if (acquire_lcb_access(dd, 0) == 0) {
  7407. *data = read_csr(dd, addr);
  7408. release_lcb_access(dd, 0);
  7409. return 0;
  7410. }
  7411. return -EBUSY;
  7412. }
  7413. /* register is an index of LCB registers: (offset - base) / 8 */
  7414. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7415. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7416. if (ret != HCMD_SUCCESS)
  7417. return -EBUSY;
  7418. return 0;
  7419. }
  7420. /*
  7421. * Provide a cache for some of the LCB registers in case the LCB is
  7422. * unavailable.
  7423. * (The LCB is unavailable in certain link states, for example.)
  7424. */
  7425. struct lcb_datum {
  7426. u32 off;
  7427. u64 val;
  7428. };
  7429. static struct lcb_datum lcb_cache[] = {
  7430. { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
  7431. { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
  7432. { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
  7433. };
  7434. static void update_lcb_cache(struct hfi1_devdata *dd)
  7435. {
  7436. int i;
  7437. int ret;
  7438. u64 val;
  7439. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7440. ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
  7441. /* Update if we get good data */
  7442. if (likely(ret != -EBUSY))
  7443. lcb_cache[i].val = val;
  7444. }
  7445. }
  7446. static int read_lcb_cache(u32 off, u64 *val)
  7447. {
  7448. int i;
  7449. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7450. if (lcb_cache[i].off == off) {
  7451. *val = lcb_cache[i].val;
  7452. return 0;
  7453. }
  7454. }
  7455. pr_warn("%s bad offset 0x%x\n", __func__, off);
  7456. return -1;
  7457. }
  7458. /*
  7459. * Read an LCB CSR. Access may not be in host control, so check.
  7460. * Return 0 on success, -EBUSY on failure.
  7461. */
  7462. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7463. {
  7464. struct hfi1_pportdata *ppd = dd->pport;
  7465. /* if up, go through the 8051 for the value */
  7466. if (ppd->host_link_state & HLS_UP)
  7467. return read_lcb_via_8051(dd, addr, data);
  7468. /* if going up or down, check the cache, otherwise, no access */
  7469. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
  7470. if (read_lcb_cache(addr, data))
  7471. return -EBUSY;
  7472. return 0;
  7473. }
  7474. /* otherwise, host has access */
  7475. *data = read_csr(dd, addr);
  7476. return 0;
  7477. }
  7478. /*
  7479. * Use the 8051 to write a LCB CSR.
  7480. */
  7481. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7482. {
  7483. u32 regno;
  7484. int ret;
  7485. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7486. (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
  7487. if (acquire_lcb_access(dd, 0) == 0) {
  7488. write_csr(dd, addr, data);
  7489. release_lcb_access(dd, 0);
  7490. return 0;
  7491. }
  7492. return -EBUSY;
  7493. }
  7494. /* register is an index of LCB registers: (offset - base) / 8 */
  7495. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7496. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7497. if (ret != HCMD_SUCCESS)
  7498. return -EBUSY;
  7499. return 0;
  7500. }
  7501. /*
  7502. * Write an LCB CSR. Access may not be in host control, so check.
  7503. * Return 0 on success, -EBUSY on failure.
  7504. */
  7505. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7506. {
  7507. struct hfi1_pportdata *ppd = dd->pport;
  7508. /* if up, go through the 8051 for the value */
  7509. if (ppd->host_link_state & HLS_UP)
  7510. return write_lcb_via_8051(dd, addr, data);
  7511. /* if going up or down, no access */
  7512. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7513. return -EBUSY;
  7514. /* otherwise, host has access */
  7515. write_csr(dd, addr, data);
  7516. return 0;
  7517. }
  7518. /*
  7519. * Returns:
  7520. * < 0 = Linux error, not able to get access
  7521. * > 0 = 8051 command RETURN_CODE
  7522. */
  7523. static int do_8051_command(
  7524. struct hfi1_devdata *dd,
  7525. u32 type,
  7526. u64 in_data,
  7527. u64 *out_data)
  7528. {
  7529. u64 reg, completed;
  7530. int return_code;
  7531. unsigned long timeout;
  7532. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7533. mutex_lock(&dd->dc8051_lock);
  7534. /* We can't send any commands to the 8051 if it's in reset */
  7535. if (dd->dc_shutdown) {
  7536. return_code = -ENODEV;
  7537. goto fail;
  7538. }
  7539. /*
  7540. * If an 8051 host command timed out previously, then the 8051 is
  7541. * stuck.
  7542. *
  7543. * On first timeout, attempt to reset and restart the entire DC
  7544. * block (including 8051). (Is this too big of a hammer?)
  7545. *
  7546. * If the 8051 times out a second time, the reset did not bring it
  7547. * back to healthy life. In that case, fail any subsequent commands.
  7548. */
  7549. if (dd->dc8051_timed_out) {
  7550. if (dd->dc8051_timed_out > 1) {
  7551. dd_dev_err(dd,
  7552. "Previous 8051 host command timed out, skipping command %u\n",
  7553. type);
  7554. return_code = -ENXIO;
  7555. goto fail;
  7556. }
  7557. _dc_shutdown(dd);
  7558. _dc_start(dd);
  7559. }
  7560. /*
  7561. * If there is no timeout, then the 8051 command interface is
  7562. * waiting for a command.
  7563. */
  7564. /*
  7565. * When writing a LCB CSR, out_data contains the full value to
  7566. * to be written, while in_data contains the relative LCB
  7567. * address in 7:0. Do the work here, rather than the caller,
  7568. * of distrubting the write data to where it needs to go:
  7569. *
  7570. * Write data
  7571. * 39:00 -> in_data[47:8]
  7572. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7573. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7574. */
  7575. if (type == HCMD_WRITE_LCB_CSR) {
  7576. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7577. /* must preserve COMPLETED - it is tied to hardware */
  7578. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
  7579. reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
  7580. reg |= ((((*out_data) >> 40) & 0xff) <<
  7581. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7582. | ((((*out_data) >> 48) & 0xffff) <<
  7583. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7584. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7585. }
  7586. /*
  7587. * Do two writes: the first to stabilize the type and req_data, the
  7588. * second to activate.
  7589. */
  7590. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7591. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7592. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7593. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7594. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7595. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7596. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7597. /* wait for completion, alternate: interrupt */
  7598. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7599. while (1) {
  7600. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7601. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7602. if (completed)
  7603. break;
  7604. if (time_after(jiffies, timeout)) {
  7605. dd->dc8051_timed_out++;
  7606. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7607. if (out_data)
  7608. *out_data = 0;
  7609. return_code = -ETIMEDOUT;
  7610. goto fail;
  7611. }
  7612. udelay(2);
  7613. }
  7614. if (out_data) {
  7615. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7616. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7617. if (type == HCMD_READ_LCB_CSR) {
  7618. /* top 16 bits are in a different register */
  7619. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7620. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7621. << (48
  7622. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7623. }
  7624. }
  7625. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7626. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7627. dd->dc8051_timed_out = 0;
  7628. /*
  7629. * Clear command for next user.
  7630. */
  7631. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7632. fail:
  7633. mutex_unlock(&dd->dc8051_lock);
  7634. return return_code;
  7635. }
  7636. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7637. {
  7638. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7639. }
  7640. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7641. u8 lane_id, u32 config_data)
  7642. {
  7643. u64 data;
  7644. int ret;
  7645. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7646. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7647. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7648. ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7649. if (ret != HCMD_SUCCESS) {
  7650. dd_dev_err(dd,
  7651. "load 8051 config: field id %d, lane %d, err %d\n",
  7652. (int)field_id, (int)lane_id, ret);
  7653. }
  7654. return ret;
  7655. }
  7656. /*
  7657. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7658. * set the result, even on error.
  7659. * Return 0 on success, -errno on failure
  7660. */
  7661. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7662. u32 *result)
  7663. {
  7664. u64 big_data;
  7665. u32 addr;
  7666. int ret;
  7667. /* address start depends on the lane_id */
  7668. if (lane_id < 4)
  7669. addr = (4 * NUM_GENERAL_FIELDS)
  7670. + (lane_id * 4 * NUM_LANE_FIELDS);
  7671. else
  7672. addr = 0;
  7673. addr += field_id * 4;
  7674. /* read is in 8-byte chunks, hardware will truncate the address down */
  7675. ret = read_8051_data(dd, addr, 8, &big_data);
  7676. if (ret == 0) {
  7677. /* extract the 4 bytes we want */
  7678. if (addr & 0x4)
  7679. *result = (u32)(big_data >> 32);
  7680. else
  7681. *result = (u32)big_data;
  7682. } else {
  7683. *result = 0;
  7684. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7685. __func__, lane_id, field_id);
  7686. }
  7687. return ret;
  7688. }
  7689. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7690. u8 continuous)
  7691. {
  7692. u32 frame;
  7693. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7694. | power_management << POWER_MANAGEMENT_SHIFT;
  7695. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7696. GENERAL_CONFIG, frame);
  7697. }
  7698. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7699. u16 vl15buf, u8 crc_sizes)
  7700. {
  7701. u32 frame;
  7702. frame = (u32)vau << VAU_SHIFT
  7703. | (u32)z << Z_SHIFT
  7704. | (u32)vcu << VCU_SHIFT
  7705. | (u32)vl15buf << VL15BUF_SHIFT
  7706. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7707. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7708. GENERAL_CONFIG, frame);
  7709. }
  7710. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  7711. u8 *flag_bits, u16 *link_widths)
  7712. {
  7713. u32 frame;
  7714. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7715. &frame);
  7716. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7717. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7718. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7719. }
  7720. static int write_vc_local_link_width(struct hfi1_devdata *dd,
  7721. u8 misc_bits,
  7722. u8 flag_bits,
  7723. u16 link_widths)
  7724. {
  7725. u32 frame;
  7726. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7727. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7728. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7729. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7730. frame);
  7731. }
  7732. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7733. u8 device_rev)
  7734. {
  7735. u32 frame;
  7736. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7737. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7738. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7739. }
  7740. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7741. u8 *device_rev)
  7742. {
  7743. u32 frame;
  7744. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7745. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7746. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7747. & REMOTE_DEVICE_REV_MASK;
  7748. }
  7749. int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
  7750. {
  7751. u32 frame;
  7752. u32 mask;
  7753. mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
  7754. read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
  7755. /* Clear, then set field */
  7756. frame &= ~mask;
  7757. frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
  7758. return load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
  7759. frame);
  7760. }
  7761. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
  7762. u8 *ver_patch)
  7763. {
  7764. u32 frame;
  7765. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7766. *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
  7767. STS_FM_VERSION_MAJOR_MASK;
  7768. *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
  7769. STS_FM_VERSION_MINOR_MASK;
  7770. read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
  7771. *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
  7772. STS_FM_VERSION_PATCH_MASK;
  7773. }
  7774. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7775. u8 *continuous)
  7776. {
  7777. u32 frame;
  7778. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7779. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7780. & POWER_MANAGEMENT_MASK;
  7781. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7782. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7783. }
  7784. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7785. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7786. {
  7787. u32 frame;
  7788. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7789. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7790. *z = (frame >> Z_SHIFT) & Z_MASK;
  7791. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7792. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7793. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7794. }
  7795. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7796. u8 *remote_tx_rate,
  7797. u16 *link_widths)
  7798. {
  7799. u32 frame;
  7800. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7801. &frame);
  7802. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7803. & REMOTE_TX_RATE_MASK;
  7804. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7805. }
  7806. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7807. {
  7808. u32 frame;
  7809. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7810. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7811. }
  7812. static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed)
  7813. {
  7814. u32 frame;
  7815. read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
  7816. *mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT) & MGMT_ALLOWED_MASK;
  7817. }
  7818. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7819. {
  7820. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7821. }
  7822. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7823. {
  7824. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7825. }
  7826. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7827. {
  7828. u32 frame;
  7829. int ret;
  7830. *link_quality = 0;
  7831. if (dd->pport->host_link_state & HLS_UP) {
  7832. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7833. &frame);
  7834. if (ret == 0)
  7835. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7836. & LINK_QUALITY_MASK;
  7837. }
  7838. }
  7839. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7840. {
  7841. u32 frame;
  7842. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7843. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7844. }
  7845. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7846. {
  7847. u32 frame;
  7848. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7849. *ldr = (frame & 0xff);
  7850. }
  7851. static int read_tx_settings(struct hfi1_devdata *dd,
  7852. u8 *enable_lane_tx,
  7853. u8 *tx_polarity_inversion,
  7854. u8 *rx_polarity_inversion,
  7855. u8 *max_rate)
  7856. {
  7857. u32 frame;
  7858. int ret;
  7859. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7860. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7861. & ENABLE_LANE_TX_MASK;
  7862. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7863. & TX_POLARITY_INVERSION_MASK;
  7864. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7865. & RX_POLARITY_INVERSION_MASK;
  7866. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7867. return ret;
  7868. }
  7869. static int write_tx_settings(struct hfi1_devdata *dd,
  7870. u8 enable_lane_tx,
  7871. u8 tx_polarity_inversion,
  7872. u8 rx_polarity_inversion,
  7873. u8 max_rate)
  7874. {
  7875. u32 frame;
  7876. /* no need to mask, all variable sizes match field widths */
  7877. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7878. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7879. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7880. | max_rate << MAX_RATE_SHIFT;
  7881. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7882. }
  7883. /*
  7884. * Read an idle LCB message.
  7885. *
  7886. * Returns 0 on success, -EINVAL on error
  7887. */
  7888. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7889. {
  7890. int ret;
  7891. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7892. if (ret != HCMD_SUCCESS) {
  7893. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7894. (u32)type, ret);
  7895. return -EINVAL;
  7896. }
  7897. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7898. /* return only the payload as we already know the type */
  7899. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7900. return 0;
  7901. }
  7902. /*
  7903. * Read an idle SMA message. To be done in response to a notification from
  7904. * the 8051.
  7905. *
  7906. * Returns 0 on success, -EINVAL on error
  7907. */
  7908. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7909. {
  7910. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7911. data);
  7912. }
  7913. /*
  7914. * Send an idle LCB message.
  7915. *
  7916. * Returns 0 on success, -EINVAL on error
  7917. */
  7918. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7919. {
  7920. int ret;
  7921. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7922. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7923. if (ret != HCMD_SUCCESS) {
  7924. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7925. data, ret);
  7926. return -EINVAL;
  7927. }
  7928. return 0;
  7929. }
  7930. /*
  7931. * Send an idle SMA message.
  7932. *
  7933. * Returns 0 on success, -EINVAL on error
  7934. */
  7935. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7936. {
  7937. u64 data;
  7938. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7939. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7940. return send_idle_message(dd, data);
  7941. }
  7942. /*
  7943. * Initialize the LCB then do a quick link up. This may or may not be
  7944. * in loopback.
  7945. *
  7946. * return 0 on success, -errno on error
  7947. */
  7948. static int do_quick_linkup(struct hfi1_devdata *dd)
  7949. {
  7950. int ret;
  7951. lcb_shutdown(dd, 0);
  7952. if (loopback) {
  7953. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7954. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7955. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  7956. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  7957. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  7958. }
  7959. /* start the LCBs */
  7960. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  7961. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  7962. /* simulator only loopback steps */
  7963. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7964. /* LCB_CFG_RUN.EN = 1 */
  7965. write_csr(dd, DC_LCB_CFG_RUN,
  7966. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  7967. ret = wait_link_transfer_active(dd, 10);
  7968. if (ret)
  7969. return ret;
  7970. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  7971. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  7972. }
  7973. if (!loopback) {
  7974. /*
  7975. * When doing quick linkup and not in loopback, both
  7976. * sides must be done with LCB set-up before either
  7977. * starts the quick linkup. Put a delay here so that
  7978. * both sides can be started and have a chance to be
  7979. * done with LCB set up before resuming.
  7980. */
  7981. dd_dev_err(dd,
  7982. "Pausing for peer to be finished with LCB set up\n");
  7983. msleep(5000);
  7984. dd_dev_err(dd, "Continuing with quick linkup\n");
  7985. }
  7986. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  7987. set_8051_lcb_access(dd);
  7988. /*
  7989. * State "quick" LinkUp request sets the physical link state to
  7990. * LinkUp without a verify capability sequence.
  7991. * This state is in simulator v37 and later.
  7992. */
  7993. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  7994. if (ret != HCMD_SUCCESS) {
  7995. dd_dev_err(dd,
  7996. "%s: set physical link state to quick LinkUp failed with return %d\n",
  7997. __func__, ret);
  7998. set_host_lcb_access(dd);
  7999. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8000. if (ret >= 0)
  8001. ret = -EINVAL;
  8002. return ret;
  8003. }
  8004. return 0; /* success */
  8005. }
  8006. /*
  8007. * Set the SerDes to internal loopback mode.
  8008. * Returns 0 on success, -errno on error.
  8009. */
  8010. static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
  8011. {
  8012. int ret;
  8013. ret = set_physical_link_state(dd, PLS_INTERNAL_SERDES_LOOPBACK);
  8014. if (ret == HCMD_SUCCESS)
  8015. return 0;
  8016. dd_dev_err(dd,
  8017. "Set physical link state to SerDes Loopback failed with return %d\n",
  8018. ret);
  8019. if (ret >= 0)
  8020. ret = -EINVAL;
  8021. return ret;
  8022. }
  8023. /*
  8024. * Do all special steps to set up loopback.
  8025. */
  8026. static int init_loopback(struct hfi1_devdata *dd)
  8027. {
  8028. dd_dev_info(dd, "Entering loopback mode\n");
  8029. /* all loopbacks should disable self GUID check */
  8030. write_csr(dd, DC_DC8051_CFG_MODE,
  8031. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  8032. /*
  8033. * The simulator has only one loopback option - LCB. Switch
  8034. * to that option, which includes quick link up.
  8035. *
  8036. * Accept all valid loopback values.
  8037. */
  8038. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  8039. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  8040. loopback == LOOPBACK_CABLE)) {
  8041. loopback = LOOPBACK_LCB;
  8042. quick_linkup = 1;
  8043. return 0;
  8044. }
  8045. /* handle serdes loopback */
  8046. if (loopback == LOOPBACK_SERDES) {
  8047. /* internal serdes loopack needs quick linkup on RTL */
  8048. if (dd->icode == ICODE_RTL_SILICON)
  8049. quick_linkup = 1;
  8050. return set_serdes_loopback_mode(dd);
  8051. }
  8052. /* LCB loopback - handled at poll time */
  8053. if (loopback == LOOPBACK_LCB) {
  8054. quick_linkup = 1; /* LCB is always quick linkup */
  8055. /* not supported in emulation due to emulation RTL changes */
  8056. if (dd->icode == ICODE_FPGA_EMULATION) {
  8057. dd_dev_err(dd,
  8058. "LCB loopback not supported in emulation\n");
  8059. return -EINVAL;
  8060. }
  8061. return 0;
  8062. }
  8063. /* external cable loopback requires no extra steps */
  8064. if (loopback == LOOPBACK_CABLE)
  8065. return 0;
  8066. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  8067. return -EINVAL;
  8068. }
  8069. /*
  8070. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  8071. * used in the Verify Capability link width attribute.
  8072. */
  8073. static u16 opa_to_vc_link_widths(u16 opa_widths)
  8074. {
  8075. int i;
  8076. u16 result = 0;
  8077. static const struct link_bits {
  8078. u16 from;
  8079. u16 to;
  8080. } opa_link_xlate[] = {
  8081. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  8082. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  8083. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  8084. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  8085. };
  8086. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  8087. if (opa_widths & opa_link_xlate[i].from)
  8088. result |= opa_link_xlate[i].to;
  8089. }
  8090. return result;
  8091. }
  8092. /*
  8093. * Set link attributes before moving to polling.
  8094. */
  8095. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  8096. {
  8097. struct hfi1_devdata *dd = ppd->dd;
  8098. u8 enable_lane_tx;
  8099. u8 tx_polarity_inversion;
  8100. u8 rx_polarity_inversion;
  8101. int ret;
  8102. /* reset our fabric serdes to clear any lingering problems */
  8103. fabric_serdes_reset(dd);
  8104. /* set the local tx rate - need to read-modify-write */
  8105. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  8106. &rx_polarity_inversion, &ppd->local_tx_rate);
  8107. if (ret)
  8108. goto set_local_link_attributes_fail;
  8109. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  8110. /* set the tx rate to the fastest enabled */
  8111. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8112. ppd->local_tx_rate = 1;
  8113. else
  8114. ppd->local_tx_rate = 0;
  8115. } else {
  8116. /* set the tx rate to all enabled */
  8117. ppd->local_tx_rate = 0;
  8118. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8119. ppd->local_tx_rate |= 2;
  8120. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  8121. ppd->local_tx_rate |= 1;
  8122. }
  8123. enable_lane_tx = 0xF; /* enable all four lanes */
  8124. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  8125. rx_polarity_inversion, ppd->local_tx_rate);
  8126. if (ret != HCMD_SUCCESS)
  8127. goto set_local_link_attributes_fail;
  8128. /*
  8129. * DC supports continuous updates.
  8130. */
  8131. ret = write_vc_local_phy(dd,
  8132. 0 /* no power management */,
  8133. 1 /* continuous updates */);
  8134. if (ret != HCMD_SUCCESS)
  8135. goto set_local_link_attributes_fail;
  8136. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  8137. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  8138. ppd->port_crc_mode_enabled);
  8139. if (ret != HCMD_SUCCESS)
  8140. goto set_local_link_attributes_fail;
  8141. ret = write_vc_local_link_width(dd, 0, 0,
  8142. opa_to_vc_link_widths(
  8143. ppd->link_width_enabled));
  8144. if (ret != HCMD_SUCCESS)
  8145. goto set_local_link_attributes_fail;
  8146. /* let peer know who we are */
  8147. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  8148. if (ret == HCMD_SUCCESS)
  8149. return 0;
  8150. set_local_link_attributes_fail:
  8151. dd_dev_err(dd,
  8152. "Failed to set local link attributes, return 0x%x\n",
  8153. ret);
  8154. return ret;
  8155. }
  8156. /*
  8157. * Call this to start the link.
  8158. * Do not do anything if the link is disabled.
  8159. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8160. */
  8161. int start_link(struct hfi1_pportdata *ppd)
  8162. {
  8163. /*
  8164. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8165. * error rate. Needs to be done before starting the link.
  8166. */
  8167. tune_serdes(ppd);
  8168. if (!ppd->driver_link_ready) {
  8169. dd_dev_info(ppd->dd,
  8170. "%s: stopping link start because driver is not ready\n",
  8171. __func__);
  8172. return 0;
  8173. }
  8174. /*
  8175. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8176. * pkey table can be configured properly if the HFI unit is connected
  8177. * to switch port with MgmtAllowed=NO
  8178. */
  8179. clear_full_mgmt_pkey(ppd);
  8180. return set_link_state(ppd, HLS_DN_POLL);
  8181. }
  8182. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8183. {
  8184. struct hfi1_devdata *dd = ppd->dd;
  8185. u64 mask;
  8186. unsigned long timeout;
  8187. /*
  8188. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8189. * effect of power up on plug-in. We ignore this false positive
  8190. * interrupt until the module has finished powering up by waiting for
  8191. * a minimum timeout of the module inrush initialization time of
  8192. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8193. * module have stabilized.
  8194. */
  8195. msleep(500);
  8196. /*
  8197. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8198. */
  8199. timeout = jiffies + msecs_to_jiffies(2000);
  8200. while (1) {
  8201. mask = read_csr(dd, dd->hfi1_id ?
  8202. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8203. if (!(mask & QSFP_HFI0_INT_N))
  8204. break;
  8205. if (time_after(jiffies, timeout)) {
  8206. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8207. __func__);
  8208. break;
  8209. }
  8210. udelay(2);
  8211. }
  8212. }
  8213. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8214. {
  8215. struct hfi1_devdata *dd = ppd->dd;
  8216. u64 mask;
  8217. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8218. if (enable) {
  8219. /*
  8220. * Clear the status register to avoid an immediate interrupt
  8221. * when we re-enable the IntN pin
  8222. */
  8223. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8224. QSFP_HFI0_INT_N);
  8225. mask |= (u64)QSFP_HFI0_INT_N;
  8226. } else {
  8227. mask &= ~(u64)QSFP_HFI0_INT_N;
  8228. }
  8229. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8230. }
  8231. void reset_qsfp(struct hfi1_pportdata *ppd)
  8232. {
  8233. struct hfi1_devdata *dd = ppd->dd;
  8234. u64 mask, qsfp_mask;
  8235. /* Disable INT_N from triggering QSFP interrupts */
  8236. set_qsfp_int_n(ppd, 0);
  8237. /* Reset the QSFP */
  8238. mask = (u64)QSFP_HFI0_RESET_N;
  8239. qsfp_mask = read_csr(dd,
  8240. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8241. qsfp_mask &= ~mask;
  8242. write_csr(dd,
  8243. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8244. udelay(10);
  8245. qsfp_mask |= mask;
  8246. write_csr(dd,
  8247. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8248. wait_for_qsfp_init(ppd);
  8249. /*
  8250. * Allow INT_N to trigger the QSFP interrupt to watch
  8251. * for alarms and warnings
  8252. */
  8253. set_qsfp_int_n(ppd, 1);
  8254. }
  8255. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8256. u8 *qsfp_interrupt_status)
  8257. {
  8258. struct hfi1_devdata *dd = ppd->dd;
  8259. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8260. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8261. dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
  8262. __func__);
  8263. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8264. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8265. dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
  8266. __func__);
  8267. /*
  8268. * The remaining alarms/warnings don't matter if the link is down.
  8269. */
  8270. if (ppd->host_link_state & HLS_DOWN)
  8271. return 0;
  8272. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8273. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8274. dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
  8275. __func__);
  8276. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8277. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8278. dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
  8279. __func__);
  8280. /* Byte 2 is vendor specific */
  8281. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8282. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8283. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
  8284. __func__);
  8285. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8286. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8287. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
  8288. __func__);
  8289. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8290. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8291. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
  8292. __func__);
  8293. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8294. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8295. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
  8296. __func__);
  8297. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8298. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8299. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8300. __func__);
  8301. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8302. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8303. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8304. __func__);
  8305. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8306. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8307. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8308. __func__);
  8309. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8310. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8311. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8312. __func__);
  8313. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8314. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8315. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
  8316. __func__);
  8317. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8318. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8319. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
  8320. __func__);
  8321. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8322. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8323. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
  8324. __func__);
  8325. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8326. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8327. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
  8328. __func__);
  8329. /* Bytes 9-10 and 11-12 are reserved */
  8330. /* Bytes 13-15 are vendor specific */
  8331. return 0;
  8332. }
  8333. /* This routine will only be scheduled if the QSFP module present is asserted */
  8334. void qsfp_event(struct work_struct *work)
  8335. {
  8336. struct qsfp_data *qd;
  8337. struct hfi1_pportdata *ppd;
  8338. struct hfi1_devdata *dd;
  8339. qd = container_of(work, struct qsfp_data, qsfp_work);
  8340. ppd = qd->ppd;
  8341. dd = ppd->dd;
  8342. /* Sanity check */
  8343. if (!qsfp_mod_present(ppd))
  8344. return;
  8345. if (ppd->host_link_state == HLS_DN_DISABLE) {
  8346. dd_dev_info(ppd->dd,
  8347. "%s: stopping link start because link is disabled\n",
  8348. __func__);
  8349. return;
  8350. }
  8351. /*
  8352. * Turn DC back on after cable has been re-inserted. Up until
  8353. * now, the DC has been in reset to save power.
  8354. */
  8355. dc_start(dd);
  8356. if (qd->cache_refresh_required) {
  8357. set_qsfp_int_n(ppd, 0);
  8358. wait_for_qsfp_init(ppd);
  8359. /*
  8360. * Allow INT_N to trigger the QSFP interrupt to watch
  8361. * for alarms and warnings
  8362. */
  8363. set_qsfp_int_n(ppd, 1);
  8364. start_link(ppd);
  8365. }
  8366. if (qd->check_interrupt_flags) {
  8367. u8 qsfp_interrupt_status[16] = {0,};
  8368. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8369. &qsfp_interrupt_status[0], 16) != 16) {
  8370. dd_dev_info(dd,
  8371. "%s: Failed to read status of QSFP module\n",
  8372. __func__);
  8373. } else {
  8374. unsigned long flags;
  8375. handle_qsfp_error_conditions(
  8376. ppd, qsfp_interrupt_status);
  8377. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8378. ppd->qsfp_info.check_interrupt_flags = 0;
  8379. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8380. flags);
  8381. }
  8382. }
  8383. }
  8384. static void init_qsfp_int(struct hfi1_devdata *dd)
  8385. {
  8386. struct hfi1_pportdata *ppd = dd->pport;
  8387. u64 qsfp_mask, cce_int_mask;
  8388. const int qsfp1_int_smask = QSFP1_INT % 64;
  8389. const int qsfp2_int_smask = QSFP2_INT % 64;
  8390. /*
  8391. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8392. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8393. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8394. * the index of the appropriate CSR in the CCEIntMask CSR array
  8395. */
  8396. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8397. (8 * (QSFP1_INT / 64)));
  8398. if (dd->hfi1_id) {
  8399. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8400. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8401. cce_int_mask);
  8402. } else {
  8403. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8404. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8405. cce_int_mask);
  8406. }
  8407. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8408. /* Clear current status to avoid spurious interrupts */
  8409. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8410. qsfp_mask);
  8411. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8412. qsfp_mask);
  8413. set_qsfp_int_n(ppd, 0);
  8414. /* Handle active low nature of INT_N and MODPRST_N pins */
  8415. if (qsfp_mod_present(ppd))
  8416. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8417. write_csr(dd,
  8418. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8419. qsfp_mask);
  8420. }
  8421. /*
  8422. * Do a one-time initialize of the LCB block.
  8423. */
  8424. static void init_lcb(struct hfi1_devdata *dd)
  8425. {
  8426. /* simulator does not correctly handle LCB cclk loopback, skip */
  8427. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8428. return;
  8429. /* the DC has been reset earlier in the driver load */
  8430. /* set LCB for cclk loopback on the port */
  8431. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8432. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8433. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8434. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8435. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8436. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8437. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8438. }
  8439. /*
  8440. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8441. * on error.
  8442. */
  8443. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8444. {
  8445. int ret;
  8446. u8 status;
  8447. /*
  8448. * Report success if not a QSFP or, if it is a QSFP, but the cable is
  8449. * not present
  8450. */
  8451. if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
  8452. return 0;
  8453. /* read byte 2, the status byte */
  8454. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8455. if (ret < 0)
  8456. return ret;
  8457. if (ret != 1)
  8458. return -EIO;
  8459. return 0; /* success */
  8460. }
  8461. /*
  8462. * Values for QSFP retry.
  8463. *
  8464. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8465. * arrived at from experience on a large cluster.
  8466. */
  8467. #define MAX_QSFP_RETRIES 20
  8468. #define QSFP_RETRY_WAIT 500 /* msec */
  8469. /*
  8470. * Try a QSFP read. If it fails, schedule a retry for later.
  8471. * Called on first link activation after driver load.
  8472. */
  8473. static void try_start_link(struct hfi1_pportdata *ppd)
  8474. {
  8475. if (test_qsfp_read(ppd)) {
  8476. /* read failed */
  8477. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8478. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8479. return;
  8480. }
  8481. dd_dev_info(ppd->dd,
  8482. "QSFP not responding, waiting and retrying %d\n",
  8483. (int)ppd->qsfp_retry_count);
  8484. ppd->qsfp_retry_count++;
  8485. queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
  8486. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8487. return;
  8488. }
  8489. ppd->qsfp_retry_count = 0;
  8490. start_link(ppd);
  8491. }
  8492. /*
  8493. * Workqueue function to start the link after a delay.
  8494. */
  8495. void handle_start_link(struct work_struct *work)
  8496. {
  8497. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8498. start_link_work.work);
  8499. try_start_link(ppd);
  8500. }
  8501. int bringup_serdes(struct hfi1_pportdata *ppd)
  8502. {
  8503. struct hfi1_devdata *dd = ppd->dd;
  8504. u64 guid;
  8505. int ret;
  8506. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8507. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8508. guid = ppd->guids[HFI1_PORT_GUID_INDEX];
  8509. if (!guid) {
  8510. if (dd->base_guid)
  8511. guid = dd->base_guid + ppd->port - 1;
  8512. ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
  8513. }
  8514. /* Set linkinit_reason on power up per OPA spec */
  8515. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8516. /* one-time init of the LCB */
  8517. init_lcb(dd);
  8518. if (loopback) {
  8519. ret = init_loopback(dd);
  8520. if (ret < 0)
  8521. return ret;
  8522. }
  8523. get_port_type(ppd);
  8524. if (ppd->port_type == PORT_TYPE_QSFP) {
  8525. set_qsfp_int_n(ppd, 0);
  8526. wait_for_qsfp_init(ppd);
  8527. set_qsfp_int_n(ppd, 1);
  8528. }
  8529. try_start_link(ppd);
  8530. return 0;
  8531. }
  8532. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8533. {
  8534. struct hfi1_devdata *dd = ppd->dd;
  8535. /*
  8536. * Shut down the link and keep it down. First turn off that the
  8537. * driver wants to allow the link to be up (driver_link_ready).
  8538. * Then make sure the link is not automatically restarted
  8539. * (link_enabled). Cancel any pending restart. And finally
  8540. * go offline.
  8541. */
  8542. ppd->driver_link_ready = 0;
  8543. ppd->link_enabled = 0;
  8544. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8545. flush_delayed_work(&ppd->start_link_work);
  8546. cancel_delayed_work_sync(&ppd->start_link_work);
  8547. ppd->offline_disabled_reason =
  8548. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
  8549. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
  8550. OPA_LINKDOWN_REASON_SMA_DISABLED);
  8551. set_link_state(ppd, HLS_DN_OFFLINE);
  8552. /* disable the port */
  8553. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8554. }
  8555. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8556. {
  8557. struct hfi1_pportdata *ppd;
  8558. int i;
  8559. ppd = (struct hfi1_pportdata *)(dd + 1);
  8560. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8561. ppd->ibport_data.rvp.rc_acks = NULL;
  8562. ppd->ibport_data.rvp.rc_qacks = NULL;
  8563. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8564. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8565. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8566. if (!ppd->ibport_data.rvp.rc_acks ||
  8567. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8568. !ppd->ibport_data.rvp.rc_qacks)
  8569. return -ENOMEM;
  8570. }
  8571. return 0;
  8572. }
  8573. /*
  8574. * index is the index into the receive array
  8575. */
  8576. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8577. u32 type, unsigned long pa, u16 order)
  8578. {
  8579. u64 reg;
  8580. if (!(dd->flags & HFI1_PRESENT))
  8581. goto done;
  8582. if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
  8583. pa = 0;
  8584. order = 0;
  8585. } else if (type > PT_INVALID) {
  8586. dd_dev_err(dd,
  8587. "unexpected receive array type %u for index %u, not handled\n",
  8588. type, index);
  8589. goto done;
  8590. }
  8591. trace_hfi1_put_tid(dd, index, type, pa, order);
  8592. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8593. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8594. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8595. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8596. << RCV_ARRAY_RT_ADDR_SHIFT;
  8597. trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
  8598. writeq(reg, dd->rcvarray_wc + (index * 8));
  8599. if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
  8600. /*
  8601. * Eager entries are written and flushed
  8602. *
  8603. * Expected entries are flushed every 4 writes
  8604. */
  8605. flush_wc();
  8606. done:
  8607. return;
  8608. }
  8609. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8610. {
  8611. struct hfi1_devdata *dd = rcd->dd;
  8612. u32 i;
  8613. /* this could be optimized */
  8614. for (i = rcd->eager_base; i < rcd->eager_base +
  8615. rcd->egrbufs.alloced; i++)
  8616. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8617. for (i = rcd->expected_base;
  8618. i < rcd->expected_base + rcd->expected_count; i++)
  8619. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8620. }
  8621. static const char * const ib_cfg_name_strings[] = {
  8622. "HFI1_IB_CFG_LIDLMC",
  8623. "HFI1_IB_CFG_LWID_DG_ENB",
  8624. "HFI1_IB_CFG_LWID_ENB",
  8625. "HFI1_IB_CFG_LWID",
  8626. "HFI1_IB_CFG_SPD_ENB",
  8627. "HFI1_IB_CFG_SPD",
  8628. "HFI1_IB_CFG_RXPOL_ENB",
  8629. "HFI1_IB_CFG_LREV_ENB",
  8630. "HFI1_IB_CFG_LINKLATENCY",
  8631. "HFI1_IB_CFG_HRTBT",
  8632. "HFI1_IB_CFG_OP_VLS",
  8633. "HFI1_IB_CFG_VL_HIGH_CAP",
  8634. "HFI1_IB_CFG_VL_LOW_CAP",
  8635. "HFI1_IB_CFG_OVERRUN_THRESH",
  8636. "HFI1_IB_CFG_PHYERR_THRESH",
  8637. "HFI1_IB_CFG_LINKDEFAULT",
  8638. "HFI1_IB_CFG_PKEYS",
  8639. "HFI1_IB_CFG_MTU",
  8640. "HFI1_IB_CFG_LSTATE",
  8641. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8642. "HFI1_IB_CFG_PMA_TICKS",
  8643. "HFI1_IB_CFG_PORT"
  8644. };
  8645. static const char *ib_cfg_name(int which)
  8646. {
  8647. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8648. return "invalid";
  8649. return ib_cfg_name_strings[which];
  8650. }
  8651. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8652. {
  8653. struct hfi1_devdata *dd = ppd->dd;
  8654. int val = 0;
  8655. switch (which) {
  8656. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8657. val = ppd->link_width_enabled;
  8658. break;
  8659. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8660. val = ppd->link_width_active;
  8661. break;
  8662. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8663. val = ppd->link_speed_enabled;
  8664. break;
  8665. case HFI1_IB_CFG_SPD: /* current Link speed */
  8666. val = ppd->link_speed_active;
  8667. break;
  8668. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8669. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8670. case HFI1_IB_CFG_LINKLATENCY:
  8671. goto unimplemented;
  8672. case HFI1_IB_CFG_OP_VLS:
  8673. val = ppd->vls_operational;
  8674. break;
  8675. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8676. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8677. break;
  8678. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8679. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8680. break;
  8681. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8682. val = ppd->overrun_threshold;
  8683. break;
  8684. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8685. val = ppd->phy_error_threshold;
  8686. break;
  8687. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8688. val = dd->link_default;
  8689. break;
  8690. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8691. case HFI1_IB_CFG_PMA_TICKS:
  8692. default:
  8693. unimplemented:
  8694. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8695. dd_dev_info(
  8696. dd,
  8697. "%s: which %s: not implemented\n",
  8698. __func__,
  8699. ib_cfg_name(which));
  8700. break;
  8701. }
  8702. return val;
  8703. }
  8704. /*
  8705. * The largest MAD packet size.
  8706. */
  8707. #define MAX_MAD_PACKET 2048
  8708. /*
  8709. * Return the maximum header bytes that can go on the _wire_
  8710. * for this device. This count includes the ICRC which is
  8711. * not part of the packet held in memory but it is appended
  8712. * by the HW.
  8713. * This is dependent on the device's receive header entry size.
  8714. * HFI allows this to be set per-receive context, but the
  8715. * driver presently enforces a global value.
  8716. */
  8717. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8718. {
  8719. /*
  8720. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8721. * the Receive Header Entry Size minus the PBC (or RHF) size
  8722. * plus one DW for the ICRC appended by HW.
  8723. *
  8724. * dd->rcd[0].rcvhdrqentsize is in DW.
  8725. * We use rcd[0] as all context will have the same value. Also,
  8726. * the first kernel context would have been allocated by now so
  8727. * we are guaranteed a valid value.
  8728. */
  8729. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8730. }
  8731. /*
  8732. * Set Send Length
  8733. * @ppd - per port data
  8734. *
  8735. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8736. * registers compare against LRH.PktLen, so use the max bytes included
  8737. * in the LRH.
  8738. *
  8739. * This routine changes all VL values except VL15, which it maintains at
  8740. * the same value.
  8741. */
  8742. static void set_send_length(struct hfi1_pportdata *ppd)
  8743. {
  8744. struct hfi1_devdata *dd = ppd->dd;
  8745. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8746. u32 maxvlmtu = dd->vld[15].mtu;
  8747. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8748. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8749. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8750. int i, j;
  8751. u32 thres;
  8752. for (i = 0; i < ppd->vls_supported; i++) {
  8753. if (dd->vld[i].mtu > maxvlmtu)
  8754. maxvlmtu = dd->vld[i].mtu;
  8755. if (i <= 3)
  8756. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8757. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8758. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8759. else
  8760. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8761. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8762. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8763. }
  8764. write_csr(dd, SEND_LEN_CHECK0, len1);
  8765. write_csr(dd, SEND_LEN_CHECK1, len2);
  8766. /* adjust kernel credit return thresholds based on new MTUs */
  8767. /* all kernel receive contexts have the same hdrqentsize */
  8768. for (i = 0; i < ppd->vls_supported; i++) {
  8769. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8770. sc_mtu_to_threshold(dd->vld[i].sc,
  8771. dd->vld[i].mtu,
  8772. dd->rcd[0]->rcvhdrqentsize));
  8773. for (j = 0; j < INIT_SC_PER_VL; j++)
  8774. sc_set_cr_threshold(
  8775. pio_select_send_context_vl(dd, j, i),
  8776. thres);
  8777. }
  8778. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8779. sc_mtu_to_threshold(dd->vld[15].sc,
  8780. dd->vld[15].mtu,
  8781. dd->rcd[0]->rcvhdrqentsize));
  8782. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8783. /* Adjust maximum MTU for the port in DC */
  8784. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8785. (ilog2(maxvlmtu >> 8) + 1);
  8786. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8787. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8788. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8789. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8790. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8791. }
  8792. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8793. {
  8794. int i;
  8795. u64 sreg = 0;
  8796. struct hfi1_devdata *dd = ppd->dd;
  8797. u32 mask = ~((1U << ppd->lmc) - 1);
  8798. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8799. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8800. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8801. c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8802. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8803. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8804. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8805. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8806. /*
  8807. * Iterate over all the send contexts and set their SLID check
  8808. */
  8809. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8810. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8811. (((ppd->lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8812. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8813. for (i = 0; i < dd->chip_send_contexts; i++) {
  8814. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8815. i, (u32)sreg);
  8816. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8817. }
  8818. /* Now we have to do the same thing for the sdma engines */
  8819. sdma_update_lmc(dd, mask, ppd->lid);
  8820. }
  8821. static const char *state_completed_string(u32 completed)
  8822. {
  8823. static const char * const state_completed[] = {
  8824. "EstablishComm",
  8825. "OptimizeEQ",
  8826. "VerifyCap"
  8827. };
  8828. if (completed < ARRAY_SIZE(state_completed))
  8829. return state_completed[completed];
  8830. return "unknown";
  8831. }
  8832. static const char all_lanes_dead_timeout_expired[] =
  8833. "All lanes were inactive – was the interconnect media removed?";
  8834. static const char tx_out_of_policy[] =
  8835. "Passing lanes on local port do not meet the local link width policy";
  8836. static const char no_state_complete[] =
  8837. "State timeout occurred before link partner completed the state";
  8838. static const char * const state_complete_reasons[] = {
  8839. [0x00] = "Reason unknown",
  8840. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8841. [0x02] = "Link partner reported failure",
  8842. [0x10] = "Unable to achieve frame sync on any lane",
  8843. [0x11] =
  8844. "Unable to find a common bit rate with the link partner",
  8845. [0x12] =
  8846. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8847. [0x13] =
  8848. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8849. [0x14] = no_state_complete,
  8850. [0x15] =
  8851. "State timeout occurred before link partner identified equalization presets",
  8852. [0x16] =
  8853. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8854. [0x17] = tx_out_of_policy,
  8855. [0x20] = all_lanes_dead_timeout_expired,
  8856. [0x21] =
  8857. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8858. [0x22] = no_state_complete,
  8859. [0x23] =
  8860. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8861. [0x24] = tx_out_of_policy,
  8862. [0x30] = all_lanes_dead_timeout_expired,
  8863. [0x31] =
  8864. "State timeout occurred waiting for host to process received frames",
  8865. [0x32] = no_state_complete,
  8866. [0x33] =
  8867. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8868. [0x34] = tx_out_of_policy,
  8869. };
  8870. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8871. u32 code)
  8872. {
  8873. const char *str = NULL;
  8874. if (code < ARRAY_SIZE(state_complete_reasons))
  8875. str = state_complete_reasons[code];
  8876. if (str)
  8877. return str;
  8878. return "Reserved";
  8879. }
  8880. /* describe the given last state complete frame */
  8881. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8882. const char *prefix)
  8883. {
  8884. struct hfi1_devdata *dd = ppd->dd;
  8885. u32 success;
  8886. u32 state;
  8887. u32 reason;
  8888. u32 lanes;
  8889. /*
  8890. * Decode frame:
  8891. * [ 0: 0] - success
  8892. * [ 3: 1] - state
  8893. * [ 7: 4] - next state timeout
  8894. * [15: 8] - reason code
  8895. * [31:16] - lanes
  8896. */
  8897. success = frame & 0x1;
  8898. state = (frame >> 1) & 0x7;
  8899. reason = (frame >> 8) & 0xff;
  8900. lanes = (frame >> 16) & 0xffff;
  8901. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8902. prefix, frame);
  8903. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8904. state_completed_string(state), state);
  8905. dd_dev_err(dd, " state successfully completed: %s\n",
  8906. success ? "yes" : "no");
  8907. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8908. reason, state_complete_reason_code_string(ppd, reason));
  8909. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8910. }
  8911. /*
  8912. * Read the last state complete frames and explain them. This routine
  8913. * expects to be called if the link went down during link negotiation
  8914. * and initialization (LNI). That is, anywhere between polling and link up.
  8915. */
  8916. static void check_lni_states(struct hfi1_pportdata *ppd)
  8917. {
  8918. u32 last_local_state;
  8919. u32 last_remote_state;
  8920. read_last_local_state(ppd->dd, &last_local_state);
  8921. read_last_remote_state(ppd->dd, &last_remote_state);
  8922. /*
  8923. * Don't report anything if there is nothing to report. A value of
  8924. * 0 means the link was taken down while polling and there was no
  8925. * training in-process.
  8926. */
  8927. if (last_local_state == 0 && last_remote_state == 0)
  8928. return;
  8929. decode_state_complete(ppd, last_local_state, "transmitted");
  8930. decode_state_complete(ppd, last_remote_state, "received");
  8931. }
  8932. /* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
  8933. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
  8934. {
  8935. u64 reg;
  8936. unsigned long timeout;
  8937. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  8938. timeout = jiffies + msecs_to_jiffies(wait_ms);
  8939. while (1) {
  8940. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  8941. if (reg)
  8942. break;
  8943. if (time_after(jiffies, timeout)) {
  8944. dd_dev_err(dd,
  8945. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  8946. return -ETIMEDOUT;
  8947. }
  8948. udelay(2);
  8949. }
  8950. return 0;
  8951. }
  8952. /* called when the logical link state is not down as it should be */
  8953. static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
  8954. {
  8955. struct hfi1_devdata *dd = ppd->dd;
  8956. /*
  8957. * Bring link up in LCB loopback
  8958. */
  8959. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  8960. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  8961. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  8962. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  8963. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
  8964. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8965. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
  8966. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  8967. (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
  8968. udelay(3);
  8969. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
  8970. write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  8971. wait_link_transfer_active(dd, 100);
  8972. /*
  8973. * Bring the link down again.
  8974. */
  8975. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  8976. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
  8977. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
  8978. /* adjust ppd->statusp, if needed */
  8979. update_statusp(ppd, IB_PORT_DOWN);
  8980. dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
  8981. }
  8982. /*
  8983. * Helper for set_link_state(). Do not call except from that routine.
  8984. * Expects ppd->hls_mutex to be held.
  8985. *
  8986. * @rem_reason value to be sent to the neighbor
  8987. *
  8988. * LinkDownReasons only set if transition succeeds.
  8989. */
  8990. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  8991. {
  8992. struct hfi1_devdata *dd = ppd->dd;
  8993. u32 previous_state;
  8994. int ret;
  8995. update_lcb_cache(dd);
  8996. previous_state = ppd->host_link_state;
  8997. ppd->host_link_state = HLS_GOING_OFFLINE;
  8998. /* start offline transition */
  8999. ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
  9000. if (ret != HCMD_SUCCESS) {
  9001. dd_dev_err(dd,
  9002. "Failed to transition to Offline link state, return %d\n",
  9003. ret);
  9004. return -EINVAL;
  9005. }
  9006. if (ppd->offline_disabled_reason ==
  9007. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  9008. ppd->offline_disabled_reason =
  9009. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  9010. /*
  9011. * Wait for offline transition. It can take a while for
  9012. * the link to go down.
  9013. */
  9014. ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 10000);
  9015. if (ret < 0)
  9016. return ret;
  9017. /*
  9018. * Now in charge of LCB - must be after the physical state is
  9019. * offline.quiet and before host_link_state is changed.
  9020. */
  9021. set_host_lcb_access(dd);
  9022. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  9023. /* make sure the logical state is also down */
  9024. ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  9025. if (ret)
  9026. force_logical_link_state_down(ppd);
  9027. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  9028. if (ppd->port_type == PORT_TYPE_QSFP &&
  9029. ppd->qsfp_info.limiting_active &&
  9030. qsfp_mod_present(ppd)) {
  9031. int ret;
  9032. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  9033. if (ret == 0) {
  9034. set_qsfp_tx(ppd, 0);
  9035. release_chip_resource(dd, qsfp_resource(dd));
  9036. } else {
  9037. /* not fatal, but should warn */
  9038. dd_dev_err(dd,
  9039. "Unable to acquire lock to turn off QSFP TX\n");
  9040. }
  9041. }
  9042. /*
  9043. * The LNI has a mandatory wait time after the physical state
  9044. * moves to Offline.Quiet. The wait time may be different
  9045. * depending on how the link went down. The 8051 firmware
  9046. * will observe the needed wait time and only move to ready
  9047. * when that is completed. The largest of the quiet timeouts
  9048. * is 6s, so wait that long and then at least 0.5s more for
  9049. * other transitions, and another 0.5s for a buffer.
  9050. */
  9051. ret = wait_fm_ready(dd, 7000);
  9052. if (ret) {
  9053. dd_dev_err(dd,
  9054. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  9055. /* state is really offline, so make it so */
  9056. ppd->host_link_state = HLS_DN_OFFLINE;
  9057. return ret;
  9058. }
  9059. /*
  9060. * The state is now offline and the 8051 is ready to accept host
  9061. * requests.
  9062. * - change our state
  9063. * - notify others if we were previously in a linkup state
  9064. */
  9065. ppd->host_link_state = HLS_DN_OFFLINE;
  9066. if (previous_state & HLS_UP) {
  9067. /* went down while link was up */
  9068. handle_linkup_change(dd, 0);
  9069. } else if (previous_state
  9070. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  9071. /* went down while attempting link up */
  9072. check_lni_states(ppd);
  9073. }
  9074. /* the active link width (downgrade) is 0 on link down */
  9075. ppd->link_width_active = 0;
  9076. ppd->link_width_downgrade_tx_active = 0;
  9077. ppd->link_width_downgrade_rx_active = 0;
  9078. ppd->current_egress_rate = 0;
  9079. return 0;
  9080. }
  9081. /* return the link state name */
  9082. static const char *link_state_name(u32 state)
  9083. {
  9084. const char *name;
  9085. int n = ilog2(state);
  9086. static const char * const names[] = {
  9087. [__HLS_UP_INIT_BP] = "INIT",
  9088. [__HLS_UP_ARMED_BP] = "ARMED",
  9089. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  9090. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  9091. [__HLS_DN_POLL_BP] = "POLL",
  9092. [__HLS_DN_DISABLE_BP] = "DISABLE",
  9093. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  9094. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  9095. [__HLS_GOING_UP_BP] = "GOING_UP",
  9096. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  9097. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  9098. };
  9099. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  9100. return name ? name : "unknown";
  9101. }
  9102. /* return the link state reason name */
  9103. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  9104. {
  9105. if (state == HLS_UP_INIT) {
  9106. switch (ppd->linkinit_reason) {
  9107. case OPA_LINKINIT_REASON_LINKUP:
  9108. return "(LINKUP)";
  9109. case OPA_LINKINIT_REASON_FLAPPING:
  9110. return "(FLAPPING)";
  9111. case OPA_LINKINIT_OUTSIDE_POLICY:
  9112. return "(OUTSIDE_POLICY)";
  9113. case OPA_LINKINIT_QUARANTINED:
  9114. return "(QUARANTINED)";
  9115. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  9116. return "(INSUFIC_CAPABILITY)";
  9117. default:
  9118. break;
  9119. }
  9120. }
  9121. return "";
  9122. }
  9123. /*
  9124. * driver_physical_state - convert the driver's notion of a port's
  9125. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  9126. * Return -1 (converted to a u32) to indicate error.
  9127. */
  9128. u32 driver_physical_state(struct hfi1_pportdata *ppd)
  9129. {
  9130. switch (ppd->host_link_state) {
  9131. case HLS_UP_INIT:
  9132. case HLS_UP_ARMED:
  9133. case HLS_UP_ACTIVE:
  9134. return IB_PORTPHYSSTATE_LINKUP;
  9135. case HLS_DN_POLL:
  9136. return IB_PORTPHYSSTATE_POLLING;
  9137. case HLS_DN_DISABLE:
  9138. return IB_PORTPHYSSTATE_DISABLED;
  9139. case HLS_DN_OFFLINE:
  9140. return OPA_PORTPHYSSTATE_OFFLINE;
  9141. case HLS_VERIFY_CAP:
  9142. return IB_PORTPHYSSTATE_POLLING;
  9143. case HLS_GOING_UP:
  9144. return IB_PORTPHYSSTATE_POLLING;
  9145. case HLS_GOING_OFFLINE:
  9146. return OPA_PORTPHYSSTATE_OFFLINE;
  9147. case HLS_LINK_COOLDOWN:
  9148. return OPA_PORTPHYSSTATE_OFFLINE;
  9149. case HLS_DN_DOWNDEF:
  9150. default:
  9151. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9152. ppd->host_link_state);
  9153. return -1;
  9154. }
  9155. }
  9156. /*
  9157. * driver_lstate - convert the driver's notion of a port's
  9158. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9159. * (converted to a u32) to indicate error.
  9160. */
  9161. u32 driver_lstate(struct hfi1_pportdata *ppd)
  9162. {
  9163. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9164. return IB_PORT_DOWN;
  9165. switch (ppd->host_link_state & HLS_UP) {
  9166. case HLS_UP_INIT:
  9167. return IB_PORT_INIT;
  9168. case HLS_UP_ARMED:
  9169. return IB_PORT_ARMED;
  9170. case HLS_UP_ACTIVE:
  9171. return IB_PORT_ACTIVE;
  9172. default:
  9173. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9174. ppd->host_link_state);
  9175. return -1;
  9176. }
  9177. }
  9178. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9179. u8 neigh_reason, u8 rem_reason)
  9180. {
  9181. if (ppd->local_link_down_reason.latest == 0 &&
  9182. ppd->neigh_link_down_reason.latest == 0) {
  9183. ppd->local_link_down_reason.latest = lcl_reason;
  9184. ppd->neigh_link_down_reason.latest = neigh_reason;
  9185. ppd->remote_link_down_reason = rem_reason;
  9186. }
  9187. }
  9188. /*
  9189. * Verify if BCT for data VLs is non-zero.
  9190. */
  9191. static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
  9192. {
  9193. return !!ppd->actual_vls_operational;
  9194. }
  9195. /*
  9196. * Change the physical and/or logical link state.
  9197. *
  9198. * Do not call this routine while inside an interrupt. It contains
  9199. * calls to routines that can take multiple seconds to finish.
  9200. *
  9201. * Returns 0 on success, -errno on failure.
  9202. */
  9203. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9204. {
  9205. struct hfi1_devdata *dd = ppd->dd;
  9206. struct ib_event event = {.device = NULL};
  9207. int ret1, ret = 0;
  9208. int orig_new_state, poll_bounce;
  9209. mutex_lock(&ppd->hls_lock);
  9210. orig_new_state = state;
  9211. if (state == HLS_DN_DOWNDEF)
  9212. state = dd->link_default;
  9213. /* interpret poll -> poll as a link bounce */
  9214. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9215. state == HLS_DN_POLL;
  9216. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9217. link_state_name(ppd->host_link_state),
  9218. link_state_name(orig_new_state),
  9219. poll_bounce ? "(bounce) " : "",
  9220. link_state_reason_name(ppd, state));
  9221. /*
  9222. * If we're going to a (HLS_*) link state that implies the logical
  9223. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9224. * reset is_sm_config_started to 0.
  9225. */
  9226. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9227. ppd->is_sm_config_started = 0;
  9228. /*
  9229. * Do nothing if the states match. Let a poll to poll link bounce
  9230. * go through.
  9231. */
  9232. if (ppd->host_link_state == state && !poll_bounce)
  9233. goto done;
  9234. switch (state) {
  9235. case HLS_UP_INIT:
  9236. if (ppd->host_link_state == HLS_DN_POLL &&
  9237. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9238. /*
  9239. * Quick link up jumps from polling to here.
  9240. *
  9241. * Whether in normal or loopback mode, the
  9242. * simulator jumps from polling to link up.
  9243. * Accept that here.
  9244. */
  9245. /* OK */
  9246. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9247. goto unexpected;
  9248. }
  9249. /*
  9250. * Wait for Link_Up physical state.
  9251. * Physical and Logical states should already be
  9252. * be transitioned to LinkUp and LinkInit respectively.
  9253. */
  9254. ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
  9255. if (ret) {
  9256. dd_dev_err(dd,
  9257. "%s: physical state did not change to LINK-UP\n",
  9258. __func__);
  9259. break;
  9260. }
  9261. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9262. if (ret) {
  9263. dd_dev_err(dd,
  9264. "%s: logical state did not change to INIT\n",
  9265. __func__);
  9266. break;
  9267. }
  9268. /* clear old transient LINKINIT_REASON code */
  9269. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9270. ppd->linkinit_reason =
  9271. OPA_LINKINIT_REASON_LINKUP;
  9272. /* enable the port */
  9273. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9274. handle_linkup_change(dd, 1);
  9275. ppd->host_link_state = HLS_UP_INIT;
  9276. break;
  9277. case HLS_UP_ARMED:
  9278. if (ppd->host_link_state != HLS_UP_INIT)
  9279. goto unexpected;
  9280. if (!data_vls_operational(ppd)) {
  9281. dd_dev_err(dd,
  9282. "%s: data VLs not operational\n", __func__);
  9283. ret = -EINVAL;
  9284. break;
  9285. }
  9286. set_logical_state(dd, LSTATE_ARMED);
  9287. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9288. if (ret) {
  9289. dd_dev_err(dd,
  9290. "%s: logical state did not change to ARMED\n",
  9291. __func__);
  9292. break;
  9293. }
  9294. ppd->host_link_state = HLS_UP_ARMED;
  9295. /*
  9296. * The simulator does not currently implement SMA messages,
  9297. * so neighbor_normal is not set. Set it here when we first
  9298. * move to Armed.
  9299. */
  9300. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9301. ppd->neighbor_normal = 1;
  9302. break;
  9303. case HLS_UP_ACTIVE:
  9304. if (ppd->host_link_state != HLS_UP_ARMED)
  9305. goto unexpected;
  9306. set_logical_state(dd, LSTATE_ACTIVE);
  9307. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9308. if (ret) {
  9309. dd_dev_err(dd,
  9310. "%s: logical state did not change to ACTIVE\n",
  9311. __func__);
  9312. } else {
  9313. /* tell all engines to go running */
  9314. sdma_all_running(dd);
  9315. ppd->host_link_state = HLS_UP_ACTIVE;
  9316. /* Signal the IB layer that the port has went active */
  9317. event.device = &dd->verbs_dev.rdi.ibdev;
  9318. event.element.port_num = ppd->port;
  9319. event.event = IB_EVENT_PORT_ACTIVE;
  9320. }
  9321. break;
  9322. case HLS_DN_POLL:
  9323. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9324. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9325. dd->dc_shutdown)
  9326. dc_start(dd);
  9327. /* Hand LED control to the DC */
  9328. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9329. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9330. u8 tmp = ppd->link_enabled;
  9331. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9332. if (ret) {
  9333. ppd->link_enabled = tmp;
  9334. break;
  9335. }
  9336. ppd->remote_link_down_reason = 0;
  9337. if (ppd->driver_link_ready)
  9338. ppd->link_enabled = 1;
  9339. }
  9340. set_all_slowpath(ppd->dd);
  9341. ret = set_local_link_attributes(ppd);
  9342. if (ret)
  9343. break;
  9344. ppd->port_error_action = 0;
  9345. ppd->host_link_state = HLS_DN_POLL;
  9346. if (quick_linkup) {
  9347. /* quick linkup does not go into polling */
  9348. ret = do_quick_linkup(dd);
  9349. } else {
  9350. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9351. if (ret1 != HCMD_SUCCESS) {
  9352. dd_dev_err(dd,
  9353. "Failed to transition to Polling link state, return 0x%x\n",
  9354. ret1);
  9355. ret = -EINVAL;
  9356. }
  9357. }
  9358. ppd->offline_disabled_reason =
  9359. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9360. /*
  9361. * If an error occurred above, go back to offline. The
  9362. * caller may reschedule another attempt.
  9363. */
  9364. if (ret)
  9365. goto_offline(ppd, 0);
  9366. else
  9367. cache_physical_state(ppd);
  9368. break;
  9369. case HLS_DN_DISABLE:
  9370. /* link is disabled */
  9371. ppd->link_enabled = 0;
  9372. /* allow any state to transition to disabled */
  9373. /* must transition to offline first */
  9374. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9375. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9376. if (ret)
  9377. break;
  9378. ppd->remote_link_down_reason = 0;
  9379. }
  9380. if (!dd->dc_shutdown) {
  9381. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9382. if (ret1 != HCMD_SUCCESS) {
  9383. dd_dev_err(dd,
  9384. "Failed to transition to Disabled link state, return 0x%x\n",
  9385. ret1);
  9386. ret = -EINVAL;
  9387. break;
  9388. }
  9389. ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
  9390. if (ret) {
  9391. dd_dev_err(dd,
  9392. "%s: physical state did not change to DISABLED\n",
  9393. __func__);
  9394. break;
  9395. }
  9396. dc_shutdown(dd);
  9397. }
  9398. ppd->host_link_state = HLS_DN_DISABLE;
  9399. break;
  9400. case HLS_DN_OFFLINE:
  9401. if (ppd->host_link_state == HLS_DN_DISABLE)
  9402. dc_start(dd);
  9403. /* allow any state to transition to offline */
  9404. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9405. if (!ret)
  9406. ppd->remote_link_down_reason = 0;
  9407. break;
  9408. case HLS_VERIFY_CAP:
  9409. if (ppd->host_link_state != HLS_DN_POLL)
  9410. goto unexpected;
  9411. ppd->host_link_state = HLS_VERIFY_CAP;
  9412. cache_physical_state(ppd);
  9413. break;
  9414. case HLS_GOING_UP:
  9415. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9416. goto unexpected;
  9417. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9418. if (ret1 != HCMD_SUCCESS) {
  9419. dd_dev_err(dd,
  9420. "Failed to transition to link up state, return 0x%x\n",
  9421. ret1);
  9422. ret = -EINVAL;
  9423. break;
  9424. }
  9425. ppd->host_link_state = HLS_GOING_UP;
  9426. break;
  9427. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9428. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9429. default:
  9430. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9431. __func__, state);
  9432. ret = -EINVAL;
  9433. break;
  9434. }
  9435. goto done;
  9436. unexpected:
  9437. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9438. __func__, link_state_name(ppd->host_link_state),
  9439. link_state_name(state));
  9440. ret = -EINVAL;
  9441. done:
  9442. mutex_unlock(&ppd->hls_lock);
  9443. if (event.device)
  9444. ib_dispatch_event(&event);
  9445. return ret;
  9446. }
  9447. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9448. {
  9449. u64 reg;
  9450. int ret = 0;
  9451. switch (which) {
  9452. case HFI1_IB_CFG_LIDLMC:
  9453. set_lidlmc(ppd);
  9454. break;
  9455. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9456. /*
  9457. * The VL Arbitrator high limit is sent in units of 4k
  9458. * bytes, while HFI stores it in units of 64 bytes.
  9459. */
  9460. val *= 4096 / 64;
  9461. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9462. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9463. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9464. break;
  9465. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9466. /* HFI only supports POLL as the default link down state */
  9467. if (val != HLS_DN_POLL)
  9468. ret = -EINVAL;
  9469. break;
  9470. case HFI1_IB_CFG_OP_VLS:
  9471. if (ppd->vls_operational != val) {
  9472. ppd->vls_operational = val;
  9473. if (!ppd->port)
  9474. ret = -EINVAL;
  9475. }
  9476. break;
  9477. /*
  9478. * For link width, link width downgrade, and speed enable, always AND
  9479. * the setting with what is actually supported. This has two benefits.
  9480. * First, enabled can't have unsupported values, no matter what the
  9481. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9482. * "fill in with your supported value" have all the bits in the
  9483. * field set, so simply ANDing with supported has the desired result.
  9484. */
  9485. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9486. ppd->link_width_enabled = val & ppd->link_width_supported;
  9487. break;
  9488. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9489. ppd->link_width_downgrade_enabled =
  9490. val & ppd->link_width_downgrade_supported;
  9491. break;
  9492. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9493. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9494. break;
  9495. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9496. /*
  9497. * HFI does not follow IB specs, save this value
  9498. * so we can report it, if asked.
  9499. */
  9500. ppd->overrun_threshold = val;
  9501. break;
  9502. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9503. /*
  9504. * HFI does not follow IB specs, save this value
  9505. * so we can report it, if asked.
  9506. */
  9507. ppd->phy_error_threshold = val;
  9508. break;
  9509. case HFI1_IB_CFG_MTU:
  9510. set_send_length(ppd);
  9511. break;
  9512. case HFI1_IB_CFG_PKEYS:
  9513. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9514. set_partition_keys(ppd);
  9515. break;
  9516. default:
  9517. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9518. dd_dev_info(ppd->dd,
  9519. "%s: which %s, val 0x%x: not implemented\n",
  9520. __func__, ib_cfg_name(which), val);
  9521. break;
  9522. }
  9523. return ret;
  9524. }
  9525. /* begin functions related to vl arbitration table caching */
  9526. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9527. {
  9528. int i;
  9529. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9530. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9531. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9532. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9533. /*
  9534. * Note that we always return values directly from the
  9535. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9536. * 'Get(VLArbTable)'. This is obviously correct after a
  9537. * 'Set(VLArbTable)', since the cache will then be up to
  9538. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9539. * since then both the cache, and the relevant h/w registers
  9540. * will be zeroed.
  9541. */
  9542. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9543. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9544. }
  9545. /*
  9546. * vl_arb_lock_cache
  9547. *
  9548. * All other vl_arb_* functions should be called only after locking
  9549. * the cache.
  9550. */
  9551. static inline struct vl_arb_cache *
  9552. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9553. {
  9554. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9555. return NULL;
  9556. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9557. return &ppd->vl_arb_cache[idx];
  9558. }
  9559. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9560. {
  9561. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9562. }
  9563. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9564. struct ib_vl_weight_elem *vl)
  9565. {
  9566. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9567. }
  9568. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9569. struct ib_vl_weight_elem *vl)
  9570. {
  9571. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9572. }
  9573. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9574. struct ib_vl_weight_elem *vl)
  9575. {
  9576. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9577. }
  9578. /* end functions related to vl arbitration table caching */
  9579. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9580. u32 size, struct ib_vl_weight_elem *vl)
  9581. {
  9582. struct hfi1_devdata *dd = ppd->dd;
  9583. u64 reg;
  9584. unsigned int i, is_up = 0;
  9585. int drain, ret = 0;
  9586. mutex_lock(&ppd->hls_lock);
  9587. if (ppd->host_link_state & HLS_UP)
  9588. is_up = 1;
  9589. drain = !is_ax(dd) && is_up;
  9590. if (drain)
  9591. /*
  9592. * Before adjusting VL arbitration weights, empty per-VL
  9593. * FIFOs, otherwise a packet whose VL weight is being
  9594. * set to 0 could get stuck in a FIFO with no chance to
  9595. * egress.
  9596. */
  9597. ret = stop_drain_data_vls(dd);
  9598. if (ret) {
  9599. dd_dev_err(
  9600. dd,
  9601. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9602. __func__);
  9603. goto err;
  9604. }
  9605. for (i = 0; i < size; i++, vl++) {
  9606. /*
  9607. * NOTE: The low priority shift and mask are used here, but
  9608. * they are the same for both the low and high registers.
  9609. */
  9610. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9611. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9612. | (((u64)vl->weight
  9613. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9614. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9615. write_csr(dd, target + (i * 8), reg);
  9616. }
  9617. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9618. if (drain)
  9619. open_fill_data_vls(dd); /* reopen all VLs */
  9620. err:
  9621. mutex_unlock(&ppd->hls_lock);
  9622. return ret;
  9623. }
  9624. /*
  9625. * Read one credit merge VL register.
  9626. */
  9627. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9628. struct vl_limit *vll)
  9629. {
  9630. u64 reg = read_csr(dd, csr);
  9631. vll->dedicated = cpu_to_be16(
  9632. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9633. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9634. vll->shared = cpu_to_be16(
  9635. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9636. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9637. }
  9638. /*
  9639. * Read the current credit merge limits.
  9640. */
  9641. static int get_buffer_control(struct hfi1_devdata *dd,
  9642. struct buffer_control *bc, u16 *overall_limit)
  9643. {
  9644. u64 reg;
  9645. int i;
  9646. /* not all entries are filled in */
  9647. memset(bc, 0, sizeof(*bc));
  9648. /* OPA and HFI have a 1-1 mapping */
  9649. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9650. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9651. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9652. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9653. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9654. bc->overall_shared_limit = cpu_to_be16(
  9655. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9656. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9657. if (overall_limit)
  9658. *overall_limit = (reg
  9659. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9660. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9661. return sizeof(struct buffer_control);
  9662. }
  9663. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9664. {
  9665. u64 reg;
  9666. int i;
  9667. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9668. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9669. for (i = 0; i < sizeof(u64); i++) {
  9670. u8 byte = *(((u8 *)&reg) + i);
  9671. dp->vlnt[2 * i] = byte & 0xf;
  9672. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9673. }
  9674. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9675. for (i = 0; i < sizeof(u64); i++) {
  9676. u8 byte = *(((u8 *)&reg) + i);
  9677. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9678. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9679. }
  9680. return sizeof(struct sc2vlnt);
  9681. }
  9682. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9683. struct ib_vl_weight_elem *vl)
  9684. {
  9685. unsigned int i;
  9686. for (i = 0; i < nelems; i++, vl++) {
  9687. vl->vl = 0xf;
  9688. vl->weight = 0;
  9689. }
  9690. }
  9691. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9692. {
  9693. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9694. DC_SC_VL_VAL(15_0,
  9695. 0, dp->vlnt[0] & 0xf,
  9696. 1, dp->vlnt[1] & 0xf,
  9697. 2, dp->vlnt[2] & 0xf,
  9698. 3, dp->vlnt[3] & 0xf,
  9699. 4, dp->vlnt[4] & 0xf,
  9700. 5, dp->vlnt[5] & 0xf,
  9701. 6, dp->vlnt[6] & 0xf,
  9702. 7, dp->vlnt[7] & 0xf,
  9703. 8, dp->vlnt[8] & 0xf,
  9704. 9, dp->vlnt[9] & 0xf,
  9705. 10, dp->vlnt[10] & 0xf,
  9706. 11, dp->vlnt[11] & 0xf,
  9707. 12, dp->vlnt[12] & 0xf,
  9708. 13, dp->vlnt[13] & 0xf,
  9709. 14, dp->vlnt[14] & 0xf,
  9710. 15, dp->vlnt[15] & 0xf));
  9711. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9712. DC_SC_VL_VAL(31_16,
  9713. 16, dp->vlnt[16] & 0xf,
  9714. 17, dp->vlnt[17] & 0xf,
  9715. 18, dp->vlnt[18] & 0xf,
  9716. 19, dp->vlnt[19] & 0xf,
  9717. 20, dp->vlnt[20] & 0xf,
  9718. 21, dp->vlnt[21] & 0xf,
  9719. 22, dp->vlnt[22] & 0xf,
  9720. 23, dp->vlnt[23] & 0xf,
  9721. 24, dp->vlnt[24] & 0xf,
  9722. 25, dp->vlnt[25] & 0xf,
  9723. 26, dp->vlnt[26] & 0xf,
  9724. 27, dp->vlnt[27] & 0xf,
  9725. 28, dp->vlnt[28] & 0xf,
  9726. 29, dp->vlnt[29] & 0xf,
  9727. 30, dp->vlnt[30] & 0xf,
  9728. 31, dp->vlnt[31] & 0xf));
  9729. }
  9730. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9731. u16 limit)
  9732. {
  9733. if (limit != 0)
  9734. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9735. what, (int)limit, idx);
  9736. }
  9737. /* change only the shared limit portion of SendCmGLobalCredit */
  9738. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9739. {
  9740. u64 reg;
  9741. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9742. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9743. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9744. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9745. }
  9746. /* change only the total credit limit portion of SendCmGLobalCredit */
  9747. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9748. {
  9749. u64 reg;
  9750. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9751. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9752. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9753. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9754. }
  9755. /* set the given per-VL shared limit */
  9756. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9757. {
  9758. u64 reg;
  9759. u32 addr;
  9760. if (vl < TXE_NUM_DATA_VL)
  9761. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9762. else
  9763. addr = SEND_CM_CREDIT_VL15;
  9764. reg = read_csr(dd, addr);
  9765. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9766. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9767. write_csr(dd, addr, reg);
  9768. }
  9769. /* set the given per-VL dedicated limit */
  9770. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9771. {
  9772. u64 reg;
  9773. u32 addr;
  9774. if (vl < TXE_NUM_DATA_VL)
  9775. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9776. else
  9777. addr = SEND_CM_CREDIT_VL15;
  9778. reg = read_csr(dd, addr);
  9779. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9780. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9781. write_csr(dd, addr, reg);
  9782. }
  9783. /* spin until the given per-VL status mask bits clear */
  9784. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9785. const char *which)
  9786. {
  9787. unsigned long timeout;
  9788. u64 reg;
  9789. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9790. while (1) {
  9791. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9792. if (reg == 0)
  9793. return; /* success */
  9794. if (time_after(jiffies, timeout))
  9795. break; /* timed out */
  9796. udelay(1);
  9797. }
  9798. dd_dev_err(dd,
  9799. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9800. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9801. /*
  9802. * If this occurs, it is likely there was a credit loss on the link.
  9803. * The only recovery from that is a link bounce.
  9804. */
  9805. dd_dev_err(dd,
  9806. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9807. }
  9808. /*
  9809. * The number of credits on the VLs may be changed while everything
  9810. * is "live", but the following algorithm must be followed due to
  9811. * how the hardware is actually implemented. In particular,
  9812. * Return_Credit_Status[] is the only correct status check.
  9813. *
  9814. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9815. * set Global_Shared_Credit_Limit = 0
  9816. * use_all_vl = 1
  9817. * mask0 = all VLs that are changing either dedicated or shared limits
  9818. * set Shared_Limit[mask0] = 0
  9819. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9820. * if (changing any dedicated limit)
  9821. * mask1 = all VLs that are lowering dedicated limits
  9822. * lower Dedicated_Limit[mask1]
  9823. * spin until Return_Credit_Status[mask1] == 0
  9824. * raise Dedicated_Limits
  9825. * raise Shared_Limits
  9826. * raise Global_Shared_Credit_Limit
  9827. *
  9828. * lower = if the new limit is lower, set the limit to the new value
  9829. * raise = if the new limit is higher than the current value (may be changed
  9830. * earlier in the algorithm), set the new limit to the new value
  9831. */
  9832. int set_buffer_control(struct hfi1_pportdata *ppd,
  9833. struct buffer_control *new_bc)
  9834. {
  9835. struct hfi1_devdata *dd = ppd->dd;
  9836. u64 changing_mask, ld_mask, stat_mask;
  9837. int change_count;
  9838. int i, use_all_mask;
  9839. int this_shared_changing;
  9840. int vl_count = 0, ret;
  9841. /*
  9842. * A0: add the variable any_shared_limit_changing below and in the
  9843. * algorithm above. If removing A0 support, it can be removed.
  9844. */
  9845. int any_shared_limit_changing;
  9846. struct buffer_control cur_bc;
  9847. u8 changing[OPA_MAX_VLS];
  9848. u8 lowering_dedicated[OPA_MAX_VLS];
  9849. u16 cur_total;
  9850. u32 new_total = 0;
  9851. const u64 all_mask =
  9852. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9853. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9854. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9855. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9856. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9857. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9858. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9859. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9860. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9861. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9862. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9863. /* find the new total credits, do sanity check on unused VLs */
  9864. for (i = 0; i < OPA_MAX_VLS; i++) {
  9865. if (valid_vl(i)) {
  9866. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9867. continue;
  9868. }
  9869. nonzero_msg(dd, i, "dedicated",
  9870. be16_to_cpu(new_bc->vl[i].dedicated));
  9871. nonzero_msg(dd, i, "shared",
  9872. be16_to_cpu(new_bc->vl[i].shared));
  9873. new_bc->vl[i].dedicated = 0;
  9874. new_bc->vl[i].shared = 0;
  9875. }
  9876. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9877. /* fetch the current values */
  9878. get_buffer_control(dd, &cur_bc, &cur_total);
  9879. /*
  9880. * Create the masks we will use.
  9881. */
  9882. memset(changing, 0, sizeof(changing));
  9883. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9884. /*
  9885. * NOTE: Assumes that the individual VL bits are adjacent and in
  9886. * increasing order
  9887. */
  9888. stat_mask =
  9889. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9890. changing_mask = 0;
  9891. ld_mask = 0;
  9892. change_count = 0;
  9893. any_shared_limit_changing = 0;
  9894. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9895. if (!valid_vl(i))
  9896. continue;
  9897. this_shared_changing = new_bc->vl[i].shared
  9898. != cur_bc.vl[i].shared;
  9899. if (this_shared_changing)
  9900. any_shared_limit_changing = 1;
  9901. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9902. this_shared_changing) {
  9903. changing[i] = 1;
  9904. changing_mask |= stat_mask;
  9905. change_count++;
  9906. }
  9907. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9908. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9909. lowering_dedicated[i] = 1;
  9910. ld_mask |= stat_mask;
  9911. }
  9912. }
  9913. /* bracket the credit change with a total adjustment */
  9914. if (new_total > cur_total)
  9915. set_global_limit(dd, new_total);
  9916. /*
  9917. * Start the credit change algorithm.
  9918. */
  9919. use_all_mask = 0;
  9920. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  9921. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  9922. (is_ax(dd) && any_shared_limit_changing)) {
  9923. set_global_shared(dd, 0);
  9924. cur_bc.overall_shared_limit = 0;
  9925. use_all_mask = 1;
  9926. }
  9927. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9928. if (!valid_vl(i))
  9929. continue;
  9930. if (changing[i]) {
  9931. set_vl_shared(dd, i, 0);
  9932. cur_bc.vl[i].shared = 0;
  9933. }
  9934. }
  9935. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  9936. "shared");
  9937. if (change_count > 0) {
  9938. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9939. if (!valid_vl(i))
  9940. continue;
  9941. if (lowering_dedicated[i]) {
  9942. set_vl_dedicated(dd, i,
  9943. be16_to_cpu(new_bc->
  9944. vl[i].dedicated));
  9945. cur_bc.vl[i].dedicated =
  9946. new_bc->vl[i].dedicated;
  9947. }
  9948. }
  9949. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  9950. /* now raise all dedicated that are going up */
  9951. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9952. if (!valid_vl(i))
  9953. continue;
  9954. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  9955. be16_to_cpu(cur_bc.vl[i].dedicated))
  9956. set_vl_dedicated(dd, i,
  9957. be16_to_cpu(new_bc->
  9958. vl[i].dedicated));
  9959. }
  9960. }
  9961. /* next raise all shared that are going up */
  9962. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9963. if (!valid_vl(i))
  9964. continue;
  9965. if (be16_to_cpu(new_bc->vl[i].shared) >
  9966. be16_to_cpu(cur_bc.vl[i].shared))
  9967. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  9968. }
  9969. /* finally raise the global shared */
  9970. if (be16_to_cpu(new_bc->overall_shared_limit) >
  9971. be16_to_cpu(cur_bc.overall_shared_limit))
  9972. set_global_shared(dd,
  9973. be16_to_cpu(new_bc->overall_shared_limit));
  9974. /* bracket the credit change with a total adjustment */
  9975. if (new_total < cur_total)
  9976. set_global_limit(dd, new_total);
  9977. /*
  9978. * Determine the actual number of operational VLS using the number of
  9979. * dedicated and shared credits for each VL.
  9980. */
  9981. if (change_count > 0) {
  9982. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9983. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  9984. be16_to_cpu(new_bc->vl[i].shared) > 0)
  9985. vl_count++;
  9986. ppd->actual_vls_operational = vl_count;
  9987. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  9988. ppd->actual_vls_operational :
  9989. ppd->vls_operational,
  9990. NULL);
  9991. if (ret == 0)
  9992. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  9993. ppd->actual_vls_operational :
  9994. ppd->vls_operational, NULL);
  9995. if (ret)
  9996. return ret;
  9997. }
  9998. return 0;
  9999. }
  10000. /*
  10001. * Read the given fabric manager table. Return the size of the
  10002. * table (in bytes) on success, and a negative error code on
  10003. * failure.
  10004. */
  10005. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  10006. {
  10007. int size;
  10008. struct vl_arb_cache *vlc;
  10009. switch (which) {
  10010. case FM_TBL_VL_HIGH_ARB:
  10011. size = 256;
  10012. /*
  10013. * OPA specifies 128 elements (of 2 bytes each), though
  10014. * HFI supports only 16 elements in h/w.
  10015. */
  10016. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10017. vl_arb_get_cache(vlc, t);
  10018. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10019. break;
  10020. case FM_TBL_VL_LOW_ARB:
  10021. size = 256;
  10022. /*
  10023. * OPA specifies 128 elements (of 2 bytes each), though
  10024. * HFI supports only 16 elements in h/w.
  10025. */
  10026. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10027. vl_arb_get_cache(vlc, t);
  10028. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10029. break;
  10030. case FM_TBL_BUFFER_CONTROL:
  10031. size = get_buffer_control(ppd->dd, t, NULL);
  10032. break;
  10033. case FM_TBL_SC2VLNT:
  10034. size = get_sc2vlnt(ppd->dd, t);
  10035. break;
  10036. case FM_TBL_VL_PREEMPT_ELEMS:
  10037. size = 256;
  10038. /* OPA specifies 128 elements, of 2 bytes each */
  10039. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  10040. break;
  10041. case FM_TBL_VL_PREEMPT_MATRIX:
  10042. size = 256;
  10043. /*
  10044. * OPA specifies that this is the same size as the VL
  10045. * arbitration tables (i.e., 256 bytes).
  10046. */
  10047. break;
  10048. default:
  10049. return -EINVAL;
  10050. }
  10051. return size;
  10052. }
  10053. /*
  10054. * Write the given fabric manager table.
  10055. */
  10056. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  10057. {
  10058. int ret = 0;
  10059. struct vl_arb_cache *vlc;
  10060. switch (which) {
  10061. case FM_TBL_VL_HIGH_ARB:
  10062. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10063. if (vl_arb_match_cache(vlc, t)) {
  10064. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10065. break;
  10066. }
  10067. vl_arb_set_cache(vlc, t);
  10068. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10069. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  10070. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  10071. break;
  10072. case FM_TBL_VL_LOW_ARB:
  10073. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10074. if (vl_arb_match_cache(vlc, t)) {
  10075. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10076. break;
  10077. }
  10078. vl_arb_set_cache(vlc, t);
  10079. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10080. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  10081. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  10082. break;
  10083. case FM_TBL_BUFFER_CONTROL:
  10084. ret = set_buffer_control(ppd, t);
  10085. break;
  10086. case FM_TBL_SC2VLNT:
  10087. set_sc2vlnt(ppd->dd, t);
  10088. break;
  10089. default:
  10090. ret = -EINVAL;
  10091. }
  10092. return ret;
  10093. }
  10094. /*
  10095. * Disable all data VLs.
  10096. *
  10097. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  10098. */
  10099. static int disable_data_vls(struct hfi1_devdata *dd)
  10100. {
  10101. if (is_ax(dd))
  10102. return 1;
  10103. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  10104. return 0;
  10105. }
  10106. /*
  10107. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  10108. * Just re-enables all data VLs (the "fill" part happens
  10109. * automatically - the name was chosen for symmetry with
  10110. * stop_drain_data_vls()).
  10111. *
  10112. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  10113. */
  10114. int open_fill_data_vls(struct hfi1_devdata *dd)
  10115. {
  10116. if (is_ax(dd))
  10117. return 1;
  10118. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  10119. return 0;
  10120. }
  10121. /*
  10122. * drain_data_vls() - assumes that disable_data_vls() has been called,
  10123. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  10124. * engines to drop to 0.
  10125. */
  10126. static void drain_data_vls(struct hfi1_devdata *dd)
  10127. {
  10128. sc_wait(dd);
  10129. sdma_wait(dd);
  10130. pause_for_credit_return(dd);
  10131. }
  10132. /*
  10133. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  10134. *
  10135. * Use open_fill_data_vls() to resume using data VLs. This pair is
  10136. * meant to be used like this:
  10137. *
  10138. * stop_drain_data_vls(dd);
  10139. * // do things with per-VL resources
  10140. * open_fill_data_vls(dd);
  10141. */
  10142. int stop_drain_data_vls(struct hfi1_devdata *dd)
  10143. {
  10144. int ret;
  10145. ret = disable_data_vls(dd);
  10146. if (ret == 0)
  10147. drain_data_vls(dd);
  10148. return ret;
  10149. }
  10150. /*
  10151. * Convert a nanosecond time to a cclock count. No matter how slow
  10152. * the cclock, a non-zero ns will always have a non-zero result.
  10153. */
  10154. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  10155. {
  10156. u32 cclocks;
  10157. if (dd->icode == ICODE_FPGA_EMULATION)
  10158. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  10159. else /* simulation pretends to be ASIC */
  10160. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  10161. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  10162. cclocks = 1;
  10163. return cclocks;
  10164. }
  10165. /*
  10166. * Convert a cclock count to nanoseconds. Not matter how slow
  10167. * the cclock, a non-zero cclocks will always have a non-zero result.
  10168. */
  10169. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  10170. {
  10171. u32 ns;
  10172. if (dd->icode == ICODE_FPGA_EMULATION)
  10173. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  10174. else /* simulation pretends to be ASIC */
  10175. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  10176. if (cclocks && !ns)
  10177. ns = 1;
  10178. return ns;
  10179. }
  10180. /*
  10181. * Dynamically adjust the receive interrupt timeout for a context based on
  10182. * incoming packet rate.
  10183. *
  10184. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  10185. */
  10186. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  10187. {
  10188. struct hfi1_devdata *dd = rcd->dd;
  10189. u32 timeout = rcd->rcvavail_timeout;
  10190. /*
  10191. * This algorithm doubles or halves the timeout depending on whether
  10192. * the number of packets received in this interrupt were less than or
  10193. * greater equal the interrupt count.
  10194. *
  10195. * The calculations below do not allow a steady state to be achieved.
  10196. * Only at the endpoints it is possible to have an unchanging
  10197. * timeout.
  10198. */
  10199. if (npkts < rcv_intr_count) {
  10200. /*
  10201. * Not enough packets arrived before the timeout, adjust
  10202. * timeout downward.
  10203. */
  10204. if (timeout < 2) /* already at minimum? */
  10205. return;
  10206. timeout >>= 1;
  10207. } else {
  10208. /*
  10209. * More than enough packets arrived before the timeout, adjust
  10210. * timeout upward.
  10211. */
  10212. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10213. return;
  10214. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10215. }
  10216. rcd->rcvavail_timeout = timeout;
  10217. /*
  10218. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10219. * been verified to be in range
  10220. */
  10221. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10222. (u64)timeout <<
  10223. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10224. }
  10225. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10226. u32 intr_adjust, u32 npkts)
  10227. {
  10228. struct hfi1_devdata *dd = rcd->dd;
  10229. u64 reg;
  10230. u32 ctxt = rcd->ctxt;
  10231. /*
  10232. * Need to write timeout register before updating RcvHdrHead to ensure
  10233. * that a new value is used when the HW decides to restart counting.
  10234. */
  10235. if (intr_adjust)
  10236. adjust_rcv_timeout(rcd, npkts);
  10237. if (updegr) {
  10238. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10239. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10240. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10241. }
  10242. mmiowb();
  10243. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10244. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10245. << RCV_HDR_HEAD_HEAD_SHIFT);
  10246. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10247. mmiowb();
  10248. }
  10249. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10250. {
  10251. u32 head, tail;
  10252. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10253. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10254. if (rcd->rcvhdrtail_kvaddr)
  10255. tail = get_rcvhdrtail(rcd);
  10256. else
  10257. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10258. return head == tail;
  10259. }
  10260. /*
  10261. * Context Control and Receive Array encoding for buffer size:
  10262. * 0x0 invalid
  10263. * 0x1 4 KB
  10264. * 0x2 8 KB
  10265. * 0x3 16 KB
  10266. * 0x4 32 KB
  10267. * 0x5 64 KB
  10268. * 0x6 128 KB
  10269. * 0x7 256 KB
  10270. * 0x8 512 KB (Receive Array only)
  10271. * 0x9 1 MB (Receive Array only)
  10272. * 0xa 2 MB (Receive Array only)
  10273. *
  10274. * 0xB-0xF - reserved (Receive Array only)
  10275. *
  10276. *
  10277. * This routine assumes that the value has already been sanity checked.
  10278. */
  10279. static u32 encoded_size(u32 size)
  10280. {
  10281. switch (size) {
  10282. case 4 * 1024: return 0x1;
  10283. case 8 * 1024: return 0x2;
  10284. case 16 * 1024: return 0x3;
  10285. case 32 * 1024: return 0x4;
  10286. case 64 * 1024: return 0x5;
  10287. case 128 * 1024: return 0x6;
  10288. case 256 * 1024: return 0x7;
  10289. case 512 * 1024: return 0x8;
  10290. case 1 * 1024 * 1024: return 0x9;
  10291. case 2 * 1024 * 1024: return 0xa;
  10292. }
  10293. return 0x1; /* if invalid, go with the minimum size */
  10294. }
  10295. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
  10296. struct hfi1_ctxtdata *rcd)
  10297. {
  10298. u64 rcvctrl, reg;
  10299. int did_enable = 0;
  10300. u16 ctxt;
  10301. if (!rcd)
  10302. return;
  10303. ctxt = rcd->ctxt;
  10304. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10305. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10306. /* if the context already enabled, don't do the extra steps */
  10307. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10308. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10309. /* reset the tail and hdr addresses, and sequence count */
  10310. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10311. rcd->rcvhdrq_dma);
  10312. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  10313. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10314. rcd->rcvhdrqtailaddr_dma);
  10315. rcd->seq_cnt = 1;
  10316. /* reset the cached receive header queue head value */
  10317. rcd->head = 0;
  10318. /*
  10319. * Zero the receive header queue so we don't get false
  10320. * positives when checking the sequence number. The
  10321. * sequence numbers could land exactly on the same spot.
  10322. * E.g. a rcd restart before the receive header wrapped.
  10323. */
  10324. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  10325. /* starting timeout */
  10326. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10327. /* enable the context */
  10328. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10329. /* clean the egr buffer size first */
  10330. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10331. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10332. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10333. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10334. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10335. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10336. did_enable = 1;
  10337. /* zero RcvEgrIndexHead */
  10338. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10339. /* set eager count and base index */
  10340. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10341. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10342. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10343. (((rcd->eager_base >> RCV_SHIFT)
  10344. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10345. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10346. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10347. /*
  10348. * Set TID (expected) count and base index.
  10349. * rcd->expected_count is set to individual RcvArray entries,
  10350. * not pairs, and the CSR takes a pair-count in groups of
  10351. * four, so divide by 8.
  10352. */
  10353. reg = (((rcd->expected_count >> RCV_SHIFT)
  10354. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10355. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10356. (((rcd->expected_base >> RCV_SHIFT)
  10357. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10358. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10359. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10360. if (ctxt == HFI1_CTRL_CTXT)
  10361. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10362. }
  10363. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10364. write_csr(dd, RCV_VL15, 0);
  10365. /*
  10366. * When receive context is being disabled turn on tail
  10367. * update with a dummy tail address and then disable
  10368. * receive context.
  10369. */
  10370. if (dd->rcvhdrtail_dummy_dma) {
  10371. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10372. dd->rcvhdrtail_dummy_dma);
  10373. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10374. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10375. }
  10376. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10377. }
  10378. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10379. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10380. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10381. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10382. if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
  10383. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10384. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10385. /* See comment on RcvCtxtCtrl.TailUpd above */
  10386. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10387. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10388. }
  10389. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10390. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10391. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10392. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10393. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10394. /*
  10395. * In one-packet-per-eager mode, the size comes from
  10396. * the RcvArray entry.
  10397. */
  10398. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10399. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10400. }
  10401. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10402. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10403. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10404. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10405. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10406. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10407. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10408. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10409. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10410. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10411. rcd->rcvctrl = rcvctrl;
  10412. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10413. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
  10414. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10415. if (did_enable &&
  10416. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10417. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10418. if (reg != 0) {
  10419. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10420. ctxt, reg);
  10421. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10422. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10423. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10424. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10425. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10426. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10427. ctxt, reg, reg == 0 ? "not" : "still");
  10428. }
  10429. }
  10430. if (did_enable) {
  10431. /*
  10432. * The interrupt timeout and count must be set after
  10433. * the context is enabled to take effect.
  10434. */
  10435. /* set interrupt timeout */
  10436. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10437. (u64)rcd->rcvavail_timeout <<
  10438. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10439. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10440. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10441. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10442. }
  10443. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10444. /*
  10445. * If the context has been disabled and the Tail Update has
  10446. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10447. * so it doesn't contain an address that is invalid.
  10448. */
  10449. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10450. dd->rcvhdrtail_dummy_dma);
  10451. }
  10452. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10453. {
  10454. int ret;
  10455. u64 val = 0;
  10456. if (namep) {
  10457. ret = dd->cntrnameslen;
  10458. *namep = dd->cntrnames;
  10459. } else {
  10460. const struct cntr_entry *entry;
  10461. int i, j;
  10462. ret = (dd->ndevcntrs) * sizeof(u64);
  10463. /* Get the start of the block of counters */
  10464. *cntrp = dd->cntrs;
  10465. /*
  10466. * Now go and fill in each counter in the block.
  10467. */
  10468. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10469. entry = &dev_cntrs[i];
  10470. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10471. if (entry->flags & CNTR_DISABLED) {
  10472. /* Nothing */
  10473. hfi1_cdbg(CNTR, "\tDisabled\n");
  10474. } else {
  10475. if (entry->flags & CNTR_VL) {
  10476. hfi1_cdbg(CNTR, "\tPer VL\n");
  10477. for (j = 0; j < C_VL_COUNT; j++) {
  10478. val = entry->rw_cntr(entry,
  10479. dd, j,
  10480. CNTR_MODE_R,
  10481. 0);
  10482. hfi1_cdbg(
  10483. CNTR,
  10484. "\t\tRead 0x%llx for %d\n",
  10485. val, j);
  10486. dd->cntrs[entry->offset + j] =
  10487. val;
  10488. }
  10489. } else if (entry->flags & CNTR_SDMA) {
  10490. hfi1_cdbg(CNTR,
  10491. "\t Per SDMA Engine\n");
  10492. for (j = 0; j < dd->chip_sdma_engines;
  10493. j++) {
  10494. val =
  10495. entry->rw_cntr(entry, dd, j,
  10496. CNTR_MODE_R, 0);
  10497. hfi1_cdbg(CNTR,
  10498. "\t\tRead 0x%llx for %d\n",
  10499. val, j);
  10500. dd->cntrs[entry->offset + j] =
  10501. val;
  10502. }
  10503. } else {
  10504. val = entry->rw_cntr(entry, dd,
  10505. CNTR_INVALID_VL,
  10506. CNTR_MODE_R, 0);
  10507. dd->cntrs[entry->offset] = val;
  10508. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10509. }
  10510. }
  10511. }
  10512. }
  10513. return ret;
  10514. }
  10515. /*
  10516. * Used by sysfs to create files for hfi stats to read
  10517. */
  10518. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10519. {
  10520. int ret;
  10521. u64 val = 0;
  10522. if (namep) {
  10523. ret = ppd->dd->portcntrnameslen;
  10524. *namep = ppd->dd->portcntrnames;
  10525. } else {
  10526. const struct cntr_entry *entry;
  10527. int i, j;
  10528. ret = ppd->dd->nportcntrs * sizeof(u64);
  10529. *cntrp = ppd->cntrs;
  10530. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10531. entry = &port_cntrs[i];
  10532. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10533. if (entry->flags & CNTR_DISABLED) {
  10534. /* Nothing */
  10535. hfi1_cdbg(CNTR, "\tDisabled\n");
  10536. continue;
  10537. }
  10538. if (entry->flags & CNTR_VL) {
  10539. hfi1_cdbg(CNTR, "\tPer VL");
  10540. for (j = 0; j < C_VL_COUNT; j++) {
  10541. val = entry->rw_cntr(entry, ppd, j,
  10542. CNTR_MODE_R,
  10543. 0);
  10544. hfi1_cdbg(
  10545. CNTR,
  10546. "\t\tRead 0x%llx for %d",
  10547. val, j);
  10548. ppd->cntrs[entry->offset + j] = val;
  10549. }
  10550. } else {
  10551. val = entry->rw_cntr(entry, ppd,
  10552. CNTR_INVALID_VL,
  10553. CNTR_MODE_R,
  10554. 0);
  10555. ppd->cntrs[entry->offset] = val;
  10556. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10557. }
  10558. }
  10559. }
  10560. return ret;
  10561. }
  10562. static void free_cntrs(struct hfi1_devdata *dd)
  10563. {
  10564. struct hfi1_pportdata *ppd;
  10565. int i;
  10566. if (dd->synth_stats_timer.data)
  10567. del_timer_sync(&dd->synth_stats_timer);
  10568. dd->synth_stats_timer.data = 0;
  10569. ppd = (struct hfi1_pportdata *)(dd + 1);
  10570. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10571. kfree(ppd->cntrs);
  10572. kfree(ppd->scntrs);
  10573. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10574. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10575. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10576. ppd->cntrs = NULL;
  10577. ppd->scntrs = NULL;
  10578. ppd->ibport_data.rvp.rc_acks = NULL;
  10579. ppd->ibport_data.rvp.rc_qacks = NULL;
  10580. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10581. }
  10582. kfree(dd->portcntrnames);
  10583. dd->portcntrnames = NULL;
  10584. kfree(dd->cntrs);
  10585. dd->cntrs = NULL;
  10586. kfree(dd->scntrs);
  10587. dd->scntrs = NULL;
  10588. kfree(dd->cntrnames);
  10589. dd->cntrnames = NULL;
  10590. if (dd->update_cntr_wq) {
  10591. destroy_workqueue(dd->update_cntr_wq);
  10592. dd->update_cntr_wq = NULL;
  10593. }
  10594. }
  10595. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10596. u64 *psval, void *context, int vl)
  10597. {
  10598. u64 val;
  10599. u64 sval = *psval;
  10600. if (entry->flags & CNTR_DISABLED) {
  10601. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10602. return 0;
  10603. }
  10604. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10605. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10606. /* If its a synthetic counter there is more work we need to do */
  10607. if (entry->flags & CNTR_SYNTH) {
  10608. if (sval == CNTR_MAX) {
  10609. /* No need to read already saturated */
  10610. return CNTR_MAX;
  10611. }
  10612. if (entry->flags & CNTR_32BIT) {
  10613. /* 32bit counters can wrap multiple times */
  10614. u64 upper = sval >> 32;
  10615. u64 lower = (sval << 32) >> 32;
  10616. if (lower > val) { /* hw wrapped */
  10617. if (upper == CNTR_32BIT_MAX)
  10618. val = CNTR_MAX;
  10619. else
  10620. upper++;
  10621. }
  10622. if (val != CNTR_MAX)
  10623. val = (upper << 32) | val;
  10624. } else {
  10625. /* If we rolled we are saturated */
  10626. if ((val < sval) || (val > CNTR_MAX))
  10627. val = CNTR_MAX;
  10628. }
  10629. }
  10630. *psval = val;
  10631. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10632. return val;
  10633. }
  10634. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10635. struct cntr_entry *entry,
  10636. u64 *psval, void *context, int vl, u64 data)
  10637. {
  10638. u64 val;
  10639. if (entry->flags & CNTR_DISABLED) {
  10640. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10641. return 0;
  10642. }
  10643. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10644. if (entry->flags & CNTR_SYNTH) {
  10645. *psval = data;
  10646. if (entry->flags & CNTR_32BIT) {
  10647. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10648. (data << 32) >> 32);
  10649. val = data; /* return the full 64bit value */
  10650. } else {
  10651. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10652. data);
  10653. }
  10654. } else {
  10655. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10656. }
  10657. *psval = val;
  10658. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10659. return val;
  10660. }
  10661. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10662. {
  10663. struct cntr_entry *entry;
  10664. u64 *sval;
  10665. entry = &dev_cntrs[index];
  10666. sval = dd->scntrs + entry->offset;
  10667. if (vl != CNTR_INVALID_VL)
  10668. sval += vl;
  10669. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10670. }
  10671. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10672. {
  10673. struct cntr_entry *entry;
  10674. u64 *sval;
  10675. entry = &dev_cntrs[index];
  10676. sval = dd->scntrs + entry->offset;
  10677. if (vl != CNTR_INVALID_VL)
  10678. sval += vl;
  10679. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10680. }
  10681. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10682. {
  10683. struct cntr_entry *entry;
  10684. u64 *sval;
  10685. entry = &port_cntrs[index];
  10686. sval = ppd->scntrs + entry->offset;
  10687. if (vl != CNTR_INVALID_VL)
  10688. sval += vl;
  10689. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10690. (index <= C_RCV_HDR_OVF_LAST)) {
  10691. /* We do not want to bother for disabled contexts */
  10692. return 0;
  10693. }
  10694. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10695. }
  10696. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10697. {
  10698. struct cntr_entry *entry;
  10699. u64 *sval;
  10700. entry = &port_cntrs[index];
  10701. sval = ppd->scntrs + entry->offset;
  10702. if (vl != CNTR_INVALID_VL)
  10703. sval += vl;
  10704. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10705. (index <= C_RCV_HDR_OVF_LAST)) {
  10706. /* We do not want to bother for disabled contexts */
  10707. return 0;
  10708. }
  10709. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10710. }
  10711. static void do_update_synth_timer(struct work_struct *work)
  10712. {
  10713. u64 cur_tx;
  10714. u64 cur_rx;
  10715. u64 total_flits;
  10716. u8 update = 0;
  10717. int i, j, vl;
  10718. struct hfi1_pportdata *ppd;
  10719. struct cntr_entry *entry;
  10720. struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
  10721. update_cntr_work);
  10722. /*
  10723. * Rather than keep beating on the CSRs pick a minimal set that we can
  10724. * check to watch for potential roll over. We can do this by looking at
  10725. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10726. * we have to iterate all the counters and update.
  10727. */
  10728. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10729. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10730. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10731. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10732. hfi1_cdbg(
  10733. CNTR,
  10734. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10735. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10736. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10737. /*
  10738. * May not be strictly necessary to update but it won't hurt and
  10739. * simplifies the logic here.
  10740. */
  10741. update = 1;
  10742. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10743. dd->unit);
  10744. } else {
  10745. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10746. hfi1_cdbg(CNTR,
  10747. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10748. total_flits, (u64)CNTR_32BIT_MAX);
  10749. if (total_flits >= CNTR_32BIT_MAX) {
  10750. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10751. dd->unit);
  10752. update = 1;
  10753. }
  10754. }
  10755. if (update) {
  10756. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10757. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10758. entry = &dev_cntrs[i];
  10759. if (entry->flags & CNTR_VL) {
  10760. for (vl = 0; vl < C_VL_COUNT; vl++)
  10761. read_dev_cntr(dd, i, vl);
  10762. } else {
  10763. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10764. }
  10765. }
  10766. ppd = (struct hfi1_pportdata *)(dd + 1);
  10767. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10768. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10769. entry = &port_cntrs[j];
  10770. if (entry->flags & CNTR_VL) {
  10771. for (vl = 0; vl < C_VL_COUNT; vl++)
  10772. read_port_cntr(ppd, j, vl);
  10773. } else {
  10774. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10775. }
  10776. }
  10777. }
  10778. /*
  10779. * We want the value in the register. The goal is to keep track
  10780. * of the number of "ticks" not the counter value. In other
  10781. * words if the register rolls we want to notice it and go ahead
  10782. * and force an update.
  10783. */
  10784. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10785. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10786. CNTR_MODE_R, 0);
  10787. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10788. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10789. CNTR_MODE_R, 0);
  10790. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10791. dd->unit, dd->last_tx, dd->last_rx);
  10792. } else {
  10793. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10794. }
  10795. }
  10796. static void update_synth_timer(unsigned long opaque)
  10797. {
  10798. struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
  10799. queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
  10800. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10801. }
  10802. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10803. static int init_cntrs(struct hfi1_devdata *dd)
  10804. {
  10805. int i, rcv_ctxts, j;
  10806. size_t sz;
  10807. char *p;
  10808. char name[C_MAX_NAME];
  10809. struct hfi1_pportdata *ppd;
  10810. const char *bit_type_32 = ",32";
  10811. const int bit_type_32_sz = strlen(bit_type_32);
  10812. /* set up the stats timer; the add_timer is done at the end */
  10813. setup_timer(&dd->synth_stats_timer, update_synth_timer,
  10814. (unsigned long)dd);
  10815. /***********************/
  10816. /* per device counters */
  10817. /***********************/
  10818. /* size names and determine how many we have*/
  10819. dd->ndevcntrs = 0;
  10820. sz = 0;
  10821. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10822. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10823. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10824. continue;
  10825. }
  10826. if (dev_cntrs[i].flags & CNTR_VL) {
  10827. dev_cntrs[i].offset = dd->ndevcntrs;
  10828. for (j = 0; j < C_VL_COUNT; j++) {
  10829. snprintf(name, C_MAX_NAME, "%s%d",
  10830. dev_cntrs[i].name, vl_from_idx(j));
  10831. sz += strlen(name);
  10832. /* Add ",32" for 32-bit counters */
  10833. if (dev_cntrs[i].flags & CNTR_32BIT)
  10834. sz += bit_type_32_sz;
  10835. sz++;
  10836. dd->ndevcntrs++;
  10837. }
  10838. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10839. dev_cntrs[i].offset = dd->ndevcntrs;
  10840. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10841. snprintf(name, C_MAX_NAME, "%s%d",
  10842. dev_cntrs[i].name, j);
  10843. sz += strlen(name);
  10844. /* Add ",32" for 32-bit counters */
  10845. if (dev_cntrs[i].flags & CNTR_32BIT)
  10846. sz += bit_type_32_sz;
  10847. sz++;
  10848. dd->ndevcntrs++;
  10849. }
  10850. } else {
  10851. /* +1 for newline. */
  10852. sz += strlen(dev_cntrs[i].name) + 1;
  10853. /* Add ",32" for 32-bit counters */
  10854. if (dev_cntrs[i].flags & CNTR_32BIT)
  10855. sz += bit_type_32_sz;
  10856. dev_cntrs[i].offset = dd->ndevcntrs;
  10857. dd->ndevcntrs++;
  10858. }
  10859. }
  10860. /* allocate space for the counter values */
  10861. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10862. if (!dd->cntrs)
  10863. goto bail;
  10864. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10865. if (!dd->scntrs)
  10866. goto bail;
  10867. /* allocate space for the counter names */
  10868. dd->cntrnameslen = sz;
  10869. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10870. if (!dd->cntrnames)
  10871. goto bail;
  10872. /* fill in the names */
  10873. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10874. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10875. /* Nothing */
  10876. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10877. for (j = 0; j < C_VL_COUNT; j++) {
  10878. snprintf(name, C_MAX_NAME, "%s%d",
  10879. dev_cntrs[i].name,
  10880. vl_from_idx(j));
  10881. memcpy(p, name, strlen(name));
  10882. p += strlen(name);
  10883. /* Counter is 32 bits */
  10884. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10885. memcpy(p, bit_type_32, bit_type_32_sz);
  10886. p += bit_type_32_sz;
  10887. }
  10888. *p++ = '\n';
  10889. }
  10890. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10891. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10892. snprintf(name, C_MAX_NAME, "%s%d",
  10893. dev_cntrs[i].name, j);
  10894. memcpy(p, name, strlen(name));
  10895. p += strlen(name);
  10896. /* Counter is 32 bits */
  10897. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10898. memcpy(p, bit_type_32, bit_type_32_sz);
  10899. p += bit_type_32_sz;
  10900. }
  10901. *p++ = '\n';
  10902. }
  10903. } else {
  10904. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10905. p += strlen(dev_cntrs[i].name);
  10906. /* Counter is 32 bits */
  10907. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10908. memcpy(p, bit_type_32, bit_type_32_sz);
  10909. p += bit_type_32_sz;
  10910. }
  10911. *p++ = '\n';
  10912. }
  10913. }
  10914. /*********************/
  10915. /* per port counters */
  10916. /*********************/
  10917. /*
  10918. * Go through the counters for the overflows and disable the ones we
  10919. * don't need. This varies based on platform so we need to do it
  10920. * dynamically here.
  10921. */
  10922. rcv_ctxts = dd->num_rcv_contexts;
  10923. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  10924. i <= C_RCV_HDR_OVF_LAST; i++) {
  10925. port_cntrs[i].flags |= CNTR_DISABLED;
  10926. }
  10927. /* size port counter names and determine how many we have*/
  10928. sz = 0;
  10929. dd->nportcntrs = 0;
  10930. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10931. if (port_cntrs[i].flags & CNTR_DISABLED) {
  10932. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  10933. continue;
  10934. }
  10935. if (port_cntrs[i].flags & CNTR_VL) {
  10936. port_cntrs[i].offset = dd->nportcntrs;
  10937. for (j = 0; j < C_VL_COUNT; j++) {
  10938. snprintf(name, C_MAX_NAME, "%s%d",
  10939. port_cntrs[i].name, vl_from_idx(j));
  10940. sz += strlen(name);
  10941. /* Add ",32" for 32-bit counters */
  10942. if (port_cntrs[i].flags & CNTR_32BIT)
  10943. sz += bit_type_32_sz;
  10944. sz++;
  10945. dd->nportcntrs++;
  10946. }
  10947. } else {
  10948. /* +1 for newline */
  10949. sz += strlen(port_cntrs[i].name) + 1;
  10950. /* Add ",32" for 32-bit counters */
  10951. if (port_cntrs[i].flags & CNTR_32BIT)
  10952. sz += bit_type_32_sz;
  10953. port_cntrs[i].offset = dd->nportcntrs;
  10954. dd->nportcntrs++;
  10955. }
  10956. }
  10957. /* allocate space for the counter names */
  10958. dd->portcntrnameslen = sz;
  10959. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  10960. if (!dd->portcntrnames)
  10961. goto bail;
  10962. /* fill in port cntr names */
  10963. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  10964. if (port_cntrs[i].flags & CNTR_DISABLED)
  10965. continue;
  10966. if (port_cntrs[i].flags & CNTR_VL) {
  10967. for (j = 0; j < C_VL_COUNT; j++) {
  10968. snprintf(name, C_MAX_NAME, "%s%d",
  10969. port_cntrs[i].name, vl_from_idx(j));
  10970. memcpy(p, name, strlen(name));
  10971. p += strlen(name);
  10972. /* Counter is 32 bits */
  10973. if (port_cntrs[i].flags & CNTR_32BIT) {
  10974. memcpy(p, bit_type_32, bit_type_32_sz);
  10975. p += bit_type_32_sz;
  10976. }
  10977. *p++ = '\n';
  10978. }
  10979. } else {
  10980. memcpy(p, port_cntrs[i].name,
  10981. strlen(port_cntrs[i].name));
  10982. p += strlen(port_cntrs[i].name);
  10983. /* Counter is 32 bits */
  10984. if (port_cntrs[i].flags & CNTR_32BIT) {
  10985. memcpy(p, bit_type_32, bit_type_32_sz);
  10986. p += bit_type_32_sz;
  10987. }
  10988. *p++ = '\n';
  10989. }
  10990. }
  10991. /* allocate per port storage for counter values */
  10992. ppd = (struct hfi1_pportdata *)(dd + 1);
  10993. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10994. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  10995. if (!ppd->cntrs)
  10996. goto bail;
  10997. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  10998. if (!ppd->scntrs)
  10999. goto bail;
  11000. }
  11001. /* CPU counters need to be allocated and zeroed */
  11002. if (init_cpu_counters(dd))
  11003. goto bail;
  11004. dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
  11005. WQ_MEM_RECLAIM, dd->unit);
  11006. if (!dd->update_cntr_wq)
  11007. goto bail;
  11008. INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
  11009. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  11010. return 0;
  11011. bail:
  11012. free_cntrs(dd);
  11013. return -ENOMEM;
  11014. }
  11015. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  11016. {
  11017. switch (chip_lstate) {
  11018. default:
  11019. dd_dev_err(dd,
  11020. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  11021. chip_lstate);
  11022. /* fall through */
  11023. case LSTATE_DOWN:
  11024. return IB_PORT_DOWN;
  11025. case LSTATE_INIT:
  11026. return IB_PORT_INIT;
  11027. case LSTATE_ARMED:
  11028. return IB_PORT_ARMED;
  11029. case LSTATE_ACTIVE:
  11030. return IB_PORT_ACTIVE;
  11031. }
  11032. }
  11033. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  11034. {
  11035. /* look at the HFI meta-states only */
  11036. switch (chip_pstate & 0xf0) {
  11037. default:
  11038. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  11039. chip_pstate);
  11040. /* fall through */
  11041. case PLS_DISABLED:
  11042. return IB_PORTPHYSSTATE_DISABLED;
  11043. case PLS_OFFLINE:
  11044. return OPA_PORTPHYSSTATE_OFFLINE;
  11045. case PLS_POLLING:
  11046. return IB_PORTPHYSSTATE_POLLING;
  11047. case PLS_CONFIGPHY:
  11048. return IB_PORTPHYSSTATE_TRAINING;
  11049. case PLS_LINKUP:
  11050. return IB_PORTPHYSSTATE_LINKUP;
  11051. case PLS_PHYTEST:
  11052. return IB_PORTPHYSSTATE_PHY_TEST;
  11053. }
  11054. }
  11055. /* return the OPA port logical state name */
  11056. const char *opa_lstate_name(u32 lstate)
  11057. {
  11058. static const char * const port_logical_names[] = {
  11059. "PORT_NOP",
  11060. "PORT_DOWN",
  11061. "PORT_INIT",
  11062. "PORT_ARMED",
  11063. "PORT_ACTIVE",
  11064. "PORT_ACTIVE_DEFER",
  11065. };
  11066. if (lstate < ARRAY_SIZE(port_logical_names))
  11067. return port_logical_names[lstate];
  11068. return "unknown";
  11069. }
  11070. /* return the OPA port physical state name */
  11071. const char *opa_pstate_name(u32 pstate)
  11072. {
  11073. static const char * const port_physical_names[] = {
  11074. "PHYS_NOP",
  11075. "reserved1",
  11076. "PHYS_POLL",
  11077. "PHYS_DISABLED",
  11078. "PHYS_TRAINING",
  11079. "PHYS_LINKUP",
  11080. "PHYS_LINK_ERR_RECOVER",
  11081. "PHYS_PHY_TEST",
  11082. "reserved8",
  11083. "PHYS_OFFLINE",
  11084. "PHYS_GANGED",
  11085. "PHYS_TEST",
  11086. };
  11087. if (pstate < ARRAY_SIZE(port_physical_names))
  11088. return port_physical_names[pstate];
  11089. return "unknown";
  11090. }
  11091. static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
  11092. {
  11093. /*
  11094. * Set port status flags in the page mapped into userspace
  11095. * memory. Do it here to ensure a reliable state - this is
  11096. * the only function called by all state handling code.
  11097. * Always set the flags due to the fact that the cache value
  11098. * might have been changed explicitly outside of this
  11099. * function.
  11100. */
  11101. if (ppd->statusp) {
  11102. switch (state) {
  11103. case IB_PORT_DOWN:
  11104. case IB_PORT_INIT:
  11105. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  11106. HFI1_STATUS_IB_READY);
  11107. break;
  11108. case IB_PORT_ARMED:
  11109. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  11110. break;
  11111. case IB_PORT_ACTIVE:
  11112. *ppd->statusp |= HFI1_STATUS_IB_READY;
  11113. break;
  11114. }
  11115. }
  11116. }
  11117. /*
  11118. * wait_logical_linkstate - wait for an IB link state change to occur
  11119. * @ppd: port device
  11120. * @state: the state to wait for
  11121. * @msecs: the number of milliseconds to wait
  11122. *
  11123. * Wait up to msecs milliseconds for IB link state change to occur.
  11124. * For now, take the easy polling route.
  11125. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11126. */
  11127. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11128. int msecs)
  11129. {
  11130. unsigned long timeout;
  11131. u32 new_state;
  11132. timeout = jiffies + msecs_to_jiffies(msecs);
  11133. while (1) {
  11134. new_state = chip_to_opa_lstate(ppd->dd,
  11135. read_logical_state(ppd->dd));
  11136. if (new_state == state)
  11137. break;
  11138. if (time_after(jiffies, timeout)) {
  11139. dd_dev_err(ppd->dd,
  11140. "timeout waiting for link state 0x%x\n",
  11141. state);
  11142. return -ETIMEDOUT;
  11143. }
  11144. msleep(20);
  11145. }
  11146. update_statusp(ppd, state);
  11147. dd_dev_info(ppd->dd,
  11148. "logical state changed to %s (0x%x)\n",
  11149. opa_lstate_name(state),
  11150. state);
  11151. return 0;
  11152. }
  11153. /*
  11154. * Read the physical hardware link state and set the driver's cached value
  11155. * of it.
  11156. */
  11157. void cache_physical_state(struct hfi1_pportdata *ppd)
  11158. {
  11159. u32 read_pstate;
  11160. u32 ib_pstate;
  11161. read_pstate = read_physical_state(ppd->dd);
  11162. ib_pstate = chip_to_opa_pstate(ppd->dd, read_pstate);
  11163. /* check if OPA pstate changed */
  11164. if (chip_to_opa_pstate(ppd->dd, ppd->pstate) != ib_pstate) {
  11165. dd_dev_info(ppd->dd,
  11166. "%s: physical state changed to %s (0x%x), phy 0x%x\n",
  11167. __func__, opa_pstate_name(ib_pstate), ib_pstate,
  11168. read_pstate);
  11169. }
  11170. ppd->pstate = read_pstate;
  11171. }
  11172. /*
  11173. * wait_physical_linkstate - wait for an physical link state change to occur
  11174. * @ppd: port device
  11175. * @state: the state to wait for
  11176. * @msecs: the number of milliseconds to wait
  11177. *
  11178. * Wait up to msecs milliseconds for physical link state change to occur.
  11179. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11180. */
  11181. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11182. int msecs)
  11183. {
  11184. unsigned long timeout;
  11185. timeout = jiffies + msecs_to_jiffies(msecs);
  11186. while (1) {
  11187. cache_physical_state(ppd);
  11188. if (ppd->pstate == state)
  11189. break;
  11190. if (time_after(jiffies, timeout)) {
  11191. dd_dev_err(ppd->dd,
  11192. "timeout waiting for phy link state 0x%x, current state is 0x%x\n",
  11193. state, ppd->pstate);
  11194. return -ETIMEDOUT;
  11195. }
  11196. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11197. }
  11198. return 0;
  11199. }
  11200. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  11201. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11202. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  11203. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11204. void hfi1_init_ctxt(struct send_context *sc)
  11205. {
  11206. if (sc) {
  11207. struct hfi1_devdata *dd = sc->dd;
  11208. u64 reg;
  11209. u8 set = (sc->type == SC_USER ?
  11210. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  11211. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  11212. reg = read_kctxt_csr(dd, sc->hw_context,
  11213. SEND_CTXT_CHECK_ENABLE);
  11214. if (set)
  11215. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  11216. else
  11217. SET_STATIC_RATE_CONTROL_SMASK(reg);
  11218. write_kctxt_csr(dd, sc->hw_context,
  11219. SEND_CTXT_CHECK_ENABLE, reg);
  11220. }
  11221. }
  11222. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  11223. {
  11224. int ret = 0;
  11225. u64 reg;
  11226. if (dd->icode != ICODE_RTL_SILICON) {
  11227. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  11228. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  11229. __func__);
  11230. return -EINVAL;
  11231. }
  11232. reg = read_csr(dd, ASIC_STS_THERM);
  11233. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  11234. ASIC_STS_THERM_CURR_TEMP_MASK);
  11235. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  11236. ASIC_STS_THERM_LO_TEMP_MASK);
  11237. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11238. ASIC_STS_THERM_HI_TEMP_MASK);
  11239. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11240. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11241. /* triggers is a 3-bit value - 1 bit per trigger. */
  11242. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11243. return ret;
  11244. }
  11245. /* ========================================================================= */
  11246. /*
  11247. * Enable/disable chip from delivering interrupts.
  11248. */
  11249. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11250. {
  11251. int i;
  11252. /*
  11253. * In HFI, the mask needs to be 1 to allow interrupts.
  11254. */
  11255. if (enable) {
  11256. /* enable all interrupts */
  11257. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11258. write_csr(dd, CCE_INT_MASK + (8 * i), ~(u64)0);
  11259. init_qsfp_int(dd);
  11260. } else {
  11261. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11262. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11263. }
  11264. }
  11265. /*
  11266. * Clear all interrupt sources on the chip.
  11267. */
  11268. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11269. {
  11270. int i;
  11271. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11272. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11273. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11274. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11275. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11276. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11277. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11278. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11279. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11280. for (i = 0; i < dd->chip_send_contexts; i++)
  11281. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11282. for (i = 0; i < dd->chip_sdma_engines; i++)
  11283. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11284. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11285. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11286. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11287. }
  11288. /* Move to pcie.c? */
  11289. static void disable_intx(struct pci_dev *pdev)
  11290. {
  11291. pci_intx(pdev, 0);
  11292. }
  11293. static void clean_up_interrupts(struct hfi1_devdata *dd)
  11294. {
  11295. int i;
  11296. /* remove irqs - must happen before disabling/turning off */
  11297. if (dd->num_msix_entries) {
  11298. /* MSI-X */
  11299. struct hfi1_msix_entry *me = dd->msix_entries;
  11300. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11301. if (!me->arg) /* => no irq, no affinity */
  11302. continue;
  11303. hfi1_put_irq_affinity(dd, me);
  11304. free_irq(me->irq, me->arg);
  11305. }
  11306. /* clean structures */
  11307. kfree(dd->msix_entries);
  11308. dd->msix_entries = NULL;
  11309. dd->num_msix_entries = 0;
  11310. } else {
  11311. /* INTx */
  11312. if (dd->requested_intx_irq) {
  11313. free_irq(dd->pcidev->irq, dd);
  11314. dd->requested_intx_irq = 0;
  11315. }
  11316. disable_intx(dd->pcidev);
  11317. }
  11318. pci_free_irq_vectors(dd->pcidev);
  11319. }
  11320. /*
  11321. * Remap the interrupt source from the general handler to the given MSI-X
  11322. * interrupt.
  11323. */
  11324. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11325. {
  11326. u64 reg;
  11327. int m, n;
  11328. /* clear from the handled mask of the general interrupt */
  11329. m = isrc / 64;
  11330. n = isrc % 64;
  11331. if (likely(m < CCE_NUM_INT_CSRS)) {
  11332. dd->gi_mask[m] &= ~((u64)1 << n);
  11333. } else {
  11334. dd_dev_err(dd, "remap interrupt err\n");
  11335. return;
  11336. }
  11337. /* direct the chip source to the given MSI-X interrupt */
  11338. m = isrc / 8;
  11339. n = isrc % 8;
  11340. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11341. reg &= ~((u64)0xff << (8 * n));
  11342. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11343. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11344. }
  11345. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11346. int engine, int msix_intr)
  11347. {
  11348. /*
  11349. * SDMA engine interrupt sources grouped by type, rather than
  11350. * engine. Per-engine interrupts are as follows:
  11351. * SDMA
  11352. * SDMAProgress
  11353. * SDMAIdle
  11354. */
  11355. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11356. msix_intr);
  11357. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11358. msix_intr);
  11359. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11360. msix_intr);
  11361. }
  11362. static int request_intx_irq(struct hfi1_devdata *dd)
  11363. {
  11364. int ret;
  11365. snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d",
  11366. dd->unit);
  11367. ret = request_irq(dd->pcidev->irq, general_interrupt,
  11368. IRQF_SHARED, dd->intx_name, dd);
  11369. if (ret)
  11370. dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
  11371. ret);
  11372. else
  11373. dd->requested_intx_irq = 1;
  11374. return ret;
  11375. }
  11376. static int request_msix_irqs(struct hfi1_devdata *dd)
  11377. {
  11378. int first_general, last_general;
  11379. int first_sdma, last_sdma;
  11380. int first_rx, last_rx;
  11381. int i, ret = 0;
  11382. /* calculate the ranges we are going to use */
  11383. first_general = 0;
  11384. last_general = first_general + 1;
  11385. first_sdma = last_general;
  11386. last_sdma = first_sdma + dd->num_sdma;
  11387. first_rx = last_sdma;
  11388. last_rx = first_rx + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
  11389. /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
  11390. dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
  11391. /*
  11392. * Sanity check - the code expects all SDMA chip source
  11393. * interrupts to be in the same CSR, starting at bit 0. Verify
  11394. * that this is true by checking the bit location of the start.
  11395. */
  11396. BUILD_BUG_ON(IS_SDMA_START % 64);
  11397. for (i = 0; i < dd->num_msix_entries; i++) {
  11398. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11399. const char *err_info;
  11400. irq_handler_t handler;
  11401. irq_handler_t thread = NULL;
  11402. void *arg = NULL;
  11403. int idx;
  11404. struct hfi1_ctxtdata *rcd = NULL;
  11405. struct sdma_engine *sde = NULL;
  11406. /* obtain the arguments to request_irq */
  11407. if (first_general <= i && i < last_general) {
  11408. idx = i - first_general;
  11409. handler = general_interrupt;
  11410. arg = dd;
  11411. snprintf(me->name, sizeof(me->name),
  11412. DRIVER_NAME "_%d", dd->unit);
  11413. err_info = "general";
  11414. me->type = IRQ_GENERAL;
  11415. } else if (first_sdma <= i && i < last_sdma) {
  11416. idx = i - first_sdma;
  11417. sde = &dd->per_sdma[idx];
  11418. handler = sdma_interrupt;
  11419. arg = sde;
  11420. snprintf(me->name, sizeof(me->name),
  11421. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11422. err_info = "sdma";
  11423. remap_sdma_interrupts(dd, idx, i);
  11424. me->type = IRQ_SDMA;
  11425. } else if (first_rx <= i && i < last_rx) {
  11426. idx = i - first_rx;
  11427. rcd = hfi1_rcd_get_by_index(dd, idx);
  11428. if (rcd) {
  11429. /*
  11430. * Set the interrupt register and mask for this
  11431. * context's interrupt.
  11432. */
  11433. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11434. rcd->imask = ((u64)1) <<
  11435. ((IS_RCVAVAIL_START + idx) % 64);
  11436. handler = receive_context_interrupt;
  11437. thread = receive_context_thread;
  11438. arg = rcd;
  11439. snprintf(me->name, sizeof(me->name),
  11440. DRIVER_NAME "_%d kctxt%d",
  11441. dd->unit, idx);
  11442. err_info = "receive context";
  11443. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11444. me->type = IRQ_RCVCTXT;
  11445. rcd->msix_intr = i;
  11446. hfi1_rcd_put(rcd);
  11447. }
  11448. } else {
  11449. /* not in our expected range - complain, then
  11450. * ignore it
  11451. */
  11452. dd_dev_err(dd,
  11453. "Unexpected extra MSI-X interrupt %d\n", i);
  11454. continue;
  11455. }
  11456. /* no argument, no interrupt */
  11457. if (!arg)
  11458. continue;
  11459. /* make sure the name is terminated */
  11460. me->name[sizeof(me->name) - 1] = 0;
  11461. me->irq = pci_irq_vector(dd->pcidev, i);
  11462. /*
  11463. * On err return me->irq. Don't need to clear this
  11464. * because 'arg' has not been set, and cleanup will
  11465. * do the right thing.
  11466. */
  11467. if (me->irq < 0)
  11468. return me->irq;
  11469. ret = request_threaded_irq(me->irq, handler, thread, 0,
  11470. me->name, arg);
  11471. if (ret) {
  11472. dd_dev_err(dd,
  11473. "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
  11474. err_info, me->irq, idx, ret);
  11475. return ret;
  11476. }
  11477. /*
  11478. * assign arg after request_irq call, so it will be
  11479. * cleaned up
  11480. */
  11481. me->arg = arg;
  11482. ret = hfi1_get_irq_affinity(dd, me);
  11483. if (ret)
  11484. dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
  11485. }
  11486. return ret;
  11487. }
  11488. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
  11489. {
  11490. int i;
  11491. if (!dd->num_msix_entries) {
  11492. synchronize_irq(dd->pcidev->irq);
  11493. return;
  11494. }
  11495. for (i = 0; i < dd->vnic.num_ctxt; i++) {
  11496. struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
  11497. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11498. synchronize_irq(me->irq);
  11499. }
  11500. }
  11501. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11502. {
  11503. struct hfi1_devdata *dd = rcd->dd;
  11504. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11505. if (!me->arg) /* => no irq, no affinity */
  11506. return;
  11507. hfi1_put_irq_affinity(dd, me);
  11508. free_irq(me->irq, me->arg);
  11509. me->arg = NULL;
  11510. }
  11511. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11512. {
  11513. struct hfi1_devdata *dd = rcd->dd;
  11514. struct hfi1_msix_entry *me;
  11515. int idx = rcd->ctxt;
  11516. void *arg = rcd;
  11517. int ret;
  11518. rcd->msix_intr = dd->vnic.msix_idx++;
  11519. me = &dd->msix_entries[rcd->msix_intr];
  11520. /*
  11521. * Set the interrupt register and mask for this
  11522. * context's interrupt.
  11523. */
  11524. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11525. rcd->imask = ((u64)1) <<
  11526. ((IS_RCVAVAIL_START + idx) % 64);
  11527. snprintf(me->name, sizeof(me->name),
  11528. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11529. me->name[sizeof(me->name) - 1] = 0;
  11530. me->type = IRQ_RCVCTXT;
  11531. me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
  11532. if (me->irq < 0) {
  11533. dd_dev_err(dd, "vnic irq vector request (idx %d) fail %d\n",
  11534. idx, me->irq);
  11535. return;
  11536. }
  11537. remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
  11538. ret = request_threaded_irq(me->irq, receive_context_interrupt,
  11539. receive_context_thread, 0, me->name, arg);
  11540. if (ret) {
  11541. dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
  11542. me->irq, idx, ret);
  11543. return;
  11544. }
  11545. /*
  11546. * assign arg after request_irq call, so it will be
  11547. * cleaned up
  11548. */
  11549. me->arg = arg;
  11550. ret = hfi1_get_irq_affinity(dd, me);
  11551. if (ret) {
  11552. dd_dev_err(dd,
  11553. "unable to pin IRQ %d\n", ret);
  11554. free_irq(me->irq, me->arg);
  11555. }
  11556. }
  11557. /*
  11558. * Set the general handler to accept all interrupts, remap all
  11559. * chip interrupts back to MSI-X 0.
  11560. */
  11561. static void reset_interrupts(struct hfi1_devdata *dd)
  11562. {
  11563. int i;
  11564. /* all interrupts handled by the general handler */
  11565. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11566. dd->gi_mask[i] = ~(u64)0;
  11567. /* all chip interrupts map to MSI-X 0 */
  11568. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11569. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11570. }
  11571. static int set_up_interrupts(struct hfi1_devdata *dd)
  11572. {
  11573. u32 total;
  11574. int ret, request;
  11575. int single_interrupt = 0; /* we expect to have all the interrupts */
  11576. /*
  11577. * Interrupt count:
  11578. * 1 general, "slow path" interrupt (includes the SDMA engines
  11579. * slow source, SDMACleanupDone)
  11580. * N interrupts - one per used SDMA engine
  11581. * M interrupt - one per kernel receive context
  11582. */
  11583. total = 1 + dd->num_sdma + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
  11584. /* ask for MSI-X interrupts */
  11585. request = request_msix(dd, total);
  11586. if (request < 0) {
  11587. ret = request;
  11588. goto fail;
  11589. } else if (request == 0) {
  11590. /* using INTx */
  11591. /* dd->num_msix_entries already zero */
  11592. single_interrupt = 1;
  11593. dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
  11594. } else if (request < total) {
  11595. /* using MSI-X, with reduced interrupts */
  11596. dd_dev_err(dd, "reduced interrupt found, wanted %u, got %u\n",
  11597. total, request);
  11598. ret = -EINVAL;
  11599. goto fail;
  11600. } else {
  11601. dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
  11602. GFP_KERNEL);
  11603. if (!dd->msix_entries) {
  11604. ret = -ENOMEM;
  11605. goto fail;
  11606. }
  11607. /* using MSI-X */
  11608. dd->num_msix_entries = total;
  11609. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11610. }
  11611. /* mask all interrupts */
  11612. set_intr_state(dd, 0);
  11613. /* clear all pending interrupts */
  11614. clear_all_interrupts(dd);
  11615. /* reset general handler mask, chip MSI-X mappings */
  11616. reset_interrupts(dd);
  11617. if (single_interrupt)
  11618. ret = request_intx_irq(dd);
  11619. else
  11620. ret = request_msix_irqs(dd);
  11621. if (ret)
  11622. goto fail;
  11623. return 0;
  11624. fail:
  11625. clean_up_interrupts(dd);
  11626. return ret;
  11627. }
  11628. /*
  11629. * Set up context values in dd. Sets:
  11630. *
  11631. * num_rcv_contexts - number of contexts being used
  11632. * n_krcv_queues - number of kernel contexts
  11633. * first_dyn_alloc_ctxt - first dynamically allocated context
  11634. * in array of contexts
  11635. * freectxts - number of free user contexts
  11636. * num_send_contexts - number of PIO send contexts being used
  11637. */
  11638. static int set_up_context_variables(struct hfi1_devdata *dd)
  11639. {
  11640. unsigned long num_kernel_contexts;
  11641. int total_contexts;
  11642. int ret;
  11643. unsigned ngroups;
  11644. int qos_rmt_count;
  11645. int user_rmt_reduced;
  11646. /*
  11647. * Kernel receive contexts:
  11648. * - Context 0 - control context (VL15/multicast/error)
  11649. * - Context 1 - first kernel context
  11650. * - Context 2 - second kernel context
  11651. * ...
  11652. */
  11653. if (n_krcvqs)
  11654. /*
  11655. * n_krcvqs is the sum of module parameter kernel receive
  11656. * contexts, krcvqs[]. It does not include the control
  11657. * context, so add that.
  11658. */
  11659. num_kernel_contexts = n_krcvqs + 1;
  11660. else
  11661. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11662. /*
  11663. * Every kernel receive context needs an ACK send context.
  11664. * one send context is allocated for each VL{0-7} and VL15
  11665. */
  11666. if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
  11667. dd_dev_err(dd,
  11668. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11669. (int)(dd->chip_send_contexts - num_vls - 1),
  11670. num_kernel_contexts);
  11671. num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
  11672. }
  11673. /*
  11674. * User contexts:
  11675. * - default to 1 user context per real (non-HT) CPU core if
  11676. * num_user_contexts is negative
  11677. */
  11678. if (num_user_contexts < 0)
  11679. num_user_contexts =
  11680. cpumask_weight(&node_affinity.real_cpu_mask);
  11681. total_contexts = num_kernel_contexts + num_user_contexts;
  11682. /*
  11683. * Adjust the counts given a global max.
  11684. */
  11685. if (total_contexts > dd->chip_rcv_contexts) {
  11686. dd_dev_err(dd,
  11687. "Reducing # user receive contexts to: %d, from %d\n",
  11688. (int)(dd->chip_rcv_contexts - num_kernel_contexts),
  11689. (int)num_user_contexts);
  11690. num_user_contexts = dd->chip_rcv_contexts - num_kernel_contexts;
  11691. /* recalculate */
  11692. total_contexts = num_kernel_contexts + num_user_contexts;
  11693. }
  11694. /* each user context requires an entry in the RMT */
  11695. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11696. if (qos_rmt_count + num_user_contexts > NUM_MAP_ENTRIES) {
  11697. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11698. dd_dev_err(dd,
  11699. "RMT size is reducing the number of user receive contexts from %d to %d\n",
  11700. (int)num_user_contexts,
  11701. user_rmt_reduced);
  11702. /* recalculate */
  11703. num_user_contexts = user_rmt_reduced;
  11704. total_contexts = num_kernel_contexts + num_user_contexts;
  11705. }
  11706. /* Accommodate VNIC contexts */
  11707. if ((total_contexts + HFI1_NUM_VNIC_CTXT) <= dd->chip_rcv_contexts)
  11708. total_contexts += HFI1_NUM_VNIC_CTXT;
  11709. /* the first N are kernel contexts, the rest are user/vnic contexts */
  11710. dd->num_rcv_contexts = total_contexts;
  11711. dd->n_krcv_queues = num_kernel_contexts;
  11712. dd->first_dyn_alloc_ctxt = num_kernel_contexts;
  11713. dd->num_user_contexts = num_user_contexts;
  11714. dd->freectxts = num_user_contexts;
  11715. dd_dev_info(dd,
  11716. "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
  11717. (int)dd->chip_rcv_contexts,
  11718. (int)dd->num_rcv_contexts,
  11719. (int)dd->n_krcv_queues,
  11720. (int)dd->num_rcv_contexts - dd->n_krcv_queues);
  11721. /*
  11722. * Receive array allocation:
  11723. * All RcvArray entries are divided into groups of 8. This
  11724. * is required by the hardware and will speed up writes to
  11725. * consecutive entries by using write-combining of the entire
  11726. * cacheline.
  11727. *
  11728. * The number of groups are evenly divided among all contexts.
  11729. * any left over groups will be given to the first N user
  11730. * contexts.
  11731. */
  11732. dd->rcv_entries.group_size = RCV_INCREMENT;
  11733. ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
  11734. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11735. dd->rcv_entries.nctxt_extra = ngroups -
  11736. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11737. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11738. dd->rcv_entries.ngroups,
  11739. dd->rcv_entries.nctxt_extra);
  11740. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11741. MAX_EAGER_ENTRIES * 2) {
  11742. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11743. dd->rcv_entries.group_size;
  11744. dd_dev_info(dd,
  11745. "RcvArray group count too high, change to %u\n",
  11746. dd->rcv_entries.ngroups);
  11747. dd->rcv_entries.nctxt_extra = 0;
  11748. }
  11749. /*
  11750. * PIO send contexts
  11751. */
  11752. ret = init_sc_pools_and_sizes(dd);
  11753. if (ret >= 0) { /* success */
  11754. dd->num_send_contexts = ret;
  11755. dd_dev_info(
  11756. dd,
  11757. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11758. dd->chip_send_contexts,
  11759. dd->num_send_contexts,
  11760. dd->sc_sizes[SC_KERNEL].count,
  11761. dd->sc_sizes[SC_ACK].count,
  11762. dd->sc_sizes[SC_USER].count,
  11763. dd->sc_sizes[SC_VL15].count);
  11764. ret = 0; /* success */
  11765. }
  11766. return ret;
  11767. }
  11768. /*
  11769. * Set the device/port partition key table. The MAD code
  11770. * will ensure that, at least, the partial management
  11771. * partition key is present in the table.
  11772. */
  11773. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11774. {
  11775. struct hfi1_devdata *dd = ppd->dd;
  11776. u64 reg = 0;
  11777. int i;
  11778. dd_dev_info(dd, "Setting partition keys\n");
  11779. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11780. reg |= (ppd->pkeys[i] &
  11781. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11782. ((i % 4) *
  11783. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11784. /* Each register holds 4 PKey values. */
  11785. if ((i % 4) == 3) {
  11786. write_csr(dd, RCV_PARTITION_KEY +
  11787. ((i - 3) * 2), reg);
  11788. reg = 0;
  11789. }
  11790. }
  11791. /* Always enable HW pkeys check when pkeys table is set */
  11792. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11793. }
  11794. /*
  11795. * These CSRs and memories are uninitialized on reset and must be
  11796. * written before reading to set the ECC/parity bits.
  11797. *
  11798. * NOTE: All user context CSRs that are not mmaped write-only
  11799. * (e.g. the TID flows) must be initialized even if the driver never
  11800. * reads them.
  11801. */
  11802. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11803. {
  11804. int i, j;
  11805. /* CceIntMap */
  11806. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11807. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11808. /* SendCtxtCreditReturnAddr */
  11809. for (i = 0; i < dd->chip_send_contexts; i++)
  11810. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11811. /* PIO Send buffers */
  11812. /* SDMA Send buffers */
  11813. /*
  11814. * These are not normally read, and (presently) have no method
  11815. * to be read, so are not pre-initialized
  11816. */
  11817. /* RcvHdrAddr */
  11818. /* RcvHdrTailAddr */
  11819. /* RcvTidFlowTable */
  11820. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11821. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11822. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11823. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11824. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11825. }
  11826. /* RcvArray */
  11827. for (i = 0; i < dd->chip_rcv_array_count; i++)
  11828. hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
  11829. /* RcvQPMapTable */
  11830. for (i = 0; i < 32; i++)
  11831. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11832. }
  11833. /*
  11834. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11835. */
  11836. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11837. u64 ctrl_bits)
  11838. {
  11839. unsigned long timeout;
  11840. u64 reg;
  11841. /* is the condition present? */
  11842. reg = read_csr(dd, CCE_STATUS);
  11843. if ((reg & status_bits) == 0)
  11844. return;
  11845. /* clear the condition */
  11846. write_csr(dd, CCE_CTRL, ctrl_bits);
  11847. /* wait for the condition to clear */
  11848. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11849. while (1) {
  11850. reg = read_csr(dd, CCE_STATUS);
  11851. if ((reg & status_bits) == 0)
  11852. return;
  11853. if (time_after(jiffies, timeout)) {
  11854. dd_dev_err(dd,
  11855. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11856. status_bits, reg & status_bits);
  11857. return;
  11858. }
  11859. udelay(1);
  11860. }
  11861. }
  11862. /* set CCE CSRs to chip reset defaults */
  11863. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11864. {
  11865. int i;
  11866. /* CCE_REVISION read-only */
  11867. /* CCE_REVISION2 read-only */
  11868. /* CCE_CTRL - bits clear automatically */
  11869. /* CCE_STATUS read-only, use CceCtrl to clear */
  11870. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11871. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  11872. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  11873. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  11874. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  11875. /* CCE_ERR_STATUS read-only */
  11876. write_csr(dd, CCE_ERR_MASK, 0);
  11877. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  11878. /* CCE_ERR_FORCE leave alone */
  11879. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  11880. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  11881. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  11882. /* CCE_PCIE_CTRL leave alone */
  11883. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  11884. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  11885. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  11886. CCE_MSIX_TABLE_UPPER_RESETCSR);
  11887. }
  11888. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  11889. /* CCE_MSIX_PBA read-only */
  11890. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  11891. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  11892. }
  11893. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11894. write_csr(dd, CCE_INT_MAP, 0);
  11895. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11896. /* CCE_INT_STATUS read-only */
  11897. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  11898. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  11899. /* CCE_INT_FORCE leave alone */
  11900. /* CCE_INT_BLOCKED read-only */
  11901. }
  11902. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  11903. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  11904. }
  11905. /* set MISC CSRs to chip reset defaults */
  11906. static void reset_misc_csrs(struct hfi1_devdata *dd)
  11907. {
  11908. int i;
  11909. for (i = 0; i < 32; i++) {
  11910. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  11911. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  11912. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  11913. }
  11914. /*
  11915. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  11916. * only be written 128-byte chunks
  11917. */
  11918. /* init RSA engine to clear lingering errors */
  11919. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  11920. write_csr(dd, MISC_CFG_RSA_MU, 0);
  11921. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  11922. /* MISC_STS_8051_DIGEST read-only */
  11923. /* MISC_STS_SBM_DIGEST read-only */
  11924. /* MISC_STS_PCIE_DIGEST read-only */
  11925. /* MISC_STS_FAB_DIGEST read-only */
  11926. /* MISC_ERR_STATUS read-only */
  11927. write_csr(dd, MISC_ERR_MASK, 0);
  11928. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  11929. /* MISC_ERR_FORCE leave alone */
  11930. }
  11931. /* set TXE CSRs to chip reset defaults */
  11932. static void reset_txe_csrs(struct hfi1_devdata *dd)
  11933. {
  11934. int i;
  11935. /*
  11936. * TXE Kernel CSRs
  11937. */
  11938. write_csr(dd, SEND_CTRL, 0);
  11939. __cm_reset(dd, 0); /* reset CM internal state */
  11940. /* SEND_CONTEXTS read-only */
  11941. /* SEND_DMA_ENGINES read-only */
  11942. /* SEND_PIO_MEM_SIZE read-only */
  11943. /* SEND_DMA_MEM_SIZE read-only */
  11944. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  11945. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  11946. /* SEND_PIO_ERR_STATUS read-only */
  11947. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  11948. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  11949. /* SEND_PIO_ERR_FORCE leave alone */
  11950. /* SEND_DMA_ERR_STATUS read-only */
  11951. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  11952. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  11953. /* SEND_DMA_ERR_FORCE leave alone */
  11954. /* SEND_EGRESS_ERR_STATUS read-only */
  11955. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  11956. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  11957. /* SEND_EGRESS_ERR_FORCE leave alone */
  11958. write_csr(dd, SEND_BTH_QP, 0);
  11959. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  11960. write_csr(dd, SEND_SC2VLT0, 0);
  11961. write_csr(dd, SEND_SC2VLT1, 0);
  11962. write_csr(dd, SEND_SC2VLT2, 0);
  11963. write_csr(dd, SEND_SC2VLT3, 0);
  11964. write_csr(dd, SEND_LEN_CHECK0, 0);
  11965. write_csr(dd, SEND_LEN_CHECK1, 0);
  11966. /* SEND_ERR_STATUS read-only */
  11967. write_csr(dd, SEND_ERR_MASK, 0);
  11968. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  11969. /* SEND_ERR_FORCE read-only */
  11970. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  11971. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  11972. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  11973. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  11974. for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
  11975. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  11976. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  11977. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  11978. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  11979. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  11980. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  11981. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  11982. /* SEND_CM_CREDIT_USED_STATUS read-only */
  11983. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  11984. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  11985. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  11986. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  11987. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  11988. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  11989. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  11990. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  11991. /* SEND_CM_CREDIT_USED_VL read-only */
  11992. /* SEND_CM_CREDIT_USED_VL15 read-only */
  11993. /* SEND_EGRESS_CTXT_STATUS read-only */
  11994. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  11995. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  11996. /* SEND_EGRESS_ERR_INFO read-only */
  11997. /* SEND_EGRESS_ERR_SOURCE read-only */
  11998. /*
  11999. * TXE Per-Context CSRs
  12000. */
  12001. for (i = 0; i < dd->chip_send_contexts; i++) {
  12002. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12003. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  12004. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  12005. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  12006. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  12007. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  12008. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  12009. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  12010. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  12011. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12012. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  12013. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  12014. }
  12015. /*
  12016. * TXE Per-SDMA CSRs
  12017. */
  12018. for (i = 0; i < dd->chip_sdma_engines; i++) {
  12019. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12020. /* SEND_DMA_STATUS read-only */
  12021. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  12022. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  12023. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  12024. /* SEND_DMA_HEAD read-only */
  12025. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  12026. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  12027. /* SEND_DMA_IDLE_CNT read-only */
  12028. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  12029. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  12030. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  12031. /* SEND_DMA_ENG_ERR_STATUS read-only */
  12032. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  12033. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  12034. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  12035. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  12036. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  12037. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  12038. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  12039. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  12040. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  12041. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  12042. }
  12043. }
  12044. /*
  12045. * Expect on entry:
  12046. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  12047. */
  12048. static void init_rbufs(struct hfi1_devdata *dd)
  12049. {
  12050. u64 reg;
  12051. int count;
  12052. /*
  12053. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  12054. * clear.
  12055. */
  12056. count = 0;
  12057. while (1) {
  12058. reg = read_csr(dd, RCV_STATUS);
  12059. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  12060. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  12061. break;
  12062. /*
  12063. * Give up after 1ms - maximum wait time.
  12064. *
  12065. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  12066. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  12067. * 136 KB / (66% * 250MB/s) = 844us
  12068. */
  12069. if (count++ > 500) {
  12070. dd_dev_err(dd,
  12071. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  12072. __func__, reg);
  12073. break;
  12074. }
  12075. udelay(2); /* do not busy-wait the CSR */
  12076. }
  12077. /* start the init - expect RcvCtrl to be 0 */
  12078. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  12079. /*
  12080. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  12081. * period after the write before RcvStatus.RxRbufInitDone is valid.
  12082. * The delay in the first run through the loop below is sufficient and
  12083. * required before the first read of RcvStatus.RxRbufInintDone.
  12084. */
  12085. read_csr(dd, RCV_CTRL);
  12086. /* wait for the init to finish */
  12087. count = 0;
  12088. while (1) {
  12089. /* delay is required first time through - see above */
  12090. udelay(2); /* do not busy-wait the CSR */
  12091. reg = read_csr(dd, RCV_STATUS);
  12092. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  12093. break;
  12094. /* give up after 100us - slowest possible at 33MHz is 73us */
  12095. if (count++ > 50) {
  12096. dd_dev_err(dd,
  12097. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  12098. __func__);
  12099. break;
  12100. }
  12101. }
  12102. }
  12103. /* set RXE CSRs to chip reset defaults */
  12104. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  12105. {
  12106. int i, j;
  12107. /*
  12108. * RXE Kernel CSRs
  12109. */
  12110. write_csr(dd, RCV_CTRL, 0);
  12111. init_rbufs(dd);
  12112. /* RCV_STATUS read-only */
  12113. /* RCV_CONTEXTS read-only */
  12114. /* RCV_ARRAY_CNT read-only */
  12115. /* RCV_BUF_SIZE read-only */
  12116. write_csr(dd, RCV_BTH_QP, 0);
  12117. write_csr(dd, RCV_MULTICAST, 0);
  12118. write_csr(dd, RCV_BYPASS, 0);
  12119. write_csr(dd, RCV_VL15, 0);
  12120. /* this is a clear-down */
  12121. write_csr(dd, RCV_ERR_INFO,
  12122. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  12123. /* RCV_ERR_STATUS read-only */
  12124. write_csr(dd, RCV_ERR_MASK, 0);
  12125. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  12126. /* RCV_ERR_FORCE leave alone */
  12127. for (i = 0; i < 32; i++)
  12128. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  12129. for (i = 0; i < 4; i++)
  12130. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  12131. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  12132. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  12133. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  12134. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  12135. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
  12136. clear_rsm_rule(dd, i);
  12137. for (i = 0; i < 32; i++)
  12138. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  12139. /*
  12140. * RXE Kernel and User Per-Context CSRs
  12141. */
  12142. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  12143. /* kernel */
  12144. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  12145. /* RCV_CTXT_STATUS read-only */
  12146. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  12147. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  12148. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  12149. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  12150. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  12151. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  12152. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  12153. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  12154. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  12155. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  12156. /* user */
  12157. /* RCV_HDR_TAIL read-only */
  12158. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  12159. /* RCV_EGR_INDEX_TAIL read-only */
  12160. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  12161. /* RCV_EGR_OFFSET_TAIL read-only */
  12162. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  12163. write_uctxt_csr(dd, i,
  12164. RCV_TID_FLOW_TABLE + (8 * j), 0);
  12165. }
  12166. }
  12167. }
  12168. /*
  12169. * Set sc2vl tables.
  12170. *
  12171. * They power on to zeros, so to avoid send context errors
  12172. * they need to be set:
  12173. *
  12174. * SC 0-7 -> VL 0-7 (respectively)
  12175. * SC 15 -> VL 15
  12176. * otherwise
  12177. * -> VL 0
  12178. */
  12179. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  12180. {
  12181. int i;
  12182. /* init per architecture spec, constrained by hardware capability */
  12183. /* HFI maps sent packets */
  12184. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  12185. 0,
  12186. 0, 0, 1, 1,
  12187. 2, 2, 3, 3,
  12188. 4, 4, 5, 5,
  12189. 6, 6, 7, 7));
  12190. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  12191. 1,
  12192. 8, 0, 9, 0,
  12193. 10, 0, 11, 0,
  12194. 12, 0, 13, 0,
  12195. 14, 0, 15, 15));
  12196. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  12197. 2,
  12198. 16, 0, 17, 0,
  12199. 18, 0, 19, 0,
  12200. 20, 0, 21, 0,
  12201. 22, 0, 23, 0));
  12202. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  12203. 3,
  12204. 24, 0, 25, 0,
  12205. 26, 0, 27, 0,
  12206. 28, 0, 29, 0,
  12207. 30, 0, 31, 0));
  12208. /* DC maps received packets */
  12209. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  12210. 15_0,
  12211. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  12212. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  12213. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  12214. 31_16,
  12215. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  12216. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  12217. /* initialize the cached sc2vl values consistently with h/w */
  12218. for (i = 0; i < 32; i++) {
  12219. if (i < 8 || i == 15)
  12220. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  12221. else
  12222. *((u8 *)(dd->sc2vl) + i) = 0;
  12223. }
  12224. }
  12225. /*
  12226. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  12227. * depend on the chip going through a power-on reset - a driver may be loaded
  12228. * and unloaded many times.
  12229. *
  12230. * Do not write any CSR values to the chip in this routine - there may be
  12231. * a reset following the (possible) FLR in this routine.
  12232. *
  12233. */
  12234. static int init_chip(struct hfi1_devdata *dd)
  12235. {
  12236. int i;
  12237. int ret = 0;
  12238. /*
  12239. * Put the HFI CSRs in a known state.
  12240. * Combine this with a DC reset.
  12241. *
  12242. * Stop the device from doing anything while we do a
  12243. * reset. We know there are no other active users of
  12244. * the device since we are now in charge. Turn off
  12245. * off all outbound and inbound traffic and make sure
  12246. * the device does not generate any interrupts.
  12247. */
  12248. /* disable send contexts and SDMA engines */
  12249. write_csr(dd, SEND_CTRL, 0);
  12250. for (i = 0; i < dd->chip_send_contexts; i++)
  12251. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12252. for (i = 0; i < dd->chip_sdma_engines; i++)
  12253. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12254. /* disable port (turn off RXE inbound traffic) and contexts */
  12255. write_csr(dd, RCV_CTRL, 0);
  12256. for (i = 0; i < dd->chip_rcv_contexts; i++)
  12257. write_csr(dd, RCV_CTXT_CTRL, 0);
  12258. /* mask all interrupt sources */
  12259. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  12260. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  12261. /*
  12262. * DC Reset: do a full DC reset before the register clear.
  12263. * A recommended length of time to hold is one CSR read,
  12264. * so reread the CceDcCtrl. Then, hold the DC in reset
  12265. * across the clear.
  12266. */
  12267. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  12268. (void)read_csr(dd, CCE_DC_CTRL);
  12269. if (use_flr) {
  12270. /*
  12271. * A FLR will reset the SPC core and part of the PCIe.
  12272. * The parts that need to be restored have already been
  12273. * saved.
  12274. */
  12275. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12276. /* do the FLR, the DC reset will remain */
  12277. pcie_flr(dd->pcidev);
  12278. /* restore command and BARs */
  12279. ret = restore_pci_variables(dd);
  12280. if (ret) {
  12281. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12282. __func__);
  12283. return ret;
  12284. }
  12285. if (is_ax(dd)) {
  12286. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12287. pcie_flr(dd->pcidev);
  12288. ret = restore_pci_variables(dd);
  12289. if (ret) {
  12290. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12291. __func__);
  12292. return ret;
  12293. }
  12294. }
  12295. } else {
  12296. dd_dev_info(dd, "Resetting CSRs with writes\n");
  12297. reset_cce_csrs(dd);
  12298. reset_txe_csrs(dd);
  12299. reset_rxe_csrs(dd);
  12300. reset_misc_csrs(dd);
  12301. }
  12302. /* clear the DC reset */
  12303. write_csr(dd, CCE_DC_CTRL, 0);
  12304. /* Set the LED off */
  12305. setextled(dd, 0);
  12306. /*
  12307. * Clear the QSFP reset.
  12308. * An FLR enforces a 0 on all out pins. The driver does not touch
  12309. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  12310. * anything plugged constantly in reset, if it pays attention
  12311. * to RESET_N.
  12312. * Prime examples of this are optical cables. Set all pins high.
  12313. * I2CCLK and I2CDAT will change per direction, and INT_N and
  12314. * MODPRS_N are input only and their value is ignored.
  12315. */
  12316. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  12317. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  12318. init_chip_resources(dd);
  12319. return ret;
  12320. }
  12321. static void init_early_variables(struct hfi1_devdata *dd)
  12322. {
  12323. int i;
  12324. /* assign link credit variables */
  12325. dd->vau = CM_VAU;
  12326. dd->link_credits = CM_GLOBAL_CREDITS;
  12327. if (is_ax(dd))
  12328. dd->link_credits--;
  12329. dd->vcu = cu_to_vcu(hfi1_cu);
  12330. /* enough room for 8 MAD packets plus header - 17K */
  12331. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12332. if (dd->vl15_init > dd->link_credits)
  12333. dd->vl15_init = dd->link_credits;
  12334. write_uninitialized_csrs_and_memories(dd);
  12335. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12336. for (i = 0; i < dd->num_pports; i++) {
  12337. struct hfi1_pportdata *ppd = &dd->pport[i];
  12338. set_partition_keys(ppd);
  12339. }
  12340. init_sc2vl_tables(dd);
  12341. }
  12342. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12343. {
  12344. /* user changed the KDETH_QP */
  12345. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12346. /* out of range or illegal value */
  12347. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12348. kdeth_qp = 0;
  12349. }
  12350. if (kdeth_qp == 0) /* not set, or failed range check */
  12351. kdeth_qp = DEFAULT_KDETH_QP;
  12352. write_csr(dd, SEND_BTH_QP,
  12353. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12354. SEND_BTH_QP_KDETH_QP_SHIFT);
  12355. write_csr(dd, RCV_BTH_QP,
  12356. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12357. RCV_BTH_QP_KDETH_QP_SHIFT);
  12358. }
  12359. /**
  12360. * init_qpmap_table
  12361. * @dd - device data
  12362. * @first_ctxt - first context
  12363. * @last_ctxt - first context
  12364. *
  12365. * This return sets the qpn mapping table that
  12366. * is indexed by qpn[8:1].
  12367. *
  12368. * The routine will round robin the 256 settings
  12369. * from first_ctxt to last_ctxt.
  12370. *
  12371. * The first/last looks ahead to having specialized
  12372. * receive contexts for mgmt and bypass. Normal
  12373. * verbs traffic will assumed to be on a range
  12374. * of receive contexts.
  12375. */
  12376. static void init_qpmap_table(struct hfi1_devdata *dd,
  12377. u32 first_ctxt,
  12378. u32 last_ctxt)
  12379. {
  12380. u64 reg = 0;
  12381. u64 regno = RCV_QP_MAP_TABLE;
  12382. int i;
  12383. u64 ctxt = first_ctxt;
  12384. for (i = 0; i < 256; i++) {
  12385. reg |= ctxt << (8 * (i % 8));
  12386. ctxt++;
  12387. if (ctxt > last_ctxt)
  12388. ctxt = first_ctxt;
  12389. if (i % 8 == 7) {
  12390. write_csr(dd, regno, reg);
  12391. reg = 0;
  12392. regno += 8;
  12393. }
  12394. }
  12395. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12396. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12397. }
  12398. struct rsm_map_table {
  12399. u64 map[NUM_MAP_REGS];
  12400. unsigned int used;
  12401. };
  12402. struct rsm_rule_data {
  12403. u8 offset;
  12404. u8 pkt_type;
  12405. u32 field1_off;
  12406. u32 field2_off;
  12407. u32 index1_off;
  12408. u32 index1_width;
  12409. u32 index2_off;
  12410. u32 index2_width;
  12411. u32 mask1;
  12412. u32 value1;
  12413. u32 mask2;
  12414. u32 value2;
  12415. };
  12416. /*
  12417. * Return an initialized RMT map table for users to fill in. OK if it
  12418. * returns NULL, indicating no table.
  12419. */
  12420. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12421. {
  12422. struct rsm_map_table *rmt;
  12423. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12424. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12425. if (rmt) {
  12426. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12427. rmt->used = 0;
  12428. }
  12429. return rmt;
  12430. }
  12431. /*
  12432. * Write the final RMT map table to the chip and free the table. OK if
  12433. * table is NULL.
  12434. */
  12435. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12436. struct rsm_map_table *rmt)
  12437. {
  12438. int i;
  12439. if (rmt) {
  12440. /* write table to chip */
  12441. for (i = 0; i < NUM_MAP_REGS; i++)
  12442. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12443. /* enable RSM */
  12444. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12445. }
  12446. }
  12447. /*
  12448. * Add a receive side mapping rule.
  12449. */
  12450. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12451. struct rsm_rule_data *rrd)
  12452. {
  12453. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12454. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12455. 1ull << rule_index | /* enable bit */
  12456. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12457. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12458. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12459. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12460. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12461. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12462. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12463. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12464. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12465. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12466. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12467. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12468. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12469. }
  12470. /*
  12471. * Clear a receive side mapping rule.
  12472. */
  12473. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
  12474. {
  12475. write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
  12476. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
  12477. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
  12478. }
  12479. /* return the number of RSM map table entries that will be used for QOS */
  12480. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12481. unsigned int *np)
  12482. {
  12483. int i;
  12484. unsigned int m, n;
  12485. u8 max_by_vl = 0;
  12486. /* is QOS active at all? */
  12487. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12488. num_vls == 1 ||
  12489. krcvqsset <= 1)
  12490. goto no_qos;
  12491. /* determine bits for qpn */
  12492. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12493. if (krcvqs[i] > max_by_vl)
  12494. max_by_vl = krcvqs[i];
  12495. if (max_by_vl > 32)
  12496. goto no_qos;
  12497. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12498. /* determine bits for vl */
  12499. n = ilog2(__roundup_pow_of_two(num_vls));
  12500. /* reject if too much is used */
  12501. if ((m + n) > 7)
  12502. goto no_qos;
  12503. if (mp)
  12504. *mp = m;
  12505. if (np)
  12506. *np = n;
  12507. return 1 << (m + n);
  12508. no_qos:
  12509. if (mp)
  12510. *mp = 0;
  12511. if (np)
  12512. *np = 0;
  12513. return 0;
  12514. }
  12515. /**
  12516. * init_qos - init RX qos
  12517. * @dd - device data
  12518. * @rmt - RSM map table
  12519. *
  12520. * This routine initializes Rule 0 and the RSM map table to implement
  12521. * quality of service (qos).
  12522. *
  12523. * If all of the limit tests succeed, qos is applied based on the array
  12524. * interpretation of krcvqs where entry 0 is VL0.
  12525. *
  12526. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12527. * feed both the RSM map table and the single rule.
  12528. */
  12529. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12530. {
  12531. struct rsm_rule_data rrd;
  12532. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12533. unsigned int rmt_entries;
  12534. u64 reg;
  12535. if (!rmt)
  12536. goto bail;
  12537. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12538. if (rmt_entries == 0)
  12539. goto bail;
  12540. qpns_per_vl = 1 << m;
  12541. /* enough room in the map table? */
  12542. rmt_entries = 1 << (m + n);
  12543. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12544. goto bail;
  12545. /* add qos entries to the the RSM map table */
  12546. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12547. unsigned tctxt;
  12548. for (qpn = 0, tctxt = ctxt;
  12549. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12550. unsigned idx, regoff, regidx;
  12551. /* generate the index the hardware will produce */
  12552. idx = rmt->used + ((qpn << n) ^ i);
  12553. regoff = (idx % 8) * 8;
  12554. regidx = idx / 8;
  12555. /* replace default with context number */
  12556. reg = rmt->map[regidx];
  12557. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12558. << regoff);
  12559. reg |= (u64)(tctxt++) << regoff;
  12560. rmt->map[regidx] = reg;
  12561. if (tctxt == ctxt + krcvqs[i])
  12562. tctxt = ctxt;
  12563. }
  12564. ctxt += krcvqs[i];
  12565. }
  12566. rrd.offset = rmt->used;
  12567. rrd.pkt_type = 2;
  12568. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12569. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12570. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12571. rrd.index1_width = n;
  12572. rrd.index2_off = QPN_SELECT_OFFSET;
  12573. rrd.index2_width = m + n;
  12574. rrd.mask1 = LRH_BTH_MASK;
  12575. rrd.value1 = LRH_BTH_VALUE;
  12576. rrd.mask2 = LRH_SC_MASK;
  12577. rrd.value2 = LRH_SC_VALUE;
  12578. /* add rule 0 */
  12579. add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
  12580. /* mark RSM map entries as used */
  12581. rmt->used += rmt_entries;
  12582. /* map everything else to the mcast/err/vl15 context */
  12583. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12584. dd->qos_shift = n + 1;
  12585. return;
  12586. bail:
  12587. dd->qos_shift = 1;
  12588. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12589. }
  12590. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12591. struct rsm_map_table *rmt)
  12592. {
  12593. struct rsm_rule_data rrd;
  12594. u64 reg;
  12595. int i, idx, regoff, regidx;
  12596. u8 offset;
  12597. /* there needs to be enough room in the map table */
  12598. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12599. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12600. return;
  12601. }
  12602. /*
  12603. * RSM will extract the destination context as an index into the
  12604. * map table. The destination contexts are a sequential block
  12605. * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
  12606. * Map entries are accessed as offset + extracted value. Adjust
  12607. * the added offset so this sequence can be placed anywhere in
  12608. * the table - as long as the entries themselves do not wrap.
  12609. * There are only enough bits in offset for the table size, so
  12610. * start with that to allow for a "negative" offset.
  12611. */
  12612. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12613. (int)dd->first_dyn_alloc_ctxt);
  12614. for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
  12615. i < dd->num_rcv_contexts; i++, idx++) {
  12616. /* replace with identity mapping */
  12617. regoff = (idx % 8) * 8;
  12618. regidx = idx / 8;
  12619. reg = rmt->map[regidx];
  12620. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12621. reg |= (u64)i << regoff;
  12622. rmt->map[regidx] = reg;
  12623. }
  12624. /*
  12625. * For RSM intercept of Expected FECN packets:
  12626. * o packet type 0 - expected
  12627. * o match on F (bit 95), using select/match 1, and
  12628. * o match on SH (bit 133), using select/match 2.
  12629. *
  12630. * Use index 1 to extract the 8-bit receive context from DestQP
  12631. * (start at bit 64). Use that as the RSM map table index.
  12632. */
  12633. rrd.offset = offset;
  12634. rrd.pkt_type = 0;
  12635. rrd.field1_off = 95;
  12636. rrd.field2_off = 133;
  12637. rrd.index1_off = 64;
  12638. rrd.index1_width = 8;
  12639. rrd.index2_off = 0;
  12640. rrd.index2_width = 0;
  12641. rrd.mask1 = 1;
  12642. rrd.value1 = 1;
  12643. rrd.mask2 = 1;
  12644. rrd.value2 = 1;
  12645. /* add rule 1 */
  12646. add_rsm_rule(dd, RSM_INS_FECN, &rrd);
  12647. rmt->used += dd->num_user_contexts;
  12648. }
  12649. /* Initialize RSM for VNIC */
  12650. void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
  12651. {
  12652. u8 i, j;
  12653. u8 ctx_id = 0;
  12654. u64 reg;
  12655. u32 regoff;
  12656. struct rsm_rule_data rrd;
  12657. if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
  12658. dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
  12659. dd->vnic.rmt_start);
  12660. return;
  12661. }
  12662. dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
  12663. dd->vnic.rmt_start,
  12664. dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
  12665. /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
  12666. regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
  12667. reg = read_csr(dd, regoff);
  12668. for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
  12669. /* Update map register with vnic context */
  12670. j = (dd->vnic.rmt_start + i) % 8;
  12671. reg &= ~(0xffllu << (j * 8));
  12672. reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
  12673. /* Wrap up vnic ctx index */
  12674. ctx_id %= dd->vnic.num_ctxt;
  12675. /* Write back map register */
  12676. if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
  12677. dev_dbg(&(dd)->pcidev->dev,
  12678. "Vnic rsm map reg[%d] =0x%llx\n",
  12679. regoff - RCV_RSM_MAP_TABLE, reg);
  12680. write_csr(dd, regoff, reg);
  12681. regoff += 8;
  12682. if (i < (NUM_VNIC_MAP_ENTRIES - 1))
  12683. reg = read_csr(dd, regoff);
  12684. }
  12685. }
  12686. /* Add rule for vnic */
  12687. rrd.offset = dd->vnic.rmt_start;
  12688. rrd.pkt_type = 4;
  12689. /* Match 16B packets */
  12690. rrd.field1_off = L2_TYPE_MATCH_OFFSET;
  12691. rrd.mask1 = L2_TYPE_MASK;
  12692. rrd.value1 = L2_16B_VALUE;
  12693. /* Match ETH L4 packets */
  12694. rrd.field2_off = L4_TYPE_MATCH_OFFSET;
  12695. rrd.mask2 = L4_16B_TYPE_MASK;
  12696. rrd.value2 = L4_16B_ETH_VALUE;
  12697. /* Calc context from veswid and entropy */
  12698. rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
  12699. rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12700. rrd.index2_off = L2_16B_ENTROPY_OFFSET;
  12701. rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12702. add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
  12703. /* Enable RSM if not already enabled */
  12704. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12705. }
  12706. void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
  12707. {
  12708. clear_rsm_rule(dd, RSM_INS_VNIC);
  12709. /* Disable RSM if used only by vnic */
  12710. if (dd->vnic.rmt_start == 0)
  12711. clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12712. }
  12713. static void init_rxe(struct hfi1_devdata *dd)
  12714. {
  12715. struct rsm_map_table *rmt;
  12716. u64 val;
  12717. /* enable all receive errors */
  12718. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12719. rmt = alloc_rsm_map_table(dd);
  12720. /* set up QOS, including the QPN map table */
  12721. init_qos(dd, rmt);
  12722. init_user_fecn_handling(dd, rmt);
  12723. complete_rsm_map_table(dd, rmt);
  12724. /* record number of used rsm map entries for vnic */
  12725. dd->vnic.rmt_start = rmt->used;
  12726. kfree(rmt);
  12727. /*
  12728. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12729. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12730. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12731. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12732. * Max_PayLoad_Size set to its minimum of 128.
  12733. *
  12734. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12735. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12736. * tune_pcie_caps() which is called after this routine.
  12737. */
  12738. /* Have 16 bytes (4DW) of bypass header available in header queue */
  12739. val = read_csr(dd, RCV_BYPASS);
  12740. val |= (4ull << 16);
  12741. write_csr(dd, RCV_BYPASS, val);
  12742. }
  12743. static void init_other(struct hfi1_devdata *dd)
  12744. {
  12745. /* enable all CCE errors */
  12746. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12747. /* enable *some* Misc errors */
  12748. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12749. /* enable all DC errors, except LCB */
  12750. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12751. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12752. }
  12753. /*
  12754. * Fill out the given AU table using the given CU. A CU is defined in terms
  12755. * AUs. The table is a an encoding: given the index, how many AUs does that
  12756. * represent?
  12757. *
  12758. * NOTE: Assumes that the register layout is the same for the
  12759. * local and remote tables.
  12760. */
  12761. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12762. u32 csr0to3, u32 csr4to7)
  12763. {
  12764. write_csr(dd, csr0to3,
  12765. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12766. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12767. 2ull * cu <<
  12768. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12769. 4ull * cu <<
  12770. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12771. write_csr(dd, csr4to7,
  12772. 8ull * cu <<
  12773. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12774. 16ull * cu <<
  12775. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12776. 32ull * cu <<
  12777. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12778. 64ull * cu <<
  12779. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12780. }
  12781. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12782. {
  12783. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12784. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12785. }
  12786. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12787. {
  12788. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12789. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12790. }
  12791. static void init_txe(struct hfi1_devdata *dd)
  12792. {
  12793. int i;
  12794. /* enable all PIO, SDMA, general, and Egress errors */
  12795. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12796. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12797. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12798. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12799. /* enable all per-context and per-SDMA engine errors */
  12800. for (i = 0; i < dd->chip_send_contexts; i++)
  12801. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12802. for (i = 0; i < dd->chip_sdma_engines; i++)
  12803. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12804. /* set the local CU to AU mapping */
  12805. assign_local_cm_au_table(dd, dd->vcu);
  12806. /*
  12807. * Set reasonable default for Credit Return Timer
  12808. * Don't set on Simulator - causes it to choke.
  12809. */
  12810. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12811. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12812. }
  12813. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12814. u16 jkey)
  12815. {
  12816. u8 hw_ctxt;
  12817. u64 reg;
  12818. if (!rcd || !rcd->sc)
  12819. return -EINVAL;
  12820. hw_ctxt = rcd->sc->hw_context;
  12821. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12822. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12823. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12824. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12825. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12826. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12827. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12828. /*
  12829. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12830. */
  12831. if (!is_ax(dd)) {
  12832. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12833. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12834. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12835. }
  12836. /* Enable J_KEY check on receive context. */
  12837. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12838. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12839. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12840. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
  12841. return 0;
  12842. }
  12843. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
  12844. {
  12845. u8 hw_ctxt;
  12846. u64 reg;
  12847. if (!rcd || !rcd->sc)
  12848. return -EINVAL;
  12849. hw_ctxt = rcd->sc->hw_context;
  12850. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12851. /*
  12852. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12853. * This check would not have been enabled for A0 h/w, see
  12854. * set_ctxt_jkey().
  12855. */
  12856. if (!is_ax(dd)) {
  12857. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12858. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12859. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12860. }
  12861. /* Turn off the J_KEY on the receive side */
  12862. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
  12863. return 0;
  12864. }
  12865. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12866. u16 pkey)
  12867. {
  12868. u8 hw_ctxt;
  12869. u64 reg;
  12870. if (!rcd || !rcd->sc)
  12871. return -EINVAL;
  12872. hw_ctxt = rcd->sc->hw_context;
  12873. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  12874. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  12875. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  12876. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12877. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12878. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  12879. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12880. return 0;
  12881. }
  12882. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
  12883. {
  12884. u8 hw_ctxt;
  12885. u64 reg;
  12886. if (!ctxt || !ctxt->sc)
  12887. return -EINVAL;
  12888. hw_ctxt = ctxt->sc->hw_context;
  12889. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12890. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12891. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12892. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12893. return 0;
  12894. }
  12895. /*
  12896. * Start doing the clean up the the chip. Our clean up happens in multiple
  12897. * stages and this is just the first.
  12898. */
  12899. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  12900. {
  12901. aspm_exit(dd);
  12902. free_cntrs(dd);
  12903. free_rcverr(dd);
  12904. clean_up_interrupts(dd);
  12905. finish_chip_resources(dd);
  12906. }
  12907. #define HFI_BASE_GUID(dev) \
  12908. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  12909. /*
  12910. * Information can be shared between the two HFIs on the same ASIC
  12911. * in the same OS. This function finds the peer device and sets
  12912. * up a shared structure.
  12913. */
  12914. static int init_asic_data(struct hfi1_devdata *dd)
  12915. {
  12916. unsigned long flags;
  12917. struct hfi1_devdata *tmp, *peer = NULL;
  12918. struct hfi1_asic_data *asic_data;
  12919. int ret = 0;
  12920. /* pre-allocate the asic structure in case we are the first device */
  12921. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  12922. if (!asic_data)
  12923. return -ENOMEM;
  12924. spin_lock_irqsave(&hfi1_devs_lock, flags);
  12925. /* Find our peer device */
  12926. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  12927. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  12928. dd->unit != tmp->unit) {
  12929. peer = tmp;
  12930. break;
  12931. }
  12932. }
  12933. if (peer) {
  12934. /* use already allocated structure */
  12935. dd->asic_data = peer->asic_data;
  12936. kfree(asic_data);
  12937. } else {
  12938. dd->asic_data = asic_data;
  12939. mutex_init(&dd->asic_data->asic_resource_mutex);
  12940. }
  12941. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  12942. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  12943. /* first one through - set up i2c devices */
  12944. if (!peer)
  12945. ret = set_up_i2c(dd, dd->asic_data);
  12946. return ret;
  12947. }
  12948. /*
  12949. * Set dd->boardname. Use a generic name if a name is not returned from
  12950. * EFI variable space.
  12951. *
  12952. * Return 0 on success, -ENOMEM if space could not be allocated.
  12953. */
  12954. static int obtain_boardname(struct hfi1_devdata *dd)
  12955. {
  12956. /* generic board description */
  12957. const char generic[] =
  12958. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  12959. unsigned long size;
  12960. int ret;
  12961. ret = read_hfi1_efi_var(dd, "description", &size,
  12962. (void **)&dd->boardname);
  12963. if (ret) {
  12964. dd_dev_info(dd, "Board description not found\n");
  12965. /* use generic description */
  12966. dd->boardname = kstrdup(generic, GFP_KERNEL);
  12967. if (!dd->boardname)
  12968. return -ENOMEM;
  12969. }
  12970. return 0;
  12971. }
  12972. /*
  12973. * Check the interrupt registers to make sure that they are mapped correctly.
  12974. * It is intended to help user identify any mismapping by VMM when the driver
  12975. * is running in a VM. This function should only be called before interrupt
  12976. * is set up properly.
  12977. *
  12978. * Return 0 on success, -EINVAL on failure.
  12979. */
  12980. static int check_int_registers(struct hfi1_devdata *dd)
  12981. {
  12982. u64 reg;
  12983. u64 all_bits = ~(u64)0;
  12984. u64 mask;
  12985. /* Clear CceIntMask[0] to avoid raising any interrupts */
  12986. mask = read_csr(dd, CCE_INT_MASK);
  12987. write_csr(dd, CCE_INT_MASK, 0ull);
  12988. reg = read_csr(dd, CCE_INT_MASK);
  12989. if (reg)
  12990. goto err_exit;
  12991. /* Clear all interrupt status bits */
  12992. write_csr(dd, CCE_INT_CLEAR, all_bits);
  12993. reg = read_csr(dd, CCE_INT_STATUS);
  12994. if (reg)
  12995. goto err_exit;
  12996. /* Set all interrupt status bits */
  12997. write_csr(dd, CCE_INT_FORCE, all_bits);
  12998. reg = read_csr(dd, CCE_INT_STATUS);
  12999. if (reg != all_bits)
  13000. goto err_exit;
  13001. /* Restore the interrupt mask */
  13002. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13003. write_csr(dd, CCE_INT_MASK, mask);
  13004. return 0;
  13005. err_exit:
  13006. write_csr(dd, CCE_INT_MASK, mask);
  13007. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  13008. return -EINVAL;
  13009. }
  13010. /**
  13011. * Allocate and initialize the device structure for the hfi.
  13012. * @dev: the pci_dev for hfi1_ib device
  13013. * @ent: pci_device_id struct for this dev
  13014. *
  13015. * Also allocates, initializes, and returns the devdata struct for this
  13016. * device instance
  13017. *
  13018. * This is global, and is called directly at init to set up the
  13019. * chip-specific function pointers for later use.
  13020. */
  13021. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  13022. const struct pci_device_id *ent)
  13023. {
  13024. struct hfi1_devdata *dd;
  13025. struct hfi1_pportdata *ppd;
  13026. u64 reg;
  13027. int i, ret;
  13028. static const char * const inames[] = { /* implementation names */
  13029. "RTL silicon",
  13030. "RTL VCS simulation",
  13031. "RTL FPGA emulation",
  13032. "Functional simulator"
  13033. };
  13034. struct pci_dev *parent = pdev->bus->self;
  13035. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  13036. sizeof(struct hfi1_pportdata));
  13037. if (IS_ERR(dd))
  13038. goto bail;
  13039. ppd = dd->pport;
  13040. for (i = 0; i < dd->num_pports; i++, ppd++) {
  13041. int vl;
  13042. /* init common fields */
  13043. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  13044. /* DC supports 4 link widths */
  13045. ppd->link_width_supported =
  13046. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  13047. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  13048. ppd->link_width_downgrade_supported =
  13049. ppd->link_width_supported;
  13050. /* start out enabling only 4X */
  13051. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  13052. ppd->link_width_downgrade_enabled =
  13053. ppd->link_width_downgrade_supported;
  13054. /* link width active is 0 when link is down */
  13055. /* link width downgrade active is 0 when link is down */
  13056. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  13057. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  13058. hfi1_early_err(&pdev->dev,
  13059. "Invalid num_vls %u, using %u VLs\n",
  13060. num_vls, HFI1_MAX_VLS_SUPPORTED);
  13061. num_vls = HFI1_MAX_VLS_SUPPORTED;
  13062. }
  13063. ppd->vls_supported = num_vls;
  13064. ppd->vls_operational = ppd->vls_supported;
  13065. /* Set the default MTU. */
  13066. for (vl = 0; vl < num_vls; vl++)
  13067. dd->vld[vl].mtu = hfi1_max_mtu;
  13068. dd->vld[15].mtu = MAX_MAD_PACKET;
  13069. /*
  13070. * Set the initial values to reasonable default, will be set
  13071. * for real when link is up.
  13072. */
  13073. ppd->overrun_threshold = 0x4;
  13074. ppd->phy_error_threshold = 0xf;
  13075. ppd->port_crc_mode_enabled = link_crc_mask;
  13076. /* initialize supported LTP CRC mode */
  13077. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  13078. /* initialize enabled LTP CRC mode */
  13079. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  13080. /* start in offline */
  13081. ppd->host_link_state = HLS_DN_OFFLINE;
  13082. init_vl_arb_caches(ppd);
  13083. ppd->pstate = PLS_OFFLINE;
  13084. }
  13085. dd->link_default = HLS_DN_POLL;
  13086. /*
  13087. * Do remaining PCIe setup and save PCIe values in dd.
  13088. * Any error printing is already done by the init code.
  13089. * On return, we have the chip mapped.
  13090. */
  13091. ret = hfi1_pcie_ddinit(dd, pdev);
  13092. if (ret < 0)
  13093. goto bail_free;
  13094. /* Save PCI space registers to rewrite after device reset */
  13095. ret = save_pci_variables(dd);
  13096. if (ret < 0)
  13097. goto bail_cleanup;
  13098. /* verify that reads actually work, save revision for reset check */
  13099. dd->revision = read_csr(dd, CCE_REVISION);
  13100. if (dd->revision == ~(u64)0) {
  13101. dd_dev_err(dd, "cannot read chip CSRs\n");
  13102. ret = -EINVAL;
  13103. goto bail_cleanup;
  13104. }
  13105. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  13106. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  13107. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  13108. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  13109. /*
  13110. * Check interrupt registers mapping if the driver has no access to
  13111. * the upstream component. In this case, it is likely that the driver
  13112. * is running in a VM.
  13113. */
  13114. if (!parent) {
  13115. ret = check_int_registers(dd);
  13116. if (ret)
  13117. goto bail_cleanup;
  13118. }
  13119. /*
  13120. * obtain the hardware ID - NOT related to unit, which is a
  13121. * software enumeration
  13122. */
  13123. reg = read_csr(dd, CCE_REVISION2);
  13124. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  13125. & CCE_REVISION2_HFI_ID_MASK;
  13126. /* the variable size will remove unwanted bits */
  13127. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  13128. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  13129. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  13130. dd->icode < ARRAY_SIZE(inames) ?
  13131. inames[dd->icode] : "unknown", (int)dd->irev);
  13132. /* speeds the hardware can support */
  13133. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  13134. /* speeds allowed to run at */
  13135. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  13136. /* give a reasonable active value, will be set on link up */
  13137. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  13138. dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
  13139. dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
  13140. dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
  13141. dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
  13142. dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
  13143. /* fix up link widths for emulation _p */
  13144. ppd = dd->pport;
  13145. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  13146. ppd->link_width_supported =
  13147. ppd->link_width_enabled =
  13148. ppd->link_width_downgrade_supported =
  13149. ppd->link_width_downgrade_enabled =
  13150. OPA_LINK_WIDTH_1X;
  13151. }
  13152. /* insure num_vls isn't larger than number of sdma engines */
  13153. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
  13154. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  13155. num_vls, dd->chip_sdma_engines);
  13156. num_vls = dd->chip_sdma_engines;
  13157. ppd->vls_supported = dd->chip_sdma_engines;
  13158. ppd->vls_operational = ppd->vls_supported;
  13159. }
  13160. /*
  13161. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  13162. * Limit the max if larger than the field holds. If timeout is
  13163. * non-zero, then the calculated field will be at least 1.
  13164. *
  13165. * Must be after icode is set up - the cclock rate depends
  13166. * on knowing the hardware being used.
  13167. */
  13168. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  13169. if (dd->rcv_intr_timeout_csr >
  13170. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  13171. dd->rcv_intr_timeout_csr =
  13172. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  13173. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  13174. dd->rcv_intr_timeout_csr = 1;
  13175. /* needs to be done before we look for the peer device */
  13176. read_guid(dd);
  13177. /* set up shared ASIC data with peer device */
  13178. ret = init_asic_data(dd);
  13179. if (ret)
  13180. goto bail_cleanup;
  13181. /* obtain chip sizes, reset chip CSRs */
  13182. ret = init_chip(dd);
  13183. if (ret)
  13184. goto bail_cleanup;
  13185. /* read in the PCIe link speed information */
  13186. ret = pcie_speeds(dd);
  13187. if (ret)
  13188. goto bail_cleanup;
  13189. /* call before get_platform_config(), after init_chip_resources() */
  13190. ret = eprom_init(dd);
  13191. if (ret)
  13192. goto bail_free_rcverr;
  13193. /* Needs to be called before hfi1_firmware_init */
  13194. get_platform_config(dd);
  13195. /* read in firmware */
  13196. ret = hfi1_firmware_init(dd);
  13197. if (ret)
  13198. goto bail_cleanup;
  13199. /*
  13200. * In general, the PCIe Gen3 transition must occur after the
  13201. * chip has been idled (so it won't initiate any PCIe transactions
  13202. * e.g. an interrupt) and before the driver changes any registers
  13203. * (the transition will reset the registers).
  13204. *
  13205. * In particular, place this call after:
  13206. * - init_chip() - the chip will not initiate any PCIe transactions
  13207. * - pcie_speeds() - reads the current link speed
  13208. * - hfi1_firmware_init() - the needed firmware is ready to be
  13209. * downloaded
  13210. */
  13211. ret = do_pcie_gen3_transition(dd);
  13212. if (ret)
  13213. goto bail_cleanup;
  13214. /* start setting dd values and adjusting CSRs */
  13215. init_early_variables(dd);
  13216. parse_platform_config(dd);
  13217. ret = obtain_boardname(dd);
  13218. if (ret)
  13219. goto bail_cleanup;
  13220. snprintf(dd->boardversion, BOARD_VERS_MAX,
  13221. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  13222. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  13223. (u32)dd->majrev,
  13224. (u32)dd->minrev,
  13225. (dd->revision >> CCE_REVISION_SW_SHIFT)
  13226. & CCE_REVISION_SW_MASK);
  13227. ret = set_up_context_variables(dd);
  13228. if (ret)
  13229. goto bail_cleanup;
  13230. /* set initial RXE CSRs */
  13231. init_rxe(dd);
  13232. /* set initial TXE CSRs */
  13233. init_txe(dd);
  13234. /* set initial non-RXE, non-TXE CSRs */
  13235. init_other(dd);
  13236. /* set up KDETH QP prefix in both RX and TX CSRs */
  13237. init_kdeth_qp(dd);
  13238. ret = hfi1_dev_affinity_init(dd);
  13239. if (ret)
  13240. goto bail_cleanup;
  13241. /* send contexts must be set up before receive contexts */
  13242. ret = init_send_contexts(dd);
  13243. if (ret)
  13244. goto bail_cleanup;
  13245. ret = hfi1_create_kctxts(dd);
  13246. if (ret)
  13247. goto bail_cleanup;
  13248. /*
  13249. * Initialize aspm, to be done after gen3 transition and setting up
  13250. * contexts and before enabling interrupts
  13251. */
  13252. aspm_init(dd);
  13253. dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
  13254. /*
  13255. * rcd[0] is guaranteed to be valid by this point. Also, all
  13256. * context are using the same value, as per the module parameter.
  13257. */
  13258. dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
  13259. ret = init_pervl_scs(dd);
  13260. if (ret)
  13261. goto bail_cleanup;
  13262. /* sdma init */
  13263. for (i = 0; i < dd->num_pports; ++i) {
  13264. ret = sdma_init(dd, i);
  13265. if (ret)
  13266. goto bail_cleanup;
  13267. }
  13268. /* use contexts created by hfi1_create_kctxts */
  13269. ret = set_up_interrupts(dd);
  13270. if (ret)
  13271. goto bail_cleanup;
  13272. /* set up LCB access - must be after set_up_interrupts() */
  13273. init_lcb_access(dd);
  13274. /*
  13275. * Serial number is created from the base guid:
  13276. * [27:24] = base guid [38:35]
  13277. * [23: 0] = base guid [23: 0]
  13278. */
  13279. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  13280. (dd->base_guid & 0xFFFFFF) |
  13281. ((dd->base_guid >> 11) & 0xF000000));
  13282. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  13283. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  13284. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  13285. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  13286. if (ret)
  13287. goto bail_clear_intr;
  13288. thermal_init(dd);
  13289. ret = init_cntrs(dd);
  13290. if (ret)
  13291. goto bail_clear_intr;
  13292. ret = init_rcverr(dd);
  13293. if (ret)
  13294. goto bail_free_cntrs;
  13295. init_completion(&dd->user_comp);
  13296. /* The user refcount starts with one to inidicate an active device */
  13297. atomic_set(&dd->user_refcount, 1);
  13298. goto bail;
  13299. bail_free_rcverr:
  13300. free_rcverr(dd);
  13301. bail_free_cntrs:
  13302. free_cntrs(dd);
  13303. bail_clear_intr:
  13304. clean_up_interrupts(dd);
  13305. bail_cleanup:
  13306. hfi1_pcie_ddcleanup(dd);
  13307. bail_free:
  13308. hfi1_free_devdata(dd);
  13309. dd = ERR_PTR(ret);
  13310. bail:
  13311. return dd;
  13312. }
  13313. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  13314. u32 dw_len)
  13315. {
  13316. u32 delta_cycles;
  13317. u32 current_egress_rate = ppd->current_egress_rate;
  13318. /* rates here are in units of 10^6 bits/sec */
  13319. if (desired_egress_rate == -1)
  13320. return 0; /* shouldn't happen */
  13321. if (desired_egress_rate >= current_egress_rate)
  13322. return 0; /* we can't help go faster, only slower */
  13323. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  13324. egress_cycles(dw_len * 4, current_egress_rate);
  13325. return (u16)delta_cycles;
  13326. }
  13327. /**
  13328. * create_pbc - build a pbc for transmission
  13329. * @flags: special case flags or-ed in built pbc
  13330. * @srate: static rate
  13331. * @vl: vl
  13332. * @dwlen: dword length (header words + data words + pbc words)
  13333. *
  13334. * Create a PBC with the given flags, rate, VL, and length.
  13335. *
  13336. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  13337. * for verbs, which does not use this PSM feature. The lone other caller
  13338. * is for the diagnostic interface which calls this if the user does not
  13339. * supply their own PBC.
  13340. */
  13341. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  13342. u32 dw_len)
  13343. {
  13344. u64 pbc, delay = 0;
  13345. if (unlikely(srate_mbs))
  13346. delay = delay_cycles(ppd, srate_mbs, dw_len);
  13347. pbc = flags
  13348. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  13349. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  13350. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  13351. | (dw_len & PBC_LENGTH_DWS_MASK)
  13352. << PBC_LENGTH_DWS_SHIFT;
  13353. return pbc;
  13354. }
  13355. #define SBUS_THERMAL 0x4f
  13356. #define SBUS_THERM_MONITOR_MODE 0x1
  13357. #define THERM_FAILURE(dev, ret, reason) \
  13358. dd_dev_err((dd), \
  13359. "Thermal sensor initialization failed: %s (%d)\n", \
  13360. (reason), (ret))
  13361. /*
  13362. * Initialize the thermal sensor.
  13363. *
  13364. * After initialization, enable polling of thermal sensor through
  13365. * SBus interface. In order for this to work, the SBus Master
  13366. * firmware has to be loaded due to the fact that the HW polling
  13367. * logic uses SBus interrupts, which are not supported with
  13368. * default firmware. Otherwise, no data will be returned through
  13369. * the ASIC_STS_THERM CSR.
  13370. */
  13371. static int thermal_init(struct hfi1_devdata *dd)
  13372. {
  13373. int ret = 0;
  13374. if (dd->icode != ICODE_RTL_SILICON ||
  13375. check_chip_resource(dd, CR_THERM_INIT, NULL))
  13376. return ret;
  13377. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  13378. if (ret) {
  13379. THERM_FAILURE(dd, ret, "Acquire SBus");
  13380. return ret;
  13381. }
  13382. dd_dev_info(dd, "Initializing thermal sensor\n");
  13383. /* Disable polling of thermal readings */
  13384. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13385. msleep(100);
  13386. /* Thermal Sensor Initialization */
  13387. /* Step 1: Reset the Thermal SBus Receiver */
  13388. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13389. RESET_SBUS_RECEIVER, 0);
  13390. if (ret) {
  13391. THERM_FAILURE(dd, ret, "Bus Reset");
  13392. goto done;
  13393. }
  13394. /* Step 2: Set Reset bit in Thermal block */
  13395. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13396. WRITE_SBUS_RECEIVER, 0x1);
  13397. if (ret) {
  13398. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13399. goto done;
  13400. }
  13401. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13402. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13403. WRITE_SBUS_RECEIVER, 0x32);
  13404. if (ret) {
  13405. THERM_FAILURE(dd, ret, "Write Clock Div");
  13406. goto done;
  13407. }
  13408. /* Step 4: Select temperature mode */
  13409. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13410. WRITE_SBUS_RECEIVER,
  13411. SBUS_THERM_MONITOR_MODE);
  13412. if (ret) {
  13413. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13414. goto done;
  13415. }
  13416. /* Step 5: De-assert block reset and start conversion */
  13417. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13418. WRITE_SBUS_RECEIVER, 0x2);
  13419. if (ret) {
  13420. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13421. goto done;
  13422. }
  13423. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13424. msleep(22);
  13425. /* Enable polling of thermal readings */
  13426. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13427. /* Set initialized flag */
  13428. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13429. if (ret)
  13430. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13431. done:
  13432. release_chip_resource(dd, CR_SBUS);
  13433. return ret;
  13434. }
  13435. static void handle_temp_err(struct hfi1_devdata *dd)
  13436. {
  13437. struct hfi1_pportdata *ppd = &dd->pport[0];
  13438. /*
  13439. * Thermal Critical Interrupt
  13440. * Put the device into forced freeze mode, take link down to
  13441. * offline, and put DC into reset.
  13442. */
  13443. dd_dev_emerg(dd,
  13444. "Critical temperature reached! Forcing device into freeze mode!\n");
  13445. dd->flags |= HFI1_FORCED_FREEZE;
  13446. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13447. /*
  13448. * Shut DC down as much and as quickly as possible.
  13449. *
  13450. * Step 1: Take the link down to OFFLINE. This will cause the
  13451. * 8051 to put the Serdes in reset. However, we don't want to
  13452. * go through the entire link state machine since we want to
  13453. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13454. * but rather an attempt to save the chip.
  13455. * Code below is almost the same as quiet_serdes() but avoids
  13456. * all the extra work and the sleeps.
  13457. */
  13458. ppd->driver_link_ready = 0;
  13459. ppd->link_enabled = 0;
  13460. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13461. PLS_OFFLINE);
  13462. /*
  13463. * Step 2: Shutdown LCB and 8051
  13464. * After shutdown, do not restore DC_CFG_RESET value.
  13465. */
  13466. dc_shutdown(dd);
  13467. }