chip.c 449 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414
  1. /*
  2. * Copyright(c) 2015 - 2017 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. /*
  48. * This file contains all of the code that is specific to the HFI chip
  49. */
  50. #include <linux/pci.h>
  51. #include <linux/delay.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/module.h>
  54. #include "hfi.h"
  55. #include "trace.h"
  56. #include "mad.h"
  57. #include "pio.h"
  58. #include "sdma.h"
  59. #include "eprom.h"
  60. #include "efivar.h"
  61. #include "platform.h"
  62. #include "aspm.h"
  63. #include "affinity.h"
  64. #include "debugfs.h"
  65. #define NUM_IB_PORTS 1
  66. uint kdeth_qp;
  67. module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
  68. MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
  69. uint num_vls = HFI1_MAX_VLS_SUPPORTED;
  70. module_param(num_vls, uint, S_IRUGO);
  71. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  72. /*
  73. * Default time to aggregate two 10K packets from the idle state
  74. * (timer not running). The timer starts at the end of the first packet,
  75. * so only the time for one 10K packet and header plus a bit extra is needed.
  76. * 10 * 1024 + 64 header byte = 10304 byte
  77. * 10304 byte / 12.5 GB/s = 824.32ns
  78. */
  79. uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
  80. module_param(rcv_intr_timeout, uint, S_IRUGO);
  81. MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
  82. uint rcv_intr_count = 16; /* same as qib */
  83. module_param(rcv_intr_count, uint, S_IRUGO);
  84. MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
  85. ushort link_crc_mask = SUPPORTED_CRCS;
  86. module_param(link_crc_mask, ushort, S_IRUGO);
  87. MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
  88. uint loopback;
  89. module_param_named(loopback, loopback, uint, S_IRUGO);
  90. MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
  91. /* Other driver tunables */
  92. uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
  93. static ushort crc_14b_sideband = 1;
  94. static uint use_flr = 1;
  95. uint quick_linkup; /* skip LNI */
  96. struct flag_table {
  97. u64 flag; /* the flag */
  98. char *str; /* description string */
  99. u16 extra; /* extra information */
  100. u16 unused0;
  101. u32 unused1;
  102. };
  103. /* str must be a string constant */
  104. #define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
  105. #define FLAG_ENTRY0(str, flag) {flag, str, 0}
  106. /* Send Error Consequences */
  107. #define SEC_WRITE_DROPPED 0x1
  108. #define SEC_PACKET_DROPPED 0x2
  109. #define SEC_SC_HALTED 0x4 /* per-context only */
  110. #define SEC_SPC_FREEZE 0x8 /* per-HFI only */
  111. #define DEFAULT_KRCVQS 2
  112. #define MIN_KERNEL_KCTXTS 2
  113. #define FIRST_KERNEL_KCTXT 1
  114. /*
  115. * RSM instance allocation
  116. * 0 - Verbs
  117. * 1 - User Fecn Handling
  118. * 2 - Vnic
  119. */
  120. #define RSM_INS_VERBS 0
  121. #define RSM_INS_FECN 1
  122. #define RSM_INS_VNIC 2
  123. /* Bit offset into the GUID which carries HFI id information */
  124. #define GUID_HFI_INDEX_SHIFT 39
  125. /* extract the emulation revision */
  126. #define emulator_rev(dd) ((dd)->irev >> 8)
  127. /* parallel and serial emulation versions are 3 and 4 respectively */
  128. #define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
  129. #define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
  130. /* RSM fields for Verbs */
  131. /* packet type */
  132. #define IB_PACKET_TYPE 2ull
  133. #define QW_SHIFT 6ull
  134. /* QPN[7..1] */
  135. #define QPN_WIDTH 7ull
  136. /* LRH.BTH: QW 0, OFFSET 48 - for match */
  137. #define LRH_BTH_QW 0ull
  138. #define LRH_BTH_BIT_OFFSET 48ull
  139. #define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
  140. #define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
  141. #define LRH_BTH_SELECT
  142. #define LRH_BTH_MASK 3ull
  143. #define LRH_BTH_VALUE 2ull
  144. /* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
  145. #define LRH_SC_QW 0ull
  146. #define LRH_SC_BIT_OFFSET 56ull
  147. #define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
  148. #define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
  149. #define LRH_SC_MASK 128ull
  150. #define LRH_SC_VALUE 0ull
  151. /* SC[n..0] QW 0, OFFSET 60 - for select */
  152. #define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
  153. /* QPN[m+n:1] QW 1, OFFSET 1 */
  154. #define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
  155. /* RSM fields for Vnic */
  156. /* L2_TYPE: QW 0, OFFSET 61 - for match */
  157. #define L2_TYPE_QW 0ull
  158. #define L2_TYPE_BIT_OFFSET 61ull
  159. #define L2_TYPE_OFFSET(off) ((L2_TYPE_QW << QW_SHIFT) | (off))
  160. #define L2_TYPE_MATCH_OFFSET L2_TYPE_OFFSET(L2_TYPE_BIT_OFFSET)
  161. #define L2_TYPE_MASK 3ull
  162. #define L2_16B_VALUE 2ull
  163. /* L4_TYPE QW 1, OFFSET 0 - for match */
  164. #define L4_TYPE_QW 1ull
  165. #define L4_TYPE_BIT_OFFSET 0ull
  166. #define L4_TYPE_OFFSET(off) ((L4_TYPE_QW << QW_SHIFT) | (off))
  167. #define L4_TYPE_MATCH_OFFSET L4_TYPE_OFFSET(L4_TYPE_BIT_OFFSET)
  168. #define L4_16B_TYPE_MASK 0xFFull
  169. #define L4_16B_ETH_VALUE 0x78ull
  170. /* 16B VESWID - for select */
  171. #define L4_16B_HDR_VESWID_OFFSET ((2 << QW_SHIFT) | (16ull))
  172. /* 16B ENTROPY - for select */
  173. #define L2_16B_ENTROPY_OFFSET ((1 << QW_SHIFT) | (32ull))
  174. /* defines to build power on SC2VL table */
  175. #define SC2VL_VAL( \
  176. num, \
  177. sc0, sc0val, \
  178. sc1, sc1val, \
  179. sc2, sc2val, \
  180. sc3, sc3val, \
  181. sc4, sc4val, \
  182. sc5, sc5val, \
  183. sc6, sc6val, \
  184. sc7, sc7val) \
  185. ( \
  186. ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
  187. ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
  188. ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
  189. ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
  190. ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
  191. ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
  192. ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
  193. ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
  194. )
  195. #define DC_SC_VL_VAL( \
  196. range, \
  197. e0, e0val, \
  198. e1, e1val, \
  199. e2, e2val, \
  200. e3, e3val, \
  201. e4, e4val, \
  202. e5, e5val, \
  203. e6, e6val, \
  204. e7, e7val, \
  205. e8, e8val, \
  206. e9, e9val, \
  207. e10, e10val, \
  208. e11, e11val, \
  209. e12, e12val, \
  210. e13, e13val, \
  211. e14, e14val, \
  212. e15, e15val) \
  213. ( \
  214. ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
  215. ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
  216. ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
  217. ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
  218. ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
  219. ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
  220. ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
  221. ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
  222. ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
  223. ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
  224. ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
  225. ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
  226. ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
  227. ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
  228. ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
  229. ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
  230. )
  231. /* all CceStatus sub-block freeze bits */
  232. #define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
  233. | CCE_STATUS_RXE_FROZE_SMASK \
  234. | CCE_STATUS_TXE_FROZE_SMASK \
  235. | CCE_STATUS_TXE_PIO_FROZE_SMASK)
  236. /* all CceStatus sub-block TXE pause bits */
  237. #define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
  238. | CCE_STATUS_TXE_PAUSED_SMASK \
  239. | CCE_STATUS_SDMA_PAUSED_SMASK)
  240. /* all CceStatus sub-block RXE pause bits */
  241. #define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
  242. #define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
  243. #define CNTR_32BIT_MAX 0x00000000FFFFFFFF
  244. /*
  245. * CCE Error flags.
  246. */
  247. static struct flag_table cce_err_status_flags[] = {
  248. /* 0*/ FLAG_ENTRY0("CceCsrParityErr",
  249. CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
  250. /* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
  251. CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
  252. /* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
  253. CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
  254. /* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
  255. CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
  256. /* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
  257. CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
  258. /* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
  259. CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
  260. /* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
  261. CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
  262. /* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
  263. CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
  264. /* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
  265. CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
  266. /* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  267. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
  268. /*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
  269. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
  270. /*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
  271. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
  272. /*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
  273. CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
  274. /*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  275. CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
  276. /*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
  277. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
  278. /*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  279. CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
  280. /*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  281. CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
  282. /*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
  283. CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
  284. /*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
  285. CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
  286. /*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
  287. CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
  288. /*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
  289. CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
  290. /*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
  291. CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
  292. /*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
  293. CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
  294. /*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
  295. CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
  296. /*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
  297. CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
  298. /*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
  299. CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
  300. /*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
  301. CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
  302. /*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
  303. CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
  304. /*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
  305. CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
  306. /*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
  307. CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
  308. /*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
  309. CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
  310. /*31*/ FLAG_ENTRY0("LATriggered",
  311. CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
  312. /*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
  313. CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
  314. /*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
  315. CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
  316. /*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
  317. CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
  318. /*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
  319. CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
  320. /*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
  321. CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
  322. /*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
  323. CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
  324. /*38*/ FLAG_ENTRY0("CceIntMapCorErr",
  325. CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
  326. /*39*/ FLAG_ENTRY0("CceIntMapUncErr",
  327. CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
  328. /*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
  329. CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
  330. /*41-63 reserved*/
  331. };
  332. /*
  333. * Misc Error flags
  334. */
  335. #define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
  336. static struct flag_table misc_err_status_flags[] = {
  337. /* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
  338. /* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
  339. /* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
  340. /* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
  341. /* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
  342. /* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
  343. /* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
  344. /* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
  345. /* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
  346. /* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
  347. /*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
  348. /*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
  349. /*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
  350. };
  351. /*
  352. * TXE PIO Error flags and consequences
  353. */
  354. static struct flag_table pio_err_status_flags[] = {
  355. /* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
  356. SEC_WRITE_DROPPED,
  357. SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
  358. /* 1*/ FLAG_ENTRY("PioWriteAddrParity",
  359. SEC_SPC_FREEZE,
  360. SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
  361. /* 2*/ FLAG_ENTRY("PioCsrParity",
  362. SEC_SPC_FREEZE,
  363. SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
  364. /* 3*/ FLAG_ENTRY("PioSbMemFifo0",
  365. SEC_SPC_FREEZE,
  366. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
  367. /* 4*/ FLAG_ENTRY("PioSbMemFifo1",
  368. SEC_SPC_FREEZE,
  369. SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
  370. /* 5*/ FLAG_ENTRY("PioPccFifoParity",
  371. SEC_SPC_FREEZE,
  372. SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
  373. /* 6*/ FLAG_ENTRY("PioPecFifoParity",
  374. SEC_SPC_FREEZE,
  375. SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
  376. /* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
  377. SEC_SPC_FREEZE,
  378. SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
  379. /* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
  380. SEC_SPC_FREEZE,
  381. SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
  382. /* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
  383. SEC_SPC_FREEZE,
  384. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
  385. /*10*/ FLAG_ENTRY("PioSmPktResetParity",
  386. SEC_SPC_FREEZE,
  387. SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
  388. /*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
  389. SEC_SPC_FREEZE,
  390. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
  391. /*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
  392. SEC_SPC_FREEZE,
  393. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
  394. /*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
  395. 0,
  396. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
  397. /*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
  398. 0,
  399. SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
  400. /*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
  401. SEC_SPC_FREEZE,
  402. SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
  403. /*16*/ FLAG_ENTRY("PioPpmcPblFifo",
  404. SEC_SPC_FREEZE,
  405. SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
  406. /*17*/ FLAG_ENTRY("PioInitSmIn",
  407. 0,
  408. SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
  409. /*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
  410. SEC_SPC_FREEZE,
  411. SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
  412. /*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
  413. SEC_SPC_FREEZE,
  414. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
  415. /*20*/ FLAG_ENTRY("PioHostAddrMemCor",
  416. 0,
  417. SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
  418. /*21*/ FLAG_ENTRY("PioWriteDataParity",
  419. SEC_SPC_FREEZE,
  420. SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
  421. /*22*/ FLAG_ENTRY("PioStateMachine",
  422. SEC_SPC_FREEZE,
  423. SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
  424. /*23*/ FLAG_ENTRY("PioWriteQwValidParity",
  425. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  426. SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
  427. /*24*/ FLAG_ENTRY("PioBlockQwCountParity",
  428. SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
  429. SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
  430. /*25*/ FLAG_ENTRY("PioVlfVlLenParity",
  431. SEC_SPC_FREEZE,
  432. SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
  433. /*26*/ FLAG_ENTRY("PioVlfSopParity",
  434. SEC_SPC_FREEZE,
  435. SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
  436. /*27*/ FLAG_ENTRY("PioVlFifoParity",
  437. SEC_SPC_FREEZE,
  438. SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
  439. /*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
  440. SEC_SPC_FREEZE,
  441. SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
  442. /*29*/ FLAG_ENTRY("PioPpmcSopLen",
  443. SEC_SPC_FREEZE,
  444. SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
  445. /*30-31 reserved*/
  446. /*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
  447. SEC_SPC_FREEZE,
  448. SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
  449. /*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
  450. SEC_SPC_FREEZE,
  451. SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
  452. /*34*/ FLAG_ENTRY("PioPccSopHeadParity",
  453. SEC_SPC_FREEZE,
  454. SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
  455. /*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
  456. SEC_SPC_FREEZE,
  457. SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
  458. /*36-63 reserved*/
  459. };
  460. /* TXE PIO errors that cause an SPC freeze */
  461. #define ALL_PIO_FREEZE_ERR \
  462. (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
  463. | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
  464. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
  465. | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
  466. | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
  467. | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
  468. | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
  469. | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
  470. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
  471. | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
  472. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
  473. | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
  474. | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
  475. | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
  476. | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
  477. | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
  478. | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
  479. | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
  480. | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
  481. | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
  482. | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
  483. | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
  484. | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
  485. | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
  486. | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
  487. | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
  488. | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
  489. | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
  490. | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
  491. /*
  492. * TXE SDMA Error flags
  493. */
  494. static struct flag_table sdma_err_status_flags[] = {
  495. /* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
  496. SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
  497. /* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
  498. SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
  499. /* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
  500. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
  501. /* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
  502. SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
  503. /*04-63 reserved*/
  504. };
  505. /* TXE SDMA errors that cause an SPC freeze */
  506. #define ALL_SDMA_FREEZE_ERR \
  507. (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
  508. | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
  509. | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
  510. /* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
  511. #define PORT_DISCARD_EGRESS_ERRS \
  512. (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
  513. | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
  514. | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
  515. /*
  516. * TXE Egress Error flags
  517. */
  518. #define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
  519. static struct flag_table egress_err_status_flags[] = {
  520. /* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
  521. /* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
  522. /* 2 reserved */
  523. /* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
  524. SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
  525. /* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
  526. /* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
  527. /* 6 reserved */
  528. /* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
  529. SEES(TX_PIO_LAUNCH_INTF_PARITY)),
  530. /* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
  531. SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
  532. /* 9-10 reserved */
  533. /*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
  534. SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
  535. /*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
  536. /*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
  537. /*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
  538. /*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
  539. /*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
  540. SEES(TX_SDMA0_DISALLOWED_PACKET)),
  541. /*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
  542. SEES(TX_SDMA1_DISALLOWED_PACKET)),
  543. /*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
  544. SEES(TX_SDMA2_DISALLOWED_PACKET)),
  545. /*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
  546. SEES(TX_SDMA3_DISALLOWED_PACKET)),
  547. /*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
  548. SEES(TX_SDMA4_DISALLOWED_PACKET)),
  549. /*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
  550. SEES(TX_SDMA5_DISALLOWED_PACKET)),
  551. /*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
  552. SEES(TX_SDMA6_DISALLOWED_PACKET)),
  553. /*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
  554. SEES(TX_SDMA7_DISALLOWED_PACKET)),
  555. /*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
  556. SEES(TX_SDMA8_DISALLOWED_PACKET)),
  557. /*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
  558. SEES(TX_SDMA9_DISALLOWED_PACKET)),
  559. /*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
  560. SEES(TX_SDMA10_DISALLOWED_PACKET)),
  561. /*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
  562. SEES(TX_SDMA11_DISALLOWED_PACKET)),
  563. /*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
  564. SEES(TX_SDMA12_DISALLOWED_PACKET)),
  565. /*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
  566. SEES(TX_SDMA13_DISALLOWED_PACKET)),
  567. /*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
  568. SEES(TX_SDMA14_DISALLOWED_PACKET)),
  569. /*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
  570. SEES(TX_SDMA15_DISALLOWED_PACKET)),
  571. /*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
  572. SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
  573. /*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
  574. SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
  575. /*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
  576. SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
  577. /*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
  578. SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
  579. /*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
  580. SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
  581. /*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
  582. SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
  583. /*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
  584. SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
  585. /*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
  586. SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
  587. /*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
  588. SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
  589. /*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
  590. /*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
  591. /*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
  592. /*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
  593. /*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
  594. /*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
  595. /*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
  596. /*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
  597. /*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
  598. /*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
  599. /*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
  600. /*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
  601. /*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
  602. /*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
  603. /*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
  604. /*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
  605. /*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
  606. /*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
  607. /*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
  608. /*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
  609. /*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
  610. /*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
  611. SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
  612. /*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
  613. SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
  614. };
  615. /*
  616. * TXE Egress Error Info flags
  617. */
  618. #define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
  619. static struct flag_table egress_err_info_flags[] = {
  620. /* 0*/ FLAG_ENTRY0("Reserved", 0ull),
  621. /* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
  622. /* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  623. /* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
  624. /* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
  625. /* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
  626. /* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
  627. /* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
  628. /* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
  629. /* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
  630. /*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
  631. /*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
  632. /*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
  633. /*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
  634. /*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
  635. /*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
  636. /*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
  637. /*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
  638. /*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
  639. /*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
  640. /*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
  641. /*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
  642. };
  643. /* TXE Egress errors that cause an SPC freeze */
  644. #define ALL_TXE_EGRESS_FREEZE_ERR \
  645. (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
  646. | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
  647. | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
  648. | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
  649. | SEES(TX_LAUNCH_CSR_PARITY) \
  650. | SEES(TX_SBRD_CTL_CSR_PARITY) \
  651. | SEES(TX_CONFIG_PARITY) \
  652. | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
  653. | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
  654. | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
  655. | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
  656. | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
  657. | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
  658. | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
  659. | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
  660. | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
  661. | SEES(TX_CREDIT_RETURN_PARITY))
  662. /*
  663. * TXE Send error flags
  664. */
  665. #define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
  666. static struct flag_table send_err_status_flags[] = {
  667. /* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
  668. /* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
  669. /* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
  670. };
  671. /*
  672. * TXE Send Context Error flags and consequences
  673. */
  674. static struct flag_table sc_err_status_flags[] = {
  675. /* 0*/ FLAG_ENTRY("InconsistentSop",
  676. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  677. SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
  678. /* 1*/ FLAG_ENTRY("DisallowedPacket",
  679. SEC_PACKET_DROPPED | SEC_SC_HALTED,
  680. SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
  681. /* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
  682. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  683. SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
  684. /* 3*/ FLAG_ENTRY("WriteOverflow",
  685. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  686. SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
  687. /* 4*/ FLAG_ENTRY("WriteOutOfBounds",
  688. SEC_WRITE_DROPPED | SEC_SC_HALTED,
  689. SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
  690. /* 5-63 reserved*/
  691. };
  692. /*
  693. * RXE Receive Error flags
  694. */
  695. #define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
  696. static struct flag_table rxe_err_status_flags[] = {
  697. /* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
  698. /* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
  699. /* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
  700. /* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
  701. /* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
  702. /* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
  703. /* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
  704. /* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
  705. /* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
  706. /* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
  707. /*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
  708. /*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
  709. /*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
  710. /*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
  711. /*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
  712. /*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
  713. /*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
  714. RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
  715. /*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
  716. /*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
  717. /*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
  718. RXES(RBUF_BLOCK_LIST_READ_UNC)),
  719. /*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
  720. RXES(RBUF_BLOCK_LIST_READ_COR)),
  721. /*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
  722. RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
  723. /*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
  724. RXES(RBUF_CSR_QENT_CNT_PARITY)),
  725. /*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
  726. RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
  727. /*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
  728. RXES(RBUF_CSR_QVLD_BIT_PARITY)),
  729. /*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
  730. /*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
  731. /*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
  732. RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
  733. /*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
  734. /*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
  735. /*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
  736. /*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
  737. /*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
  738. /*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
  739. /*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
  740. /*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
  741. RXES(RBUF_FL_INITDONE_PARITY)),
  742. /*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
  743. RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
  744. /*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
  745. /*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
  746. /*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
  747. /*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
  748. RXES(LOOKUP_DES_PART1_UNC_COR)),
  749. /*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
  750. RXES(LOOKUP_DES_PART2_PARITY)),
  751. /*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
  752. /*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
  753. /*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
  754. /*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
  755. /*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
  756. /*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
  757. /*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
  758. /*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
  759. /*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
  760. /*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
  761. /*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
  762. /*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
  763. /*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
  764. /*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
  765. /*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
  766. /*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
  767. /*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
  768. /*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
  769. /*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
  770. /*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
  771. /*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
  772. /*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
  773. };
  774. /* RXE errors that will trigger an SPC freeze */
  775. #define ALL_RXE_FREEZE_ERR \
  776. (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
  777. | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
  778. | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
  779. | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
  780. | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
  781. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
  782. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
  783. | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
  784. | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
  785. | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
  786. | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
  787. | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
  788. | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
  789. | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
  790. | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
  791. | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
  792. | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
  793. | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
  794. | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
  795. | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
  796. | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
  797. | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
  798. | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
  799. | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
  800. | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
  801. | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
  802. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
  803. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
  804. | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
  805. | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
  806. | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
  807. | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
  808. | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
  809. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
  810. | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
  811. | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
  812. | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
  813. | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
  814. | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
  815. | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
  816. | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
  817. | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
  818. | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
  819. | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
  820. #define RXE_FREEZE_ABORT_MASK \
  821. (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
  822. RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
  823. RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
  824. /*
  825. * DCC Error Flags
  826. */
  827. #define DCCE(name) DCC_ERR_FLG_##name##_SMASK
  828. static struct flag_table dcc_err_flags[] = {
  829. FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
  830. FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
  831. FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
  832. FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
  833. FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
  834. FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
  835. FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
  836. FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
  837. FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
  838. FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
  839. FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
  840. FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
  841. FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
  842. FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
  843. FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
  844. FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
  845. FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
  846. FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
  847. FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
  848. FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
  849. FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
  850. FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
  851. FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
  852. FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
  853. FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
  854. FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
  855. FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
  856. FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
  857. FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
  858. FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
  859. FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
  860. FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
  861. FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
  862. FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
  863. FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
  864. FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
  865. FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
  866. FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
  867. FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
  868. FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
  869. FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
  870. FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
  871. FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
  872. FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
  873. FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
  874. FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
  875. };
  876. /*
  877. * LCB error flags
  878. */
  879. #define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
  880. static struct flag_table lcb_err_flags[] = {
  881. /* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
  882. /* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
  883. /* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
  884. /* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
  885. LCBE(ALL_LNS_FAILED_REINIT_TEST)),
  886. /* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
  887. /* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
  888. /* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
  889. /* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
  890. /* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
  891. /* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
  892. /*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
  893. /*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
  894. /*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
  895. /*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
  896. LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
  897. /*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
  898. /*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
  899. /*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
  900. /*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
  901. /*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
  902. /*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
  903. LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
  904. /*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
  905. /*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
  906. /*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
  907. /*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
  908. /*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
  909. /*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
  910. /*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
  911. LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
  912. /*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
  913. /*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
  914. LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
  915. /*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
  916. LCBE(REDUNDANT_FLIT_PARITY_ERR))
  917. };
  918. /*
  919. * DC8051 Error Flags
  920. */
  921. #define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
  922. static struct flag_table dc8051_err_flags[] = {
  923. FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
  924. FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
  925. FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
  926. FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
  927. FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
  928. FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
  929. FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
  930. FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
  931. FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
  932. D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
  933. FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
  934. };
  935. /*
  936. * DC8051 Information Error flags
  937. *
  938. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
  939. */
  940. static struct flag_table dc8051_info_err_flags[] = {
  941. FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
  942. FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
  943. FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
  944. FLAG_ENTRY0("Serdes internal loopback failure",
  945. FAILED_SERDES_INTERNAL_LOOPBACK),
  946. FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
  947. FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
  948. FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
  949. FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
  950. FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
  951. FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
  952. FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
  953. FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
  954. FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
  955. FLAG_ENTRY0("External Device Request Timeout",
  956. EXTERNAL_DEVICE_REQ_TIMEOUT),
  957. };
  958. /*
  959. * DC8051 Information Host Information flags
  960. *
  961. * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
  962. */
  963. static struct flag_table dc8051_info_host_msg_flags[] = {
  964. FLAG_ENTRY0("Host request done", 0x0001),
  965. FLAG_ENTRY0("BC PWR_MGM message", 0x0002),
  966. FLAG_ENTRY0("BC SMA message", 0x0004),
  967. FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
  968. FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
  969. FLAG_ENTRY0("External device config request", 0x0020),
  970. FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
  971. FLAG_ENTRY0("LinkUp achieved", 0x0080),
  972. FLAG_ENTRY0("Link going down", 0x0100),
  973. FLAG_ENTRY0("Link width downgraded", 0x0200),
  974. };
  975. static u32 encoded_size(u32 size);
  976. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
  977. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
  978. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  979. u8 *continuous);
  980. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  981. u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
  982. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  983. u8 *remote_tx_rate, u16 *link_widths);
  984. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  985. u8 *flag_bits, u16 *link_widths);
  986. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  987. u8 *device_rev);
  988. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
  989. static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
  990. u8 *tx_polarity_inversion,
  991. u8 *rx_polarity_inversion, u8 *max_rate);
  992. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  993. unsigned int context, u64 err_status);
  994. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
  995. static void handle_dcc_err(struct hfi1_devdata *dd,
  996. unsigned int context, u64 err_status);
  997. static void handle_lcb_err(struct hfi1_devdata *dd,
  998. unsigned int context, u64 err_status);
  999. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1000. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1001. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1002. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1003. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1004. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1005. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1006. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
  1007. static void set_partition_keys(struct hfi1_pportdata *ppd);
  1008. static const char *link_state_name(u32 state);
  1009. static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
  1010. u32 state);
  1011. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  1012. u64 *out_data);
  1013. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
  1014. static int thermal_init(struct hfi1_devdata *dd);
  1015. static void update_statusp(struct hfi1_pportdata *ppd, u32 state);
  1016. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  1017. int msecs);
  1018. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1019. int msecs);
  1020. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state);
  1021. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state);
  1022. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  1023. int msecs);
  1024. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
  1025. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
  1026. static void handle_temp_err(struct hfi1_devdata *dd);
  1027. static void dc_shutdown(struct hfi1_devdata *dd);
  1028. static void dc_start(struct hfi1_devdata *dd);
  1029. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  1030. unsigned int *np);
  1031. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
  1032. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
  1033. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index);
  1034. /*
  1035. * Error interrupt table entry. This is used as input to the interrupt
  1036. * "clear down" routine used for all second tier error interrupt register.
  1037. * Second tier interrupt registers have a single bit representing them
  1038. * in the top-level CceIntStatus.
  1039. */
  1040. struct err_reg_info {
  1041. u32 status; /* status CSR offset */
  1042. u32 clear; /* clear CSR offset */
  1043. u32 mask; /* mask CSR offset */
  1044. void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
  1045. const char *desc;
  1046. };
  1047. #define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
  1048. #define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
  1049. #define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
  1050. /*
  1051. * Helpers for building HFI and DC error interrupt table entries. Different
  1052. * helpers are needed because of inconsistent register names.
  1053. */
  1054. #define EE(reg, handler, desc) \
  1055. { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
  1056. handler, desc }
  1057. #define DC_EE1(reg, handler, desc) \
  1058. { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
  1059. #define DC_EE2(reg, handler, desc) \
  1060. { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
  1061. /*
  1062. * Table of the "misc" grouping of error interrupts. Each entry refers to
  1063. * another register containing more information.
  1064. */
  1065. static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
  1066. /* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
  1067. /* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
  1068. /* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
  1069. /* 3*/ { 0, 0, 0, NULL }, /* reserved */
  1070. /* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
  1071. /* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
  1072. /* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
  1073. /* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
  1074. /* the rest are reserved */
  1075. };
  1076. /*
  1077. * Index into the Various section of the interrupt sources
  1078. * corresponding to the Critical Temperature interrupt.
  1079. */
  1080. #define TCRIT_INT_SOURCE 4
  1081. /*
  1082. * SDMA error interrupt entry - refers to another register containing more
  1083. * information.
  1084. */
  1085. static const struct err_reg_info sdma_eng_err =
  1086. EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
  1087. static const struct err_reg_info various_err[NUM_VARIOUS] = {
  1088. /* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
  1089. /* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
  1090. /* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
  1091. /* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
  1092. /* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
  1093. /* rest are reserved */
  1094. };
  1095. /*
  1096. * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
  1097. * register can not be derived from the MTU value because 10K is not
  1098. * a power of 2. Therefore, we need a constant. Everything else can
  1099. * be calculated.
  1100. */
  1101. #define DCC_CFG_PORT_MTU_CAP_10240 7
  1102. /*
  1103. * Table of the DC grouping of error interrupts. Each entry refers to
  1104. * another register containing more information.
  1105. */
  1106. static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
  1107. /* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
  1108. /* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
  1109. /* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
  1110. /* 3*/ /* dc_lbm_int - special, see is_dc_int() */
  1111. /* the rest are reserved */
  1112. };
  1113. struct cntr_entry {
  1114. /*
  1115. * counter name
  1116. */
  1117. char *name;
  1118. /*
  1119. * csr to read for name (if applicable)
  1120. */
  1121. u64 csr;
  1122. /*
  1123. * offset into dd or ppd to store the counter's value
  1124. */
  1125. int offset;
  1126. /*
  1127. * flags
  1128. */
  1129. u8 flags;
  1130. /*
  1131. * accessor for stat element, context either dd or ppd
  1132. */
  1133. u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
  1134. int mode, u64 data);
  1135. };
  1136. #define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
  1137. #define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
  1138. #define CNTR_ELEM(name, csr, offset, flags, accessor) \
  1139. { \
  1140. name, \
  1141. csr, \
  1142. offset, \
  1143. flags, \
  1144. accessor \
  1145. }
  1146. /* 32bit RXE */
  1147. #define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1148. CNTR_ELEM(#name, \
  1149. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1150. 0, flags | CNTR_32BIT, \
  1151. port_access_u32_csr)
  1152. #define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
  1153. CNTR_ELEM(#name, \
  1154. (counter * 8 + RCV_COUNTER_ARRAY32), \
  1155. 0, flags | CNTR_32BIT, \
  1156. dev_access_u32_csr)
  1157. /* 64bit RXE */
  1158. #define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1159. CNTR_ELEM(#name, \
  1160. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1161. 0, flags, \
  1162. port_access_u64_csr)
  1163. #define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
  1164. CNTR_ELEM(#name, \
  1165. (counter * 8 + RCV_COUNTER_ARRAY64), \
  1166. 0, flags, \
  1167. dev_access_u64_csr)
  1168. #define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
  1169. #define OVR_ELM(ctx) \
  1170. CNTR_ELEM("RcvHdrOvr" #ctx, \
  1171. (RCV_HDR_OVFL_CNT + ctx * 0x100), \
  1172. 0, CNTR_NORMAL, port_access_u64_csr)
  1173. /* 32bit TXE */
  1174. #define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
  1175. CNTR_ELEM(#name, \
  1176. (counter * 8 + SEND_COUNTER_ARRAY32), \
  1177. 0, flags | CNTR_32BIT, \
  1178. port_access_u32_csr)
  1179. /* 64bit TXE */
  1180. #define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
  1181. CNTR_ELEM(#name, \
  1182. (counter * 8 + SEND_COUNTER_ARRAY64), \
  1183. 0, flags, \
  1184. port_access_u64_csr)
  1185. # define TX64_DEV_CNTR_ELEM(name, counter, flags) \
  1186. CNTR_ELEM(#name,\
  1187. counter * 8 + SEND_COUNTER_ARRAY64, \
  1188. 0, \
  1189. flags, \
  1190. dev_access_u64_csr)
  1191. /* CCE */
  1192. #define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
  1193. CNTR_ELEM(#name, \
  1194. (counter * 8 + CCE_COUNTER_ARRAY32), \
  1195. 0, flags | CNTR_32BIT, \
  1196. dev_access_u32_csr)
  1197. #define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
  1198. CNTR_ELEM(#name, \
  1199. (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
  1200. 0, flags | CNTR_32BIT, \
  1201. dev_access_u32_csr)
  1202. /* DC */
  1203. #define DC_PERF_CNTR(name, counter, flags) \
  1204. CNTR_ELEM(#name, \
  1205. counter, \
  1206. 0, \
  1207. flags, \
  1208. dev_access_u64_csr)
  1209. #define DC_PERF_CNTR_LCB(name, counter, flags) \
  1210. CNTR_ELEM(#name, \
  1211. counter, \
  1212. 0, \
  1213. flags, \
  1214. dc_access_lcb_cntr)
  1215. /* ibp counters */
  1216. #define SW_IBP_CNTR(name, cntr) \
  1217. CNTR_ELEM(#name, \
  1218. 0, \
  1219. 0, \
  1220. CNTR_SYNTH, \
  1221. access_ibp_##cntr)
  1222. /**
  1223. * hfi_addr_from_offset - return addr for readq/writeq
  1224. * @dd - the dd device
  1225. * @offset - the offset of the CSR within bar0
  1226. *
  1227. * This routine selects the appropriate base address
  1228. * based on the indicated offset.
  1229. */
  1230. static inline void __iomem *hfi1_addr_from_offset(
  1231. const struct hfi1_devdata *dd,
  1232. u32 offset)
  1233. {
  1234. if (offset >= dd->base2_start)
  1235. return dd->kregbase2 + (offset - dd->base2_start);
  1236. return dd->kregbase1 + offset;
  1237. }
  1238. /**
  1239. * read_csr - read CSR at the indicated offset
  1240. * @dd - the dd device
  1241. * @offset - the offset of the CSR within bar0
  1242. *
  1243. * Return: the value read or all FF's if there
  1244. * is no mapping
  1245. */
  1246. u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
  1247. {
  1248. if (dd->flags & HFI1_PRESENT)
  1249. return readq(hfi1_addr_from_offset(dd, offset));
  1250. return -1;
  1251. }
  1252. /**
  1253. * write_csr - write CSR at the indicated offset
  1254. * @dd - the dd device
  1255. * @offset - the offset of the CSR within bar0
  1256. * @value - value to write
  1257. */
  1258. void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
  1259. {
  1260. if (dd->flags & HFI1_PRESENT) {
  1261. void __iomem *base = hfi1_addr_from_offset(dd, offset);
  1262. /* avoid write to RcvArray */
  1263. if (WARN_ON(offset >= RCV_ARRAY && offset < dd->base2_start))
  1264. return;
  1265. writeq(value, base);
  1266. }
  1267. }
  1268. /**
  1269. * get_csr_addr - return te iomem address for offset
  1270. * @dd - the dd device
  1271. * @offset - the offset of the CSR within bar0
  1272. *
  1273. * Return: The iomem address to use in subsequent
  1274. * writeq/readq operations.
  1275. */
  1276. void __iomem *get_csr_addr(
  1277. const struct hfi1_devdata *dd,
  1278. u32 offset)
  1279. {
  1280. if (dd->flags & HFI1_PRESENT)
  1281. return hfi1_addr_from_offset(dd, offset);
  1282. return NULL;
  1283. }
  1284. static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
  1285. int mode, u64 value)
  1286. {
  1287. u64 ret;
  1288. if (mode == CNTR_MODE_R) {
  1289. ret = read_csr(dd, csr);
  1290. } else if (mode == CNTR_MODE_W) {
  1291. write_csr(dd, csr, value);
  1292. ret = value;
  1293. } else {
  1294. dd_dev_err(dd, "Invalid cntr register access mode");
  1295. return 0;
  1296. }
  1297. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
  1298. return ret;
  1299. }
  1300. /* Dev Access */
  1301. static u64 dev_access_u32_csr(const struct cntr_entry *entry,
  1302. void *context, int vl, int mode, u64 data)
  1303. {
  1304. struct hfi1_devdata *dd = context;
  1305. u64 csr = entry->csr;
  1306. if (entry->flags & CNTR_SDMA) {
  1307. if (vl == CNTR_INVALID_VL)
  1308. return 0;
  1309. csr += 0x100 * vl;
  1310. } else {
  1311. if (vl != CNTR_INVALID_VL)
  1312. return 0;
  1313. }
  1314. return read_write_csr(dd, csr, mode, data);
  1315. }
  1316. static u64 access_sde_err_cnt(const struct cntr_entry *entry,
  1317. void *context, int idx, int mode, u64 data)
  1318. {
  1319. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1320. if (dd->per_sdma && idx < dd->num_sdma)
  1321. return dd->per_sdma[idx].err_cnt;
  1322. return 0;
  1323. }
  1324. static u64 access_sde_int_cnt(const struct cntr_entry *entry,
  1325. void *context, int idx, int mode, u64 data)
  1326. {
  1327. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1328. if (dd->per_sdma && idx < dd->num_sdma)
  1329. return dd->per_sdma[idx].sdma_int_cnt;
  1330. return 0;
  1331. }
  1332. static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
  1333. void *context, int idx, int mode, u64 data)
  1334. {
  1335. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1336. if (dd->per_sdma && idx < dd->num_sdma)
  1337. return dd->per_sdma[idx].idle_int_cnt;
  1338. return 0;
  1339. }
  1340. static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
  1341. void *context, int idx, int mode,
  1342. u64 data)
  1343. {
  1344. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1345. if (dd->per_sdma && idx < dd->num_sdma)
  1346. return dd->per_sdma[idx].progress_int_cnt;
  1347. return 0;
  1348. }
  1349. static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
  1350. int vl, int mode, u64 data)
  1351. {
  1352. struct hfi1_devdata *dd = context;
  1353. u64 val = 0;
  1354. u64 csr = entry->csr;
  1355. if (entry->flags & CNTR_VL) {
  1356. if (vl == CNTR_INVALID_VL)
  1357. return 0;
  1358. csr += 8 * vl;
  1359. } else {
  1360. if (vl != CNTR_INVALID_VL)
  1361. return 0;
  1362. }
  1363. val = read_write_csr(dd, csr, mode, data);
  1364. return val;
  1365. }
  1366. static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
  1367. int vl, int mode, u64 data)
  1368. {
  1369. struct hfi1_devdata *dd = context;
  1370. u32 csr = entry->csr;
  1371. int ret = 0;
  1372. if (vl != CNTR_INVALID_VL)
  1373. return 0;
  1374. if (mode == CNTR_MODE_R)
  1375. ret = read_lcb_csr(dd, csr, &data);
  1376. else if (mode == CNTR_MODE_W)
  1377. ret = write_lcb_csr(dd, csr, data);
  1378. if (ret) {
  1379. dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
  1380. return 0;
  1381. }
  1382. hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
  1383. return data;
  1384. }
  1385. /* Port Access */
  1386. static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
  1387. int vl, int mode, u64 data)
  1388. {
  1389. struct hfi1_pportdata *ppd = context;
  1390. if (vl != CNTR_INVALID_VL)
  1391. return 0;
  1392. return read_write_csr(ppd->dd, entry->csr, mode, data);
  1393. }
  1394. static u64 port_access_u64_csr(const struct cntr_entry *entry,
  1395. void *context, int vl, int mode, u64 data)
  1396. {
  1397. struct hfi1_pportdata *ppd = context;
  1398. u64 val;
  1399. u64 csr = entry->csr;
  1400. if (entry->flags & CNTR_VL) {
  1401. if (vl == CNTR_INVALID_VL)
  1402. return 0;
  1403. csr += 8 * vl;
  1404. } else {
  1405. if (vl != CNTR_INVALID_VL)
  1406. return 0;
  1407. }
  1408. val = read_write_csr(ppd->dd, csr, mode, data);
  1409. return val;
  1410. }
  1411. /* Software defined */
  1412. static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
  1413. u64 data)
  1414. {
  1415. u64 ret;
  1416. if (mode == CNTR_MODE_R) {
  1417. ret = *cntr;
  1418. } else if (mode == CNTR_MODE_W) {
  1419. *cntr = data;
  1420. ret = data;
  1421. } else {
  1422. dd_dev_err(dd, "Invalid cntr sw access mode");
  1423. return 0;
  1424. }
  1425. hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
  1426. return ret;
  1427. }
  1428. static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
  1429. int vl, int mode, u64 data)
  1430. {
  1431. struct hfi1_pportdata *ppd = context;
  1432. if (vl != CNTR_INVALID_VL)
  1433. return 0;
  1434. return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
  1435. }
  1436. static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
  1437. int vl, int mode, u64 data)
  1438. {
  1439. struct hfi1_pportdata *ppd = context;
  1440. if (vl != CNTR_INVALID_VL)
  1441. return 0;
  1442. return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
  1443. }
  1444. static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
  1445. void *context, int vl, int mode,
  1446. u64 data)
  1447. {
  1448. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1449. if (vl != CNTR_INVALID_VL)
  1450. return 0;
  1451. return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
  1452. }
  1453. static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
  1454. void *context, int vl, int mode, u64 data)
  1455. {
  1456. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
  1457. u64 zero = 0;
  1458. u64 *counter;
  1459. if (vl == CNTR_INVALID_VL)
  1460. counter = &ppd->port_xmit_discards;
  1461. else if (vl >= 0 && vl < C_VL_COUNT)
  1462. counter = &ppd->port_xmit_discards_vl[vl];
  1463. else
  1464. counter = &zero;
  1465. return read_write_sw(ppd->dd, counter, mode, data);
  1466. }
  1467. static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
  1468. void *context, int vl, int mode,
  1469. u64 data)
  1470. {
  1471. struct hfi1_pportdata *ppd = context;
  1472. if (vl != CNTR_INVALID_VL)
  1473. return 0;
  1474. return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
  1475. mode, data);
  1476. }
  1477. static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
  1478. void *context, int vl, int mode, u64 data)
  1479. {
  1480. struct hfi1_pportdata *ppd = context;
  1481. if (vl != CNTR_INVALID_VL)
  1482. return 0;
  1483. return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
  1484. mode, data);
  1485. }
  1486. u64 get_all_cpu_total(u64 __percpu *cntr)
  1487. {
  1488. int cpu;
  1489. u64 counter = 0;
  1490. for_each_possible_cpu(cpu)
  1491. counter += *per_cpu_ptr(cntr, cpu);
  1492. return counter;
  1493. }
  1494. static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
  1495. u64 __percpu *cntr,
  1496. int vl, int mode, u64 data)
  1497. {
  1498. u64 ret = 0;
  1499. if (vl != CNTR_INVALID_VL)
  1500. return 0;
  1501. if (mode == CNTR_MODE_R) {
  1502. ret = get_all_cpu_total(cntr) - *z_val;
  1503. } else if (mode == CNTR_MODE_W) {
  1504. /* A write can only zero the counter */
  1505. if (data == 0)
  1506. *z_val = get_all_cpu_total(cntr);
  1507. else
  1508. dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
  1509. } else {
  1510. dd_dev_err(dd, "Invalid cntr sw cpu access mode");
  1511. return 0;
  1512. }
  1513. return ret;
  1514. }
  1515. static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
  1516. void *context, int vl, int mode, u64 data)
  1517. {
  1518. struct hfi1_devdata *dd = context;
  1519. return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
  1520. mode, data);
  1521. }
  1522. static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
  1523. void *context, int vl, int mode, u64 data)
  1524. {
  1525. struct hfi1_devdata *dd = context;
  1526. return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
  1527. mode, data);
  1528. }
  1529. static u64 access_sw_pio_wait(const struct cntr_entry *entry,
  1530. void *context, int vl, int mode, u64 data)
  1531. {
  1532. struct hfi1_devdata *dd = context;
  1533. return dd->verbs_dev.n_piowait;
  1534. }
  1535. static u64 access_sw_pio_drain(const struct cntr_entry *entry,
  1536. void *context, int vl, int mode, u64 data)
  1537. {
  1538. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1539. return dd->verbs_dev.n_piodrain;
  1540. }
  1541. static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
  1542. void *context, int vl, int mode, u64 data)
  1543. {
  1544. struct hfi1_devdata *dd = context;
  1545. return dd->verbs_dev.n_txwait;
  1546. }
  1547. static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
  1548. void *context, int vl, int mode, u64 data)
  1549. {
  1550. struct hfi1_devdata *dd = context;
  1551. return dd->verbs_dev.n_kmem_wait;
  1552. }
  1553. static u64 access_sw_send_schedule(const struct cntr_entry *entry,
  1554. void *context, int vl, int mode, u64 data)
  1555. {
  1556. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1557. return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
  1558. mode, data);
  1559. }
  1560. /* Software counters for the error status bits within MISC_ERR_STATUS */
  1561. static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
  1562. void *context, int vl, int mode,
  1563. u64 data)
  1564. {
  1565. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1566. return dd->misc_err_status_cnt[12];
  1567. }
  1568. static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
  1569. void *context, int vl, int mode,
  1570. u64 data)
  1571. {
  1572. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1573. return dd->misc_err_status_cnt[11];
  1574. }
  1575. static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
  1576. void *context, int vl, int mode,
  1577. u64 data)
  1578. {
  1579. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1580. return dd->misc_err_status_cnt[10];
  1581. }
  1582. static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
  1583. void *context, int vl,
  1584. int mode, u64 data)
  1585. {
  1586. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1587. return dd->misc_err_status_cnt[9];
  1588. }
  1589. static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
  1590. void *context, int vl, int mode,
  1591. u64 data)
  1592. {
  1593. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1594. return dd->misc_err_status_cnt[8];
  1595. }
  1596. static u64 access_misc_efuse_read_bad_addr_err_cnt(
  1597. const struct cntr_entry *entry,
  1598. void *context, int vl, int mode, u64 data)
  1599. {
  1600. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1601. return dd->misc_err_status_cnt[7];
  1602. }
  1603. static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
  1604. void *context, int vl,
  1605. int mode, u64 data)
  1606. {
  1607. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1608. return dd->misc_err_status_cnt[6];
  1609. }
  1610. static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
  1611. void *context, int vl, int mode,
  1612. u64 data)
  1613. {
  1614. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1615. return dd->misc_err_status_cnt[5];
  1616. }
  1617. static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
  1618. void *context, int vl, int mode,
  1619. u64 data)
  1620. {
  1621. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1622. return dd->misc_err_status_cnt[4];
  1623. }
  1624. static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
  1625. void *context, int vl,
  1626. int mode, u64 data)
  1627. {
  1628. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1629. return dd->misc_err_status_cnt[3];
  1630. }
  1631. static u64 access_misc_csr_write_bad_addr_err_cnt(
  1632. const struct cntr_entry *entry,
  1633. void *context, int vl, int mode, u64 data)
  1634. {
  1635. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1636. return dd->misc_err_status_cnt[2];
  1637. }
  1638. static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1639. void *context, int vl,
  1640. int mode, u64 data)
  1641. {
  1642. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1643. return dd->misc_err_status_cnt[1];
  1644. }
  1645. static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
  1646. void *context, int vl, int mode,
  1647. u64 data)
  1648. {
  1649. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1650. return dd->misc_err_status_cnt[0];
  1651. }
  1652. /*
  1653. * Software counter for the aggregate of
  1654. * individual CceErrStatus counters
  1655. */
  1656. static u64 access_sw_cce_err_status_aggregated_cnt(
  1657. const struct cntr_entry *entry,
  1658. void *context, int vl, int mode, u64 data)
  1659. {
  1660. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1661. return dd->sw_cce_err_status_aggregate;
  1662. }
  1663. /*
  1664. * Software counters corresponding to each of the
  1665. * error status bits within CceErrStatus
  1666. */
  1667. static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
  1668. void *context, int vl, int mode,
  1669. u64 data)
  1670. {
  1671. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1672. return dd->cce_err_status_cnt[40];
  1673. }
  1674. static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
  1675. void *context, int vl, int mode,
  1676. u64 data)
  1677. {
  1678. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1679. return dd->cce_err_status_cnt[39];
  1680. }
  1681. static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
  1682. void *context, int vl, int mode,
  1683. u64 data)
  1684. {
  1685. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1686. return dd->cce_err_status_cnt[38];
  1687. }
  1688. static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
  1689. void *context, int vl, int mode,
  1690. u64 data)
  1691. {
  1692. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1693. return dd->cce_err_status_cnt[37];
  1694. }
  1695. static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
  1696. void *context, int vl, int mode,
  1697. u64 data)
  1698. {
  1699. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1700. return dd->cce_err_status_cnt[36];
  1701. }
  1702. static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
  1703. const struct cntr_entry *entry,
  1704. void *context, int vl, int mode, u64 data)
  1705. {
  1706. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1707. return dd->cce_err_status_cnt[35];
  1708. }
  1709. static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
  1710. const struct cntr_entry *entry,
  1711. void *context, int vl, int mode, u64 data)
  1712. {
  1713. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1714. return dd->cce_err_status_cnt[34];
  1715. }
  1716. static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1717. void *context, int vl,
  1718. int mode, u64 data)
  1719. {
  1720. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1721. return dd->cce_err_status_cnt[33];
  1722. }
  1723. static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1724. void *context, int vl, int mode,
  1725. u64 data)
  1726. {
  1727. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1728. return dd->cce_err_status_cnt[32];
  1729. }
  1730. static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
  1731. void *context, int vl, int mode, u64 data)
  1732. {
  1733. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1734. return dd->cce_err_status_cnt[31];
  1735. }
  1736. static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
  1737. void *context, int vl, int mode,
  1738. u64 data)
  1739. {
  1740. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1741. return dd->cce_err_status_cnt[30];
  1742. }
  1743. static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
  1744. void *context, int vl, int mode,
  1745. u64 data)
  1746. {
  1747. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1748. return dd->cce_err_status_cnt[29];
  1749. }
  1750. static u64 access_pcic_transmit_back_parity_err_cnt(
  1751. const struct cntr_entry *entry,
  1752. void *context, int vl, int mode, u64 data)
  1753. {
  1754. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1755. return dd->cce_err_status_cnt[28];
  1756. }
  1757. static u64 access_pcic_transmit_front_parity_err_cnt(
  1758. const struct cntr_entry *entry,
  1759. void *context, int vl, int mode, u64 data)
  1760. {
  1761. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1762. return dd->cce_err_status_cnt[27];
  1763. }
  1764. static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1765. void *context, int vl, int mode,
  1766. u64 data)
  1767. {
  1768. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1769. return dd->cce_err_status_cnt[26];
  1770. }
  1771. static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1772. void *context, int vl, int mode,
  1773. u64 data)
  1774. {
  1775. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1776. return dd->cce_err_status_cnt[25];
  1777. }
  1778. static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
  1779. void *context, int vl, int mode,
  1780. u64 data)
  1781. {
  1782. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1783. return dd->cce_err_status_cnt[24];
  1784. }
  1785. static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
  1786. void *context, int vl, int mode,
  1787. u64 data)
  1788. {
  1789. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1790. return dd->cce_err_status_cnt[23];
  1791. }
  1792. static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
  1793. void *context, int vl,
  1794. int mode, u64 data)
  1795. {
  1796. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1797. return dd->cce_err_status_cnt[22];
  1798. }
  1799. static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
  1800. void *context, int vl, int mode,
  1801. u64 data)
  1802. {
  1803. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1804. return dd->cce_err_status_cnt[21];
  1805. }
  1806. static u64 access_pcic_n_post_dat_q_parity_err_cnt(
  1807. const struct cntr_entry *entry,
  1808. void *context, int vl, int mode, u64 data)
  1809. {
  1810. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1811. return dd->cce_err_status_cnt[20];
  1812. }
  1813. static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
  1814. void *context, int vl,
  1815. int mode, u64 data)
  1816. {
  1817. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1818. return dd->cce_err_status_cnt[19];
  1819. }
  1820. static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1821. void *context, int vl, int mode,
  1822. u64 data)
  1823. {
  1824. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1825. return dd->cce_err_status_cnt[18];
  1826. }
  1827. static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1828. void *context, int vl, int mode,
  1829. u64 data)
  1830. {
  1831. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1832. return dd->cce_err_status_cnt[17];
  1833. }
  1834. static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
  1835. void *context, int vl, int mode,
  1836. u64 data)
  1837. {
  1838. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1839. return dd->cce_err_status_cnt[16];
  1840. }
  1841. static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
  1842. void *context, int vl, int mode,
  1843. u64 data)
  1844. {
  1845. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1846. return dd->cce_err_status_cnt[15];
  1847. }
  1848. static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
  1849. void *context, int vl,
  1850. int mode, u64 data)
  1851. {
  1852. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1853. return dd->cce_err_status_cnt[14];
  1854. }
  1855. static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
  1856. void *context, int vl, int mode,
  1857. u64 data)
  1858. {
  1859. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1860. return dd->cce_err_status_cnt[13];
  1861. }
  1862. static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
  1863. const struct cntr_entry *entry,
  1864. void *context, int vl, int mode, u64 data)
  1865. {
  1866. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1867. return dd->cce_err_status_cnt[12];
  1868. }
  1869. static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
  1870. const struct cntr_entry *entry,
  1871. void *context, int vl, int mode, u64 data)
  1872. {
  1873. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1874. return dd->cce_err_status_cnt[11];
  1875. }
  1876. static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
  1877. const struct cntr_entry *entry,
  1878. void *context, int vl, int mode, u64 data)
  1879. {
  1880. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1881. return dd->cce_err_status_cnt[10];
  1882. }
  1883. static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
  1884. const struct cntr_entry *entry,
  1885. void *context, int vl, int mode, u64 data)
  1886. {
  1887. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1888. return dd->cce_err_status_cnt[9];
  1889. }
  1890. static u64 access_cce_cli2_async_fifo_parity_err_cnt(
  1891. const struct cntr_entry *entry,
  1892. void *context, int vl, int mode, u64 data)
  1893. {
  1894. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1895. return dd->cce_err_status_cnt[8];
  1896. }
  1897. static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
  1898. void *context, int vl,
  1899. int mode, u64 data)
  1900. {
  1901. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1902. return dd->cce_err_status_cnt[7];
  1903. }
  1904. static u64 access_cce_cli0_async_fifo_parity_err_cnt(
  1905. const struct cntr_entry *entry,
  1906. void *context, int vl, int mode, u64 data)
  1907. {
  1908. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1909. return dd->cce_err_status_cnt[6];
  1910. }
  1911. static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
  1912. void *context, int vl, int mode,
  1913. u64 data)
  1914. {
  1915. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1916. return dd->cce_err_status_cnt[5];
  1917. }
  1918. static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry,
  1919. void *context, int vl, int mode,
  1920. u64 data)
  1921. {
  1922. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1923. return dd->cce_err_status_cnt[4];
  1924. }
  1925. static u64 access_cce_trgt_async_fifo_parity_err_cnt(
  1926. const struct cntr_entry *entry,
  1927. void *context, int vl, int mode, u64 data)
  1928. {
  1929. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1930. return dd->cce_err_status_cnt[3];
  1931. }
  1932. static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1933. void *context, int vl,
  1934. int mode, u64 data)
  1935. {
  1936. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1937. return dd->cce_err_status_cnt[2];
  1938. }
  1939. static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1940. void *context, int vl,
  1941. int mode, u64 data)
  1942. {
  1943. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1944. return dd->cce_err_status_cnt[1];
  1945. }
  1946. static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
  1947. void *context, int vl, int mode,
  1948. u64 data)
  1949. {
  1950. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1951. return dd->cce_err_status_cnt[0];
  1952. }
  1953. /*
  1954. * Software counters corresponding to each of the
  1955. * error status bits within RcvErrStatus
  1956. */
  1957. static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
  1958. void *context, int vl, int mode,
  1959. u64 data)
  1960. {
  1961. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1962. return dd->rcv_err_status_cnt[63];
  1963. }
  1964. static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
  1965. void *context, int vl,
  1966. int mode, u64 data)
  1967. {
  1968. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1969. return dd->rcv_err_status_cnt[62];
  1970. }
  1971. static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  1972. void *context, int vl, int mode,
  1973. u64 data)
  1974. {
  1975. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1976. return dd->rcv_err_status_cnt[61];
  1977. }
  1978. static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
  1979. void *context, int vl, int mode,
  1980. u64 data)
  1981. {
  1982. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1983. return dd->rcv_err_status_cnt[60];
  1984. }
  1985. static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1986. void *context, int vl,
  1987. int mode, u64 data)
  1988. {
  1989. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1990. return dd->rcv_err_status_cnt[59];
  1991. }
  1992. static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  1993. void *context, int vl,
  1994. int mode, u64 data)
  1995. {
  1996. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  1997. return dd->rcv_err_status_cnt[58];
  1998. }
  1999. static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2000. void *context, int vl, int mode,
  2001. u64 data)
  2002. {
  2003. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2004. return dd->rcv_err_status_cnt[57];
  2005. }
  2006. static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
  2007. void *context, int vl, int mode,
  2008. u64 data)
  2009. {
  2010. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2011. return dd->rcv_err_status_cnt[56];
  2012. }
  2013. static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
  2014. void *context, int vl, int mode,
  2015. u64 data)
  2016. {
  2017. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2018. return dd->rcv_err_status_cnt[55];
  2019. }
  2020. static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
  2021. const struct cntr_entry *entry,
  2022. void *context, int vl, int mode, u64 data)
  2023. {
  2024. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2025. return dd->rcv_err_status_cnt[54];
  2026. }
  2027. static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
  2028. const struct cntr_entry *entry,
  2029. void *context, int vl, int mode, u64 data)
  2030. {
  2031. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2032. return dd->rcv_err_status_cnt[53];
  2033. }
  2034. static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
  2035. void *context, int vl,
  2036. int mode, u64 data)
  2037. {
  2038. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2039. return dd->rcv_err_status_cnt[52];
  2040. }
  2041. static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
  2042. void *context, int vl,
  2043. int mode, u64 data)
  2044. {
  2045. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2046. return dd->rcv_err_status_cnt[51];
  2047. }
  2048. static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
  2049. void *context, int vl,
  2050. int mode, u64 data)
  2051. {
  2052. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2053. return dd->rcv_err_status_cnt[50];
  2054. }
  2055. static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
  2056. void *context, int vl,
  2057. int mode, u64 data)
  2058. {
  2059. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2060. return dd->rcv_err_status_cnt[49];
  2061. }
  2062. static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
  2063. void *context, int vl,
  2064. int mode, u64 data)
  2065. {
  2066. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2067. return dd->rcv_err_status_cnt[48];
  2068. }
  2069. static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
  2070. void *context, int vl,
  2071. int mode, u64 data)
  2072. {
  2073. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2074. return dd->rcv_err_status_cnt[47];
  2075. }
  2076. static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
  2077. void *context, int vl, int mode,
  2078. u64 data)
  2079. {
  2080. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2081. return dd->rcv_err_status_cnt[46];
  2082. }
  2083. static u64 access_rx_hq_intr_csr_parity_err_cnt(
  2084. const struct cntr_entry *entry,
  2085. void *context, int vl, int mode, u64 data)
  2086. {
  2087. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2088. return dd->rcv_err_status_cnt[45];
  2089. }
  2090. static u64 access_rx_lookup_csr_parity_err_cnt(
  2091. const struct cntr_entry *entry,
  2092. void *context, int vl, int mode, u64 data)
  2093. {
  2094. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2095. return dd->rcv_err_status_cnt[44];
  2096. }
  2097. static u64 access_rx_lookup_rcv_array_cor_err_cnt(
  2098. const struct cntr_entry *entry,
  2099. void *context, int vl, int mode, u64 data)
  2100. {
  2101. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2102. return dd->rcv_err_status_cnt[43];
  2103. }
  2104. static u64 access_rx_lookup_rcv_array_unc_err_cnt(
  2105. const struct cntr_entry *entry,
  2106. void *context, int vl, int mode, u64 data)
  2107. {
  2108. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2109. return dd->rcv_err_status_cnt[42];
  2110. }
  2111. static u64 access_rx_lookup_des_part2_parity_err_cnt(
  2112. const struct cntr_entry *entry,
  2113. void *context, int vl, int mode, u64 data)
  2114. {
  2115. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2116. return dd->rcv_err_status_cnt[41];
  2117. }
  2118. static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
  2119. const struct cntr_entry *entry,
  2120. void *context, int vl, int mode, u64 data)
  2121. {
  2122. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2123. return dd->rcv_err_status_cnt[40];
  2124. }
  2125. static u64 access_rx_lookup_des_part1_unc_err_cnt(
  2126. const struct cntr_entry *entry,
  2127. void *context, int vl, int mode, u64 data)
  2128. {
  2129. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2130. return dd->rcv_err_status_cnt[39];
  2131. }
  2132. static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
  2133. const struct cntr_entry *entry,
  2134. void *context, int vl, int mode, u64 data)
  2135. {
  2136. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2137. return dd->rcv_err_status_cnt[38];
  2138. }
  2139. static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
  2140. const struct cntr_entry *entry,
  2141. void *context, int vl, int mode, u64 data)
  2142. {
  2143. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2144. return dd->rcv_err_status_cnt[37];
  2145. }
  2146. static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
  2147. const struct cntr_entry *entry,
  2148. void *context, int vl, int mode, u64 data)
  2149. {
  2150. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2151. return dd->rcv_err_status_cnt[36];
  2152. }
  2153. static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
  2154. const struct cntr_entry *entry,
  2155. void *context, int vl, int mode, u64 data)
  2156. {
  2157. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2158. return dd->rcv_err_status_cnt[35];
  2159. }
  2160. static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
  2161. const struct cntr_entry *entry,
  2162. void *context, int vl, int mode, u64 data)
  2163. {
  2164. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2165. return dd->rcv_err_status_cnt[34];
  2166. }
  2167. static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
  2168. const struct cntr_entry *entry,
  2169. void *context, int vl, int mode, u64 data)
  2170. {
  2171. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2172. return dd->rcv_err_status_cnt[33];
  2173. }
  2174. static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
  2175. void *context, int vl, int mode,
  2176. u64 data)
  2177. {
  2178. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2179. return dd->rcv_err_status_cnt[32];
  2180. }
  2181. static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
  2182. void *context, int vl, int mode,
  2183. u64 data)
  2184. {
  2185. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2186. return dd->rcv_err_status_cnt[31];
  2187. }
  2188. static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
  2189. void *context, int vl, int mode,
  2190. u64 data)
  2191. {
  2192. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2193. return dd->rcv_err_status_cnt[30];
  2194. }
  2195. static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
  2196. void *context, int vl, int mode,
  2197. u64 data)
  2198. {
  2199. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2200. return dd->rcv_err_status_cnt[29];
  2201. }
  2202. static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
  2203. void *context, int vl,
  2204. int mode, u64 data)
  2205. {
  2206. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2207. return dd->rcv_err_status_cnt[28];
  2208. }
  2209. static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
  2210. const struct cntr_entry *entry,
  2211. void *context, int vl, int mode, u64 data)
  2212. {
  2213. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2214. return dd->rcv_err_status_cnt[27];
  2215. }
  2216. static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
  2217. const struct cntr_entry *entry,
  2218. void *context, int vl, int mode, u64 data)
  2219. {
  2220. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2221. return dd->rcv_err_status_cnt[26];
  2222. }
  2223. static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
  2224. const struct cntr_entry *entry,
  2225. void *context, int vl, int mode, u64 data)
  2226. {
  2227. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2228. return dd->rcv_err_status_cnt[25];
  2229. }
  2230. static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
  2231. const struct cntr_entry *entry,
  2232. void *context, int vl, int mode, u64 data)
  2233. {
  2234. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2235. return dd->rcv_err_status_cnt[24];
  2236. }
  2237. static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
  2238. const struct cntr_entry *entry,
  2239. void *context, int vl, int mode, u64 data)
  2240. {
  2241. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2242. return dd->rcv_err_status_cnt[23];
  2243. }
  2244. static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
  2245. const struct cntr_entry *entry,
  2246. void *context, int vl, int mode, u64 data)
  2247. {
  2248. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2249. return dd->rcv_err_status_cnt[22];
  2250. }
  2251. static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
  2252. const struct cntr_entry *entry,
  2253. void *context, int vl, int mode, u64 data)
  2254. {
  2255. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2256. return dd->rcv_err_status_cnt[21];
  2257. }
  2258. static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
  2259. const struct cntr_entry *entry,
  2260. void *context, int vl, int mode, u64 data)
  2261. {
  2262. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2263. return dd->rcv_err_status_cnt[20];
  2264. }
  2265. static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
  2266. const struct cntr_entry *entry,
  2267. void *context, int vl, int mode, u64 data)
  2268. {
  2269. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2270. return dd->rcv_err_status_cnt[19];
  2271. }
  2272. static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
  2273. void *context, int vl,
  2274. int mode, u64 data)
  2275. {
  2276. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2277. return dd->rcv_err_status_cnt[18];
  2278. }
  2279. static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
  2280. void *context, int vl,
  2281. int mode, u64 data)
  2282. {
  2283. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2284. return dd->rcv_err_status_cnt[17];
  2285. }
  2286. static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
  2287. const struct cntr_entry *entry,
  2288. void *context, int vl, int mode, u64 data)
  2289. {
  2290. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2291. return dd->rcv_err_status_cnt[16];
  2292. }
  2293. static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
  2294. const struct cntr_entry *entry,
  2295. void *context, int vl, int mode, u64 data)
  2296. {
  2297. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2298. return dd->rcv_err_status_cnt[15];
  2299. }
  2300. static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
  2301. void *context, int vl,
  2302. int mode, u64 data)
  2303. {
  2304. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2305. return dd->rcv_err_status_cnt[14];
  2306. }
  2307. static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
  2308. void *context, int vl,
  2309. int mode, u64 data)
  2310. {
  2311. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2312. return dd->rcv_err_status_cnt[13];
  2313. }
  2314. static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
  2315. void *context, int vl, int mode,
  2316. u64 data)
  2317. {
  2318. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2319. return dd->rcv_err_status_cnt[12];
  2320. }
  2321. static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
  2322. void *context, int vl, int mode,
  2323. u64 data)
  2324. {
  2325. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2326. return dd->rcv_err_status_cnt[11];
  2327. }
  2328. static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
  2329. void *context, int vl, int mode,
  2330. u64 data)
  2331. {
  2332. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2333. return dd->rcv_err_status_cnt[10];
  2334. }
  2335. static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
  2336. void *context, int vl, int mode,
  2337. u64 data)
  2338. {
  2339. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2340. return dd->rcv_err_status_cnt[9];
  2341. }
  2342. static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
  2343. void *context, int vl, int mode,
  2344. u64 data)
  2345. {
  2346. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2347. return dd->rcv_err_status_cnt[8];
  2348. }
  2349. static u64 access_rx_rcv_qp_map_table_cor_err_cnt(
  2350. const struct cntr_entry *entry,
  2351. void *context, int vl, int mode, u64 data)
  2352. {
  2353. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2354. return dd->rcv_err_status_cnt[7];
  2355. }
  2356. static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
  2357. const struct cntr_entry *entry,
  2358. void *context, int vl, int mode, u64 data)
  2359. {
  2360. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2361. return dd->rcv_err_status_cnt[6];
  2362. }
  2363. static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry,
  2364. void *context, int vl, int mode,
  2365. u64 data)
  2366. {
  2367. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2368. return dd->rcv_err_status_cnt[5];
  2369. }
  2370. static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry,
  2371. void *context, int vl, int mode,
  2372. u64 data)
  2373. {
  2374. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2375. return dd->rcv_err_status_cnt[4];
  2376. }
  2377. static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2378. void *context, int vl, int mode,
  2379. u64 data)
  2380. {
  2381. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2382. return dd->rcv_err_status_cnt[3];
  2383. }
  2384. static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2385. void *context, int vl, int mode,
  2386. u64 data)
  2387. {
  2388. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2389. return dd->rcv_err_status_cnt[2];
  2390. }
  2391. static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry,
  2392. void *context, int vl, int mode,
  2393. u64 data)
  2394. {
  2395. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2396. return dd->rcv_err_status_cnt[1];
  2397. }
  2398. static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
  2399. void *context, int vl, int mode,
  2400. u64 data)
  2401. {
  2402. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2403. return dd->rcv_err_status_cnt[0];
  2404. }
  2405. /*
  2406. * Software counters corresponding to each of the
  2407. * error status bits within SendPioErrStatus
  2408. */
  2409. static u64 access_pio_pec_sop_head_parity_err_cnt(
  2410. const struct cntr_entry *entry,
  2411. void *context, int vl, int mode, u64 data)
  2412. {
  2413. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2414. return dd->send_pio_err_status_cnt[35];
  2415. }
  2416. static u64 access_pio_pcc_sop_head_parity_err_cnt(
  2417. const struct cntr_entry *entry,
  2418. void *context, int vl, int mode, u64 data)
  2419. {
  2420. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2421. return dd->send_pio_err_status_cnt[34];
  2422. }
  2423. static u64 access_pio_last_returned_cnt_parity_err_cnt(
  2424. const struct cntr_entry *entry,
  2425. void *context, int vl, int mode, u64 data)
  2426. {
  2427. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2428. return dd->send_pio_err_status_cnt[33];
  2429. }
  2430. static u64 access_pio_current_free_cnt_parity_err_cnt(
  2431. const struct cntr_entry *entry,
  2432. void *context, int vl, int mode, u64 data)
  2433. {
  2434. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2435. return dd->send_pio_err_status_cnt[32];
  2436. }
  2437. static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
  2438. void *context, int vl, int mode,
  2439. u64 data)
  2440. {
  2441. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2442. return dd->send_pio_err_status_cnt[31];
  2443. }
  2444. static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
  2445. void *context, int vl, int mode,
  2446. u64 data)
  2447. {
  2448. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2449. return dd->send_pio_err_status_cnt[30];
  2450. }
  2451. static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
  2452. void *context, int vl, int mode,
  2453. u64 data)
  2454. {
  2455. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2456. return dd->send_pio_err_status_cnt[29];
  2457. }
  2458. static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
  2459. const struct cntr_entry *entry,
  2460. void *context, int vl, int mode, u64 data)
  2461. {
  2462. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2463. return dd->send_pio_err_status_cnt[28];
  2464. }
  2465. static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2466. void *context, int vl, int mode,
  2467. u64 data)
  2468. {
  2469. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2470. return dd->send_pio_err_status_cnt[27];
  2471. }
  2472. static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
  2473. void *context, int vl, int mode,
  2474. u64 data)
  2475. {
  2476. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2477. return dd->send_pio_err_status_cnt[26];
  2478. }
  2479. static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
  2480. void *context, int vl,
  2481. int mode, u64 data)
  2482. {
  2483. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2484. return dd->send_pio_err_status_cnt[25];
  2485. }
  2486. static u64 access_pio_block_qw_count_parity_err_cnt(
  2487. const struct cntr_entry *entry,
  2488. void *context, int vl, int mode, u64 data)
  2489. {
  2490. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2491. return dd->send_pio_err_status_cnt[24];
  2492. }
  2493. static u64 access_pio_write_qw_valid_parity_err_cnt(
  2494. const struct cntr_entry *entry,
  2495. void *context, int vl, int mode, u64 data)
  2496. {
  2497. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2498. return dd->send_pio_err_status_cnt[23];
  2499. }
  2500. static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
  2501. void *context, int vl, int mode,
  2502. u64 data)
  2503. {
  2504. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2505. return dd->send_pio_err_status_cnt[22];
  2506. }
  2507. static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
  2508. void *context, int vl,
  2509. int mode, u64 data)
  2510. {
  2511. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2512. return dd->send_pio_err_status_cnt[21];
  2513. }
  2514. static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
  2515. void *context, int vl,
  2516. int mode, u64 data)
  2517. {
  2518. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2519. return dd->send_pio_err_status_cnt[20];
  2520. }
  2521. static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
  2522. void *context, int vl,
  2523. int mode, u64 data)
  2524. {
  2525. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2526. return dd->send_pio_err_status_cnt[19];
  2527. }
  2528. static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
  2529. const struct cntr_entry *entry,
  2530. void *context, int vl, int mode, u64 data)
  2531. {
  2532. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2533. return dd->send_pio_err_status_cnt[18];
  2534. }
  2535. static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
  2536. void *context, int vl, int mode,
  2537. u64 data)
  2538. {
  2539. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2540. return dd->send_pio_err_status_cnt[17];
  2541. }
  2542. static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
  2543. void *context, int vl, int mode,
  2544. u64 data)
  2545. {
  2546. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2547. return dd->send_pio_err_status_cnt[16];
  2548. }
  2549. static u64 access_pio_credit_ret_fifo_parity_err_cnt(
  2550. const struct cntr_entry *entry,
  2551. void *context, int vl, int mode, u64 data)
  2552. {
  2553. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2554. return dd->send_pio_err_status_cnt[15];
  2555. }
  2556. static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
  2557. const struct cntr_entry *entry,
  2558. void *context, int vl, int mode, u64 data)
  2559. {
  2560. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2561. return dd->send_pio_err_status_cnt[14];
  2562. }
  2563. static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
  2564. const struct cntr_entry *entry,
  2565. void *context, int vl, int mode, u64 data)
  2566. {
  2567. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2568. return dd->send_pio_err_status_cnt[13];
  2569. }
  2570. static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
  2571. const struct cntr_entry *entry,
  2572. void *context, int vl, int mode, u64 data)
  2573. {
  2574. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2575. return dd->send_pio_err_status_cnt[12];
  2576. }
  2577. static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
  2578. const struct cntr_entry *entry,
  2579. void *context, int vl, int mode, u64 data)
  2580. {
  2581. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2582. return dd->send_pio_err_status_cnt[11];
  2583. }
  2584. static u64 access_pio_sm_pkt_reset_parity_err_cnt(
  2585. const struct cntr_entry *entry,
  2586. void *context, int vl, int mode, u64 data)
  2587. {
  2588. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2589. return dd->send_pio_err_status_cnt[10];
  2590. }
  2591. static u64 access_pio_pkt_evict_fifo_parity_err_cnt(
  2592. const struct cntr_entry *entry,
  2593. void *context, int vl, int mode, u64 data)
  2594. {
  2595. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2596. return dd->send_pio_err_status_cnt[9];
  2597. }
  2598. static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
  2599. const struct cntr_entry *entry,
  2600. void *context, int vl, int mode, u64 data)
  2601. {
  2602. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2603. return dd->send_pio_err_status_cnt[8];
  2604. }
  2605. static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
  2606. const struct cntr_entry *entry,
  2607. void *context, int vl, int mode, u64 data)
  2608. {
  2609. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2610. return dd->send_pio_err_status_cnt[7];
  2611. }
  2612. static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2613. void *context, int vl, int mode,
  2614. u64 data)
  2615. {
  2616. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2617. return dd->send_pio_err_status_cnt[6];
  2618. }
  2619. static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
  2620. void *context, int vl, int mode,
  2621. u64 data)
  2622. {
  2623. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2624. return dd->send_pio_err_status_cnt[5];
  2625. }
  2626. static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
  2627. void *context, int vl, int mode,
  2628. u64 data)
  2629. {
  2630. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2631. return dd->send_pio_err_status_cnt[4];
  2632. }
  2633. static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
  2634. void *context, int vl, int mode,
  2635. u64 data)
  2636. {
  2637. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2638. return dd->send_pio_err_status_cnt[3];
  2639. }
  2640. static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
  2641. void *context, int vl, int mode,
  2642. u64 data)
  2643. {
  2644. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2645. return dd->send_pio_err_status_cnt[2];
  2646. }
  2647. static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
  2648. void *context, int vl,
  2649. int mode, u64 data)
  2650. {
  2651. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2652. return dd->send_pio_err_status_cnt[1];
  2653. }
  2654. static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
  2655. void *context, int vl, int mode,
  2656. u64 data)
  2657. {
  2658. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2659. return dd->send_pio_err_status_cnt[0];
  2660. }
  2661. /*
  2662. * Software counters corresponding to each of the
  2663. * error status bits within SendDmaErrStatus
  2664. */
  2665. static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
  2666. const struct cntr_entry *entry,
  2667. void *context, int vl, int mode, u64 data)
  2668. {
  2669. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2670. return dd->send_dma_err_status_cnt[3];
  2671. }
  2672. static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
  2673. const struct cntr_entry *entry,
  2674. void *context, int vl, int mode, u64 data)
  2675. {
  2676. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2677. return dd->send_dma_err_status_cnt[2];
  2678. }
  2679. static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry,
  2680. void *context, int vl, int mode,
  2681. u64 data)
  2682. {
  2683. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2684. return dd->send_dma_err_status_cnt[1];
  2685. }
  2686. static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry,
  2687. void *context, int vl, int mode,
  2688. u64 data)
  2689. {
  2690. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2691. return dd->send_dma_err_status_cnt[0];
  2692. }
  2693. /*
  2694. * Software counters corresponding to each of the
  2695. * error status bits within SendEgressErrStatus
  2696. */
  2697. static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
  2698. const struct cntr_entry *entry,
  2699. void *context, int vl, int mode, u64 data)
  2700. {
  2701. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2702. return dd->send_egress_err_status_cnt[63];
  2703. }
  2704. static u64 access_tx_read_sdma_memory_csr_err_cnt(
  2705. const struct cntr_entry *entry,
  2706. void *context, int vl, int mode, u64 data)
  2707. {
  2708. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2709. return dd->send_egress_err_status_cnt[62];
  2710. }
  2711. static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
  2712. void *context, int vl, int mode,
  2713. u64 data)
  2714. {
  2715. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2716. return dd->send_egress_err_status_cnt[61];
  2717. }
  2718. static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
  2719. void *context, int vl,
  2720. int mode, u64 data)
  2721. {
  2722. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2723. return dd->send_egress_err_status_cnt[60];
  2724. }
  2725. static u64 access_tx_read_sdma_memory_cor_err_cnt(
  2726. const struct cntr_entry *entry,
  2727. void *context, int vl, int mode, u64 data)
  2728. {
  2729. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2730. return dd->send_egress_err_status_cnt[59];
  2731. }
  2732. static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
  2733. void *context, int vl, int mode,
  2734. u64 data)
  2735. {
  2736. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2737. return dd->send_egress_err_status_cnt[58];
  2738. }
  2739. static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
  2740. void *context, int vl, int mode,
  2741. u64 data)
  2742. {
  2743. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2744. return dd->send_egress_err_status_cnt[57];
  2745. }
  2746. static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
  2747. void *context, int vl, int mode,
  2748. u64 data)
  2749. {
  2750. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2751. return dd->send_egress_err_status_cnt[56];
  2752. }
  2753. static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
  2754. void *context, int vl, int mode,
  2755. u64 data)
  2756. {
  2757. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2758. return dd->send_egress_err_status_cnt[55];
  2759. }
  2760. static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
  2761. void *context, int vl, int mode,
  2762. u64 data)
  2763. {
  2764. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2765. return dd->send_egress_err_status_cnt[54];
  2766. }
  2767. static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
  2768. void *context, int vl, int mode,
  2769. u64 data)
  2770. {
  2771. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2772. return dd->send_egress_err_status_cnt[53];
  2773. }
  2774. static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
  2775. void *context, int vl, int mode,
  2776. u64 data)
  2777. {
  2778. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2779. return dd->send_egress_err_status_cnt[52];
  2780. }
  2781. static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
  2782. void *context, int vl, int mode,
  2783. u64 data)
  2784. {
  2785. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2786. return dd->send_egress_err_status_cnt[51];
  2787. }
  2788. static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
  2789. void *context, int vl, int mode,
  2790. u64 data)
  2791. {
  2792. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2793. return dd->send_egress_err_status_cnt[50];
  2794. }
  2795. static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
  2796. void *context, int vl, int mode,
  2797. u64 data)
  2798. {
  2799. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2800. return dd->send_egress_err_status_cnt[49];
  2801. }
  2802. static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
  2803. void *context, int vl, int mode,
  2804. u64 data)
  2805. {
  2806. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2807. return dd->send_egress_err_status_cnt[48];
  2808. }
  2809. static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
  2810. void *context, int vl, int mode,
  2811. u64 data)
  2812. {
  2813. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2814. return dd->send_egress_err_status_cnt[47];
  2815. }
  2816. static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
  2817. void *context, int vl, int mode,
  2818. u64 data)
  2819. {
  2820. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2821. return dd->send_egress_err_status_cnt[46];
  2822. }
  2823. static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
  2824. void *context, int vl, int mode,
  2825. u64 data)
  2826. {
  2827. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2828. return dd->send_egress_err_status_cnt[45];
  2829. }
  2830. static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
  2831. void *context, int vl,
  2832. int mode, u64 data)
  2833. {
  2834. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2835. return dd->send_egress_err_status_cnt[44];
  2836. }
  2837. static u64 access_tx_read_sdma_memory_unc_err_cnt(
  2838. const struct cntr_entry *entry,
  2839. void *context, int vl, int mode, u64 data)
  2840. {
  2841. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2842. return dd->send_egress_err_status_cnt[43];
  2843. }
  2844. static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
  2845. void *context, int vl, int mode,
  2846. u64 data)
  2847. {
  2848. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2849. return dd->send_egress_err_status_cnt[42];
  2850. }
  2851. static u64 access_tx_credit_return_partiy_err_cnt(
  2852. const struct cntr_entry *entry,
  2853. void *context, int vl, int mode, u64 data)
  2854. {
  2855. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2856. return dd->send_egress_err_status_cnt[41];
  2857. }
  2858. static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
  2859. const struct cntr_entry *entry,
  2860. void *context, int vl, int mode, u64 data)
  2861. {
  2862. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2863. return dd->send_egress_err_status_cnt[40];
  2864. }
  2865. static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
  2866. const struct cntr_entry *entry,
  2867. void *context, int vl, int mode, u64 data)
  2868. {
  2869. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2870. return dd->send_egress_err_status_cnt[39];
  2871. }
  2872. static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
  2873. const struct cntr_entry *entry,
  2874. void *context, int vl, int mode, u64 data)
  2875. {
  2876. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2877. return dd->send_egress_err_status_cnt[38];
  2878. }
  2879. static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
  2880. const struct cntr_entry *entry,
  2881. void *context, int vl, int mode, u64 data)
  2882. {
  2883. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2884. return dd->send_egress_err_status_cnt[37];
  2885. }
  2886. static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
  2887. const struct cntr_entry *entry,
  2888. void *context, int vl, int mode, u64 data)
  2889. {
  2890. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2891. return dd->send_egress_err_status_cnt[36];
  2892. }
  2893. static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
  2894. const struct cntr_entry *entry,
  2895. void *context, int vl, int mode, u64 data)
  2896. {
  2897. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2898. return dd->send_egress_err_status_cnt[35];
  2899. }
  2900. static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
  2901. const struct cntr_entry *entry,
  2902. void *context, int vl, int mode, u64 data)
  2903. {
  2904. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2905. return dd->send_egress_err_status_cnt[34];
  2906. }
  2907. static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
  2908. const struct cntr_entry *entry,
  2909. void *context, int vl, int mode, u64 data)
  2910. {
  2911. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2912. return dd->send_egress_err_status_cnt[33];
  2913. }
  2914. static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
  2915. const struct cntr_entry *entry,
  2916. void *context, int vl, int mode, u64 data)
  2917. {
  2918. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2919. return dd->send_egress_err_status_cnt[32];
  2920. }
  2921. static u64 access_tx_sdma15_disallowed_packet_err_cnt(
  2922. const struct cntr_entry *entry,
  2923. void *context, int vl, int mode, u64 data)
  2924. {
  2925. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2926. return dd->send_egress_err_status_cnt[31];
  2927. }
  2928. static u64 access_tx_sdma14_disallowed_packet_err_cnt(
  2929. const struct cntr_entry *entry,
  2930. void *context, int vl, int mode, u64 data)
  2931. {
  2932. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2933. return dd->send_egress_err_status_cnt[30];
  2934. }
  2935. static u64 access_tx_sdma13_disallowed_packet_err_cnt(
  2936. const struct cntr_entry *entry,
  2937. void *context, int vl, int mode, u64 data)
  2938. {
  2939. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2940. return dd->send_egress_err_status_cnt[29];
  2941. }
  2942. static u64 access_tx_sdma12_disallowed_packet_err_cnt(
  2943. const struct cntr_entry *entry,
  2944. void *context, int vl, int mode, u64 data)
  2945. {
  2946. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2947. return dd->send_egress_err_status_cnt[28];
  2948. }
  2949. static u64 access_tx_sdma11_disallowed_packet_err_cnt(
  2950. const struct cntr_entry *entry,
  2951. void *context, int vl, int mode, u64 data)
  2952. {
  2953. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2954. return dd->send_egress_err_status_cnt[27];
  2955. }
  2956. static u64 access_tx_sdma10_disallowed_packet_err_cnt(
  2957. const struct cntr_entry *entry,
  2958. void *context, int vl, int mode, u64 data)
  2959. {
  2960. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2961. return dd->send_egress_err_status_cnt[26];
  2962. }
  2963. static u64 access_tx_sdma9_disallowed_packet_err_cnt(
  2964. const struct cntr_entry *entry,
  2965. void *context, int vl, int mode, u64 data)
  2966. {
  2967. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2968. return dd->send_egress_err_status_cnt[25];
  2969. }
  2970. static u64 access_tx_sdma8_disallowed_packet_err_cnt(
  2971. const struct cntr_entry *entry,
  2972. void *context, int vl, int mode, u64 data)
  2973. {
  2974. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2975. return dd->send_egress_err_status_cnt[24];
  2976. }
  2977. static u64 access_tx_sdma7_disallowed_packet_err_cnt(
  2978. const struct cntr_entry *entry,
  2979. void *context, int vl, int mode, u64 data)
  2980. {
  2981. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2982. return dd->send_egress_err_status_cnt[23];
  2983. }
  2984. static u64 access_tx_sdma6_disallowed_packet_err_cnt(
  2985. const struct cntr_entry *entry,
  2986. void *context, int vl, int mode, u64 data)
  2987. {
  2988. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2989. return dd->send_egress_err_status_cnt[22];
  2990. }
  2991. static u64 access_tx_sdma5_disallowed_packet_err_cnt(
  2992. const struct cntr_entry *entry,
  2993. void *context, int vl, int mode, u64 data)
  2994. {
  2995. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  2996. return dd->send_egress_err_status_cnt[21];
  2997. }
  2998. static u64 access_tx_sdma4_disallowed_packet_err_cnt(
  2999. const struct cntr_entry *entry,
  3000. void *context, int vl, int mode, u64 data)
  3001. {
  3002. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3003. return dd->send_egress_err_status_cnt[20];
  3004. }
  3005. static u64 access_tx_sdma3_disallowed_packet_err_cnt(
  3006. const struct cntr_entry *entry,
  3007. void *context, int vl, int mode, u64 data)
  3008. {
  3009. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3010. return dd->send_egress_err_status_cnt[19];
  3011. }
  3012. static u64 access_tx_sdma2_disallowed_packet_err_cnt(
  3013. const struct cntr_entry *entry,
  3014. void *context, int vl, int mode, u64 data)
  3015. {
  3016. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3017. return dd->send_egress_err_status_cnt[18];
  3018. }
  3019. static u64 access_tx_sdma1_disallowed_packet_err_cnt(
  3020. const struct cntr_entry *entry,
  3021. void *context, int vl, int mode, u64 data)
  3022. {
  3023. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3024. return dd->send_egress_err_status_cnt[17];
  3025. }
  3026. static u64 access_tx_sdma0_disallowed_packet_err_cnt(
  3027. const struct cntr_entry *entry,
  3028. void *context, int vl, int mode, u64 data)
  3029. {
  3030. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3031. return dd->send_egress_err_status_cnt[16];
  3032. }
  3033. static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
  3034. void *context, int vl, int mode,
  3035. u64 data)
  3036. {
  3037. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3038. return dd->send_egress_err_status_cnt[15];
  3039. }
  3040. static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
  3041. void *context, int vl,
  3042. int mode, u64 data)
  3043. {
  3044. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3045. return dd->send_egress_err_status_cnt[14];
  3046. }
  3047. static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
  3048. void *context, int vl, int mode,
  3049. u64 data)
  3050. {
  3051. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3052. return dd->send_egress_err_status_cnt[13];
  3053. }
  3054. static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
  3055. void *context, int vl, int mode,
  3056. u64 data)
  3057. {
  3058. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3059. return dd->send_egress_err_status_cnt[12];
  3060. }
  3061. static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
  3062. const struct cntr_entry *entry,
  3063. void *context, int vl, int mode, u64 data)
  3064. {
  3065. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3066. return dd->send_egress_err_status_cnt[11];
  3067. }
  3068. static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
  3069. void *context, int vl, int mode,
  3070. u64 data)
  3071. {
  3072. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3073. return dd->send_egress_err_status_cnt[10];
  3074. }
  3075. static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
  3076. void *context, int vl, int mode,
  3077. u64 data)
  3078. {
  3079. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3080. return dd->send_egress_err_status_cnt[9];
  3081. }
  3082. static u64 access_tx_sdma_launch_intf_parity_err_cnt(
  3083. const struct cntr_entry *entry,
  3084. void *context, int vl, int mode, u64 data)
  3085. {
  3086. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3087. return dd->send_egress_err_status_cnt[8];
  3088. }
  3089. static u64 access_tx_pio_launch_intf_parity_err_cnt(
  3090. const struct cntr_entry *entry,
  3091. void *context, int vl, int mode, u64 data)
  3092. {
  3093. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3094. return dd->send_egress_err_status_cnt[7];
  3095. }
  3096. static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
  3097. void *context, int vl, int mode,
  3098. u64 data)
  3099. {
  3100. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3101. return dd->send_egress_err_status_cnt[6];
  3102. }
  3103. static u64 access_tx_incorrect_link_state_err_cnt(
  3104. const struct cntr_entry *entry,
  3105. void *context, int vl, int mode, u64 data)
  3106. {
  3107. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3108. return dd->send_egress_err_status_cnt[5];
  3109. }
  3110. static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
  3111. void *context, int vl, int mode,
  3112. u64 data)
  3113. {
  3114. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3115. return dd->send_egress_err_status_cnt[4];
  3116. }
  3117. static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
  3118. const struct cntr_entry *entry,
  3119. void *context, int vl, int mode, u64 data)
  3120. {
  3121. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3122. return dd->send_egress_err_status_cnt[3];
  3123. }
  3124. static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
  3125. void *context, int vl, int mode,
  3126. u64 data)
  3127. {
  3128. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3129. return dd->send_egress_err_status_cnt[2];
  3130. }
  3131. static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
  3132. const struct cntr_entry *entry,
  3133. void *context, int vl, int mode, u64 data)
  3134. {
  3135. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3136. return dd->send_egress_err_status_cnt[1];
  3137. }
  3138. static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
  3139. const struct cntr_entry *entry,
  3140. void *context, int vl, int mode, u64 data)
  3141. {
  3142. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3143. return dd->send_egress_err_status_cnt[0];
  3144. }
  3145. /*
  3146. * Software counters corresponding to each of the
  3147. * error status bits within SendErrStatus
  3148. */
  3149. static u64 access_send_csr_write_bad_addr_err_cnt(
  3150. const struct cntr_entry *entry,
  3151. void *context, int vl, int mode, u64 data)
  3152. {
  3153. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3154. return dd->send_err_status_cnt[2];
  3155. }
  3156. static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
  3157. void *context, int vl,
  3158. int mode, u64 data)
  3159. {
  3160. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3161. return dd->send_err_status_cnt[1];
  3162. }
  3163. static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
  3164. void *context, int vl, int mode,
  3165. u64 data)
  3166. {
  3167. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3168. return dd->send_err_status_cnt[0];
  3169. }
  3170. /*
  3171. * Software counters corresponding to each of the
  3172. * error status bits within SendCtxtErrStatus
  3173. */
  3174. static u64 access_pio_write_out_of_bounds_err_cnt(
  3175. const struct cntr_entry *entry,
  3176. void *context, int vl, int mode, u64 data)
  3177. {
  3178. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3179. return dd->sw_ctxt_err_status_cnt[4];
  3180. }
  3181. static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
  3182. void *context, int vl, int mode,
  3183. u64 data)
  3184. {
  3185. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3186. return dd->sw_ctxt_err_status_cnt[3];
  3187. }
  3188. static u64 access_pio_write_crosses_boundary_err_cnt(
  3189. const struct cntr_entry *entry,
  3190. void *context, int vl, int mode, u64 data)
  3191. {
  3192. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3193. return dd->sw_ctxt_err_status_cnt[2];
  3194. }
  3195. static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
  3196. void *context, int vl,
  3197. int mode, u64 data)
  3198. {
  3199. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3200. return dd->sw_ctxt_err_status_cnt[1];
  3201. }
  3202. static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry,
  3203. void *context, int vl, int mode,
  3204. u64 data)
  3205. {
  3206. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3207. return dd->sw_ctxt_err_status_cnt[0];
  3208. }
  3209. /*
  3210. * Software counters corresponding to each of the
  3211. * error status bits within SendDmaEngErrStatus
  3212. */
  3213. static u64 access_sdma_header_request_fifo_cor_err_cnt(
  3214. const struct cntr_entry *entry,
  3215. void *context, int vl, int mode, u64 data)
  3216. {
  3217. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3218. return dd->sw_send_dma_eng_err_status_cnt[23];
  3219. }
  3220. static u64 access_sdma_header_storage_cor_err_cnt(
  3221. const struct cntr_entry *entry,
  3222. void *context, int vl, int mode, u64 data)
  3223. {
  3224. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3225. return dd->sw_send_dma_eng_err_status_cnt[22];
  3226. }
  3227. static u64 access_sdma_packet_tracking_cor_err_cnt(
  3228. const struct cntr_entry *entry,
  3229. void *context, int vl, int mode, u64 data)
  3230. {
  3231. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3232. return dd->sw_send_dma_eng_err_status_cnt[21];
  3233. }
  3234. static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
  3235. void *context, int vl, int mode,
  3236. u64 data)
  3237. {
  3238. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3239. return dd->sw_send_dma_eng_err_status_cnt[20];
  3240. }
  3241. static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
  3242. void *context, int vl, int mode,
  3243. u64 data)
  3244. {
  3245. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3246. return dd->sw_send_dma_eng_err_status_cnt[19];
  3247. }
  3248. static u64 access_sdma_header_request_fifo_unc_err_cnt(
  3249. const struct cntr_entry *entry,
  3250. void *context, int vl, int mode, u64 data)
  3251. {
  3252. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3253. return dd->sw_send_dma_eng_err_status_cnt[18];
  3254. }
  3255. static u64 access_sdma_header_storage_unc_err_cnt(
  3256. const struct cntr_entry *entry,
  3257. void *context, int vl, int mode, u64 data)
  3258. {
  3259. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3260. return dd->sw_send_dma_eng_err_status_cnt[17];
  3261. }
  3262. static u64 access_sdma_packet_tracking_unc_err_cnt(
  3263. const struct cntr_entry *entry,
  3264. void *context, int vl, int mode, u64 data)
  3265. {
  3266. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3267. return dd->sw_send_dma_eng_err_status_cnt[16];
  3268. }
  3269. static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
  3270. void *context, int vl, int mode,
  3271. u64 data)
  3272. {
  3273. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3274. return dd->sw_send_dma_eng_err_status_cnt[15];
  3275. }
  3276. static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
  3277. void *context, int vl, int mode,
  3278. u64 data)
  3279. {
  3280. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3281. return dd->sw_send_dma_eng_err_status_cnt[14];
  3282. }
  3283. static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
  3284. void *context, int vl, int mode,
  3285. u64 data)
  3286. {
  3287. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3288. return dd->sw_send_dma_eng_err_status_cnt[13];
  3289. }
  3290. static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
  3291. void *context, int vl, int mode,
  3292. u64 data)
  3293. {
  3294. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3295. return dd->sw_send_dma_eng_err_status_cnt[12];
  3296. }
  3297. static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
  3298. void *context, int vl, int mode,
  3299. u64 data)
  3300. {
  3301. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3302. return dd->sw_send_dma_eng_err_status_cnt[11];
  3303. }
  3304. static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
  3305. void *context, int vl, int mode,
  3306. u64 data)
  3307. {
  3308. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3309. return dd->sw_send_dma_eng_err_status_cnt[10];
  3310. }
  3311. static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
  3312. void *context, int vl, int mode,
  3313. u64 data)
  3314. {
  3315. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3316. return dd->sw_send_dma_eng_err_status_cnt[9];
  3317. }
  3318. static u64 access_sdma_packet_desc_overflow_err_cnt(
  3319. const struct cntr_entry *entry,
  3320. void *context, int vl, int mode, u64 data)
  3321. {
  3322. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3323. return dd->sw_send_dma_eng_err_status_cnt[8];
  3324. }
  3325. static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
  3326. void *context, int vl,
  3327. int mode, u64 data)
  3328. {
  3329. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3330. return dd->sw_send_dma_eng_err_status_cnt[7];
  3331. }
  3332. static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
  3333. void *context, int vl, int mode, u64 data)
  3334. {
  3335. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3336. return dd->sw_send_dma_eng_err_status_cnt[6];
  3337. }
  3338. static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
  3339. void *context, int vl, int mode,
  3340. u64 data)
  3341. {
  3342. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3343. return dd->sw_send_dma_eng_err_status_cnt[5];
  3344. }
  3345. static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
  3346. void *context, int vl, int mode,
  3347. u64 data)
  3348. {
  3349. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3350. return dd->sw_send_dma_eng_err_status_cnt[4];
  3351. }
  3352. static u64 access_sdma_tail_out_of_bounds_err_cnt(
  3353. const struct cntr_entry *entry,
  3354. void *context, int vl, int mode, u64 data)
  3355. {
  3356. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3357. return dd->sw_send_dma_eng_err_status_cnt[3];
  3358. }
  3359. static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
  3360. void *context, int vl, int mode,
  3361. u64 data)
  3362. {
  3363. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3364. return dd->sw_send_dma_eng_err_status_cnt[2];
  3365. }
  3366. static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
  3367. void *context, int vl, int mode,
  3368. u64 data)
  3369. {
  3370. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3371. return dd->sw_send_dma_eng_err_status_cnt[1];
  3372. }
  3373. static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
  3374. void *context, int vl, int mode,
  3375. u64 data)
  3376. {
  3377. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3378. return dd->sw_send_dma_eng_err_status_cnt[0];
  3379. }
  3380. static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
  3381. void *context, int vl, int mode,
  3382. u64 data)
  3383. {
  3384. struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
  3385. u64 val = 0;
  3386. u64 csr = entry->csr;
  3387. val = read_write_csr(dd, csr, mode, data);
  3388. if (mode == CNTR_MODE_R) {
  3389. val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
  3390. CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
  3391. } else if (mode == CNTR_MODE_W) {
  3392. dd->sw_rcv_bypass_packet_errors = 0;
  3393. } else {
  3394. dd_dev_err(dd, "Invalid cntr register access mode");
  3395. return 0;
  3396. }
  3397. return val;
  3398. }
  3399. #define def_access_sw_cpu(cntr) \
  3400. static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
  3401. void *context, int vl, int mode, u64 data) \
  3402. { \
  3403. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3404. return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
  3405. ppd->ibport_data.rvp.cntr, vl, \
  3406. mode, data); \
  3407. }
  3408. def_access_sw_cpu(rc_acks);
  3409. def_access_sw_cpu(rc_qacks);
  3410. def_access_sw_cpu(rc_delayed_comp);
  3411. #define def_access_ibp_counter(cntr) \
  3412. static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
  3413. void *context, int vl, int mode, u64 data) \
  3414. { \
  3415. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
  3416. \
  3417. if (vl != CNTR_INVALID_VL) \
  3418. return 0; \
  3419. \
  3420. return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
  3421. mode, data); \
  3422. }
  3423. def_access_ibp_counter(loop_pkts);
  3424. def_access_ibp_counter(rc_resends);
  3425. def_access_ibp_counter(rnr_naks);
  3426. def_access_ibp_counter(other_naks);
  3427. def_access_ibp_counter(rc_timeouts);
  3428. def_access_ibp_counter(pkt_drops);
  3429. def_access_ibp_counter(dmawait);
  3430. def_access_ibp_counter(rc_seqnak);
  3431. def_access_ibp_counter(rc_dupreq);
  3432. def_access_ibp_counter(rdma_seq);
  3433. def_access_ibp_counter(unaligned);
  3434. def_access_ibp_counter(seq_naks);
  3435. static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
  3436. [C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
  3437. [C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
  3438. CNTR_NORMAL),
  3439. [C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
  3440. CNTR_NORMAL),
  3441. [C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
  3442. RCV_TID_FLOW_GEN_MISMATCH_CNT,
  3443. CNTR_NORMAL),
  3444. [C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
  3445. CNTR_NORMAL),
  3446. [C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
  3447. RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
  3448. [C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
  3449. CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
  3450. [C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
  3451. CNTR_NORMAL),
  3452. [C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
  3453. CNTR_NORMAL),
  3454. [C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
  3455. CNTR_NORMAL),
  3456. [C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
  3457. CNTR_NORMAL),
  3458. [C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
  3459. CNTR_NORMAL),
  3460. [C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
  3461. CNTR_NORMAL),
  3462. [C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
  3463. CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
  3464. [C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
  3465. CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
  3466. [C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
  3467. CNTR_SYNTH),
  3468. [C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
  3469. access_dc_rcv_err_cnt),
  3470. [C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
  3471. CNTR_SYNTH),
  3472. [C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
  3473. CNTR_SYNTH),
  3474. [C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
  3475. CNTR_SYNTH),
  3476. [C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
  3477. DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
  3478. [C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
  3479. DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
  3480. CNTR_SYNTH),
  3481. [C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
  3482. DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
  3483. [C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
  3484. CNTR_SYNTH),
  3485. [C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
  3486. CNTR_SYNTH),
  3487. [C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
  3488. CNTR_SYNTH),
  3489. [C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
  3490. CNTR_SYNTH),
  3491. [C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
  3492. CNTR_SYNTH),
  3493. [C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
  3494. CNTR_SYNTH),
  3495. [C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
  3496. CNTR_SYNTH),
  3497. [C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
  3498. CNTR_SYNTH | CNTR_VL),
  3499. [C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
  3500. CNTR_SYNTH | CNTR_VL),
  3501. [C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
  3502. [C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
  3503. CNTR_SYNTH | CNTR_VL),
  3504. [C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
  3505. [C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
  3506. CNTR_SYNTH | CNTR_VL),
  3507. [C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
  3508. CNTR_SYNTH),
  3509. [C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
  3510. CNTR_SYNTH | CNTR_VL),
  3511. [C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
  3512. CNTR_SYNTH),
  3513. [C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
  3514. CNTR_SYNTH | CNTR_VL),
  3515. [C_DC_TOTAL_CRC] =
  3516. DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
  3517. CNTR_SYNTH),
  3518. [C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
  3519. CNTR_SYNTH),
  3520. [C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
  3521. CNTR_SYNTH),
  3522. [C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
  3523. CNTR_SYNTH),
  3524. [C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
  3525. CNTR_SYNTH),
  3526. [C_DC_CRC_MULT_LN] =
  3527. DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
  3528. CNTR_SYNTH),
  3529. [C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
  3530. CNTR_SYNTH),
  3531. [C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
  3532. CNTR_SYNTH),
  3533. [C_DC_SEQ_CRC_CNT] =
  3534. DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
  3535. CNTR_SYNTH),
  3536. [C_DC_ESC0_ONLY_CNT] =
  3537. DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
  3538. CNTR_SYNTH),
  3539. [C_DC_ESC0_PLUS1_CNT] =
  3540. DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
  3541. CNTR_SYNTH),
  3542. [C_DC_ESC0_PLUS2_CNT] =
  3543. DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
  3544. CNTR_SYNTH),
  3545. [C_DC_REINIT_FROM_PEER_CNT] =
  3546. DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
  3547. CNTR_SYNTH),
  3548. [C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
  3549. CNTR_SYNTH),
  3550. [C_DC_MISC_FLG_CNT] =
  3551. DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
  3552. CNTR_SYNTH),
  3553. [C_DC_PRF_GOOD_LTP_CNT] =
  3554. DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
  3555. [C_DC_PRF_ACCEPTED_LTP_CNT] =
  3556. DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
  3557. CNTR_SYNTH),
  3558. [C_DC_PRF_RX_FLIT_CNT] =
  3559. DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
  3560. [C_DC_PRF_TX_FLIT_CNT] =
  3561. DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
  3562. [C_DC_PRF_CLK_CNTR] =
  3563. DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
  3564. [C_DC_PG_DBG_FLIT_CRDTS_CNT] =
  3565. DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
  3566. [C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
  3567. DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
  3568. CNTR_SYNTH),
  3569. [C_DC_PG_STS_TX_SBE_CNT] =
  3570. DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
  3571. [C_DC_PG_STS_TX_MBE_CNT] =
  3572. DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
  3573. CNTR_SYNTH),
  3574. [C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
  3575. access_sw_cpu_intr),
  3576. [C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
  3577. access_sw_cpu_rcv_limit),
  3578. [C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
  3579. access_sw_vtx_wait),
  3580. [C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
  3581. access_sw_pio_wait),
  3582. [C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
  3583. access_sw_pio_drain),
  3584. [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
  3585. access_sw_kmem_wait),
  3586. [C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
  3587. access_sw_send_schedule),
  3588. [C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
  3589. SEND_DMA_DESC_FETCHED_CNT, 0,
  3590. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3591. dev_access_u32_csr),
  3592. [C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
  3593. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3594. access_sde_int_cnt),
  3595. [C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
  3596. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3597. access_sde_err_cnt),
  3598. [C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
  3599. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3600. access_sde_idle_int_cnt),
  3601. [C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
  3602. CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
  3603. access_sde_progress_int_cnt),
  3604. /* MISC_ERR_STATUS */
  3605. [C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
  3606. CNTR_NORMAL,
  3607. access_misc_pll_lock_fail_err_cnt),
  3608. [C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
  3609. CNTR_NORMAL,
  3610. access_misc_mbist_fail_err_cnt),
  3611. [C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
  3612. CNTR_NORMAL,
  3613. access_misc_invalid_eep_cmd_err_cnt),
  3614. [C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
  3615. CNTR_NORMAL,
  3616. access_misc_efuse_done_parity_err_cnt),
  3617. [C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
  3618. CNTR_NORMAL,
  3619. access_misc_efuse_write_err_cnt),
  3620. [C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
  3621. 0, CNTR_NORMAL,
  3622. access_misc_efuse_read_bad_addr_err_cnt),
  3623. [C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
  3624. CNTR_NORMAL,
  3625. access_misc_efuse_csr_parity_err_cnt),
  3626. [C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
  3627. CNTR_NORMAL,
  3628. access_misc_fw_auth_failed_err_cnt),
  3629. [C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
  3630. CNTR_NORMAL,
  3631. access_misc_key_mismatch_err_cnt),
  3632. [C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
  3633. CNTR_NORMAL,
  3634. access_misc_sbus_write_failed_err_cnt),
  3635. [C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
  3636. CNTR_NORMAL,
  3637. access_misc_csr_write_bad_addr_err_cnt),
  3638. [C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
  3639. CNTR_NORMAL,
  3640. access_misc_csr_read_bad_addr_err_cnt),
  3641. [C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
  3642. CNTR_NORMAL,
  3643. access_misc_csr_parity_err_cnt),
  3644. /* CceErrStatus */
  3645. [C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
  3646. CNTR_NORMAL,
  3647. access_sw_cce_err_status_aggregated_cnt),
  3648. [C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
  3649. CNTR_NORMAL,
  3650. access_cce_msix_csr_parity_err_cnt),
  3651. [C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
  3652. CNTR_NORMAL,
  3653. access_cce_int_map_unc_err_cnt),
  3654. [C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
  3655. CNTR_NORMAL,
  3656. access_cce_int_map_cor_err_cnt),
  3657. [C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
  3658. CNTR_NORMAL,
  3659. access_cce_msix_table_unc_err_cnt),
  3660. [C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
  3661. CNTR_NORMAL,
  3662. access_cce_msix_table_cor_err_cnt),
  3663. [C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
  3664. 0, CNTR_NORMAL,
  3665. access_cce_rxdma_conv_fifo_parity_err_cnt),
  3666. [C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
  3667. 0, CNTR_NORMAL,
  3668. access_cce_rcpl_async_fifo_parity_err_cnt),
  3669. [C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
  3670. CNTR_NORMAL,
  3671. access_cce_seg_write_bad_addr_err_cnt),
  3672. [C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
  3673. CNTR_NORMAL,
  3674. access_cce_seg_read_bad_addr_err_cnt),
  3675. [C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
  3676. CNTR_NORMAL,
  3677. access_la_triggered_cnt),
  3678. [C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
  3679. CNTR_NORMAL,
  3680. access_cce_trgt_cpl_timeout_err_cnt),
  3681. [C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
  3682. CNTR_NORMAL,
  3683. access_pcic_receive_parity_err_cnt),
  3684. [C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
  3685. CNTR_NORMAL,
  3686. access_pcic_transmit_back_parity_err_cnt),
  3687. [C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
  3688. 0, CNTR_NORMAL,
  3689. access_pcic_transmit_front_parity_err_cnt),
  3690. [C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
  3691. CNTR_NORMAL,
  3692. access_pcic_cpl_dat_q_unc_err_cnt),
  3693. [C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
  3694. CNTR_NORMAL,
  3695. access_pcic_cpl_hd_q_unc_err_cnt),
  3696. [C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
  3697. CNTR_NORMAL,
  3698. access_pcic_post_dat_q_unc_err_cnt),
  3699. [C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
  3700. CNTR_NORMAL,
  3701. access_pcic_post_hd_q_unc_err_cnt),
  3702. [C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
  3703. CNTR_NORMAL,
  3704. access_pcic_retry_sot_mem_unc_err_cnt),
  3705. [C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
  3706. CNTR_NORMAL,
  3707. access_pcic_retry_mem_unc_err),
  3708. [C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
  3709. CNTR_NORMAL,
  3710. access_pcic_n_post_dat_q_parity_err_cnt),
  3711. [C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
  3712. CNTR_NORMAL,
  3713. access_pcic_n_post_h_q_parity_err_cnt),
  3714. [C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
  3715. CNTR_NORMAL,
  3716. access_pcic_cpl_dat_q_cor_err_cnt),
  3717. [C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
  3718. CNTR_NORMAL,
  3719. access_pcic_cpl_hd_q_cor_err_cnt),
  3720. [C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
  3721. CNTR_NORMAL,
  3722. access_pcic_post_dat_q_cor_err_cnt),
  3723. [C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
  3724. CNTR_NORMAL,
  3725. access_pcic_post_hd_q_cor_err_cnt),
  3726. [C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
  3727. CNTR_NORMAL,
  3728. access_pcic_retry_sot_mem_cor_err_cnt),
  3729. [C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
  3730. CNTR_NORMAL,
  3731. access_pcic_retry_mem_cor_err_cnt),
  3732. [C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
  3733. "CceCli1AsyncFifoDbgParityError", 0, 0,
  3734. CNTR_NORMAL,
  3735. access_cce_cli1_async_fifo_dbg_parity_err_cnt),
  3736. [C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
  3737. "CceCli1AsyncFifoRxdmaParityError", 0, 0,
  3738. CNTR_NORMAL,
  3739. access_cce_cli1_async_fifo_rxdma_parity_err_cnt
  3740. ),
  3741. [C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
  3742. "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
  3743. CNTR_NORMAL,
  3744. access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
  3745. [C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
  3746. "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
  3747. CNTR_NORMAL,
  3748. access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
  3749. [C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
  3750. 0, CNTR_NORMAL,
  3751. access_cce_cli2_async_fifo_parity_err_cnt),
  3752. [C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
  3753. CNTR_NORMAL,
  3754. access_cce_csr_cfg_bus_parity_err_cnt),
  3755. [C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
  3756. 0, CNTR_NORMAL,
  3757. access_cce_cli0_async_fifo_parity_err_cnt),
  3758. [C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
  3759. CNTR_NORMAL,
  3760. access_cce_rspd_data_parity_err_cnt),
  3761. [C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
  3762. CNTR_NORMAL,
  3763. access_cce_trgt_access_err_cnt),
  3764. [C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
  3765. 0, CNTR_NORMAL,
  3766. access_cce_trgt_async_fifo_parity_err_cnt),
  3767. [C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
  3768. CNTR_NORMAL,
  3769. access_cce_csr_write_bad_addr_err_cnt),
  3770. [C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
  3771. CNTR_NORMAL,
  3772. access_cce_csr_read_bad_addr_err_cnt),
  3773. [C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
  3774. CNTR_NORMAL,
  3775. access_ccs_csr_parity_err_cnt),
  3776. /* RcvErrStatus */
  3777. [C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
  3778. CNTR_NORMAL,
  3779. access_rx_csr_parity_err_cnt),
  3780. [C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
  3781. CNTR_NORMAL,
  3782. access_rx_csr_write_bad_addr_err_cnt),
  3783. [C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
  3784. CNTR_NORMAL,
  3785. access_rx_csr_read_bad_addr_err_cnt),
  3786. [C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
  3787. CNTR_NORMAL,
  3788. access_rx_dma_csr_unc_err_cnt),
  3789. [C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
  3790. CNTR_NORMAL,
  3791. access_rx_dma_dq_fsm_encoding_err_cnt),
  3792. [C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
  3793. CNTR_NORMAL,
  3794. access_rx_dma_eq_fsm_encoding_err_cnt),
  3795. [C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
  3796. CNTR_NORMAL,
  3797. access_rx_dma_csr_parity_err_cnt),
  3798. [C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
  3799. CNTR_NORMAL,
  3800. access_rx_rbuf_data_cor_err_cnt),
  3801. [C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
  3802. CNTR_NORMAL,
  3803. access_rx_rbuf_data_unc_err_cnt),
  3804. [C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
  3805. CNTR_NORMAL,
  3806. access_rx_dma_data_fifo_rd_cor_err_cnt),
  3807. [C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
  3808. CNTR_NORMAL,
  3809. access_rx_dma_data_fifo_rd_unc_err_cnt),
  3810. [C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
  3811. CNTR_NORMAL,
  3812. access_rx_dma_hdr_fifo_rd_cor_err_cnt),
  3813. [C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
  3814. CNTR_NORMAL,
  3815. access_rx_dma_hdr_fifo_rd_unc_err_cnt),
  3816. [C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
  3817. CNTR_NORMAL,
  3818. access_rx_rbuf_desc_part2_cor_err_cnt),
  3819. [C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
  3820. CNTR_NORMAL,
  3821. access_rx_rbuf_desc_part2_unc_err_cnt),
  3822. [C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
  3823. CNTR_NORMAL,
  3824. access_rx_rbuf_desc_part1_cor_err_cnt),
  3825. [C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
  3826. CNTR_NORMAL,
  3827. access_rx_rbuf_desc_part1_unc_err_cnt),
  3828. [C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
  3829. CNTR_NORMAL,
  3830. access_rx_hq_intr_fsm_err_cnt),
  3831. [C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
  3832. CNTR_NORMAL,
  3833. access_rx_hq_intr_csr_parity_err_cnt),
  3834. [C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
  3835. CNTR_NORMAL,
  3836. access_rx_lookup_csr_parity_err_cnt),
  3837. [C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
  3838. CNTR_NORMAL,
  3839. access_rx_lookup_rcv_array_cor_err_cnt),
  3840. [C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
  3841. CNTR_NORMAL,
  3842. access_rx_lookup_rcv_array_unc_err_cnt),
  3843. [C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
  3844. 0, CNTR_NORMAL,
  3845. access_rx_lookup_des_part2_parity_err_cnt),
  3846. [C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
  3847. 0, CNTR_NORMAL,
  3848. access_rx_lookup_des_part1_unc_cor_err_cnt),
  3849. [C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
  3850. CNTR_NORMAL,
  3851. access_rx_lookup_des_part1_unc_err_cnt),
  3852. [C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
  3853. CNTR_NORMAL,
  3854. access_rx_rbuf_next_free_buf_cor_err_cnt),
  3855. [C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
  3856. CNTR_NORMAL,
  3857. access_rx_rbuf_next_free_buf_unc_err_cnt),
  3858. [C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
  3859. "RxRbufFlInitWrAddrParityErr", 0, 0,
  3860. CNTR_NORMAL,
  3861. access_rbuf_fl_init_wr_addr_parity_err_cnt),
  3862. [C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
  3863. 0, CNTR_NORMAL,
  3864. access_rx_rbuf_fl_initdone_parity_err_cnt),
  3865. [C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
  3866. 0, CNTR_NORMAL,
  3867. access_rx_rbuf_fl_write_addr_parity_err_cnt),
  3868. [C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
  3869. CNTR_NORMAL,
  3870. access_rx_rbuf_fl_rd_addr_parity_err_cnt),
  3871. [C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
  3872. CNTR_NORMAL,
  3873. access_rx_rbuf_empty_err_cnt),
  3874. [C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
  3875. CNTR_NORMAL,
  3876. access_rx_rbuf_full_err_cnt),
  3877. [C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
  3878. CNTR_NORMAL,
  3879. access_rbuf_bad_lookup_err_cnt),
  3880. [C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
  3881. CNTR_NORMAL,
  3882. access_rbuf_ctx_id_parity_err_cnt),
  3883. [C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
  3884. CNTR_NORMAL,
  3885. access_rbuf_csr_qeopdw_parity_err_cnt),
  3886. [C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
  3887. "RxRbufCsrQNumOfPktParityErr", 0, 0,
  3888. CNTR_NORMAL,
  3889. access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
  3890. [C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
  3891. "RxRbufCsrQTlPtrParityErr", 0, 0,
  3892. CNTR_NORMAL,
  3893. access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
  3894. [C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
  3895. 0, CNTR_NORMAL,
  3896. access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
  3897. [C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
  3898. 0, CNTR_NORMAL,
  3899. access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
  3900. [C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
  3901. 0, 0, CNTR_NORMAL,
  3902. access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
  3903. [C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
  3904. 0, CNTR_NORMAL,
  3905. access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
  3906. [C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
  3907. "RxRbufCsrQHeadBufNumParityErr", 0, 0,
  3908. CNTR_NORMAL,
  3909. access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
  3910. [C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
  3911. 0, CNTR_NORMAL,
  3912. access_rx_rbuf_block_list_read_cor_err_cnt),
  3913. [C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
  3914. 0, CNTR_NORMAL,
  3915. access_rx_rbuf_block_list_read_unc_err_cnt),
  3916. [C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
  3917. CNTR_NORMAL,
  3918. access_rx_rbuf_lookup_des_cor_err_cnt),
  3919. [C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
  3920. CNTR_NORMAL,
  3921. access_rx_rbuf_lookup_des_unc_err_cnt),
  3922. [C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
  3923. "RxRbufLookupDesRegUncCorErr", 0, 0,
  3924. CNTR_NORMAL,
  3925. access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
  3926. [C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
  3927. CNTR_NORMAL,
  3928. access_rx_rbuf_lookup_des_reg_unc_err_cnt),
  3929. [C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
  3930. CNTR_NORMAL,
  3931. access_rx_rbuf_free_list_cor_err_cnt),
  3932. [C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
  3933. CNTR_NORMAL,
  3934. access_rx_rbuf_free_list_unc_err_cnt),
  3935. [C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
  3936. CNTR_NORMAL,
  3937. access_rx_rcv_fsm_encoding_err_cnt),
  3938. [C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
  3939. CNTR_NORMAL,
  3940. access_rx_dma_flag_cor_err_cnt),
  3941. [C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
  3942. CNTR_NORMAL,
  3943. access_rx_dma_flag_unc_err_cnt),
  3944. [C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
  3945. CNTR_NORMAL,
  3946. access_rx_dc_sop_eop_parity_err_cnt),
  3947. [C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
  3948. CNTR_NORMAL,
  3949. access_rx_rcv_csr_parity_err_cnt),
  3950. [C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
  3951. CNTR_NORMAL,
  3952. access_rx_rcv_qp_map_table_cor_err_cnt),
  3953. [C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
  3954. CNTR_NORMAL,
  3955. access_rx_rcv_qp_map_table_unc_err_cnt),
  3956. [C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
  3957. CNTR_NORMAL,
  3958. access_rx_rcv_data_cor_err_cnt),
  3959. [C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
  3960. CNTR_NORMAL,
  3961. access_rx_rcv_data_unc_err_cnt),
  3962. [C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
  3963. CNTR_NORMAL,
  3964. access_rx_rcv_hdr_cor_err_cnt),
  3965. [C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
  3966. CNTR_NORMAL,
  3967. access_rx_rcv_hdr_unc_err_cnt),
  3968. [C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
  3969. CNTR_NORMAL,
  3970. access_rx_dc_intf_parity_err_cnt),
  3971. [C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
  3972. CNTR_NORMAL,
  3973. access_rx_dma_csr_cor_err_cnt),
  3974. /* SendPioErrStatus */
  3975. [C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
  3976. CNTR_NORMAL,
  3977. access_pio_pec_sop_head_parity_err_cnt),
  3978. [C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
  3979. CNTR_NORMAL,
  3980. access_pio_pcc_sop_head_parity_err_cnt),
  3981. [C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
  3982. 0, 0, CNTR_NORMAL,
  3983. access_pio_last_returned_cnt_parity_err_cnt),
  3984. [C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
  3985. 0, CNTR_NORMAL,
  3986. access_pio_current_free_cnt_parity_err_cnt),
  3987. [C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
  3988. CNTR_NORMAL,
  3989. access_pio_reserved_31_err_cnt),
  3990. [C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
  3991. CNTR_NORMAL,
  3992. access_pio_reserved_30_err_cnt),
  3993. [C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
  3994. CNTR_NORMAL,
  3995. access_pio_ppmc_sop_len_err_cnt),
  3996. [C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
  3997. CNTR_NORMAL,
  3998. access_pio_ppmc_bqc_mem_parity_err_cnt),
  3999. [C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
  4000. CNTR_NORMAL,
  4001. access_pio_vl_fifo_parity_err_cnt),
  4002. [C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
  4003. CNTR_NORMAL,
  4004. access_pio_vlf_sop_parity_err_cnt),
  4005. [C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
  4006. CNTR_NORMAL,
  4007. access_pio_vlf_v1_len_parity_err_cnt),
  4008. [C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
  4009. CNTR_NORMAL,
  4010. access_pio_block_qw_count_parity_err_cnt),
  4011. [C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
  4012. CNTR_NORMAL,
  4013. access_pio_write_qw_valid_parity_err_cnt),
  4014. [C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
  4015. CNTR_NORMAL,
  4016. access_pio_state_machine_err_cnt),
  4017. [C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
  4018. CNTR_NORMAL,
  4019. access_pio_write_data_parity_err_cnt),
  4020. [C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
  4021. CNTR_NORMAL,
  4022. access_pio_host_addr_mem_cor_err_cnt),
  4023. [C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
  4024. CNTR_NORMAL,
  4025. access_pio_host_addr_mem_unc_err_cnt),
  4026. [C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
  4027. CNTR_NORMAL,
  4028. access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
  4029. [C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
  4030. CNTR_NORMAL,
  4031. access_pio_init_sm_in_err_cnt),
  4032. [C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
  4033. CNTR_NORMAL,
  4034. access_pio_ppmc_pbl_fifo_err_cnt),
  4035. [C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
  4036. 0, CNTR_NORMAL,
  4037. access_pio_credit_ret_fifo_parity_err_cnt),
  4038. [C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
  4039. CNTR_NORMAL,
  4040. access_pio_v1_len_mem_bank1_cor_err_cnt),
  4041. [C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
  4042. CNTR_NORMAL,
  4043. access_pio_v1_len_mem_bank0_cor_err_cnt),
  4044. [C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
  4045. CNTR_NORMAL,
  4046. access_pio_v1_len_mem_bank1_unc_err_cnt),
  4047. [C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
  4048. CNTR_NORMAL,
  4049. access_pio_v1_len_mem_bank0_unc_err_cnt),
  4050. [C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
  4051. CNTR_NORMAL,
  4052. access_pio_sm_pkt_reset_parity_err_cnt),
  4053. [C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
  4054. CNTR_NORMAL,
  4055. access_pio_pkt_evict_fifo_parity_err_cnt),
  4056. [C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
  4057. "PioSbrdctrlCrrelFifoParityErr", 0, 0,
  4058. CNTR_NORMAL,
  4059. access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
  4060. [C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
  4061. CNTR_NORMAL,
  4062. access_pio_sbrdctl_crrel_parity_err_cnt),
  4063. [C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
  4064. CNTR_NORMAL,
  4065. access_pio_pec_fifo_parity_err_cnt),
  4066. [C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
  4067. CNTR_NORMAL,
  4068. access_pio_pcc_fifo_parity_err_cnt),
  4069. [C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
  4070. CNTR_NORMAL,
  4071. access_pio_sb_mem_fifo1_err_cnt),
  4072. [C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
  4073. CNTR_NORMAL,
  4074. access_pio_sb_mem_fifo0_err_cnt),
  4075. [C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
  4076. CNTR_NORMAL,
  4077. access_pio_csr_parity_err_cnt),
  4078. [C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
  4079. CNTR_NORMAL,
  4080. access_pio_write_addr_parity_err_cnt),
  4081. [C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
  4082. CNTR_NORMAL,
  4083. access_pio_write_bad_ctxt_err_cnt),
  4084. /* SendDmaErrStatus */
  4085. [C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
  4086. 0, CNTR_NORMAL,
  4087. access_sdma_pcie_req_tracking_cor_err_cnt),
  4088. [C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
  4089. 0, CNTR_NORMAL,
  4090. access_sdma_pcie_req_tracking_unc_err_cnt),
  4091. [C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
  4092. CNTR_NORMAL,
  4093. access_sdma_csr_parity_err_cnt),
  4094. [C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
  4095. CNTR_NORMAL,
  4096. access_sdma_rpy_tag_err_cnt),
  4097. /* SendEgressErrStatus */
  4098. [C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
  4099. CNTR_NORMAL,
  4100. access_tx_read_pio_memory_csr_unc_err_cnt),
  4101. [C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
  4102. 0, CNTR_NORMAL,
  4103. access_tx_read_sdma_memory_csr_err_cnt),
  4104. [C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
  4105. CNTR_NORMAL,
  4106. access_tx_egress_fifo_cor_err_cnt),
  4107. [C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
  4108. CNTR_NORMAL,
  4109. access_tx_read_pio_memory_cor_err_cnt),
  4110. [C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
  4111. CNTR_NORMAL,
  4112. access_tx_read_sdma_memory_cor_err_cnt),
  4113. [C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
  4114. CNTR_NORMAL,
  4115. access_tx_sb_hdr_cor_err_cnt),
  4116. [C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
  4117. CNTR_NORMAL,
  4118. access_tx_credit_overrun_err_cnt),
  4119. [C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
  4120. CNTR_NORMAL,
  4121. access_tx_launch_fifo8_cor_err_cnt),
  4122. [C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
  4123. CNTR_NORMAL,
  4124. access_tx_launch_fifo7_cor_err_cnt),
  4125. [C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
  4126. CNTR_NORMAL,
  4127. access_tx_launch_fifo6_cor_err_cnt),
  4128. [C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
  4129. CNTR_NORMAL,
  4130. access_tx_launch_fifo5_cor_err_cnt),
  4131. [C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
  4132. CNTR_NORMAL,
  4133. access_tx_launch_fifo4_cor_err_cnt),
  4134. [C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
  4135. CNTR_NORMAL,
  4136. access_tx_launch_fifo3_cor_err_cnt),
  4137. [C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
  4138. CNTR_NORMAL,
  4139. access_tx_launch_fifo2_cor_err_cnt),
  4140. [C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
  4141. CNTR_NORMAL,
  4142. access_tx_launch_fifo1_cor_err_cnt),
  4143. [C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
  4144. CNTR_NORMAL,
  4145. access_tx_launch_fifo0_cor_err_cnt),
  4146. [C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
  4147. CNTR_NORMAL,
  4148. access_tx_credit_return_vl_err_cnt),
  4149. [C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
  4150. CNTR_NORMAL,
  4151. access_tx_hcrc_insertion_err_cnt),
  4152. [C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
  4153. CNTR_NORMAL,
  4154. access_tx_egress_fifo_unc_err_cnt),
  4155. [C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
  4156. CNTR_NORMAL,
  4157. access_tx_read_pio_memory_unc_err_cnt),
  4158. [C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
  4159. CNTR_NORMAL,
  4160. access_tx_read_sdma_memory_unc_err_cnt),
  4161. [C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
  4162. CNTR_NORMAL,
  4163. access_tx_sb_hdr_unc_err_cnt),
  4164. [C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
  4165. CNTR_NORMAL,
  4166. access_tx_credit_return_partiy_err_cnt),
  4167. [C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
  4168. 0, 0, CNTR_NORMAL,
  4169. access_tx_launch_fifo8_unc_or_parity_err_cnt),
  4170. [C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
  4171. 0, 0, CNTR_NORMAL,
  4172. access_tx_launch_fifo7_unc_or_parity_err_cnt),
  4173. [C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
  4174. 0, 0, CNTR_NORMAL,
  4175. access_tx_launch_fifo6_unc_or_parity_err_cnt),
  4176. [C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
  4177. 0, 0, CNTR_NORMAL,
  4178. access_tx_launch_fifo5_unc_or_parity_err_cnt),
  4179. [C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
  4180. 0, 0, CNTR_NORMAL,
  4181. access_tx_launch_fifo4_unc_or_parity_err_cnt),
  4182. [C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
  4183. 0, 0, CNTR_NORMAL,
  4184. access_tx_launch_fifo3_unc_or_parity_err_cnt),
  4185. [C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
  4186. 0, 0, CNTR_NORMAL,
  4187. access_tx_launch_fifo2_unc_or_parity_err_cnt),
  4188. [C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
  4189. 0, 0, CNTR_NORMAL,
  4190. access_tx_launch_fifo1_unc_or_parity_err_cnt),
  4191. [C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
  4192. 0, 0, CNTR_NORMAL,
  4193. access_tx_launch_fifo0_unc_or_parity_err_cnt),
  4194. [C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
  4195. 0, 0, CNTR_NORMAL,
  4196. access_tx_sdma15_disallowed_packet_err_cnt),
  4197. [C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
  4198. 0, 0, CNTR_NORMAL,
  4199. access_tx_sdma14_disallowed_packet_err_cnt),
  4200. [C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
  4201. 0, 0, CNTR_NORMAL,
  4202. access_tx_sdma13_disallowed_packet_err_cnt),
  4203. [C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
  4204. 0, 0, CNTR_NORMAL,
  4205. access_tx_sdma12_disallowed_packet_err_cnt),
  4206. [C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
  4207. 0, 0, CNTR_NORMAL,
  4208. access_tx_sdma11_disallowed_packet_err_cnt),
  4209. [C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
  4210. 0, 0, CNTR_NORMAL,
  4211. access_tx_sdma10_disallowed_packet_err_cnt),
  4212. [C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
  4213. 0, 0, CNTR_NORMAL,
  4214. access_tx_sdma9_disallowed_packet_err_cnt),
  4215. [C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
  4216. 0, 0, CNTR_NORMAL,
  4217. access_tx_sdma8_disallowed_packet_err_cnt),
  4218. [C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
  4219. 0, 0, CNTR_NORMAL,
  4220. access_tx_sdma7_disallowed_packet_err_cnt),
  4221. [C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
  4222. 0, 0, CNTR_NORMAL,
  4223. access_tx_sdma6_disallowed_packet_err_cnt),
  4224. [C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
  4225. 0, 0, CNTR_NORMAL,
  4226. access_tx_sdma5_disallowed_packet_err_cnt),
  4227. [C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
  4228. 0, 0, CNTR_NORMAL,
  4229. access_tx_sdma4_disallowed_packet_err_cnt),
  4230. [C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
  4231. 0, 0, CNTR_NORMAL,
  4232. access_tx_sdma3_disallowed_packet_err_cnt),
  4233. [C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
  4234. 0, 0, CNTR_NORMAL,
  4235. access_tx_sdma2_disallowed_packet_err_cnt),
  4236. [C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
  4237. 0, 0, CNTR_NORMAL,
  4238. access_tx_sdma1_disallowed_packet_err_cnt),
  4239. [C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
  4240. 0, 0, CNTR_NORMAL,
  4241. access_tx_sdma0_disallowed_packet_err_cnt),
  4242. [C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
  4243. CNTR_NORMAL,
  4244. access_tx_config_parity_err_cnt),
  4245. [C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
  4246. CNTR_NORMAL,
  4247. access_tx_sbrd_ctl_csr_parity_err_cnt),
  4248. [C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
  4249. CNTR_NORMAL,
  4250. access_tx_launch_csr_parity_err_cnt),
  4251. [C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
  4252. CNTR_NORMAL,
  4253. access_tx_illegal_vl_err_cnt),
  4254. [C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
  4255. "TxSbrdCtlStateMachineParityErr", 0, 0,
  4256. CNTR_NORMAL,
  4257. access_tx_sbrd_ctl_state_machine_parity_err_cnt),
  4258. [C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
  4259. CNTR_NORMAL,
  4260. access_egress_reserved_10_err_cnt),
  4261. [C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
  4262. CNTR_NORMAL,
  4263. access_egress_reserved_9_err_cnt),
  4264. [C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
  4265. 0, 0, CNTR_NORMAL,
  4266. access_tx_sdma_launch_intf_parity_err_cnt),
  4267. [C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
  4268. CNTR_NORMAL,
  4269. access_tx_pio_launch_intf_parity_err_cnt),
  4270. [C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
  4271. CNTR_NORMAL,
  4272. access_egress_reserved_6_err_cnt),
  4273. [C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
  4274. CNTR_NORMAL,
  4275. access_tx_incorrect_link_state_err_cnt),
  4276. [C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
  4277. CNTR_NORMAL,
  4278. access_tx_linkdown_err_cnt),
  4279. [C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
  4280. "EgressFifoUnderrunOrParityErr", 0, 0,
  4281. CNTR_NORMAL,
  4282. access_tx_egress_fifi_underrun_or_parity_err_cnt),
  4283. [C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
  4284. CNTR_NORMAL,
  4285. access_egress_reserved_2_err_cnt),
  4286. [C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
  4287. CNTR_NORMAL,
  4288. access_tx_pkt_integrity_mem_unc_err_cnt),
  4289. [C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
  4290. CNTR_NORMAL,
  4291. access_tx_pkt_integrity_mem_cor_err_cnt),
  4292. /* SendErrStatus */
  4293. [C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
  4294. CNTR_NORMAL,
  4295. access_send_csr_write_bad_addr_err_cnt),
  4296. [C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
  4297. CNTR_NORMAL,
  4298. access_send_csr_read_bad_addr_err_cnt),
  4299. [C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
  4300. CNTR_NORMAL,
  4301. access_send_csr_parity_cnt),
  4302. /* SendCtxtErrStatus */
  4303. [C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
  4304. CNTR_NORMAL,
  4305. access_pio_write_out_of_bounds_err_cnt),
  4306. [C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
  4307. CNTR_NORMAL,
  4308. access_pio_write_overflow_err_cnt),
  4309. [C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
  4310. 0, 0, CNTR_NORMAL,
  4311. access_pio_write_crosses_boundary_err_cnt),
  4312. [C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
  4313. CNTR_NORMAL,
  4314. access_pio_disallowed_packet_err_cnt),
  4315. [C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
  4316. CNTR_NORMAL,
  4317. access_pio_inconsistent_sop_err_cnt),
  4318. /* SendDmaEngErrStatus */
  4319. [C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
  4320. 0, 0, CNTR_NORMAL,
  4321. access_sdma_header_request_fifo_cor_err_cnt),
  4322. [C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
  4323. CNTR_NORMAL,
  4324. access_sdma_header_storage_cor_err_cnt),
  4325. [C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
  4326. CNTR_NORMAL,
  4327. access_sdma_packet_tracking_cor_err_cnt),
  4328. [C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
  4329. CNTR_NORMAL,
  4330. access_sdma_assembly_cor_err_cnt),
  4331. [C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
  4332. CNTR_NORMAL,
  4333. access_sdma_desc_table_cor_err_cnt),
  4334. [C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
  4335. 0, 0, CNTR_NORMAL,
  4336. access_sdma_header_request_fifo_unc_err_cnt),
  4337. [C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
  4338. CNTR_NORMAL,
  4339. access_sdma_header_storage_unc_err_cnt),
  4340. [C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
  4341. CNTR_NORMAL,
  4342. access_sdma_packet_tracking_unc_err_cnt),
  4343. [C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
  4344. CNTR_NORMAL,
  4345. access_sdma_assembly_unc_err_cnt),
  4346. [C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
  4347. CNTR_NORMAL,
  4348. access_sdma_desc_table_unc_err_cnt),
  4349. [C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
  4350. CNTR_NORMAL,
  4351. access_sdma_timeout_err_cnt),
  4352. [C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
  4353. CNTR_NORMAL,
  4354. access_sdma_header_length_err_cnt),
  4355. [C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
  4356. CNTR_NORMAL,
  4357. access_sdma_header_address_err_cnt),
  4358. [C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
  4359. CNTR_NORMAL,
  4360. access_sdma_header_select_err_cnt),
  4361. [C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
  4362. CNTR_NORMAL,
  4363. access_sdma_reserved_9_err_cnt),
  4364. [C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
  4365. CNTR_NORMAL,
  4366. access_sdma_packet_desc_overflow_err_cnt),
  4367. [C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
  4368. CNTR_NORMAL,
  4369. access_sdma_length_mismatch_err_cnt),
  4370. [C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
  4371. CNTR_NORMAL,
  4372. access_sdma_halt_err_cnt),
  4373. [C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
  4374. CNTR_NORMAL,
  4375. access_sdma_mem_read_err_cnt),
  4376. [C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
  4377. CNTR_NORMAL,
  4378. access_sdma_first_desc_err_cnt),
  4379. [C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
  4380. CNTR_NORMAL,
  4381. access_sdma_tail_out_of_bounds_err_cnt),
  4382. [C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
  4383. CNTR_NORMAL,
  4384. access_sdma_too_long_err_cnt),
  4385. [C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
  4386. CNTR_NORMAL,
  4387. access_sdma_gen_mismatch_err_cnt),
  4388. [C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
  4389. CNTR_NORMAL,
  4390. access_sdma_wrong_dw_err_cnt),
  4391. };
  4392. static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
  4393. [C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
  4394. CNTR_NORMAL),
  4395. [C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
  4396. CNTR_NORMAL),
  4397. [C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
  4398. CNTR_NORMAL),
  4399. [C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
  4400. CNTR_NORMAL),
  4401. [C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
  4402. CNTR_NORMAL),
  4403. [C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
  4404. CNTR_NORMAL),
  4405. [C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
  4406. CNTR_NORMAL),
  4407. [C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
  4408. [C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
  4409. [C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
  4410. [C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
  4411. CNTR_SYNTH | CNTR_VL),
  4412. [C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
  4413. CNTR_SYNTH | CNTR_VL),
  4414. [C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
  4415. CNTR_SYNTH | CNTR_VL),
  4416. [C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
  4417. [C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
  4418. [C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4419. access_sw_link_dn_cnt),
  4420. [C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4421. access_sw_link_up_cnt),
  4422. [C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
  4423. access_sw_unknown_frame_cnt),
  4424. [C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
  4425. access_sw_xmit_discards),
  4426. [C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
  4427. CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
  4428. access_sw_xmit_discards),
  4429. [C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
  4430. access_xmit_constraint_errs),
  4431. [C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
  4432. access_rcv_constraint_errs),
  4433. [C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
  4434. [C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
  4435. [C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
  4436. [C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
  4437. [C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
  4438. [C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
  4439. [C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
  4440. [C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
  4441. [C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
  4442. [C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
  4443. [C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
  4444. [C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
  4445. [C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
  4446. access_sw_cpu_rc_acks),
  4447. [C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
  4448. access_sw_cpu_rc_qacks),
  4449. [C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
  4450. access_sw_cpu_rc_delayed_comp),
  4451. [OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
  4452. [OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
  4453. [OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
  4454. [OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
  4455. [OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
  4456. [OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
  4457. [OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
  4458. [OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
  4459. [OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
  4460. [OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
  4461. [OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
  4462. [OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
  4463. [OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
  4464. [OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
  4465. [OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
  4466. [OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
  4467. [OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
  4468. [OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
  4469. [OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
  4470. [OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
  4471. [OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
  4472. [OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
  4473. [OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
  4474. [OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
  4475. [OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
  4476. [OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
  4477. [OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
  4478. [OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
  4479. [OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
  4480. [OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
  4481. [OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
  4482. [OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
  4483. [OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
  4484. [OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
  4485. [OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
  4486. [OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
  4487. [OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
  4488. [OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
  4489. [OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
  4490. [OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
  4491. [OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
  4492. [OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
  4493. [OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
  4494. [OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
  4495. [OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
  4496. [OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
  4497. [OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
  4498. [OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
  4499. [OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
  4500. [OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
  4501. [OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
  4502. [OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
  4503. [OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
  4504. [OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
  4505. [OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
  4506. [OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
  4507. [OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
  4508. [OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
  4509. [OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
  4510. [OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
  4511. [OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
  4512. [OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
  4513. [OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
  4514. [OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
  4515. [OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
  4516. [OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
  4517. [OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
  4518. [OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
  4519. [OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
  4520. [OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
  4521. [OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
  4522. [OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
  4523. [OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
  4524. [OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
  4525. [OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
  4526. [OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
  4527. [OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
  4528. [OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
  4529. [OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
  4530. [OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
  4531. };
  4532. /* ======================================================================== */
  4533. /* return true if this is chip revision revision a */
  4534. int is_ax(struct hfi1_devdata *dd)
  4535. {
  4536. u8 chip_rev_minor =
  4537. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4538. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4539. return (chip_rev_minor & 0xf0) == 0;
  4540. }
  4541. /* return true if this is chip revision revision b */
  4542. int is_bx(struct hfi1_devdata *dd)
  4543. {
  4544. u8 chip_rev_minor =
  4545. dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
  4546. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  4547. return (chip_rev_minor & 0xF0) == 0x10;
  4548. }
  4549. /*
  4550. * Append string s to buffer buf. Arguments curp and len are the current
  4551. * position and remaining length, respectively.
  4552. *
  4553. * return 0 on success, 1 on out of room
  4554. */
  4555. static int append_str(char *buf, char **curp, int *lenp, const char *s)
  4556. {
  4557. char *p = *curp;
  4558. int len = *lenp;
  4559. int result = 0; /* success */
  4560. char c;
  4561. /* add a comma, if first in the buffer */
  4562. if (p != buf) {
  4563. if (len == 0) {
  4564. result = 1; /* out of room */
  4565. goto done;
  4566. }
  4567. *p++ = ',';
  4568. len--;
  4569. }
  4570. /* copy the string */
  4571. while ((c = *s++) != 0) {
  4572. if (len == 0) {
  4573. result = 1; /* out of room */
  4574. goto done;
  4575. }
  4576. *p++ = c;
  4577. len--;
  4578. }
  4579. done:
  4580. /* write return values */
  4581. *curp = p;
  4582. *lenp = len;
  4583. return result;
  4584. }
  4585. /*
  4586. * Using the given flag table, print a comma separated string into
  4587. * the buffer. End in '*' if the buffer is too short.
  4588. */
  4589. static char *flag_string(char *buf, int buf_len, u64 flags,
  4590. struct flag_table *table, int table_size)
  4591. {
  4592. char extra[32];
  4593. char *p = buf;
  4594. int len = buf_len;
  4595. int no_room = 0;
  4596. int i;
  4597. /* make sure there is at least 2 so we can form "*" */
  4598. if (len < 2)
  4599. return "";
  4600. len--; /* leave room for a nul */
  4601. for (i = 0; i < table_size; i++) {
  4602. if (flags & table[i].flag) {
  4603. no_room = append_str(buf, &p, &len, table[i].str);
  4604. if (no_room)
  4605. break;
  4606. flags &= ~table[i].flag;
  4607. }
  4608. }
  4609. /* any undocumented bits left? */
  4610. if (!no_room && flags) {
  4611. snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
  4612. no_room = append_str(buf, &p, &len, extra);
  4613. }
  4614. /* add * if ran out of room */
  4615. if (no_room) {
  4616. /* may need to back up to add space for a '*' */
  4617. if (len == 0)
  4618. --p;
  4619. *p++ = '*';
  4620. }
  4621. /* add final nul - space already allocated above */
  4622. *p = 0;
  4623. return buf;
  4624. }
  4625. /* first 8 CCE error interrupt source names */
  4626. static const char * const cce_misc_names[] = {
  4627. "CceErrInt", /* 0 */
  4628. "RxeErrInt", /* 1 */
  4629. "MiscErrInt", /* 2 */
  4630. "Reserved3", /* 3 */
  4631. "PioErrInt", /* 4 */
  4632. "SDmaErrInt", /* 5 */
  4633. "EgressErrInt", /* 6 */
  4634. "TxeErrInt" /* 7 */
  4635. };
  4636. /*
  4637. * Return the miscellaneous error interrupt name.
  4638. */
  4639. static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
  4640. {
  4641. if (source < ARRAY_SIZE(cce_misc_names))
  4642. strncpy(buf, cce_misc_names[source], bsize);
  4643. else
  4644. snprintf(buf, bsize, "Reserved%u",
  4645. source + IS_GENERAL_ERR_START);
  4646. return buf;
  4647. }
  4648. /*
  4649. * Return the SDMA engine error interrupt name.
  4650. */
  4651. static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
  4652. {
  4653. snprintf(buf, bsize, "SDmaEngErrInt%u", source);
  4654. return buf;
  4655. }
  4656. /*
  4657. * Return the send context error interrupt name.
  4658. */
  4659. static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
  4660. {
  4661. snprintf(buf, bsize, "SendCtxtErrInt%u", source);
  4662. return buf;
  4663. }
  4664. static const char * const various_names[] = {
  4665. "PbcInt",
  4666. "GpioAssertInt",
  4667. "Qsfp1Int",
  4668. "Qsfp2Int",
  4669. "TCritInt"
  4670. };
  4671. /*
  4672. * Return the various interrupt name.
  4673. */
  4674. static char *is_various_name(char *buf, size_t bsize, unsigned int source)
  4675. {
  4676. if (source < ARRAY_SIZE(various_names))
  4677. strncpy(buf, various_names[source], bsize);
  4678. else
  4679. snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
  4680. return buf;
  4681. }
  4682. /*
  4683. * Return the DC interrupt name.
  4684. */
  4685. static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
  4686. {
  4687. static const char * const dc_int_names[] = {
  4688. "common",
  4689. "lcb",
  4690. "8051",
  4691. "lbm" /* local block merge */
  4692. };
  4693. if (source < ARRAY_SIZE(dc_int_names))
  4694. snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
  4695. else
  4696. snprintf(buf, bsize, "DCInt%u", source);
  4697. return buf;
  4698. }
  4699. static const char * const sdma_int_names[] = {
  4700. "SDmaInt",
  4701. "SdmaIdleInt",
  4702. "SdmaProgressInt",
  4703. };
  4704. /*
  4705. * Return the SDMA engine interrupt name.
  4706. */
  4707. static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
  4708. {
  4709. /* what interrupt */
  4710. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  4711. /* which engine */
  4712. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  4713. if (likely(what < 3))
  4714. snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
  4715. else
  4716. snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
  4717. return buf;
  4718. }
  4719. /*
  4720. * Return the receive available interrupt name.
  4721. */
  4722. static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
  4723. {
  4724. snprintf(buf, bsize, "RcvAvailInt%u", source);
  4725. return buf;
  4726. }
  4727. /*
  4728. * Return the receive urgent interrupt name.
  4729. */
  4730. static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
  4731. {
  4732. snprintf(buf, bsize, "RcvUrgentInt%u", source);
  4733. return buf;
  4734. }
  4735. /*
  4736. * Return the send credit interrupt name.
  4737. */
  4738. static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
  4739. {
  4740. snprintf(buf, bsize, "SendCreditInt%u", source);
  4741. return buf;
  4742. }
  4743. /*
  4744. * Return the reserved interrupt name.
  4745. */
  4746. static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
  4747. {
  4748. snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
  4749. return buf;
  4750. }
  4751. static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
  4752. {
  4753. return flag_string(buf, buf_len, flags,
  4754. cce_err_status_flags,
  4755. ARRAY_SIZE(cce_err_status_flags));
  4756. }
  4757. static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
  4758. {
  4759. return flag_string(buf, buf_len, flags,
  4760. rxe_err_status_flags,
  4761. ARRAY_SIZE(rxe_err_status_flags));
  4762. }
  4763. static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
  4764. {
  4765. return flag_string(buf, buf_len, flags, misc_err_status_flags,
  4766. ARRAY_SIZE(misc_err_status_flags));
  4767. }
  4768. static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
  4769. {
  4770. return flag_string(buf, buf_len, flags,
  4771. pio_err_status_flags,
  4772. ARRAY_SIZE(pio_err_status_flags));
  4773. }
  4774. static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
  4775. {
  4776. return flag_string(buf, buf_len, flags,
  4777. sdma_err_status_flags,
  4778. ARRAY_SIZE(sdma_err_status_flags));
  4779. }
  4780. static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
  4781. {
  4782. return flag_string(buf, buf_len, flags,
  4783. egress_err_status_flags,
  4784. ARRAY_SIZE(egress_err_status_flags));
  4785. }
  4786. static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
  4787. {
  4788. return flag_string(buf, buf_len, flags,
  4789. egress_err_info_flags,
  4790. ARRAY_SIZE(egress_err_info_flags));
  4791. }
  4792. static char *send_err_status_string(char *buf, int buf_len, u64 flags)
  4793. {
  4794. return flag_string(buf, buf_len, flags,
  4795. send_err_status_flags,
  4796. ARRAY_SIZE(send_err_status_flags));
  4797. }
  4798. static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4799. {
  4800. char buf[96];
  4801. int i = 0;
  4802. /*
  4803. * For most these errors, there is nothing that can be done except
  4804. * report or record it.
  4805. */
  4806. dd_dev_info(dd, "CCE Error: %s\n",
  4807. cce_err_status_string(buf, sizeof(buf), reg));
  4808. if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
  4809. is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
  4810. /* this error requires a manual drop into SPC freeze mode */
  4811. /* then a fix up */
  4812. start_freeze_handling(dd->pport, FREEZE_SELF);
  4813. }
  4814. for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
  4815. if (reg & (1ull << i)) {
  4816. incr_cntr64(&dd->cce_err_status_cnt[i]);
  4817. /* maintain a counter over all cce_err_status errors */
  4818. incr_cntr64(&dd->sw_cce_err_status_aggregate);
  4819. }
  4820. }
  4821. }
  4822. /*
  4823. * Check counters for receive errors that do not have an interrupt
  4824. * associated with them.
  4825. */
  4826. #define RCVERR_CHECK_TIME 10
  4827. static void update_rcverr_timer(struct timer_list *t)
  4828. {
  4829. struct hfi1_devdata *dd = from_timer(dd, t, rcverr_timer);
  4830. struct hfi1_pportdata *ppd = dd->pport;
  4831. u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  4832. if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
  4833. ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
  4834. dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
  4835. set_link_down_reason(
  4836. ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
  4837. OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
  4838. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  4839. }
  4840. dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
  4841. mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4842. }
  4843. static int init_rcverr(struct hfi1_devdata *dd)
  4844. {
  4845. timer_setup(&dd->rcverr_timer, update_rcverr_timer, 0);
  4846. /* Assume the hardware counter has been reset */
  4847. dd->rcv_ovfl_cnt = 0;
  4848. return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
  4849. }
  4850. static void free_rcverr(struct hfi1_devdata *dd)
  4851. {
  4852. if (dd->rcverr_timer.function)
  4853. del_timer_sync(&dd->rcverr_timer);
  4854. }
  4855. static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4856. {
  4857. char buf[96];
  4858. int i = 0;
  4859. dd_dev_info(dd, "Receive Error: %s\n",
  4860. rxe_err_status_string(buf, sizeof(buf), reg));
  4861. if (reg & ALL_RXE_FREEZE_ERR) {
  4862. int flags = 0;
  4863. /*
  4864. * Freeze mode recovery is disabled for the errors
  4865. * in RXE_FREEZE_ABORT_MASK
  4866. */
  4867. if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
  4868. flags = FREEZE_ABORT;
  4869. start_freeze_handling(dd->pport, flags);
  4870. }
  4871. for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
  4872. if (reg & (1ull << i))
  4873. incr_cntr64(&dd->rcv_err_status_cnt[i]);
  4874. }
  4875. }
  4876. static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4877. {
  4878. char buf[96];
  4879. int i = 0;
  4880. dd_dev_info(dd, "Misc Error: %s",
  4881. misc_err_status_string(buf, sizeof(buf), reg));
  4882. for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
  4883. if (reg & (1ull << i))
  4884. incr_cntr64(&dd->misc_err_status_cnt[i]);
  4885. }
  4886. }
  4887. static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4888. {
  4889. char buf[96];
  4890. int i = 0;
  4891. dd_dev_info(dd, "PIO Error: %s\n",
  4892. pio_err_status_string(buf, sizeof(buf), reg));
  4893. if (reg & ALL_PIO_FREEZE_ERR)
  4894. start_freeze_handling(dd->pport, 0);
  4895. for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
  4896. if (reg & (1ull << i))
  4897. incr_cntr64(&dd->send_pio_err_status_cnt[i]);
  4898. }
  4899. }
  4900. static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  4901. {
  4902. char buf[96];
  4903. int i = 0;
  4904. dd_dev_info(dd, "SDMA Error: %s\n",
  4905. sdma_err_status_string(buf, sizeof(buf), reg));
  4906. if (reg & ALL_SDMA_FREEZE_ERR)
  4907. start_freeze_handling(dd->pport, 0);
  4908. for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
  4909. if (reg & (1ull << i))
  4910. incr_cntr64(&dd->send_dma_err_status_cnt[i]);
  4911. }
  4912. }
  4913. static inline void __count_port_discards(struct hfi1_pportdata *ppd)
  4914. {
  4915. incr_cntr64(&ppd->port_xmit_discards);
  4916. }
  4917. static void count_port_inactive(struct hfi1_devdata *dd)
  4918. {
  4919. __count_port_discards(dd->pport);
  4920. }
  4921. /*
  4922. * We have had a "disallowed packet" error during egress. Determine the
  4923. * integrity check which failed, and update relevant error counter, etc.
  4924. *
  4925. * Note that the SEND_EGRESS_ERR_INFO register has only a single
  4926. * bit of state per integrity check, and so we can miss the reason for an
  4927. * egress error if more than one packet fails the same integrity check
  4928. * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
  4929. */
  4930. static void handle_send_egress_err_info(struct hfi1_devdata *dd,
  4931. int vl)
  4932. {
  4933. struct hfi1_pportdata *ppd = dd->pport;
  4934. u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
  4935. u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
  4936. char buf[96];
  4937. /* clear down all observed info as quickly as possible after read */
  4938. write_csr(dd, SEND_EGRESS_ERR_INFO, info);
  4939. dd_dev_info(dd,
  4940. "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
  4941. info, egress_err_info_string(buf, sizeof(buf), info), src);
  4942. /* Eventually add other counters for each bit */
  4943. if (info & PORT_DISCARD_EGRESS_ERRS) {
  4944. int weight, i;
  4945. /*
  4946. * Count all applicable bits as individual errors and
  4947. * attribute them to the packet that triggered this handler.
  4948. * This may not be completely accurate due to limitations
  4949. * on the available hardware error information. There is
  4950. * a single information register and any number of error
  4951. * packets may have occurred and contributed to it before
  4952. * this routine is called. This means that:
  4953. * a) If multiple packets with the same error occur before
  4954. * this routine is called, earlier packets are missed.
  4955. * There is only a single bit for each error type.
  4956. * b) Errors may not be attributed to the correct VL.
  4957. * The driver is attributing all bits in the info register
  4958. * to the packet that triggered this call, but bits
  4959. * could be an accumulation of different packets with
  4960. * different VLs.
  4961. * c) A single error packet may have multiple counts attached
  4962. * to it. There is no way for the driver to know if
  4963. * multiple bits set in the info register are due to a
  4964. * single packet or multiple packets. The driver assumes
  4965. * multiple packets.
  4966. */
  4967. weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
  4968. for (i = 0; i < weight; i++) {
  4969. __count_port_discards(ppd);
  4970. if (vl >= 0 && vl < TXE_NUM_DATA_VL)
  4971. incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
  4972. else if (vl == 15)
  4973. incr_cntr64(&ppd->port_xmit_discards_vl
  4974. [C_VL_15]);
  4975. }
  4976. }
  4977. }
  4978. /*
  4979. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4980. * register. Does it represent a 'port inactive' error?
  4981. */
  4982. static inline int port_inactive_err(u64 posn)
  4983. {
  4984. return (posn >= SEES(TX_LINKDOWN) &&
  4985. posn <= SEES(TX_INCORRECT_LINK_STATE));
  4986. }
  4987. /*
  4988. * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
  4989. * register. Does it represent a 'disallowed packet' error?
  4990. */
  4991. static inline int disallowed_pkt_err(int posn)
  4992. {
  4993. return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
  4994. posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
  4995. }
  4996. /*
  4997. * Input value is a bit position of one of the SDMA engine disallowed
  4998. * packet errors. Return which engine. Use of this must be guarded by
  4999. * disallowed_pkt_err().
  5000. */
  5001. static inline int disallowed_pkt_engine(int posn)
  5002. {
  5003. return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
  5004. }
  5005. /*
  5006. * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
  5007. * be done.
  5008. */
  5009. static int engine_to_vl(struct hfi1_devdata *dd, int engine)
  5010. {
  5011. struct sdma_vl_map *m;
  5012. int vl;
  5013. /* range check */
  5014. if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
  5015. return -1;
  5016. rcu_read_lock();
  5017. m = rcu_dereference(dd->sdma_map);
  5018. vl = m->engine_to_vl[engine];
  5019. rcu_read_unlock();
  5020. return vl;
  5021. }
  5022. /*
  5023. * Translate the send context (sofware index) into a VL. Return -1 if the
  5024. * translation cannot be done.
  5025. */
  5026. static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
  5027. {
  5028. struct send_context_info *sci;
  5029. struct send_context *sc;
  5030. int i;
  5031. sci = &dd->send_contexts[sw_index];
  5032. /* there is no information for user (PSM) and ack contexts */
  5033. if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
  5034. return -1;
  5035. sc = sci->sc;
  5036. if (!sc)
  5037. return -1;
  5038. if (dd->vld[15].sc == sc)
  5039. return 15;
  5040. for (i = 0; i < num_vls; i++)
  5041. if (dd->vld[i].sc == sc)
  5042. return i;
  5043. return -1;
  5044. }
  5045. static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5046. {
  5047. u64 reg_copy = reg, handled = 0;
  5048. char buf[96];
  5049. int i = 0;
  5050. if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
  5051. start_freeze_handling(dd->pport, 0);
  5052. else if (is_ax(dd) &&
  5053. (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
  5054. (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
  5055. start_freeze_handling(dd->pport, 0);
  5056. while (reg_copy) {
  5057. int posn = fls64(reg_copy);
  5058. /* fls64() returns a 1-based offset, we want it zero based */
  5059. int shift = posn - 1;
  5060. u64 mask = 1ULL << shift;
  5061. if (port_inactive_err(shift)) {
  5062. count_port_inactive(dd);
  5063. handled |= mask;
  5064. } else if (disallowed_pkt_err(shift)) {
  5065. int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
  5066. handle_send_egress_err_info(dd, vl);
  5067. handled |= mask;
  5068. }
  5069. reg_copy &= ~mask;
  5070. }
  5071. reg &= ~handled;
  5072. if (reg)
  5073. dd_dev_info(dd, "Egress Error: %s\n",
  5074. egress_err_status_string(buf, sizeof(buf), reg));
  5075. for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
  5076. if (reg & (1ull << i))
  5077. incr_cntr64(&dd->send_egress_err_status_cnt[i]);
  5078. }
  5079. }
  5080. static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  5081. {
  5082. char buf[96];
  5083. int i = 0;
  5084. dd_dev_info(dd, "Send Error: %s\n",
  5085. send_err_status_string(buf, sizeof(buf), reg));
  5086. for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
  5087. if (reg & (1ull << i))
  5088. incr_cntr64(&dd->send_err_status_cnt[i]);
  5089. }
  5090. }
  5091. /*
  5092. * The maximum number of times the error clear down will loop before
  5093. * blocking a repeating error. This value is arbitrary.
  5094. */
  5095. #define MAX_CLEAR_COUNT 20
  5096. /*
  5097. * Clear and handle an error register. All error interrupts are funneled
  5098. * through here to have a central location to correctly handle single-
  5099. * or multi-shot errors.
  5100. *
  5101. * For non per-context registers, call this routine with a context value
  5102. * of 0 so the per-context offset is zero.
  5103. *
  5104. * If the handler loops too many times, assume that something is wrong
  5105. * and can't be fixed, so mask the error bits.
  5106. */
  5107. static void interrupt_clear_down(struct hfi1_devdata *dd,
  5108. u32 context,
  5109. const struct err_reg_info *eri)
  5110. {
  5111. u64 reg;
  5112. u32 count;
  5113. /* read in a loop until no more errors are seen */
  5114. count = 0;
  5115. while (1) {
  5116. reg = read_kctxt_csr(dd, context, eri->status);
  5117. if (reg == 0)
  5118. break;
  5119. write_kctxt_csr(dd, context, eri->clear, reg);
  5120. if (likely(eri->handler))
  5121. eri->handler(dd, context, reg);
  5122. count++;
  5123. if (count > MAX_CLEAR_COUNT) {
  5124. u64 mask;
  5125. dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
  5126. eri->desc, reg);
  5127. /*
  5128. * Read-modify-write so any other masked bits
  5129. * remain masked.
  5130. */
  5131. mask = read_kctxt_csr(dd, context, eri->mask);
  5132. mask &= ~reg;
  5133. write_kctxt_csr(dd, context, eri->mask, mask);
  5134. break;
  5135. }
  5136. }
  5137. }
  5138. /*
  5139. * CCE block "misc" interrupt. Source is < 16.
  5140. */
  5141. static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
  5142. {
  5143. const struct err_reg_info *eri = &misc_errs[source];
  5144. if (eri->handler) {
  5145. interrupt_clear_down(dd, 0, eri);
  5146. } else {
  5147. dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
  5148. source);
  5149. }
  5150. }
  5151. static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
  5152. {
  5153. return flag_string(buf, buf_len, flags,
  5154. sc_err_status_flags,
  5155. ARRAY_SIZE(sc_err_status_flags));
  5156. }
  5157. /*
  5158. * Send context error interrupt. Source (hw_context) is < 160.
  5159. *
  5160. * All send context errors cause the send context to halt. The normal
  5161. * clear-down mechanism cannot be used because we cannot clear the
  5162. * error bits until several other long-running items are done first.
  5163. * This is OK because with the context halted, nothing else is going
  5164. * to happen on it anyway.
  5165. */
  5166. static void is_sendctxt_err_int(struct hfi1_devdata *dd,
  5167. unsigned int hw_context)
  5168. {
  5169. struct send_context_info *sci;
  5170. struct send_context *sc;
  5171. char flags[96];
  5172. u64 status;
  5173. u32 sw_index;
  5174. int i = 0;
  5175. sw_index = dd->hw_to_sw[hw_context];
  5176. if (sw_index >= dd->num_send_contexts) {
  5177. dd_dev_err(dd,
  5178. "out of range sw index %u for send context %u\n",
  5179. sw_index, hw_context);
  5180. return;
  5181. }
  5182. sci = &dd->send_contexts[sw_index];
  5183. sc = sci->sc;
  5184. if (!sc) {
  5185. dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
  5186. sw_index, hw_context);
  5187. return;
  5188. }
  5189. /* tell the software that a halt has begun */
  5190. sc_stop(sc, SCF_HALTED);
  5191. status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
  5192. dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
  5193. send_context_err_status_string(flags, sizeof(flags),
  5194. status));
  5195. if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
  5196. handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
  5197. /*
  5198. * Automatically restart halted kernel contexts out of interrupt
  5199. * context. User contexts must ask the driver to restart the context.
  5200. */
  5201. if (sc->type != SC_USER)
  5202. queue_work(dd->pport->hfi1_wq, &sc->halt_work);
  5203. /*
  5204. * Update the counters for the corresponding status bits.
  5205. * Note that these particular counters are aggregated over all
  5206. * 160 contexts.
  5207. */
  5208. for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
  5209. if (status & (1ull << i))
  5210. incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
  5211. }
  5212. }
  5213. static void handle_sdma_eng_err(struct hfi1_devdata *dd,
  5214. unsigned int source, u64 status)
  5215. {
  5216. struct sdma_engine *sde;
  5217. int i = 0;
  5218. sde = &dd->per_sdma[source];
  5219. #ifdef CONFIG_SDMA_VERBOSITY
  5220. dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5221. slashstrip(__FILE__), __LINE__, __func__);
  5222. dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
  5223. sde->this_idx, source, (unsigned long long)status);
  5224. #endif
  5225. sde->err_cnt++;
  5226. sdma_engine_error(sde, status);
  5227. /*
  5228. * Update the counters for the corresponding status bits.
  5229. * Note that these particular counters are aggregated over
  5230. * all 16 DMA engines.
  5231. */
  5232. for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
  5233. if (status & (1ull << i))
  5234. incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
  5235. }
  5236. }
  5237. /*
  5238. * CCE block SDMA error interrupt. Source is < 16.
  5239. */
  5240. static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
  5241. {
  5242. #ifdef CONFIG_SDMA_VERBOSITY
  5243. struct sdma_engine *sde = &dd->per_sdma[source];
  5244. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  5245. slashstrip(__FILE__), __LINE__, __func__);
  5246. dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
  5247. source);
  5248. sdma_dumpstate(sde);
  5249. #endif
  5250. interrupt_clear_down(dd, source, &sdma_eng_err);
  5251. }
  5252. /*
  5253. * CCE block "various" interrupt. Source is < 8.
  5254. */
  5255. static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
  5256. {
  5257. const struct err_reg_info *eri = &various_err[source];
  5258. /*
  5259. * TCritInt cannot go through interrupt_clear_down()
  5260. * because it is not a second tier interrupt. The handler
  5261. * should be called directly.
  5262. */
  5263. if (source == TCRIT_INT_SOURCE)
  5264. handle_temp_err(dd);
  5265. else if (eri->handler)
  5266. interrupt_clear_down(dd, 0, eri);
  5267. else
  5268. dd_dev_info(dd,
  5269. "%s: Unimplemented/reserved interrupt %d\n",
  5270. __func__, source);
  5271. }
  5272. static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
  5273. {
  5274. /* src_ctx is always zero */
  5275. struct hfi1_pportdata *ppd = dd->pport;
  5276. unsigned long flags;
  5277. u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  5278. if (reg & QSFP_HFI0_MODPRST_N) {
  5279. if (!qsfp_mod_present(ppd)) {
  5280. dd_dev_info(dd, "%s: QSFP module removed\n",
  5281. __func__);
  5282. ppd->driver_link_ready = 0;
  5283. /*
  5284. * Cable removed, reset all our information about the
  5285. * cache and cable capabilities
  5286. */
  5287. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5288. /*
  5289. * We don't set cache_refresh_required here as we expect
  5290. * an interrupt when a cable is inserted
  5291. */
  5292. ppd->qsfp_info.cache_valid = 0;
  5293. ppd->qsfp_info.reset_needed = 0;
  5294. ppd->qsfp_info.limiting_active = 0;
  5295. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5296. flags);
  5297. /* Invert the ModPresent pin now to detect plug-in */
  5298. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5299. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5300. if ((ppd->offline_disabled_reason >
  5301. HFI1_ODR_MASK(
  5302. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
  5303. (ppd->offline_disabled_reason ==
  5304. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  5305. ppd->offline_disabled_reason =
  5306. HFI1_ODR_MASK(
  5307. OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
  5308. if (ppd->host_link_state == HLS_DN_POLL) {
  5309. /*
  5310. * The link is still in POLL. This means
  5311. * that the normal link down processing
  5312. * will not happen. We have to do it here
  5313. * before turning the DC off.
  5314. */
  5315. queue_work(ppd->link_wq, &ppd->link_down_work);
  5316. }
  5317. } else {
  5318. dd_dev_info(dd, "%s: QSFP module inserted\n",
  5319. __func__);
  5320. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5321. ppd->qsfp_info.cache_valid = 0;
  5322. ppd->qsfp_info.cache_refresh_required = 1;
  5323. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  5324. flags);
  5325. /*
  5326. * Stop inversion of ModPresent pin to detect
  5327. * removal of the cable
  5328. */
  5329. qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
  5330. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
  5331. ASIC_QSFP1_INVERT, qsfp_int_mgmt);
  5332. ppd->offline_disabled_reason =
  5333. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  5334. }
  5335. }
  5336. if (reg & QSFP_HFI0_INT_N) {
  5337. dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
  5338. __func__);
  5339. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  5340. ppd->qsfp_info.check_interrupt_flags = 1;
  5341. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
  5342. }
  5343. /* Schedule the QSFP work only if there is a cable attached. */
  5344. if (qsfp_mod_present(ppd))
  5345. queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
  5346. }
  5347. static int request_host_lcb_access(struct hfi1_devdata *dd)
  5348. {
  5349. int ret;
  5350. ret = do_8051_command(dd, HCMD_MISC,
  5351. (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
  5352. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5353. if (ret != HCMD_SUCCESS) {
  5354. dd_dev_err(dd, "%s: command failed with error %d\n",
  5355. __func__, ret);
  5356. }
  5357. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5358. }
  5359. static int request_8051_lcb_access(struct hfi1_devdata *dd)
  5360. {
  5361. int ret;
  5362. ret = do_8051_command(dd, HCMD_MISC,
  5363. (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
  5364. LOAD_DATA_FIELD_ID_SHIFT, NULL);
  5365. if (ret != HCMD_SUCCESS) {
  5366. dd_dev_err(dd, "%s: command failed with error %d\n",
  5367. __func__, ret);
  5368. }
  5369. return ret == HCMD_SUCCESS ? 0 : -EBUSY;
  5370. }
  5371. /*
  5372. * Set the LCB selector - allow host access. The DCC selector always
  5373. * points to the host.
  5374. */
  5375. static inline void set_host_lcb_access(struct hfi1_devdata *dd)
  5376. {
  5377. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5378. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
  5379. DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
  5380. }
  5381. /*
  5382. * Clear the LCB selector - allow 8051 access. The DCC selector always
  5383. * points to the host.
  5384. */
  5385. static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
  5386. {
  5387. write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
  5388. DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
  5389. }
  5390. /*
  5391. * Acquire LCB access from the 8051. If the host already has access,
  5392. * just increment a counter. Otherwise, inform the 8051 that the
  5393. * host is taking access.
  5394. *
  5395. * Returns:
  5396. * 0 on success
  5397. * -EBUSY if the 8051 has control and cannot be disturbed
  5398. * -errno if unable to acquire access from the 8051
  5399. */
  5400. int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5401. {
  5402. struct hfi1_pportdata *ppd = dd->pport;
  5403. int ret = 0;
  5404. /*
  5405. * Use the host link state lock so the operation of this routine
  5406. * { link state check, selector change, count increment } can occur
  5407. * as a unit against a link state change. Otherwise there is a
  5408. * race between the state change and the count increment.
  5409. */
  5410. if (sleep_ok) {
  5411. mutex_lock(&ppd->hls_lock);
  5412. } else {
  5413. while (!mutex_trylock(&ppd->hls_lock))
  5414. udelay(1);
  5415. }
  5416. /* this access is valid only when the link is up */
  5417. if (ppd->host_link_state & HLS_DOWN) {
  5418. dd_dev_info(dd, "%s: link state %s not up\n",
  5419. __func__, link_state_name(ppd->host_link_state));
  5420. ret = -EBUSY;
  5421. goto done;
  5422. }
  5423. if (dd->lcb_access_count == 0) {
  5424. ret = request_host_lcb_access(dd);
  5425. if (ret) {
  5426. dd_dev_err(dd,
  5427. "%s: unable to acquire LCB access, err %d\n",
  5428. __func__, ret);
  5429. goto done;
  5430. }
  5431. set_host_lcb_access(dd);
  5432. }
  5433. dd->lcb_access_count++;
  5434. done:
  5435. mutex_unlock(&ppd->hls_lock);
  5436. return ret;
  5437. }
  5438. /*
  5439. * Release LCB access by decrementing the use count. If the count is moving
  5440. * from 1 to 0, inform 8051 that it has control back.
  5441. *
  5442. * Returns:
  5443. * 0 on success
  5444. * -errno if unable to release access to the 8051
  5445. */
  5446. int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
  5447. {
  5448. int ret = 0;
  5449. /*
  5450. * Use the host link state lock because the acquire needed it.
  5451. * Here, we only need to keep { selector change, count decrement }
  5452. * as a unit.
  5453. */
  5454. if (sleep_ok) {
  5455. mutex_lock(&dd->pport->hls_lock);
  5456. } else {
  5457. while (!mutex_trylock(&dd->pport->hls_lock))
  5458. udelay(1);
  5459. }
  5460. if (dd->lcb_access_count == 0) {
  5461. dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
  5462. __func__);
  5463. goto done;
  5464. }
  5465. if (dd->lcb_access_count == 1) {
  5466. set_8051_lcb_access(dd);
  5467. ret = request_8051_lcb_access(dd);
  5468. if (ret) {
  5469. dd_dev_err(dd,
  5470. "%s: unable to release LCB access, err %d\n",
  5471. __func__, ret);
  5472. /* restore host access if the grant didn't work */
  5473. set_host_lcb_access(dd);
  5474. goto done;
  5475. }
  5476. }
  5477. dd->lcb_access_count--;
  5478. done:
  5479. mutex_unlock(&dd->pport->hls_lock);
  5480. return ret;
  5481. }
  5482. /*
  5483. * Initialize LCB access variables and state. Called during driver load,
  5484. * after most of the initialization is finished.
  5485. *
  5486. * The DC default is LCB access on for the host. The driver defaults to
  5487. * leaving access to the 8051. Assign access now - this constrains the call
  5488. * to this routine to be after all LCB set-up is done. In particular, after
  5489. * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
  5490. */
  5491. static void init_lcb_access(struct hfi1_devdata *dd)
  5492. {
  5493. dd->lcb_access_count = 0;
  5494. }
  5495. /*
  5496. * Write a response back to a 8051 request.
  5497. */
  5498. static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
  5499. {
  5500. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
  5501. DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
  5502. (u64)return_code <<
  5503. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
  5504. (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  5505. }
  5506. /*
  5507. * Handle host requests from the 8051.
  5508. */
  5509. static void handle_8051_request(struct hfi1_pportdata *ppd)
  5510. {
  5511. struct hfi1_devdata *dd = ppd->dd;
  5512. u64 reg;
  5513. u16 data = 0;
  5514. u8 type;
  5515. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
  5516. if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
  5517. return; /* no request */
  5518. /* zero out COMPLETED so the response is seen */
  5519. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
  5520. /* extract request details */
  5521. type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
  5522. & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
  5523. data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
  5524. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
  5525. switch (type) {
  5526. case HREQ_LOAD_CONFIG:
  5527. case HREQ_SAVE_CONFIG:
  5528. case HREQ_READ_CONFIG:
  5529. case HREQ_SET_TX_EQ_ABS:
  5530. case HREQ_SET_TX_EQ_REL:
  5531. case HREQ_ENABLE:
  5532. dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
  5533. type);
  5534. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5535. break;
  5536. case HREQ_CONFIG_DONE:
  5537. hreq_response(dd, HREQ_SUCCESS, 0);
  5538. break;
  5539. case HREQ_INTERFACE_TEST:
  5540. hreq_response(dd, HREQ_SUCCESS, data);
  5541. break;
  5542. default:
  5543. dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
  5544. hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
  5545. break;
  5546. }
  5547. }
  5548. /*
  5549. * Set up allocation unit vaulue.
  5550. */
  5551. void set_up_vau(struct hfi1_devdata *dd, u8 vau)
  5552. {
  5553. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5554. /* do not modify other values in the register */
  5555. reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
  5556. reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
  5557. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5558. }
  5559. /*
  5560. * Set up initial VL15 credits of the remote. Assumes the rest of
  5561. * the CM credit registers are zero from a previous global or credit reset.
  5562. * Shared limit for VL15 will always be 0.
  5563. */
  5564. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
  5565. {
  5566. u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  5567. /* set initial values for total and shared credit limit */
  5568. reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
  5569. SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
  5570. /*
  5571. * Set total limit to be equal to VL15 credits.
  5572. * Leave shared limit at 0.
  5573. */
  5574. reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  5575. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  5576. write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
  5577. << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
  5578. }
  5579. /*
  5580. * Zero all credit details from the previous connection and
  5581. * reset the CM manager's internal counters.
  5582. */
  5583. void reset_link_credits(struct hfi1_devdata *dd)
  5584. {
  5585. int i;
  5586. /* remove all previous VL credit limits */
  5587. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  5588. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  5589. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  5590. write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
  5591. /* reset the CM block */
  5592. pio_send_control(dd, PSC_CM_RESET);
  5593. /* reset cached value */
  5594. dd->vl15buf_cached = 0;
  5595. }
  5596. /* convert a vCU to a CU */
  5597. static u32 vcu_to_cu(u8 vcu)
  5598. {
  5599. return 1 << vcu;
  5600. }
  5601. /* convert a CU to a vCU */
  5602. static u8 cu_to_vcu(u32 cu)
  5603. {
  5604. return ilog2(cu);
  5605. }
  5606. /* convert a vAU to an AU */
  5607. static u32 vau_to_au(u8 vau)
  5608. {
  5609. return 8 * (1 << vau);
  5610. }
  5611. static void set_linkup_defaults(struct hfi1_pportdata *ppd)
  5612. {
  5613. ppd->sm_trap_qp = 0x0;
  5614. ppd->sa_qp = 0x1;
  5615. }
  5616. /*
  5617. * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
  5618. */
  5619. static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
  5620. {
  5621. u64 reg;
  5622. /* clear lcb run: LCB_CFG_RUN.EN = 0 */
  5623. write_csr(dd, DC_LCB_CFG_RUN, 0);
  5624. /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
  5625. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
  5626. 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
  5627. /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
  5628. dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
  5629. reg = read_csr(dd, DCC_CFG_RESET);
  5630. write_csr(dd, DCC_CFG_RESET, reg |
  5631. (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
  5632. (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
  5633. (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
  5634. if (!abort) {
  5635. udelay(1); /* must hold for the longer of 16cclks or 20ns */
  5636. write_csr(dd, DCC_CFG_RESET, reg);
  5637. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5638. }
  5639. }
  5640. /*
  5641. * This routine should be called after the link has been transitioned to
  5642. * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
  5643. * reset).
  5644. *
  5645. * The expectation is that the caller of this routine would have taken
  5646. * care of properly transitioning the link into the correct state.
  5647. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5648. * before calling this function.
  5649. */
  5650. static void _dc_shutdown(struct hfi1_devdata *dd)
  5651. {
  5652. lockdep_assert_held(&dd->dc8051_lock);
  5653. if (dd->dc_shutdown)
  5654. return;
  5655. dd->dc_shutdown = 1;
  5656. /* Shutdown the LCB */
  5657. lcb_shutdown(dd, 1);
  5658. /*
  5659. * Going to OFFLINE would have causes the 8051 to put the
  5660. * SerDes into reset already. Just need to shut down the 8051,
  5661. * itself.
  5662. */
  5663. write_csr(dd, DC_DC8051_CFG_RST, 0x1);
  5664. }
  5665. static void dc_shutdown(struct hfi1_devdata *dd)
  5666. {
  5667. mutex_lock(&dd->dc8051_lock);
  5668. _dc_shutdown(dd);
  5669. mutex_unlock(&dd->dc8051_lock);
  5670. }
  5671. /*
  5672. * Calling this after the DC has been brought out of reset should not
  5673. * do any damage.
  5674. * NOTE: the caller needs to acquire the dd->dc8051_lock lock
  5675. * before calling this function.
  5676. */
  5677. static void _dc_start(struct hfi1_devdata *dd)
  5678. {
  5679. lockdep_assert_held(&dd->dc8051_lock);
  5680. if (!dd->dc_shutdown)
  5681. return;
  5682. /*
  5683. * Take the 8051 out of reset, wait until 8051 is ready, and set host
  5684. * version bit.
  5685. */
  5686. release_and_wait_ready_8051_firmware(dd);
  5687. /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
  5688. write_csr(dd, DCC_CFG_RESET, 0x10);
  5689. /* lcb_shutdown() with abort=1 does not restore these */
  5690. write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
  5691. dd->dc_shutdown = 0;
  5692. }
  5693. static void dc_start(struct hfi1_devdata *dd)
  5694. {
  5695. mutex_lock(&dd->dc8051_lock);
  5696. _dc_start(dd);
  5697. mutex_unlock(&dd->dc8051_lock);
  5698. }
  5699. /*
  5700. * These LCB adjustments are for the Aurora SerDes core in the FPGA.
  5701. */
  5702. static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
  5703. {
  5704. u64 rx_radr, tx_radr;
  5705. u32 version;
  5706. if (dd->icode != ICODE_FPGA_EMULATION)
  5707. return;
  5708. /*
  5709. * These LCB defaults on emulator _s are good, nothing to do here:
  5710. * LCB_CFG_TX_FIFOS_RADR
  5711. * LCB_CFG_RX_FIFOS_RADR
  5712. * LCB_CFG_LN_DCLK
  5713. * LCB_CFG_IGNORE_LOST_RCLK
  5714. */
  5715. if (is_emulator_s(dd))
  5716. return;
  5717. /* else this is _p */
  5718. version = emulator_rev(dd);
  5719. if (!is_ax(dd))
  5720. version = 0x2d; /* all B0 use 0x2d or higher settings */
  5721. if (version <= 0x12) {
  5722. /* release 0x12 and below */
  5723. /*
  5724. * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
  5725. * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
  5726. * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
  5727. */
  5728. rx_radr =
  5729. 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5730. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5731. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5732. /*
  5733. * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
  5734. * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
  5735. */
  5736. tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5737. } else if (version <= 0x18) {
  5738. /* release 0x13 up to 0x18 */
  5739. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5740. rx_radr =
  5741. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5742. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5743. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5744. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5745. } else if (version == 0x19) {
  5746. /* release 0x19 */
  5747. /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
  5748. rx_radr =
  5749. 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5750. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5751. | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5752. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5753. } else if (version == 0x1a) {
  5754. /* release 0x1a */
  5755. /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
  5756. rx_radr =
  5757. 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5758. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5759. | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5760. tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5761. write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
  5762. } else {
  5763. /* release 0x1b and higher */
  5764. /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
  5765. rx_radr =
  5766. 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
  5767. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
  5768. | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
  5769. tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
  5770. }
  5771. write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
  5772. /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
  5773. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  5774. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  5775. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
  5776. }
  5777. /*
  5778. * Handle a SMA idle message
  5779. *
  5780. * This is a work-queue function outside of the interrupt.
  5781. */
  5782. void handle_sma_message(struct work_struct *work)
  5783. {
  5784. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5785. sma_message_work);
  5786. struct hfi1_devdata *dd = ppd->dd;
  5787. u64 msg;
  5788. int ret;
  5789. /*
  5790. * msg is bytes 1-4 of the 40-bit idle message - the command code
  5791. * is stripped off
  5792. */
  5793. ret = read_idle_sma(dd, &msg);
  5794. if (ret)
  5795. return;
  5796. dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
  5797. /*
  5798. * React to the SMA message. Byte[1] (0 for us) is the command.
  5799. */
  5800. switch (msg & 0xff) {
  5801. case SMA_IDLE_ARM:
  5802. /*
  5803. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5804. * State Transitions
  5805. *
  5806. * Only expected in INIT or ARMED, discard otherwise.
  5807. */
  5808. if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
  5809. ppd->neighbor_normal = 1;
  5810. break;
  5811. case SMA_IDLE_ACTIVE:
  5812. /*
  5813. * See OPAv1 table 9-14 - HFI and External Switch Ports Key
  5814. * State Transitions
  5815. *
  5816. * Can activate the node. Discard otherwise.
  5817. */
  5818. if (ppd->host_link_state == HLS_UP_ARMED &&
  5819. ppd->is_active_optimize_enabled) {
  5820. ppd->neighbor_normal = 1;
  5821. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  5822. if (ret)
  5823. dd_dev_err(
  5824. dd,
  5825. "%s: received Active SMA idle message, couldn't set link to Active\n",
  5826. __func__);
  5827. }
  5828. break;
  5829. default:
  5830. dd_dev_err(dd,
  5831. "%s: received unexpected SMA idle message 0x%llx\n",
  5832. __func__, msg);
  5833. break;
  5834. }
  5835. }
  5836. static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
  5837. {
  5838. u64 rcvctrl;
  5839. unsigned long flags;
  5840. spin_lock_irqsave(&dd->rcvctrl_lock, flags);
  5841. rcvctrl = read_csr(dd, RCV_CTRL);
  5842. rcvctrl |= add;
  5843. rcvctrl &= ~clear;
  5844. write_csr(dd, RCV_CTRL, rcvctrl);
  5845. spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
  5846. }
  5847. static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
  5848. {
  5849. adjust_rcvctrl(dd, add, 0);
  5850. }
  5851. static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
  5852. {
  5853. adjust_rcvctrl(dd, 0, clear);
  5854. }
  5855. /*
  5856. * Called from all interrupt handlers to start handling an SPC freeze.
  5857. */
  5858. void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
  5859. {
  5860. struct hfi1_devdata *dd = ppd->dd;
  5861. struct send_context *sc;
  5862. int i;
  5863. if (flags & FREEZE_SELF)
  5864. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5865. /* enter frozen mode */
  5866. dd->flags |= HFI1_FROZEN;
  5867. /* notify all SDMA engines that they are going into a freeze */
  5868. sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
  5869. /* do halt pre-handling on all enabled send contexts */
  5870. for (i = 0; i < dd->num_send_contexts; i++) {
  5871. sc = dd->send_contexts[i].sc;
  5872. if (sc && (sc->flags & SCF_ENABLED))
  5873. sc_stop(sc, SCF_FROZEN | SCF_HALTED);
  5874. }
  5875. /* Send context are frozen. Notify user space */
  5876. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
  5877. if (flags & FREEZE_ABORT) {
  5878. dd_dev_err(dd,
  5879. "Aborted freeze recovery. Please REBOOT system\n");
  5880. return;
  5881. }
  5882. /* queue non-interrupt handler */
  5883. queue_work(ppd->hfi1_wq, &ppd->freeze_work);
  5884. }
  5885. /*
  5886. * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
  5887. * depending on the "freeze" parameter.
  5888. *
  5889. * No need to return an error if it times out, our only option
  5890. * is to proceed anyway.
  5891. */
  5892. static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
  5893. {
  5894. unsigned long timeout;
  5895. u64 reg;
  5896. timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
  5897. while (1) {
  5898. reg = read_csr(dd, CCE_STATUS);
  5899. if (freeze) {
  5900. /* waiting until all indicators are set */
  5901. if ((reg & ALL_FROZE) == ALL_FROZE)
  5902. return; /* all done */
  5903. } else {
  5904. /* waiting until all indicators are clear */
  5905. if ((reg & ALL_FROZE) == 0)
  5906. return; /* all done */
  5907. }
  5908. if (time_after(jiffies, timeout)) {
  5909. dd_dev_err(dd,
  5910. "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
  5911. freeze ? "" : "un", reg & ALL_FROZE,
  5912. freeze ? ALL_FROZE : 0ull);
  5913. return;
  5914. }
  5915. usleep_range(80, 120);
  5916. }
  5917. }
  5918. /*
  5919. * Do all freeze handling for the RXE block.
  5920. */
  5921. static void rxe_freeze(struct hfi1_devdata *dd)
  5922. {
  5923. int i;
  5924. struct hfi1_ctxtdata *rcd;
  5925. /* disable port */
  5926. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5927. /* disable all receive contexts */
  5928. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5929. rcd = hfi1_rcd_get_by_index(dd, i);
  5930. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
  5931. hfi1_rcd_put(rcd);
  5932. }
  5933. }
  5934. /*
  5935. * Unfreeze handling for the RXE block - kernel contexts only.
  5936. * This will also enable the port. User contexts will do unfreeze
  5937. * handling on a per-context basis as they call into the driver.
  5938. *
  5939. */
  5940. static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
  5941. {
  5942. u32 rcvmask;
  5943. u16 i;
  5944. struct hfi1_ctxtdata *rcd;
  5945. /* enable all kernel contexts */
  5946. for (i = 0; i < dd->num_rcv_contexts; i++) {
  5947. rcd = hfi1_rcd_get_by_index(dd, i);
  5948. /* Ensure all non-user contexts(including vnic) are enabled */
  5949. if (!rcd ||
  5950. (i >= dd->first_dyn_alloc_ctxt && !rcd->is_vnic)) {
  5951. hfi1_rcd_put(rcd);
  5952. continue;
  5953. }
  5954. rcvmask = HFI1_RCVCTRL_CTXT_ENB;
  5955. /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
  5956. rcvmask |= HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
  5957. HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
  5958. hfi1_rcvctrl(dd, rcvmask, rcd);
  5959. hfi1_rcd_put(rcd);
  5960. }
  5961. /* enable port */
  5962. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  5963. }
  5964. /*
  5965. * Non-interrupt SPC freeze handling.
  5966. *
  5967. * This is a work-queue function outside of the triggering interrupt.
  5968. */
  5969. void handle_freeze(struct work_struct *work)
  5970. {
  5971. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  5972. freeze_work);
  5973. struct hfi1_devdata *dd = ppd->dd;
  5974. /* wait for freeze indicators on all affected blocks */
  5975. wait_for_freeze_status(dd, 1);
  5976. /* SPC is now frozen */
  5977. /* do send PIO freeze steps */
  5978. pio_freeze(dd);
  5979. /* do send DMA freeze steps */
  5980. sdma_freeze(dd);
  5981. /* do send egress freeze steps - nothing to do */
  5982. /* do receive freeze steps */
  5983. rxe_freeze(dd);
  5984. /*
  5985. * Unfreeze the hardware - clear the freeze, wait for each
  5986. * block's frozen bit to clear, then clear the frozen flag.
  5987. */
  5988. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5989. wait_for_freeze_status(dd, 0);
  5990. if (is_ax(dd)) {
  5991. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
  5992. wait_for_freeze_status(dd, 1);
  5993. write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
  5994. wait_for_freeze_status(dd, 0);
  5995. }
  5996. /* do send PIO unfreeze steps for kernel contexts */
  5997. pio_kernel_unfreeze(dd);
  5998. /* do send DMA unfreeze steps */
  5999. sdma_unfreeze(dd);
  6000. /* do send egress unfreeze steps - nothing to do */
  6001. /* do receive unfreeze steps for kernel contexts */
  6002. rxe_kernel_unfreeze(dd);
  6003. /*
  6004. * The unfreeze procedure touches global device registers when
  6005. * it disables and re-enables RXE. Mark the device unfrozen
  6006. * after all that is done so other parts of the driver waiting
  6007. * for the device to unfreeze don't do things out of order.
  6008. *
  6009. * The above implies that the meaning of HFI1_FROZEN flag is
  6010. * "Device has gone into freeze mode and freeze mode handling
  6011. * is still in progress."
  6012. *
  6013. * The flag will be removed when freeze mode processing has
  6014. * completed.
  6015. */
  6016. dd->flags &= ~HFI1_FROZEN;
  6017. wake_up(&dd->event_queue);
  6018. /* no longer frozen */
  6019. }
  6020. /*
  6021. * Handle a link up interrupt from the 8051.
  6022. *
  6023. * This is a work-queue function outside of the interrupt.
  6024. */
  6025. void handle_link_up(struct work_struct *work)
  6026. {
  6027. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6028. link_up_work);
  6029. struct hfi1_devdata *dd = ppd->dd;
  6030. set_link_state(ppd, HLS_UP_INIT);
  6031. /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  6032. read_ltp_rtt(dd);
  6033. /*
  6034. * OPA specifies that certain counters are cleared on a transition
  6035. * to link up, so do that.
  6036. */
  6037. clear_linkup_counters(dd);
  6038. /*
  6039. * And (re)set link up default values.
  6040. */
  6041. set_linkup_defaults(ppd);
  6042. /*
  6043. * Set VL15 credits. Use cached value from verify cap interrupt.
  6044. * In case of quick linkup or simulator, vl15 value will be set by
  6045. * handle_linkup_change. VerifyCap interrupt handler will not be
  6046. * called in those scenarios.
  6047. */
  6048. if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
  6049. set_up_vl15(dd, dd->vl15buf_cached);
  6050. /* enforce link speed enabled */
  6051. if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
  6052. /* oops - current speed is not enabled, bounce */
  6053. dd_dev_err(dd,
  6054. "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
  6055. ppd->link_speed_active, ppd->link_speed_enabled);
  6056. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
  6057. OPA_LINKDOWN_REASON_SPEED_POLICY);
  6058. set_link_state(ppd, HLS_DN_OFFLINE);
  6059. start_link(ppd);
  6060. }
  6061. }
  6062. /*
  6063. * Several pieces of LNI information were cached for SMA in ppd.
  6064. * Reset these on link down
  6065. */
  6066. static void reset_neighbor_info(struct hfi1_pportdata *ppd)
  6067. {
  6068. ppd->neighbor_guid = 0;
  6069. ppd->neighbor_port_number = 0;
  6070. ppd->neighbor_type = 0;
  6071. ppd->neighbor_fm_security = 0;
  6072. }
  6073. static const char * const link_down_reason_strs[] = {
  6074. [OPA_LINKDOWN_REASON_NONE] = "None",
  6075. [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
  6076. [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
  6077. [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
  6078. [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
  6079. [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
  6080. [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
  6081. [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
  6082. [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
  6083. [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
  6084. [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
  6085. [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
  6086. [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
  6087. [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
  6088. [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
  6089. [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
  6090. [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
  6091. [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
  6092. [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
  6093. [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
  6094. [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
  6095. [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
  6096. [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
  6097. [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
  6098. [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
  6099. [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
  6100. [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
  6101. [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
  6102. [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
  6103. [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
  6104. [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
  6105. [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
  6106. [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
  6107. "Excessive buffer overrun",
  6108. [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
  6109. [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
  6110. [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
  6111. [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
  6112. [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
  6113. [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
  6114. [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
  6115. [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
  6116. "Local media not installed",
  6117. [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
  6118. [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
  6119. [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
  6120. "End to end not installed",
  6121. [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
  6122. [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
  6123. [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
  6124. [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
  6125. [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
  6126. [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
  6127. };
  6128. /* return the neighbor link down reason string */
  6129. static const char *link_down_reason_str(u8 reason)
  6130. {
  6131. const char *str = NULL;
  6132. if (reason < ARRAY_SIZE(link_down_reason_strs))
  6133. str = link_down_reason_strs[reason];
  6134. if (!str)
  6135. str = "(invalid)";
  6136. return str;
  6137. }
  6138. /*
  6139. * Handle a link down interrupt from the 8051.
  6140. *
  6141. * This is a work-queue function outside of the interrupt.
  6142. */
  6143. void handle_link_down(struct work_struct *work)
  6144. {
  6145. u8 lcl_reason, neigh_reason = 0;
  6146. u8 link_down_reason;
  6147. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6148. link_down_work);
  6149. int was_up;
  6150. static const char ldr_str[] = "Link down reason: ";
  6151. if ((ppd->host_link_state &
  6152. (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
  6153. ppd->port_type == PORT_TYPE_FIXED)
  6154. ppd->offline_disabled_reason =
  6155. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
  6156. /* Go offline first, then deal with reading/writing through 8051 */
  6157. was_up = !!(ppd->host_link_state & HLS_UP);
  6158. set_link_state(ppd, HLS_DN_OFFLINE);
  6159. xchg(&ppd->is_link_down_queued, 0);
  6160. if (was_up) {
  6161. lcl_reason = 0;
  6162. /* link down reason is only valid if the link was up */
  6163. read_link_down_reason(ppd->dd, &link_down_reason);
  6164. switch (link_down_reason) {
  6165. case LDR_LINK_TRANSFER_ACTIVE_LOW:
  6166. /* the link went down, no idle message reason */
  6167. dd_dev_info(ppd->dd, "%sUnexpected link down\n",
  6168. ldr_str);
  6169. break;
  6170. case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
  6171. /*
  6172. * The neighbor reason is only valid if an idle message
  6173. * was received for it.
  6174. */
  6175. read_planned_down_reason_code(ppd->dd, &neigh_reason);
  6176. dd_dev_info(ppd->dd,
  6177. "%sNeighbor link down message %d, %s\n",
  6178. ldr_str, neigh_reason,
  6179. link_down_reason_str(neigh_reason));
  6180. break;
  6181. case LDR_RECEIVED_HOST_OFFLINE_REQ:
  6182. dd_dev_info(ppd->dd,
  6183. "%sHost requested link to go offline\n",
  6184. ldr_str);
  6185. break;
  6186. default:
  6187. dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
  6188. ldr_str, link_down_reason);
  6189. break;
  6190. }
  6191. /*
  6192. * If no reason, assume peer-initiated but missed
  6193. * LinkGoingDown idle flits.
  6194. */
  6195. if (neigh_reason == 0)
  6196. lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
  6197. } else {
  6198. /* went down while polling or going up */
  6199. lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
  6200. }
  6201. set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
  6202. /* inform the SMA when the link transitions from up to down */
  6203. if (was_up && ppd->local_link_down_reason.sma == 0 &&
  6204. ppd->neigh_link_down_reason.sma == 0) {
  6205. ppd->local_link_down_reason.sma =
  6206. ppd->local_link_down_reason.latest;
  6207. ppd->neigh_link_down_reason.sma =
  6208. ppd->neigh_link_down_reason.latest;
  6209. }
  6210. reset_neighbor_info(ppd);
  6211. /* disable the port */
  6212. clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  6213. /*
  6214. * If there is no cable attached, turn the DC off. Otherwise,
  6215. * start the link bring up.
  6216. */
  6217. if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
  6218. dc_shutdown(ppd->dd);
  6219. else
  6220. start_link(ppd);
  6221. }
  6222. void handle_link_bounce(struct work_struct *work)
  6223. {
  6224. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6225. link_bounce_work);
  6226. /*
  6227. * Only do something if the link is currently up.
  6228. */
  6229. if (ppd->host_link_state & HLS_UP) {
  6230. set_link_state(ppd, HLS_DN_OFFLINE);
  6231. start_link(ppd);
  6232. } else {
  6233. dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
  6234. __func__, link_state_name(ppd->host_link_state));
  6235. }
  6236. }
  6237. /*
  6238. * Mask conversion: Capability exchange to Port LTP. The capability
  6239. * exchange has an implicit 16b CRC that is mandatory.
  6240. */
  6241. static int cap_to_port_ltp(int cap)
  6242. {
  6243. int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
  6244. if (cap & CAP_CRC_14B)
  6245. port_ltp |= PORT_LTP_CRC_MODE_14;
  6246. if (cap & CAP_CRC_48B)
  6247. port_ltp |= PORT_LTP_CRC_MODE_48;
  6248. if (cap & CAP_CRC_12B_16B_PER_LANE)
  6249. port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
  6250. return port_ltp;
  6251. }
  6252. /*
  6253. * Convert an OPA Port LTP mask to capability mask
  6254. */
  6255. int port_ltp_to_cap(int port_ltp)
  6256. {
  6257. int cap_mask = 0;
  6258. if (port_ltp & PORT_LTP_CRC_MODE_14)
  6259. cap_mask |= CAP_CRC_14B;
  6260. if (port_ltp & PORT_LTP_CRC_MODE_48)
  6261. cap_mask |= CAP_CRC_48B;
  6262. if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
  6263. cap_mask |= CAP_CRC_12B_16B_PER_LANE;
  6264. return cap_mask;
  6265. }
  6266. /*
  6267. * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
  6268. */
  6269. static int lcb_to_port_ltp(int lcb_crc)
  6270. {
  6271. int port_ltp = 0;
  6272. if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
  6273. port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
  6274. else if (lcb_crc == LCB_CRC_48B)
  6275. port_ltp = PORT_LTP_CRC_MODE_48;
  6276. else if (lcb_crc == LCB_CRC_14B)
  6277. port_ltp = PORT_LTP_CRC_MODE_14;
  6278. else
  6279. port_ltp = PORT_LTP_CRC_MODE_16;
  6280. return port_ltp;
  6281. }
  6282. static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  6283. {
  6284. if (ppd->pkeys[2] != 0) {
  6285. ppd->pkeys[2] = 0;
  6286. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  6287. hfi1_event_pkey_change(ppd->dd, ppd->port);
  6288. }
  6289. }
  6290. /*
  6291. * Convert the given link width to the OPA link width bitmask.
  6292. */
  6293. static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
  6294. {
  6295. switch (width) {
  6296. case 0:
  6297. /*
  6298. * Simulator and quick linkup do not set the width.
  6299. * Just set it to 4x without complaint.
  6300. */
  6301. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
  6302. return OPA_LINK_WIDTH_4X;
  6303. return 0; /* no lanes up */
  6304. case 1: return OPA_LINK_WIDTH_1X;
  6305. case 2: return OPA_LINK_WIDTH_2X;
  6306. case 3: return OPA_LINK_WIDTH_3X;
  6307. default:
  6308. dd_dev_info(dd, "%s: invalid width %d, using 4\n",
  6309. __func__, width);
  6310. /* fall through */
  6311. case 4: return OPA_LINK_WIDTH_4X;
  6312. }
  6313. }
  6314. /*
  6315. * Do a population count on the bottom nibble.
  6316. */
  6317. static const u8 bit_counts[16] = {
  6318. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  6319. };
  6320. static inline u8 nibble_to_count(u8 nibble)
  6321. {
  6322. return bit_counts[nibble & 0xf];
  6323. }
  6324. /*
  6325. * Read the active lane information from the 8051 registers and return
  6326. * their widths.
  6327. *
  6328. * Active lane information is found in these 8051 registers:
  6329. * enable_lane_tx
  6330. * enable_lane_rx
  6331. */
  6332. static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6333. u16 *rx_width)
  6334. {
  6335. u16 tx, rx;
  6336. u8 enable_lane_rx;
  6337. u8 enable_lane_tx;
  6338. u8 tx_polarity_inversion;
  6339. u8 rx_polarity_inversion;
  6340. u8 max_rate;
  6341. /* read the active lanes */
  6342. read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  6343. &rx_polarity_inversion, &max_rate);
  6344. read_local_lni(dd, &enable_lane_rx);
  6345. /* convert to counts */
  6346. tx = nibble_to_count(enable_lane_tx);
  6347. rx = nibble_to_count(enable_lane_rx);
  6348. /*
  6349. * Set link_speed_active here, overriding what was set in
  6350. * handle_verify_cap(). The ASIC 8051 firmware does not correctly
  6351. * set the max_rate field in handle_verify_cap until v0.19.
  6352. */
  6353. if ((dd->icode == ICODE_RTL_SILICON) &&
  6354. (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
  6355. /* max_rate: 0 = 12.5G, 1 = 25G */
  6356. switch (max_rate) {
  6357. case 0:
  6358. dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
  6359. break;
  6360. default:
  6361. dd_dev_err(dd,
  6362. "%s: unexpected max rate %d, using 25Gb\n",
  6363. __func__, (int)max_rate);
  6364. /* fall through */
  6365. case 1:
  6366. dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
  6367. break;
  6368. }
  6369. }
  6370. dd_dev_info(dd,
  6371. "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
  6372. enable_lane_tx, tx, enable_lane_rx, rx);
  6373. *tx_width = link_width_to_bits(dd, tx);
  6374. *rx_width = link_width_to_bits(dd, rx);
  6375. }
  6376. /*
  6377. * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
  6378. * Valid after the end of VerifyCap and during LinkUp. Does not change
  6379. * after link up. I.e. look elsewhere for downgrade information.
  6380. *
  6381. * Bits are:
  6382. * + bits [7:4] contain the number of active transmitters
  6383. * + bits [3:0] contain the number of active receivers
  6384. * These are numbers 1 through 4 and can be different values if the
  6385. * link is asymmetric.
  6386. *
  6387. * verify_cap_local_fm_link_width[0] retains its original value.
  6388. */
  6389. static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
  6390. u16 *rx_width)
  6391. {
  6392. u16 widths, tx, rx;
  6393. u8 misc_bits, local_flags;
  6394. u16 active_tx, active_rx;
  6395. read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
  6396. tx = widths >> 12;
  6397. rx = (widths >> 8) & 0xf;
  6398. *tx_width = link_width_to_bits(dd, tx);
  6399. *rx_width = link_width_to_bits(dd, rx);
  6400. /* print the active widths */
  6401. get_link_widths(dd, &active_tx, &active_rx);
  6402. }
  6403. /*
  6404. * Set ppd->link_width_active and ppd->link_width_downgrade_active using
  6405. * hardware information when the link first comes up.
  6406. *
  6407. * The link width is not available until after VerifyCap.AllFramesReceived
  6408. * (the trigger for handle_verify_cap), so this is outside that routine
  6409. * and should be called when the 8051 signals linkup.
  6410. */
  6411. void get_linkup_link_widths(struct hfi1_pportdata *ppd)
  6412. {
  6413. u16 tx_width, rx_width;
  6414. /* get end-of-LNI link widths */
  6415. get_linkup_widths(ppd->dd, &tx_width, &rx_width);
  6416. /* use tx_width as the link is supposed to be symmetric on link up */
  6417. ppd->link_width_active = tx_width;
  6418. /* link width downgrade active (LWD.A) starts out matching LW.A */
  6419. ppd->link_width_downgrade_tx_active = ppd->link_width_active;
  6420. ppd->link_width_downgrade_rx_active = ppd->link_width_active;
  6421. /* per OPA spec, on link up LWD.E resets to LWD.S */
  6422. ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
  6423. /* cache the active egress rate (units {10^6 bits/sec]) */
  6424. ppd->current_egress_rate = active_egress_rate(ppd);
  6425. }
  6426. /*
  6427. * Handle a verify capabilities interrupt from the 8051.
  6428. *
  6429. * This is a work-queue function outside of the interrupt.
  6430. */
  6431. void handle_verify_cap(struct work_struct *work)
  6432. {
  6433. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6434. link_vc_work);
  6435. struct hfi1_devdata *dd = ppd->dd;
  6436. u64 reg;
  6437. u8 power_management;
  6438. u8 continuous;
  6439. u8 vcu;
  6440. u8 vau;
  6441. u8 z;
  6442. u16 vl15buf;
  6443. u16 link_widths;
  6444. u16 crc_mask;
  6445. u16 crc_val;
  6446. u16 device_id;
  6447. u16 active_tx, active_rx;
  6448. u8 partner_supported_crc;
  6449. u8 remote_tx_rate;
  6450. u8 device_rev;
  6451. set_link_state(ppd, HLS_VERIFY_CAP);
  6452. lcb_shutdown(dd, 0);
  6453. adjust_lcb_for_fpga_serdes(dd);
  6454. read_vc_remote_phy(dd, &power_management, &continuous);
  6455. read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
  6456. &partner_supported_crc);
  6457. read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
  6458. read_remote_device_id(dd, &device_id, &device_rev);
  6459. /* print the active widths */
  6460. get_link_widths(dd, &active_tx, &active_rx);
  6461. dd_dev_info(dd,
  6462. "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
  6463. (int)power_management, (int)continuous);
  6464. dd_dev_info(dd,
  6465. "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
  6466. (int)vau, (int)z, (int)vcu, (int)vl15buf,
  6467. (int)partner_supported_crc);
  6468. dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
  6469. (u32)remote_tx_rate, (u32)link_widths);
  6470. dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
  6471. (u32)device_id, (u32)device_rev);
  6472. /*
  6473. * The peer vAU value just read is the peer receiver value. HFI does
  6474. * not support a transmit vAU of 0 (AU == 8). We advertised that
  6475. * with Z=1 in the fabric capabilities sent to the peer. The peer
  6476. * will see our Z=1, and, if it advertised a vAU of 0, will move its
  6477. * receive to vAU of 1 (AU == 16). Do the same here. We do not care
  6478. * about the peer Z value - our sent vAU is 3 (hardwired) and is not
  6479. * subject to the Z value exception.
  6480. */
  6481. if (vau == 0)
  6482. vau = 1;
  6483. set_up_vau(dd, vau);
  6484. /*
  6485. * Set VL15 credits to 0 in global credit register. Cache remote VL15
  6486. * credits value and wait for link-up interrupt ot set it.
  6487. */
  6488. set_up_vl15(dd, 0);
  6489. dd->vl15buf_cached = vl15buf;
  6490. /* set up the LCB CRC mode */
  6491. crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
  6492. /* order is important: use the lowest bit in common */
  6493. if (crc_mask & CAP_CRC_14B)
  6494. crc_val = LCB_CRC_14B;
  6495. else if (crc_mask & CAP_CRC_48B)
  6496. crc_val = LCB_CRC_48B;
  6497. else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
  6498. crc_val = LCB_CRC_12B_16B_PER_LANE;
  6499. else
  6500. crc_val = LCB_CRC_16B;
  6501. dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
  6502. write_csr(dd, DC_LCB_CFG_CRC_MODE,
  6503. (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
  6504. /* set (14b only) or clear sideband credit */
  6505. reg = read_csr(dd, SEND_CM_CTRL);
  6506. if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
  6507. write_csr(dd, SEND_CM_CTRL,
  6508. reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6509. } else {
  6510. write_csr(dd, SEND_CM_CTRL,
  6511. reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
  6512. }
  6513. ppd->link_speed_active = 0; /* invalid value */
  6514. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  6515. /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
  6516. switch (remote_tx_rate) {
  6517. case 0:
  6518. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6519. break;
  6520. case 1:
  6521. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6522. break;
  6523. }
  6524. } else {
  6525. /* actual rate is highest bit of the ANDed rates */
  6526. u8 rate = remote_tx_rate & ppd->local_tx_rate;
  6527. if (rate & 2)
  6528. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6529. else if (rate & 1)
  6530. ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
  6531. }
  6532. if (ppd->link_speed_active == 0) {
  6533. dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
  6534. __func__, (int)remote_tx_rate);
  6535. ppd->link_speed_active = OPA_LINK_SPEED_25G;
  6536. }
  6537. /*
  6538. * Cache the values of the supported, enabled, and active
  6539. * LTP CRC modes to return in 'portinfo' queries. But the bit
  6540. * flags that are returned in the portinfo query differ from
  6541. * what's in the link_crc_mask, crc_sizes, and crc_val
  6542. * variables. Convert these here.
  6543. */
  6544. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  6545. /* supported crc modes */
  6546. ppd->port_ltp_crc_mode |=
  6547. cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
  6548. /* enabled crc modes */
  6549. ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
  6550. /* active crc mode */
  6551. /* set up the remote credit return table */
  6552. assign_remote_cm_au_table(dd, vcu);
  6553. /*
  6554. * The LCB is reset on entry to handle_verify_cap(), so this must
  6555. * be applied on every link up.
  6556. *
  6557. * Adjust LCB error kill enable to kill the link if
  6558. * these RBUF errors are seen:
  6559. * REPLAY_BUF_MBE_SMASK
  6560. * FLIT_INPUT_BUF_MBE_SMASK
  6561. */
  6562. if (is_ax(dd)) { /* fixed in B0 */
  6563. reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
  6564. reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
  6565. | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
  6566. write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
  6567. }
  6568. /* pull LCB fifos out of reset - all fifo clocks must be stable */
  6569. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  6570. /* give 8051 access to the LCB CSRs */
  6571. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  6572. set_8051_lcb_access(dd);
  6573. /* tell the 8051 to go to LinkUp */
  6574. set_link_state(ppd, HLS_GOING_UP);
  6575. }
  6576. /*
  6577. * Apply the link width downgrade enabled policy against the current active
  6578. * link widths.
  6579. *
  6580. * Called when the enabled policy changes or the active link widths change.
  6581. */
  6582. void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
  6583. {
  6584. int do_bounce = 0;
  6585. int tries;
  6586. u16 lwde;
  6587. u16 tx, rx;
  6588. /* use the hls lock to avoid a race with actual link up */
  6589. tries = 0;
  6590. retry:
  6591. mutex_lock(&ppd->hls_lock);
  6592. /* only apply if the link is up */
  6593. if (ppd->host_link_state & HLS_DOWN) {
  6594. /* still going up..wait and retry */
  6595. if (ppd->host_link_state & HLS_GOING_UP) {
  6596. if (++tries < 1000) {
  6597. mutex_unlock(&ppd->hls_lock);
  6598. usleep_range(100, 120); /* arbitrary */
  6599. goto retry;
  6600. }
  6601. dd_dev_err(ppd->dd,
  6602. "%s: giving up waiting for link state change\n",
  6603. __func__);
  6604. }
  6605. goto done;
  6606. }
  6607. lwde = ppd->link_width_downgrade_enabled;
  6608. if (refresh_widths) {
  6609. get_link_widths(ppd->dd, &tx, &rx);
  6610. ppd->link_width_downgrade_tx_active = tx;
  6611. ppd->link_width_downgrade_rx_active = rx;
  6612. }
  6613. if (ppd->link_width_downgrade_tx_active == 0 ||
  6614. ppd->link_width_downgrade_rx_active == 0) {
  6615. /* the 8051 reported a dead link as a downgrade */
  6616. dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
  6617. } else if (lwde == 0) {
  6618. /* downgrade is disabled */
  6619. /* bounce if not at starting active width */
  6620. if ((ppd->link_width_active !=
  6621. ppd->link_width_downgrade_tx_active) ||
  6622. (ppd->link_width_active !=
  6623. ppd->link_width_downgrade_rx_active)) {
  6624. dd_dev_err(ppd->dd,
  6625. "Link downgrade is disabled and link has downgraded, downing link\n");
  6626. dd_dev_err(ppd->dd,
  6627. " original 0x%x, tx active 0x%x, rx active 0x%x\n",
  6628. ppd->link_width_active,
  6629. ppd->link_width_downgrade_tx_active,
  6630. ppd->link_width_downgrade_rx_active);
  6631. do_bounce = 1;
  6632. }
  6633. } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
  6634. (lwde & ppd->link_width_downgrade_rx_active) == 0) {
  6635. /* Tx or Rx is outside the enabled policy */
  6636. dd_dev_err(ppd->dd,
  6637. "Link is outside of downgrade allowed, downing link\n");
  6638. dd_dev_err(ppd->dd,
  6639. " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
  6640. lwde, ppd->link_width_downgrade_tx_active,
  6641. ppd->link_width_downgrade_rx_active);
  6642. do_bounce = 1;
  6643. }
  6644. done:
  6645. mutex_unlock(&ppd->hls_lock);
  6646. if (do_bounce) {
  6647. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
  6648. OPA_LINKDOWN_REASON_WIDTH_POLICY);
  6649. set_link_state(ppd, HLS_DN_OFFLINE);
  6650. start_link(ppd);
  6651. }
  6652. }
  6653. /*
  6654. * Handle a link downgrade interrupt from the 8051.
  6655. *
  6656. * This is a work-queue function outside of the interrupt.
  6657. */
  6658. void handle_link_downgrade(struct work_struct *work)
  6659. {
  6660. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  6661. link_downgrade_work);
  6662. dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
  6663. apply_link_downgrade_policy(ppd, 1);
  6664. }
  6665. static char *dcc_err_string(char *buf, int buf_len, u64 flags)
  6666. {
  6667. return flag_string(buf, buf_len, flags, dcc_err_flags,
  6668. ARRAY_SIZE(dcc_err_flags));
  6669. }
  6670. static char *lcb_err_string(char *buf, int buf_len, u64 flags)
  6671. {
  6672. return flag_string(buf, buf_len, flags, lcb_err_flags,
  6673. ARRAY_SIZE(lcb_err_flags));
  6674. }
  6675. static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
  6676. {
  6677. return flag_string(buf, buf_len, flags, dc8051_err_flags,
  6678. ARRAY_SIZE(dc8051_err_flags));
  6679. }
  6680. static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
  6681. {
  6682. return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
  6683. ARRAY_SIZE(dc8051_info_err_flags));
  6684. }
  6685. static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
  6686. {
  6687. return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
  6688. ARRAY_SIZE(dc8051_info_host_msg_flags));
  6689. }
  6690. static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6691. {
  6692. struct hfi1_pportdata *ppd = dd->pport;
  6693. u64 info, err, host_msg;
  6694. int queue_link_down = 0;
  6695. char buf[96];
  6696. /* look at the flags */
  6697. if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
  6698. /* 8051 information set by firmware */
  6699. /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
  6700. info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
  6701. err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
  6702. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
  6703. host_msg = (info >>
  6704. DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
  6705. & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
  6706. /*
  6707. * Handle error flags.
  6708. */
  6709. if (err & FAILED_LNI) {
  6710. /*
  6711. * LNI error indications are cleared by the 8051
  6712. * only when starting polling. Only pay attention
  6713. * to them when in the states that occur during
  6714. * LNI.
  6715. */
  6716. if (ppd->host_link_state
  6717. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  6718. queue_link_down = 1;
  6719. dd_dev_info(dd, "Link error: %s\n",
  6720. dc8051_info_err_string(buf,
  6721. sizeof(buf),
  6722. err &
  6723. FAILED_LNI));
  6724. }
  6725. err &= ~(u64)FAILED_LNI;
  6726. }
  6727. /* unknown frames can happen durning LNI, just count */
  6728. if (err & UNKNOWN_FRAME) {
  6729. ppd->unknown_frame_count++;
  6730. err &= ~(u64)UNKNOWN_FRAME;
  6731. }
  6732. if (err) {
  6733. /* report remaining errors, but do not do anything */
  6734. dd_dev_err(dd, "8051 info error: %s\n",
  6735. dc8051_info_err_string(buf, sizeof(buf),
  6736. err));
  6737. }
  6738. /*
  6739. * Handle host message flags.
  6740. */
  6741. if (host_msg & HOST_REQ_DONE) {
  6742. /*
  6743. * Presently, the driver does a busy wait for
  6744. * host requests to complete. This is only an
  6745. * informational message.
  6746. * NOTE: The 8051 clears the host message
  6747. * information *on the next 8051 command*.
  6748. * Therefore, when linkup is achieved,
  6749. * this flag will still be set.
  6750. */
  6751. host_msg &= ~(u64)HOST_REQ_DONE;
  6752. }
  6753. if (host_msg & BC_SMA_MSG) {
  6754. queue_work(ppd->link_wq, &ppd->sma_message_work);
  6755. host_msg &= ~(u64)BC_SMA_MSG;
  6756. }
  6757. if (host_msg & LINKUP_ACHIEVED) {
  6758. dd_dev_info(dd, "8051: Link up\n");
  6759. queue_work(ppd->link_wq, &ppd->link_up_work);
  6760. host_msg &= ~(u64)LINKUP_ACHIEVED;
  6761. }
  6762. if (host_msg & EXT_DEVICE_CFG_REQ) {
  6763. handle_8051_request(ppd);
  6764. host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
  6765. }
  6766. if (host_msg & VERIFY_CAP_FRAME) {
  6767. queue_work(ppd->link_wq, &ppd->link_vc_work);
  6768. host_msg &= ~(u64)VERIFY_CAP_FRAME;
  6769. }
  6770. if (host_msg & LINK_GOING_DOWN) {
  6771. const char *extra = "";
  6772. /* no downgrade action needed if going down */
  6773. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6774. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6775. extra = " (ignoring downgrade)";
  6776. }
  6777. dd_dev_info(dd, "8051: Link down%s\n", extra);
  6778. queue_link_down = 1;
  6779. host_msg &= ~(u64)LINK_GOING_DOWN;
  6780. }
  6781. if (host_msg & LINK_WIDTH_DOWNGRADED) {
  6782. queue_work(ppd->link_wq, &ppd->link_downgrade_work);
  6783. host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
  6784. }
  6785. if (host_msg) {
  6786. /* report remaining messages, but do not do anything */
  6787. dd_dev_info(dd, "8051 info host message: %s\n",
  6788. dc8051_info_host_msg_string(buf,
  6789. sizeof(buf),
  6790. host_msg));
  6791. }
  6792. reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
  6793. }
  6794. if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
  6795. /*
  6796. * Lost the 8051 heartbeat. If this happens, we
  6797. * receive constant interrupts about it. Disable
  6798. * the interrupt after the first.
  6799. */
  6800. dd_dev_err(dd, "Lost 8051 heartbeat\n");
  6801. write_csr(dd, DC_DC8051_ERR_EN,
  6802. read_csr(dd, DC_DC8051_ERR_EN) &
  6803. ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
  6804. reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
  6805. }
  6806. if (reg) {
  6807. /* report the error, but do not do anything */
  6808. dd_dev_err(dd, "8051 error: %s\n",
  6809. dc8051_err_string(buf, sizeof(buf), reg));
  6810. }
  6811. if (queue_link_down) {
  6812. /*
  6813. * if the link is already going down or disabled, do not
  6814. * queue another. If there's a link down entry already
  6815. * queued, don't queue another one.
  6816. */
  6817. if ((ppd->host_link_state &
  6818. (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
  6819. ppd->link_enabled == 0) {
  6820. dd_dev_info(dd, "%s: not queuing link down. host_link_state %x, link_enabled %x\n",
  6821. __func__, ppd->host_link_state,
  6822. ppd->link_enabled);
  6823. } else {
  6824. if (xchg(&ppd->is_link_down_queued, 1) == 1)
  6825. dd_dev_info(dd,
  6826. "%s: link down request already queued\n",
  6827. __func__);
  6828. else
  6829. queue_work(ppd->link_wq, &ppd->link_down_work);
  6830. }
  6831. }
  6832. }
  6833. static const char * const fm_config_txt[] = {
  6834. [0] =
  6835. "BadHeadDist: Distance violation between two head flits",
  6836. [1] =
  6837. "BadTailDist: Distance violation between two tail flits",
  6838. [2] =
  6839. "BadCtrlDist: Distance violation between two credit control flits",
  6840. [3] =
  6841. "BadCrdAck: Credits return for unsupported VL",
  6842. [4] =
  6843. "UnsupportedVLMarker: Received VL Marker",
  6844. [5] =
  6845. "BadPreempt: Exceeded the preemption nesting level",
  6846. [6] =
  6847. "BadControlFlit: Received unsupported control flit",
  6848. /* no 7 */
  6849. [8] =
  6850. "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
  6851. };
  6852. static const char * const port_rcv_txt[] = {
  6853. [1] =
  6854. "BadPktLen: Illegal PktLen",
  6855. [2] =
  6856. "PktLenTooLong: Packet longer than PktLen",
  6857. [3] =
  6858. "PktLenTooShort: Packet shorter than PktLen",
  6859. [4] =
  6860. "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
  6861. [5] =
  6862. "BadDLID: Illegal DLID (0, doesn't match HFI)",
  6863. [6] =
  6864. "BadL2: Illegal L2 opcode",
  6865. [7] =
  6866. "BadSC: Unsupported SC",
  6867. [9] =
  6868. "BadRC: Illegal RC",
  6869. [11] =
  6870. "PreemptError: Preempting with same VL",
  6871. [12] =
  6872. "PreemptVL15: Preempting a VL15 packet",
  6873. };
  6874. #define OPA_LDR_FMCONFIG_OFFSET 16
  6875. #define OPA_LDR_PORTRCV_OFFSET 0
  6876. static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  6877. {
  6878. u64 info, hdr0, hdr1;
  6879. const char *extra;
  6880. char buf[96];
  6881. struct hfi1_pportdata *ppd = dd->pport;
  6882. u8 lcl_reason = 0;
  6883. int do_bounce = 0;
  6884. if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
  6885. if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
  6886. info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
  6887. dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
  6888. /* set status bit */
  6889. dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
  6890. }
  6891. reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
  6892. }
  6893. if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
  6894. struct hfi1_pportdata *ppd = dd->pport;
  6895. /* this counter saturates at (2^32) - 1 */
  6896. if (ppd->link_downed < (u32)UINT_MAX)
  6897. ppd->link_downed++;
  6898. reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
  6899. }
  6900. if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
  6901. u8 reason_valid = 1;
  6902. info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
  6903. if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
  6904. dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
  6905. /* set status bit */
  6906. dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
  6907. }
  6908. switch (info) {
  6909. case 0:
  6910. case 1:
  6911. case 2:
  6912. case 3:
  6913. case 4:
  6914. case 5:
  6915. case 6:
  6916. extra = fm_config_txt[info];
  6917. break;
  6918. case 8:
  6919. extra = fm_config_txt[info];
  6920. if (ppd->port_error_action &
  6921. OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
  6922. do_bounce = 1;
  6923. /*
  6924. * lcl_reason cannot be derived from info
  6925. * for this error
  6926. */
  6927. lcl_reason =
  6928. OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
  6929. }
  6930. break;
  6931. default:
  6932. reason_valid = 0;
  6933. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6934. extra = buf;
  6935. break;
  6936. }
  6937. if (reason_valid && !do_bounce) {
  6938. do_bounce = ppd->port_error_action &
  6939. (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
  6940. lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
  6941. }
  6942. /* just report this */
  6943. dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
  6944. extra);
  6945. reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
  6946. }
  6947. if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
  6948. u8 reason_valid = 1;
  6949. info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
  6950. hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
  6951. hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
  6952. if (!(dd->err_info_rcvport.status_and_code &
  6953. OPA_EI_STATUS_SMASK)) {
  6954. dd->err_info_rcvport.status_and_code =
  6955. info & OPA_EI_CODE_SMASK;
  6956. /* set status bit */
  6957. dd->err_info_rcvport.status_and_code |=
  6958. OPA_EI_STATUS_SMASK;
  6959. /*
  6960. * save first 2 flits in the packet that caused
  6961. * the error
  6962. */
  6963. dd->err_info_rcvport.packet_flit1 = hdr0;
  6964. dd->err_info_rcvport.packet_flit2 = hdr1;
  6965. }
  6966. switch (info) {
  6967. case 1:
  6968. case 2:
  6969. case 3:
  6970. case 4:
  6971. case 5:
  6972. case 6:
  6973. case 7:
  6974. case 9:
  6975. case 11:
  6976. case 12:
  6977. extra = port_rcv_txt[info];
  6978. break;
  6979. default:
  6980. reason_valid = 0;
  6981. snprintf(buf, sizeof(buf), "reserved%lld", info);
  6982. extra = buf;
  6983. break;
  6984. }
  6985. if (reason_valid && !do_bounce) {
  6986. do_bounce = ppd->port_error_action &
  6987. (1 << (OPA_LDR_PORTRCV_OFFSET + info));
  6988. lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
  6989. }
  6990. /* just report this */
  6991. dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
  6992. " hdr0 0x%llx, hdr1 0x%llx\n",
  6993. extra, hdr0, hdr1);
  6994. reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
  6995. }
  6996. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
  6997. /* informative only */
  6998. dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
  6999. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
  7000. }
  7001. if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
  7002. /* informative only */
  7003. dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
  7004. reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
  7005. }
  7006. if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
  7007. reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
  7008. /* report any remaining errors */
  7009. if (reg)
  7010. dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
  7011. dcc_err_string(buf, sizeof(buf), reg));
  7012. if (lcl_reason == 0)
  7013. lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
  7014. if (do_bounce) {
  7015. dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
  7016. __func__);
  7017. set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
  7018. queue_work(ppd->link_wq, &ppd->link_bounce_work);
  7019. }
  7020. }
  7021. static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
  7022. {
  7023. char buf[96];
  7024. dd_dev_info(dd, "LCB Error: %s\n",
  7025. lcb_err_string(buf, sizeof(buf), reg));
  7026. }
  7027. /*
  7028. * CCE block DC interrupt. Source is < 8.
  7029. */
  7030. static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
  7031. {
  7032. const struct err_reg_info *eri = &dc_errs[source];
  7033. if (eri->handler) {
  7034. interrupt_clear_down(dd, 0, eri);
  7035. } else if (source == 3 /* dc_lbm_int */) {
  7036. /*
  7037. * This indicates that a parity error has occurred on the
  7038. * address/control lines presented to the LBM. The error
  7039. * is a single pulse, there is no associated error flag,
  7040. * and it is non-maskable. This is because if a parity
  7041. * error occurs on the request the request is dropped.
  7042. * This should never occur, but it is nice to know if it
  7043. * ever does.
  7044. */
  7045. dd_dev_err(dd, "Parity error in DC LBM block\n");
  7046. } else {
  7047. dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
  7048. }
  7049. }
  7050. /*
  7051. * TX block send credit interrupt. Source is < 160.
  7052. */
  7053. static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
  7054. {
  7055. sc_group_release_update(dd, source);
  7056. }
  7057. /*
  7058. * TX block SDMA interrupt. Source is < 48.
  7059. *
  7060. * SDMA interrupts are grouped by type:
  7061. *
  7062. * 0 - N-1 = SDma
  7063. * N - 2N-1 = SDmaProgress
  7064. * 2N - 3N-1 = SDmaIdle
  7065. */
  7066. static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
  7067. {
  7068. /* what interrupt */
  7069. unsigned int what = source / TXE_NUM_SDMA_ENGINES;
  7070. /* which engine */
  7071. unsigned int which = source % TXE_NUM_SDMA_ENGINES;
  7072. #ifdef CONFIG_SDMA_VERBOSITY
  7073. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
  7074. slashstrip(__FILE__), __LINE__, __func__);
  7075. sdma_dumpstate(&dd->per_sdma[which]);
  7076. #endif
  7077. if (likely(what < 3 && which < dd->num_sdma)) {
  7078. sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
  7079. } else {
  7080. /* should not happen */
  7081. dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
  7082. }
  7083. }
  7084. /*
  7085. * RX block receive available interrupt. Source is < 160.
  7086. */
  7087. static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
  7088. {
  7089. struct hfi1_ctxtdata *rcd;
  7090. char *err_detail;
  7091. if (likely(source < dd->num_rcv_contexts)) {
  7092. rcd = hfi1_rcd_get_by_index(dd, source);
  7093. if (rcd) {
  7094. /* Check for non-user contexts, including vnic */
  7095. if (source < dd->first_dyn_alloc_ctxt || rcd->is_vnic)
  7096. rcd->do_interrupt(rcd, 0);
  7097. else
  7098. handle_user_interrupt(rcd);
  7099. hfi1_rcd_put(rcd);
  7100. return; /* OK */
  7101. }
  7102. /* received an interrupt, but no rcd */
  7103. err_detail = "dataless";
  7104. } else {
  7105. /* received an interrupt, but are not using that context */
  7106. err_detail = "out of range";
  7107. }
  7108. dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
  7109. err_detail, source);
  7110. }
  7111. /*
  7112. * RX block receive urgent interrupt. Source is < 160.
  7113. */
  7114. static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
  7115. {
  7116. struct hfi1_ctxtdata *rcd;
  7117. char *err_detail;
  7118. if (likely(source < dd->num_rcv_contexts)) {
  7119. rcd = hfi1_rcd_get_by_index(dd, source);
  7120. if (rcd) {
  7121. /* only pay attention to user urgent interrupts */
  7122. if (source >= dd->first_dyn_alloc_ctxt &&
  7123. !rcd->is_vnic)
  7124. handle_user_interrupt(rcd);
  7125. hfi1_rcd_put(rcd);
  7126. return; /* OK */
  7127. }
  7128. /* received an interrupt, but no rcd */
  7129. err_detail = "dataless";
  7130. } else {
  7131. /* received an interrupt, but are not using that context */
  7132. err_detail = "out of range";
  7133. }
  7134. dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
  7135. err_detail, source);
  7136. }
  7137. /*
  7138. * Reserved range interrupt. Should not be called in normal operation.
  7139. */
  7140. static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
  7141. {
  7142. char name[64];
  7143. dd_dev_err(dd, "unexpected %s interrupt\n",
  7144. is_reserved_name(name, sizeof(name), source));
  7145. }
  7146. static const struct is_table is_table[] = {
  7147. /*
  7148. * start end
  7149. * name func interrupt func
  7150. */
  7151. { IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
  7152. is_misc_err_name, is_misc_err_int },
  7153. { IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
  7154. is_sdma_eng_err_name, is_sdma_eng_err_int },
  7155. { IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
  7156. is_sendctxt_err_name, is_sendctxt_err_int },
  7157. { IS_SDMA_START, IS_SDMA_END,
  7158. is_sdma_eng_name, is_sdma_eng_int },
  7159. { IS_VARIOUS_START, IS_VARIOUS_END,
  7160. is_various_name, is_various_int },
  7161. { IS_DC_START, IS_DC_END,
  7162. is_dc_name, is_dc_int },
  7163. { IS_RCVAVAIL_START, IS_RCVAVAIL_END,
  7164. is_rcv_avail_name, is_rcv_avail_int },
  7165. { IS_RCVURGENT_START, IS_RCVURGENT_END,
  7166. is_rcv_urgent_name, is_rcv_urgent_int },
  7167. { IS_SENDCREDIT_START, IS_SENDCREDIT_END,
  7168. is_send_credit_name, is_send_credit_int},
  7169. { IS_RESERVED_START, IS_RESERVED_END,
  7170. is_reserved_name, is_reserved_int},
  7171. };
  7172. /*
  7173. * Interrupt source interrupt - called when the given source has an interrupt.
  7174. * Source is a bit index into an array of 64-bit integers.
  7175. */
  7176. static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
  7177. {
  7178. const struct is_table *entry;
  7179. /* avoids a double compare by walking the table in-order */
  7180. for (entry = &is_table[0]; entry->is_name; entry++) {
  7181. if (source < entry->end) {
  7182. trace_hfi1_interrupt(dd, entry, source);
  7183. entry->is_int(dd, source - entry->start);
  7184. return;
  7185. }
  7186. }
  7187. /* fell off the end */
  7188. dd_dev_err(dd, "invalid interrupt source %u\n", source);
  7189. }
  7190. /*
  7191. * General interrupt handler. This is able to correctly handle
  7192. * all interrupts in case INTx is used.
  7193. */
  7194. static irqreturn_t general_interrupt(int irq, void *data)
  7195. {
  7196. struct hfi1_devdata *dd = data;
  7197. u64 regs[CCE_NUM_INT_CSRS];
  7198. u32 bit;
  7199. int i;
  7200. irqreturn_t handled = IRQ_NONE;
  7201. this_cpu_inc(*dd->int_counter);
  7202. /* phase 1: scan and clear all handled interrupts */
  7203. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  7204. if (dd->gi_mask[i] == 0) {
  7205. regs[i] = 0; /* used later */
  7206. continue;
  7207. }
  7208. regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
  7209. dd->gi_mask[i];
  7210. /* only clear if anything is set */
  7211. if (regs[i])
  7212. write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
  7213. }
  7214. /* phase 2: call the appropriate handler */
  7215. for_each_set_bit(bit, (unsigned long *)&regs[0],
  7216. CCE_NUM_INT_CSRS * 64) {
  7217. is_interrupt(dd, bit);
  7218. handled = IRQ_HANDLED;
  7219. }
  7220. return handled;
  7221. }
  7222. static irqreturn_t sdma_interrupt(int irq, void *data)
  7223. {
  7224. struct sdma_engine *sde = data;
  7225. struct hfi1_devdata *dd = sde->dd;
  7226. u64 status;
  7227. #ifdef CONFIG_SDMA_VERBOSITY
  7228. dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
  7229. slashstrip(__FILE__), __LINE__, __func__);
  7230. sdma_dumpstate(sde);
  7231. #endif
  7232. this_cpu_inc(*dd->int_counter);
  7233. /* This read_csr is really bad in the hot path */
  7234. status = read_csr(dd,
  7235. CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
  7236. & sde->imask;
  7237. if (likely(status)) {
  7238. /* clear the interrupt(s) */
  7239. write_csr(dd,
  7240. CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
  7241. status);
  7242. /* handle the interrupt(s) */
  7243. sdma_engine_interrupt(sde, status);
  7244. } else {
  7245. dd_dev_err_ratelimited(dd, "SDMA engine %u interrupt, but no status bits set\n",
  7246. sde->this_idx);
  7247. }
  7248. return IRQ_HANDLED;
  7249. }
  7250. /*
  7251. * Clear the receive interrupt. Use a read of the interrupt clear CSR
  7252. * to insure that the write completed. This does NOT guarantee that
  7253. * queued DMA writes to memory from the chip are pushed.
  7254. */
  7255. static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
  7256. {
  7257. struct hfi1_devdata *dd = rcd->dd;
  7258. u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
  7259. mmiowb(); /* make sure everything before is written */
  7260. write_csr(dd, addr, rcd->imask);
  7261. /* force the above write on the chip and get a value back */
  7262. (void)read_csr(dd, addr);
  7263. }
  7264. /* force the receive interrupt */
  7265. void force_recv_intr(struct hfi1_ctxtdata *rcd)
  7266. {
  7267. write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
  7268. }
  7269. /*
  7270. * Return non-zero if a packet is present.
  7271. *
  7272. * This routine is called when rechecking for packets after the RcvAvail
  7273. * interrupt has been cleared down. First, do a quick check of memory for
  7274. * a packet present. If not found, use an expensive CSR read of the context
  7275. * tail to determine the actual tail. The CSR read is necessary because there
  7276. * is no method to push pending DMAs to memory other than an interrupt and we
  7277. * are trying to determine if we need to force an interrupt.
  7278. */
  7279. static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
  7280. {
  7281. u32 tail;
  7282. int present;
  7283. if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
  7284. present = (rcd->seq_cnt ==
  7285. rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
  7286. else /* is RDMA rtail */
  7287. present = (rcd->head != get_rcvhdrtail(rcd));
  7288. if (present)
  7289. return 1;
  7290. /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
  7291. tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  7292. return rcd->head != tail;
  7293. }
  7294. /*
  7295. * Receive packet IRQ handler. This routine expects to be on its own IRQ.
  7296. * This routine will try to handle packets immediately (latency), but if
  7297. * it finds too many, it will invoke the thread handler (bandwitdh). The
  7298. * chip receive interrupt is *not* cleared down until this or the thread (if
  7299. * invoked) is finished. The intent is to avoid extra interrupts while we
  7300. * are processing packets anyway.
  7301. */
  7302. static irqreturn_t receive_context_interrupt(int irq, void *data)
  7303. {
  7304. struct hfi1_ctxtdata *rcd = data;
  7305. struct hfi1_devdata *dd = rcd->dd;
  7306. int disposition;
  7307. int present;
  7308. trace_hfi1_receive_interrupt(dd, rcd);
  7309. this_cpu_inc(*dd->int_counter);
  7310. aspm_ctx_disable(rcd);
  7311. /* receive interrupt remains blocked while processing packets */
  7312. disposition = rcd->do_interrupt(rcd, 0);
  7313. /*
  7314. * Too many packets were seen while processing packets in this
  7315. * IRQ handler. Invoke the handler thread. The receive interrupt
  7316. * remains blocked.
  7317. */
  7318. if (disposition == RCV_PKT_LIMIT)
  7319. return IRQ_WAKE_THREAD;
  7320. /*
  7321. * The packet processor detected no more packets. Clear the receive
  7322. * interrupt and recheck for a packet packet that may have arrived
  7323. * after the previous check and interrupt clear. If a packet arrived,
  7324. * force another interrupt.
  7325. */
  7326. clear_recv_intr(rcd);
  7327. present = check_packet_present(rcd);
  7328. if (present)
  7329. force_recv_intr(rcd);
  7330. return IRQ_HANDLED;
  7331. }
  7332. /*
  7333. * Receive packet thread handler. This expects to be invoked with the
  7334. * receive interrupt still blocked.
  7335. */
  7336. static irqreturn_t receive_context_thread(int irq, void *data)
  7337. {
  7338. struct hfi1_ctxtdata *rcd = data;
  7339. int present;
  7340. /* receive interrupt is still blocked from the IRQ handler */
  7341. (void)rcd->do_interrupt(rcd, 1);
  7342. /*
  7343. * The packet processor will only return if it detected no more
  7344. * packets. Hold IRQs here so we can safely clear the interrupt and
  7345. * recheck for a packet that may have arrived after the previous
  7346. * check and the interrupt clear. If a packet arrived, force another
  7347. * interrupt.
  7348. */
  7349. local_irq_disable();
  7350. clear_recv_intr(rcd);
  7351. present = check_packet_present(rcd);
  7352. if (present)
  7353. force_recv_intr(rcd);
  7354. local_irq_enable();
  7355. return IRQ_HANDLED;
  7356. }
  7357. /* ========================================================================= */
  7358. u32 read_physical_state(struct hfi1_devdata *dd)
  7359. {
  7360. u64 reg;
  7361. reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
  7362. return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
  7363. & DC_DC8051_STS_CUR_STATE_PORT_MASK;
  7364. }
  7365. u32 read_logical_state(struct hfi1_devdata *dd)
  7366. {
  7367. u64 reg;
  7368. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7369. return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
  7370. & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
  7371. }
  7372. static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
  7373. {
  7374. u64 reg;
  7375. reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
  7376. /* clear current state, set new state */
  7377. reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
  7378. reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
  7379. write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
  7380. }
  7381. /*
  7382. * Use the 8051 to read a LCB CSR.
  7383. */
  7384. static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7385. {
  7386. u32 regno;
  7387. int ret;
  7388. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7389. if (acquire_lcb_access(dd, 0) == 0) {
  7390. *data = read_csr(dd, addr);
  7391. release_lcb_access(dd, 0);
  7392. return 0;
  7393. }
  7394. return -EBUSY;
  7395. }
  7396. /* register is an index of LCB registers: (offset - base) / 8 */
  7397. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7398. ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
  7399. if (ret != HCMD_SUCCESS)
  7400. return -EBUSY;
  7401. return 0;
  7402. }
  7403. /*
  7404. * Provide a cache for some of the LCB registers in case the LCB is
  7405. * unavailable.
  7406. * (The LCB is unavailable in certain link states, for example.)
  7407. */
  7408. struct lcb_datum {
  7409. u32 off;
  7410. u64 val;
  7411. };
  7412. static struct lcb_datum lcb_cache[] = {
  7413. { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
  7414. { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
  7415. { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
  7416. };
  7417. static void update_lcb_cache(struct hfi1_devdata *dd)
  7418. {
  7419. int i;
  7420. int ret;
  7421. u64 val;
  7422. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7423. ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
  7424. /* Update if we get good data */
  7425. if (likely(ret != -EBUSY))
  7426. lcb_cache[i].val = val;
  7427. }
  7428. }
  7429. static int read_lcb_cache(u32 off, u64 *val)
  7430. {
  7431. int i;
  7432. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  7433. if (lcb_cache[i].off == off) {
  7434. *val = lcb_cache[i].val;
  7435. return 0;
  7436. }
  7437. }
  7438. pr_warn("%s bad offset 0x%x\n", __func__, off);
  7439. return -1;
  7440. }
  7441. /*
  7442. * Read an LCB CSR. Access may not be in host control, so check.
  7443. * Return 0 on success, -EBUSY on failure.
  7444. */
  7445. int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
  7446. {
  7447. struct hfi1_pportdata *ppd = dd->pport;
  7448. /* if up, go through the 8051 for the value */
  7449. if (ppd->host_link_state & HLS_UP)
  7450. return read_lcb_via_8051(dd, addr, data);
  7451. /* if going up or down, check the cache, otherwise, no access */
  7452. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
  7453. if (read_lcb_cache(addr, data))
  7454. return -EBUSY;
  7455. return 0;
  7456. }
  7457. /* otherwise, host has access */
  7458. *data = read_csr(dd, addr);
  7459. return 0;
  7460. }
  7461. /*
  7462. * Use the 8051 to write a LCB CSR.
  7463. */
  7464. static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
  7465. {
  7466. u32 regno;
  7467. int ret;
  7468. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
  7469. (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
  7470. if (acquire_lcb_access(dd, 0) == 0) {
  7471. write_csr(dd, addr, data);
  7472. release_lcb_access(dd, 0);
  7473. return 0;
  7474. }
  7475. return -EBUSY;
  7476. }
  7477. /* register is an index of LCB registers: (offset - base) / 8 */
  7478. regno = (addr - DC_LCB_CFG_RUN) >> 3;
  7479. ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
  7480. if (ret != HCMD_SUCCESS)
  7481. return -EBUSY;
  7482. return 0;
  7483. }
  7484. /*
  7485. * Write an LCB CSR. Access may not be in host control, so check.
  7486. * Return 0 on success, -EBUSY on failure.
  7487. */
  7488. int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
  7489. {
  7490. struct hfi1_pportdata *ppd = dd->pport;
  7491. /* if up, go through the 8051 for the value */
  7492. if (ppd->host_link_state & HLS_UP)
  7493. return write_lcb_via_8051(dd, addr, data);
  7494. /* if going up or down, no access */
  7495. if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
  7496. return -EBUSY;
  7497. /* otherwise, host has access */
  7498. write_csr(dd, addr, data);
  7499. return 0;
  7500. }
  7501. /*
  7502. * If the 8051 is in reset mode (dd->dc_shutdown == 1), this function
  7503. * will still continue executing.
  7504. *
  7505. * Returns:
  7506. * < 0 = Linux error, not able to get access
  7507. * > 0 = 8051 command RETURN_CODE
  7508. */
  7509. static int _do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  7510. u64 *out_data)
  7511. {
  7512. u64 reg, completed;
  7513. int return_code;
  7514. unsigned long timeout;
  7515. lockdep_assert_held(&dd->dc8051_lock);
  7516. hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
  7517. /*
  7518. * If an 8051 host command timed out previously, then the 8051 is
  7519. * stuck.
  7520. *
  7521. * On first timeout, attempt to reset and restart the entire DC
  7522. * block (including 8051). (Is this too big of a hammer?)
  7523. *
  7524. * If the 8051 times out a second time, the reset did not bring it
  7525. * back to healthy life. In that case, fail any subsequent commands.
  7526. */
  7527. if (dd->dc8051_timed_out) {
  7528. if (dd->dc8051_timed_out > 1) {
  7529. dd_dev_err(dd,
  7530. "Previous 8051 host command timed out, skipping command %u\n",
  7531. type);
  7532. return_code = -ENXIO;
  7533. goto fail;
  7534. }
  7535. _dc_shutdown(dd);
  7536. _dc_start(dd);
  7537. }
  7538. /*
  7539. * If there is no timeout, then the 8051 command interface is
  7540. * waiting for a command.
  7541. */
  7542. /*
  7543. * When writing a LCB CSR, out_data contains the full value to
  7544. * to be written, while in_data contains the relative LCB
  7545. * address in 7:0. Do the work here, rather than the caller,
  7546. * of distrubting the write data to where it needs to go:
  7547. *
  7548. * Write data
  7549. * 39:00 -> in_data[47:8]
  7550. * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
  7551. * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
  7552. */
  7553. if (type == HCMD_WRITE_LCB_CSR) {
  7554. in_data |= ((*out_data) & 0xffffffffffull) << 8;
  7555. /* must preserve COMPLETED - it is tied to hardware */
  7556. reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
  7557. reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
  7558. reg |= ((((*out_data) >> 40) & 0xff) <<
  7559. DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
  7560. | ((((*out_data) >> 48) & 0xffff) <<
  7561. DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
  7562. write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
  7563. }
  7564. /*
  7565. * Do two writes: the first to stabilize the type and req_data, the
  7566. * second to activate.
  7567. */
  7568. reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
  7569. << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
  7570. | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
  7571. << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
  7572. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7573. reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
  7574. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
  7575. /* wait for completion, alternate: interrupt */
  7576. timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
  7577. while (1) {
  7578. reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
  7579. completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
  7580. if (completed)
  7581. break;
  7582. if (time_after(jiffies, timeout)) {
  7583. dd->dc8051_timed_out++;
  7584. dd_dev_err(dd, "8051 host command %u timeout\n", type);
  7585. if (out_data)
  7586. *out_data = 0;
  7587. return_code = -ETIMEDOUT;
  7588. goto fail;
  7589. }
  7590. udelay(2);
  7591. }
  7592. if (out_data) {
  7593. *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
  7594. & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
  7595. if (type == HCMD_READ_LCB_CSR) {
  7596. /* top 16 bits are in a different register */
  7597. *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
  7598. & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
  7599. << (48
  7600. - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
  7601. }
  7602. }
  7603. return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
  7604. & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
  7605. dd->dc8051_timed_out = 0;
  7606. /*
  7607. * Clear command for next user.
  7608. */
  7609. write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
  7610. fail:
  7611. return return_code;
  7612. }
  7613. /*
  7614. * Returns:
  7615. * < 0 = Linux error, not able to get access
  7616. * > 0 = 8051 command RETURN_CODE
  7617. */
  7618. static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
  7619. u64 *out_data)
  7620. {
  7621. int return_code;
  7622. mutex_lock(&dd->dc8051_lock);
  7623. /* We can't send any commands to the 8051 if it's in reset */
  7624. if (dd->dc_shutdown) {
  7625. return_code = -ENODEV;
  7626. goto fail;
  7627. }
  7628. return_code = _do_8051_command(dd, type, in_data, out_data);
  7629. fail:
  7630. mutex_unlock(&dd->dc8051_lock);
  7631. return return_code;
  7632. }
  7633. static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
  7634. {
  7635. return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
  7636. }
  7637. static int _load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7638. u8 lane_id, u32 config_data)
  7639. {
  7640. u64 data;
  7641. int ret;
  7642. lockdep_assert_held(&dd->dc8051_lock);
  7643. data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
  7644. | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
  7645. | (u64)config_data << LOAD_DATA_DATA_SHIFT;
  7646. ret = _do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
  7647. if (ret != HCMD_SUCCESS) {
  7648. dd_dev_err(dd,
  7649. "load 8051 config: field id %d, lane %d, err %d\n",
  7650. (int)field_id, (int)lane_id, ret);
  7651. }
  7652. return ret;
  7653. }
  7654. int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
  7655. u8 lane_id, u32 config_data)
  7656. {
  7657. int return_code;
  7658. mutex_lock(&dd->dc8051_lock);
  7659. return_code = _load_8051_config(dd, field_id, lane_id, config_data);
  7660. mutex_unlock(&dd->dc8051_lock);
  7661. return return_code;
  7662. }
  7663. /*
  7664. * Read the 8051 firmware "registers". Use the RAM directly. Always
  7665. * set the result, even on error.
  7666. * Return 0 on success, -errno on failure
  7667. */
  7668. int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
  7669. u32 *result)
  7670. {
  7671. u64 big_data;
  7672. u32 addr;
  7673. int ret;
  7674. /* address start depends on the lane_id */
  7675. if (lane_id < 4)
  7676. addr = (4 * NUM_GENERAL_FIELDS)
  7677. + (lane_id * 4 * NUM_LANE_FIELDS);
  7678. else
  7679. addr = 0;
  7680. addr += field_id * 4;
  7681. /* read is in 8-byte chunks, hardware will truncate the address down */
  7682. ret = read_8051_data(dd, addr, 8, &big_data);
  7683. if (ret == 0) {
  7684. /* extract the 4 bytes we want */
  7685. if (addr & 0x4)
  7686. *result = (u32)(big_data >> 32);
  7687. else
  7688. *result = (u32)big_data;
  7689. } else {
  7690. *result = 0;
  7691. dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
  7692. __func__, lane_id, field_id);
  7693. }
  7694. return ret;
  7695. }
  7696. static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
  7697. u8 continuous)
  7698. {
  7699. u32 frame;
  7700. frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
  7701. | power_management << POWER_MANAGEMENT_SHIFT;
  7702. return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
  7703. GENERAL_CONFIG, frame);
  7704. }
  7705. static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
  7706. u16 vl15buf, u8 crc_sizes)
  7707. {
  7708. u32 frame;
  7709. frame = (u32)vau << VAU_SHIFT
  7710. | (u32)z << Z_SHIFT
  7711. | (u32)vcu << VCU_SHIFT
  7712. | (u32)vl15buf << VL15BUF_SHIFT
  7713. | (u32)crc_sizes << CRC_SIZES_SHIFT;
  7714. return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
  7715. GENERAL_CONFIG, frame);
  7716. }
  7717. static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
  7718. u8 *flag_bits, u16 *link_widths)
  7719. {
  7720. u32 frame;
  7721. read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7722. &frame);
  7723. *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
  7724. *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
  7725. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7726. }
  7727. static int write_vc_local_link_width(struct hfi1_devdata *dd,
  7728. u8 misc_bits,
  7729. u8 flag_bits,
  7730. u16 link_widths)
  7731. {
  7732. u32 frame;
  7733. frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
  7734. | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
  7735. | (u32)link_widths << LINK_WIDTH_SHIFT;
  7736. return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
  7737. frame);
  7738. }
  7739. static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
  7740. u8 device_rev)
  7741. {
  7742. u32 frame;
  7743. frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
  7744. | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
  7745. return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
  7746. }
  7747. static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
  7748. u8 *device_rev)
  7749. {
  7750. u32 frame;
  7751. read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
  7752. *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
  7753. *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
  7754. & REMOTE_DEVICE_REV_MASK;
  7755. }
  7756. int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
  7757. {
  7758. u32 frame;
  7759. u32 mask;
  7760. lockdep_assert_held(&dd->dc8051_lock);
  7761. mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
  7762. read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
  7763. /* Clear, then set field */
  7764. frame &= ~mask;
  7765. frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
  7766. return _load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
  7767. frame);
  7768. }
  7769. void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
  7770. u8 *ver_patch)
  7771. {
  7772. u32 frame;
  7773. read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
  7774. *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
  7775. STS_FM_VERSION_MAJOR_MASK;
  7776. *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
  7777. STS_FM_VERSION_MINOR_MASK;
  7778. read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
  7779. *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
  7780. STS_FM_VERSION_PATCH_MASK;
  7781. }
  7782. static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
  7783. u8 *continuous)
  7784. {
  7785. u32 frame;
  7786. read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
  7787. *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
  7788. & POWER_MANAGEMENT_MASK;
  7789. *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
  7790. & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
  7791. }
  7792. static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
  7793. u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
  7794. {
  7795. u32 frame;
  7796. read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
  7797. *vau = (frame >> VAU_SHIFT) & VAU_MASK;
  7798. *z = (frame >> Z_SHIFT) & Z_MASK;
  7799. *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
  7800. *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
  7801. *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
  7802. }
  7803. static void read_vc_remote_link_width(struct hfi1_devdata *dd,
  7804. u8 *remote_tx_rate,
  7805. u16 *link_widths)
  7806. {
  7807. u32 frame;
  7808. read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
  7809. &frame);
  7810. *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
  7811. & REMOTE_TX_RATE_MASK;
  7812. *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
  7813. }
  7814. static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
  7815. {
  7816. u32 frame;
  7817. read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
  7818. *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
  7819. }
  7820. static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
  7821. {
  7822. read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
  7823. }
  7824. static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
  7825. {
  7826. read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
  7827. }
  7828. void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
  7829. {
  7830. u32 frame;
  7831. int ret;
  7832. *link_quality = 0;
  7833. if (dd->pport->host_link_state & HLS_UP) {
  7834. ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
  7835. &frame);
  7836. if (ret == 0)
  7837. *link_quality = (frame >> LINK_QUALITY_SHIFT)
  7838. & LINK_QUALITY_MASK;
  7839. }
  7840. }
  7841. static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
  7842. {
  7843. u32 frame;
  7844. read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
  7845. *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
  7846. }
  7847. static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
  7848. {
  7849. u32 frame;
  7850. read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
  7851. *ldr = (frame & 0xff);
  7852. }
  7853. static int read_tx_settings(struct hfi1_devdata *dd,
  7854. u8 *enable_lane_tx,
  7855. u8 *tx_polarity_inversion,
  7856. u8 *rx_polarity_inversion,
  7857. u8 *max_rate)
  7858. {
  7859. u32 frame;
  7860. int ret;
  7861. ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
  7862. *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
  7863. & ENABLE_LANE_TX_MASK;
  7864. *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
  7865. & TX_POLARITY_INVERSION_MASK;
  7866. *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
  7867. & RX_POLARITY_INVERSION_MASK;
  7868. *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
  7869. return ret;
  7870. }
  7871. static int write_tx_settings(struct hfi1_devdata *dd,
  7872. u8 enable_lane_tx,
  7873. u8 tx_polarity_inversion,
  7874. u8 rx_polarity_inversion,
  7875. u8 max_rate)
  7876. {
  7877. u32 frame;
  7878. /* no need to mask, all variable sizes match field widths */
  7879. frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
  7880. | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
  7881. | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
  7882. | max_rate << MAX_RATE_SHIFT;
  7883. return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
  7884. }
  7885. /*
  7886. * Read an idle LCB message.
  7887. *
  7888. * Returns 0 on success, -EINVAL on error
  7889. */
  7890. static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
  7891. {
  7892. int ret;
  7893. ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
  7894. if (ret != HCMD_SUCCESS) {
  7895. dd_dev_err(dd, "read idle message: type %d, err %d\n",
  7896. (u32)type, ret);
  7897. return -EINVAL;
  7898. }
  7899. dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
  7900. /* return only the payload as we already know the type */
  7901. *data_out >>= IDLE_PAYLOAD_SHIFT;
  7902. return 0;
  7903. }
  7904. /*
  7905. * Read an idle SMA message. To be done in response to a notification from
  7906. * the 8051.
  7907. *
  7908. * Returns 0 on success, -EINVAL on error
  7909. */
  7910. static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
  7911. {
  7912. return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
  7913. data);
  7914. }
  7915. /*
  7916. * Send an idle LCB message.
  7917. *
  7918. * Returns 0 on success, -EINVAL on error
  7919. */
  7920. static int send_idle_message(struct hfi1_devdata *dd, u64 data)
  7921. {
  7922. int ret;
  7923. dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
  7924. ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
  7925. if (ret != HCMD_SUCCESS) {
  7926. dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
  7927. data, ret);
  7928. return -EINVAL;
  7929. }
  7930. return 0;
  7931. }
  7932. /*
  7933. * Send an idle SMA message.
  7934. *
  7935. * Returns 0 on success, -EINVAL on error
  7936. */
  7937. int send_idle_sma(struct hfi1_devdata *dd, u64 message)
  7938. {
  7939. u64 data;
  7940. data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
  7941. ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
  7942. return send_idle_message(dd, data);
  7943. }
  7944. /*
  7945. * Initialize the LCB then do a quick link up. This may or may not be
  7946. * in loopback.
  7947. *
  7948. * return 0 on success, -errno on error
  7949. */
  7950. static int do_quick_linkup(struct hfi1_devdata *dd)
  7951. {
  7952. int ret;
  7953. lcb_shutdown(dd, 0);
  7954. if (loopback) {
  7955. /* LCB_CFG_LOOPBACK.VAL = 2 */
  7956. /* LCB_CFG_LANE_WIDTH.VAL = 0 */
  7957. write_csr(dd, DC_LCB_CFG_LOOPBACK,
  7958. IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
  7959. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  7960. }
  7961. /* start the LCBs */
  7962. /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
  7963. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  7964. /* simulator only loopback steps */
  7965. if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  7966. /* LCB_CFG_RUN.EN = 1 */
  7967. write_csr(dd, DC_LCB_CFG_RUN,
  7968. 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  7969. ret = wait_link_transfer_active(dd, 10);
  7970. if (ret)
  7971. return ret;
  7972. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
  7973. 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
  7974. }
  7975. if (!loopback) {
  7976. /*
  7977. * When doing quick linkup and not in loopback, both
  7978. * sides must be done with LCB set-up before either
  7979. * starts the quick linkup. Put a delay here so that
  7980. * both sides can be started and have a chance to be
  7981. * done with LCB set up before resuming.
  7982. */
  7983. dd_dev_err(dd,
  7984. "Pausing for peer to be finished with LCB set up\n");
  7985. msleep(5000);
  7986. dd_dev_err(dd, "Continuing with quick linkup\n");
  7987. }
  7988. write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
  7989. set_8051_lcb_access(dd);
  7990. /*
  7991. * State "quick" LinkUp request sets the physical link state to
  7992. * LinkUp without a verify capability sequence.
  7993. * This state is in simulator v37 and later.
  7994. */
  7995. ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
  7996. if (ret != HCMD_SUCCESS) {
  7997. dd_dev_err(dd,
  7998. "%s: set physical link state to quick LinkUp failed with return %d\n",
  7999. __func__, ret);
  8000. set_host_lcb_access(dd);
  8001. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  8002. if (ret >= 0)
  8003. ret = -EINVAL;
  8004. return ret;
  8005. }
  8006. return 0; /* success */
  8007. }
  8008. /*
  8009. * Do all special steps to set up loopback.
  8010. */
  8011. static int init_loopback(struct hfi1_devdata *dd)
  8012. {
  8013. dd_dev_info(dd, "Entering loopback mode\n");
  8014. /* all loopbacks should disable self GUID check */
  8015. write_csr(dd, DC_DC8051_CFG_MODE,
  8016. (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
  8017. /*
  8018. * The simulator has only one loopback option - LCB. Switch
  8019. * to that option, which includes quick link up.
  8020. *
  8021. * Accept all valid loopback values.
  8022. */
  8023. if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
  8024. (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
  8025. loopback == LOOPBACK_CABLE)) {
  8026. loopback = LOOPBACK_LCB;
  8027. quick_linkup = 1;
  8028. return 0;
  8029. }
  8030. /*
  8031. * SerDes loopback init sequence is handled in set_local_link_attributes
  8032. */
  8033. if (loopback == LOOPBACK_SERDES)
  8034. return 0;
  8035. /* LCB loopback - handled at poll time */
  8036. if (loopback == LOOPBACK_LCB) {
  8037. quick_linkup = 1; /* LCB is always quick linkup */
  8038. /* not supported in emulation due to emulation RTL changes */
  8039. if (dd->icode == ICODE_FPGA_EMULATION) {
  8040. dd_dev_err(dd,
  8041. "LCB loopback not supported in emulation\n");
  8042. return -EINVAL;
  8043. }
  8044. return 0;
  8045. }
  8046. /* external cable loopback requires no extra steps */
  8047. if (loopback == LOOPBACK_CABLE)
  8048. return 0;
  8049. dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
  8050. return -EINVAL;
  8051. }
  8052. /*
  8053. * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
  8054. * used in the Verify Capability link width attribute.
  8055. */
  8056. static u16 opa_to_vc_link_widths(u16 opa_widths)
  8057. {
  8058. int i;
  8059. u16 result = 0;
  8060. static const struct link_bits {
  8061. u16 from;
  8062. u16 to;
  8063. } opa_link_xlate[] = {
  8064. { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
  8065. { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
  8066. { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
  8067. { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
  8068. };
  8069. for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
  8070. if (opa_widths & opa_link_xlate[i].from)
  8071. result |= opa_link_xlate[i].to;
  8072. }
  8073. return result;
  8074. }
  8075. /*
  8076. * Set link attributes before moving to polling.
  8077. */
  8078. static int set_local_link_attributes(struct hfi1_pportdata *ppd)
  8079. {
  8080. struct hfi1_devdata *dd = ppd->dd;
  8081. u8 enable_lane_tx;
  8082. u8 tx_polarity_inversion;
  8083. u8 rx_polarity_inversion;
  8084. int ret;
  8085. u32 misc_bits = 0;
  8086. /* reset our fabric serdes to clear any lingering problems */
  8087. fabric_serdes_reset(dd);
  8088. /* set the local tx rate - need to read-modify-write */
  8089. ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
  8090. &rx_polarity_inversion, &ppd->local_tx_rate);
  8091. if (ret)
  8092. goto set_local_link_attributes_fail;
  8093. if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
  8094. /* set the tx rate to the fastest enabled */
  8095. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8096. ppd->local_tx_rate = 1;
  8097. else
  8098. ppd->local_tx_rate = 0;
  8099. } else {
  8100. /* set the tx rate to all enabled */
  8101. ppd->local_tx_rate = 0;
  8102. if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
  8103. ppd->local_tx_rate |= 2;
  8104. if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
  8105. ppd->local_tx_rate |= 1;
  8106. }
  8107. enable_lane_tx = 0xF; /* enable all four lanes */
  8108. ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
  8109. rx_polarity_inversion, ppd->local_tx_rate);
  8110. if (ret != HCMD_SUCCESS)
  8111. goto set_local_link_attributes_fail;
  8112. /*
  8113. * DC supports continuous updates.
  8114. */
  8115. ret = write_vc_local_phy(dd,
  8116. 0 /* no power management */,
  8117. 1 /* continuous updates */);
  8118. if (ret != HCMD_SUCCESS)
  8119. goto set_local_link_attributes_fail;
  8120. /* z=1 in the next call: AU of 0 is not supported by the hardware */
  8121. ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
  8122. ppd->port_crc_mode_enabled);
  8123. if (ret != HCMD_SUCCESS)
  8124. goto set_local_link_attributes_fail;
  8125. /*
  8126. * SerDes loopback init sequence requires
  8127. * setting bit 0 of MISC_CONFIG_BITS
  8128. */
  8129. if (loopback == LOOPBACK_SERDES)
  8130. misc_bits |= 1 << LOOPBACK_SERDES_CONFIG_BIT_MASK_SHIFT;
  8131. ret = write_vc_local_link_width(dd, misc_bits, 0,
  8132. opa_to_vc_link_widths(
  8133. ppd->link_width_enabled));
  8134. if (ret != HCMD_SUCCESS)
  8135. goto set_local_link_attributes_fail;
  8136. /* let peer know who we are */
  8137. ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
  8138. if (ret == HCMD_SUCCESS)
  8139. return 0;
  8140. set_local_link_attributes_fail:
  8141. dd_dev_err(dd,
  8142. "Failed to set local link attributes, return 0x%x\n",
  8143. ret);
  8144. return ret;
  8145. }
  8146. /*
  8147. * Call this to start the link.
  8148. * Do not do anything if the link is disabled.
  8149. * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
  8150. */
  8151. int start_link(struct hfi1_pportdata *ppd)
  8152. {
  8153. /*
  8154. * Tune the SerDes to a ballpark setting for optimal signal and bit
  8155. * error rate. Needs to be done before starting the link.
  8156. */
  8157. tune_serdes(ppd);
  8158. if (!ppd->driver_link_ready) {
  8159. dd_dev_info(ppd->dd,
  8160. "%s: stopping link start because driver is not ready\n",
  8161. __func__);
  8162. return 0;
  8163. }
  8164. /*
  8165. * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
  8166. * pkey table can be configured properly if the HFI unit is connected
  8167. * to switch port with MgmtAllowed=NO
  8168. */
  8169. clear_full_mgmt_pkey(ppd);
  8170. return set_link_state(ppd, HLS_DN_POLL);
  8171. }
  8172. static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
  8173. {
  8174. struct hfi1_devdata *dd = ppd->dd;
  8175. u64 mask;
  8176. unsigned long timeout;
  8177. /*
  8178. * Some QSFP cables have a quirk that asserts the IntN line as a side
  8179. * effect of power up on plug-in. We ignore this false positive
  8180. * interrupt until the module has finished powering up by waiting for
  8181. * a minimum timeout of the module inrush initialization time of
  8182. * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
  8183. * module have stabilized.
  8184. */
  8185. msleep(500);
  8186. /*
  8187. * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
  8188. */
  8189. timeout = jiffies + msecs_to_jiffies(2000);
  8190. while (1) {
  8191. mask = read_csr(dd, dd->hfi1_id ?
  8192. ASIC_QSFP2_IN : ASIC_QSFP1_IN);
  8193. if (!(mask & QSFP_HFI0_INT_N))
  8194. break;
  8195. if (time_after(jiffies, timeout)) {
  8196. dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
  8197. __func__);
  8198. break;
  8199. }
  8200. udelay(2);
  8201. }
  8202. }
  8203. static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
  8204. {
  8205. struct hfi1_devdata *dd = ppd->dd;
  8206. u64 mask;
  8207. mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
  8208. if (enable) {
  8209. /*
  8210. * Clear the status register to avoid an immediate interrupt
  8211. * when we re-enable the IntN pin
  8212. */
  8213. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8214. QSFP_HFI0_INT_N);
  8215. mask |= (u64)QSFP_HFI0_INT_N;
  8216. } else {
  8217. mask &= ~(u64)QSFP_HFI0_INT_N;
  8218. }
  8219. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
  8220. }
  8221. int reset_qsfp(struct hfi1_pportdata *ppd)
  8222. {
  8223. struct hfi1_devdata *dd = ppd->dd;
  8224. u64 mask, qsfp_mask;
  8225. /* Disable INT_N from triggering QSFP interrupts */
  8226. set_qsfp_int_n(ppd, 0);
  8227. /* Reset the QSFP */
  8228. mask = (u64)QSFP_HFI0_RESET_N;
  8229. qsfp_mask = read_csr(dd,
  8230. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
  8231. qsfp_mask &= ~mask;
  8232. write_csr(dd,
  8233. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8234. udelay(10);
  8235. qsfp_mask |= mask;
  8236. write_csr(dd,
  8237. dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
  8238. wait_for_qsfp_init(ppd);
  8239. /*
  8240. * Allow INT_N to trigger the QSFP interrupt to watch
  8241. * for alarms and warnings
  8242. */
  8243. set_qsfp_int_n(ppd, 1);
  8244. /*
  8245. * After the reset, AOC transmitters are enabled by default. They need
  8246. * to be turned off to complete the QSFP setup before they can be
  8247. * enabled again.
  8248. */
  8249. return set_qsfp_tx(ppd, 0);
  8250. }
  8251. static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
  8252. u8 *qsfp_interrupt_status)
  8253. {
  8254. struct hfi1_devdata *dd = ppd->dd;
  8255. if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
  8256. (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
  8257. dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
  8258. __func__);
  8259. if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
  8260. (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
  8261. dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
  8262. __func__);
  8263. /*
  8264. * The remaining alarms/warnings don't matter if the link is down.
  8265. */
  8266. if (ppd->host_link_state & HLS_DOWN)
  8267. return 0;
  8268. if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
  8269. (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
  8270. dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
  8271. __func__);
  8272. if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
  8273. (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
  8274. dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
  8275. __func__);
  8276. /* Byte 2 is vendor specific */
  8277. if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
  8278. (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
  8279. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
  8280. __func__);
  8281. if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
  8282. (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
  8283. dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
  8284. __func__);
  8285. if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
  8286. (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
  8287. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
  8288. __func__);
  8289. if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
  8290. (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
  8291. dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
  8292. __func__);
  8293. if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
  8294. (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
  8295. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
  8296. __func__);
  8297. if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
  8298. (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
  8299. dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
  8300. __func__);
  8301. if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
  8302. (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
  8303. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
  8304. __func__);
  8305. if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
  8306. (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
  8307. dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
  8308. __func__);
  8309. if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
  8310. (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
  8311. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
  8312. __func__);
  8313. if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
  8314. (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
  8315. dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
  8316. __func__);
  8317. if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
  8318. (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
  8319. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
  8320. __func__);
  8321. if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
  8322. (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
  8323. dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
  8324. __func__);
  8325. /* Bytes 9-10 and 11-12 are reserved */
  8326. /* Bytes 13-15 are vendor specific */
  8327. return 0;
  8328. }
  8329. /* This routine will only be scheduled if the QSFP module present is asserted */
  8330. void qsfp_event(struct work_struct *work)
  8331. {
  8332. struct qsfp_data *qd;
  8333. struct hfi1_pportdata *ppd;
  8334. struct hfi1_devdata *dd;
  8335. qd = container_of(work, struct qsfp_data, qsfp_work);
  8336. ppd = qd->ppd;
  8337. dd = ppd->dd;
  8338. /* Sanity check */
  8339. if (!qsfp_mod_present(ppd))
  8340. return;
  8341. if (ppd->host_link_state == HLS_DN_DISABLE) {
  8342. dd_dev_info(ppd->dd,
  8343. "%s: stopping link start because link is disabled\n",
  8344. __func__);
  8345. return;
  8346. }
  8347. /*
  8348. * Turn DC back on after cable has been re-inserted. Up until
  8349. * now, the DC has been in reset to save power.
  8350. */
  8351. dc_start(dd);
  8352. if (qd->cache_refresh_required) {
  8353. set_qsfp_int_n(ppd, 0);
  8354. wait_for_qsfp_init(ppd);
  8355. /*
  8356. * Allow INT_N to trigger the QSFP interrupt to watch
  8357. * for alarms and warnings
  8358. */
  8359. set_qsfp_int_n(ppd, 1);
  8360. start_link(ppd);
  8361. }
  8362. if (qd->check_interrupt_flags) {
  8363. u8 qsfp_interrupt_status[16] = {0,};
  8364. if (one_qsfp_read(ppd, dd->hfi1_id, 6,
  8365. &qsfp_interrupt_status[0], 16) != 16) {
  8366. dd_dev_info(dd,
  8367. "%s: Failed to read status of QSFP module\n",
  8368. __func__);
  8369. } else {
  8370. unsigned long flags;
  8371. handle_qsfp_error_conditions(
  8372. ppd, qsfp_interrupt_status);
  8373. spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
  8374. ppd->qsfp_info.check_interrupt_flags = 0;
  8375. spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
  8376. flags);
  8377. }
  8378. }
  8379. }
  8380. static void init_qsfp_int(struct hfi1_devdata *dd)
  8381. {
  8382. struct hfi1_pportdata *ppd = dd->pport;
  8383. u64 qsfp_mask, cce_int_mask;
  8384. const int qsfp1_int_smask = QSFP1_INT % 64;
  8385. const int qsfp2_int_smask = QSFP2_INT % 64;
  8386. /*
  8387. * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
  8388. * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
  8389. * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
  8390. * the index of the appropriate CSR in the CCEIntMask CSR array
  8391. */
  8392. cce_int_mask = read_csr(dd, CCE_INT_MASK +
  8393. (8 * (QSFP1_INT / 64)));
  8394. if (dd->hfi1_id) {
  8395. cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
  8396. write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
  8397. cce_int_mask);
  8398. } else {
  8399. cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
  8400. write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
  8401. cce_int_mask);
  8402. }
  8403. qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
  8404. /* Clear current status to avoid spurious interrupts */
  8405. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
  8406. qsfp_mask);
  8407. write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
  8408. qsfp_mask);
  8409. set_qsfp_int_n(ppd, 0);
  8410. /* Handle active low nature of INT_N and MODPRST_N pins */
  8411. if (qsfp_mod_present(ppd))
  8412. qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
  8413. write_csr(dd,
  8414. dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
  8415. qsfp_mask);
  8416. }
  8417. /*
  8418. * Do a one-time initialize of the LCB block.
  8419. */
  8420. static void init_lcb(struct hfi1_devdata *dd)
  8421. {
  8422. /* simulator does not correctly handle LCB cclk loopback, skip */
  8423. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  8424. return;
  8425. /* the DC has been reset earlier in the driver load */
  8426. /* set LCB for cclk loopback on the port */
  8427. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
  8428. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
  8429. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
  8430. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8431. write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
  8432. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
  8433. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
  8434. }
  8435. /*
  8436. * Perform a test read on the QSFP. Return 0 on success, -ERRNO
  8437. * on error.
  8438. */
  8439. static int test_qsfp_read(struct hfi1_pportdata *ppd)
  8440. {
  8441. int ret;
  8442. u8 status;
  8443. /*
  8444. * Report success if not a QSFP or, if it is a QSFP, but the cable is
  8445. * not present
  8446. */
  8447. if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
  8448. return 0;
  8449. /* read byte 2, the status byte */
  8450. ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
  8451. if (ret < 0)
  8452. return ret;
  8453. if (ret != 1)
  8454. return -EIO;
  8455. return 0; /* success */
  8456. }
  8457. /*
  8458. * Values for QSFP retry.
  8459. *
  8460. * Give up after 10s (20 x 500ms). The overall timeout was empirically
  8461. * arrived at from experience on a large cluster.
  8462. */
  8463. #define MAX_QSFP_RETRIES 20
  8464. #define QSFP_RETRY_WAIT 500 /* msec */
  8465. /*
  8466. * Try a QSFP read. If it fails, schedule a retry for later.
  8467. * Called on first link activation after driver load.
  8468. */
  8469. static void try_start_link(struct hfi1_pportdata *ppd)
  8470. {
  8471. if (test_qsfp_read(ppd)) {
  8472. /* read failed */
  8473. if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
  8474. dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
  8475. return;
  8476. }
  8477. dd_dev_info(ppd->dd,
  8478. "QSFP not responding, waiting and retrying %d\n",
  8479. (int)ppd->qsfp_retry_count);
  8480. ppd->qsfp_retry_count++;
  8481. queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
  8482. msecs_to_jiffies(QSFP_RETRY_WAIT));
  8483. return;
  8484. }
  8485. ppd->qsfp_retry_count = 0;
  8486. start_link(ppd);
  8487. }
  8488. /*
  8489. * Workqueue function to start the link after a delay.
  8490. */
  8491. void handle_start_link(struct work_struct *work)
  8492. {
  8493. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  8494. start_link_work.work);
  8495. try_start_link(ppd);
  8496. }
  8497. int bringup_serdes(struct hfi1_pportdata *ppd)
  8498. {
  8499. struct hfi1_devdata *dd = ppd->dd;
  8500. u64 guid;
  8501. int ret;
  8502. if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
  8503. add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
  8504. guid = ppd->guids[HFI1_PORT_GUID_INDEX];
  8505. if (!guid) {
  8506. if (dd->base_guid)
  8507. guid = dd->base_guid + ppd->port - 1;
  8508. ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
  8509. }
  8510. /* Set linkinit_reason on power up per OPA spec */
  8511. ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
  8512. /* one-time init of the LCB */
  8513. init_lcb(dd);
  8514. if (loopback) {
  8515. ret = init_loopback(dd);
  8516. if (ret < 0)
  8517. return ret;
  8518. }
  8519. get_port_type(ppd);
  8520. if (ppd->port_type == PORT_TYPE_QSFP) {
  8521. set_qsfp_int_n(ppd, 0);
  8522. wait_for_qsfp_init(ppd);
  8523. set_qsfp_int_n(ppd, 1);
  8524. }
  8525. try_start_link(ppd);
  8526. return 0;
  8527. }
  8528. void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
  8529. {
  8530. struct hfi1_devdata *dd = ppd->dd;
  8531. /*
  8532. * Shut down the link and keep it down. First turn off that the
  8533. * driver wants to allow the link to be up (driver_link_ready).
  8534. * Then make sure the link is not automatically restarted
  8535. * (link_enabled). Cancel any pending restart. And finally
  8536. * go offline.
  8537. */
  8538. ppd->driver_link_ready = 0;
  8539. ppd->link_enabled = 0;
  8540. ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
  8541. flush_delayed_work(&ppd->start_link_work);
  8542. cancel_delayed_work_sync(&ppd->start_link_work);
  8543. ppd->offline_disabled_reason =
  8544. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_REBOOT);
  8545. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_REBOOT, 0,
  8546. OPA_LINKDOWN_REASON_REBOOT);
  8547. set_link_state(ppd, HLS_DN_OFFLINE);
  8548. /* disable the port */
  8549. clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  8550. }
  8551. static inline int init_cpu_counters(struct hfi1_devdata *dd)
  8552. {
  8553. struct hfi1_pportdata *ppd;
  8554. int i;
  8555. ppd = (struct hfi1_pportdata *)(dd + 1);
  8556. for (i = 0; i < dd->num_pports; i++, ppd++) {
  8557. ppd->ibport_data.rvp.rc_acks = NULL;
  8558. ppd->ibport_data.rvp.rc_qacks = NULL;
  8559. ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
  8560. ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
  8561. ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
  8562. if (!ppd->ibport_data.rvp.rc_acks ||
  8563. !ppd->ibport_data.rvp.rc_delayed_comp ||
  8564. !ppd->ibport_data.rvp.rc_qacks)
  8565. return -ENOMEM;
  8566. }
  8567. return 0;
  8568. }
  8569. /*
  8570. * index is the index into the receive array
  8571. */
  8572. void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
  8573. u32 type, unsigned long pa, u16 order)
  8574. {
  8575. u64 reg;
  8576. if (!(dd->flags & HFI1_PRESENT))
  8577. goto done;
  8578. if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
  8579. pa = 0;
  8580. order = 0;
  8581. } else if (type > PT_INVALID) {
  8582. dd_dev_err(dd,
  8583. "unexpected receive array type %u for index %u, not handled\n",
  8584. type, index);
  8585. goto done;
  8586. }
  8587. trace_hfi1_put_tid(dd, index, type, pa, order);
  8588. #define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
  8589. reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
  8590. | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
  8591. | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
  8592. << RCV_ARRAY_RT_ADDR_SHIFT;
  8593. trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
  8594. writeq(reg, dd->rcvarray_wc + (index * 8));
  8595. if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
  8596. /*
  8597. * Eager entries are written and flushed
  8598. *
  8599. * Expected entries are flushed every 4 writes
  8600. */
  8601. flush_wc();
  8602. done:
  8603. return;
  8604. }
  8605. void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
  8606. {
  8607. struct hfi1_devdata *dd = rcd->dd;
  8608. u32 i;
  8609. /* this could be optimized */
  8610. for (i = rcd->eager_base; i < rcd->eager_base +
  8611. rcd->egrbufs.alloced; i++)
  8612. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8613. for (i = rcd->expected_base;
  8614. i < rcd->expected_base + rcd->expected_count; i++)
  8615. hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
  8616. }
  8617. static const char * const ib_cfg_name_strings[] = {
  8618. "HFI1_IB_CFG_LIDLMC",
  8619. "HFI1_IB_CFG_LWID_DG_ENB",
  8620. "HFI1_IB_CFG_LWID_ENB",
  8621. "HFI1_IB_CFG_LWID",
  8622. "HFI1_IB_CFG_SPD_ENB",
  8623. "HFI1_IB_CFG_SPD",
  8624. "HFI1_IB_CFG_RXPOL_ENB",
  8625. "HFI1_IB_CFG_LREV_ENB",
  8626. "HFI1_IB_CFG_LINKLATENCY",
  8627. "HFI1_IB_CFG_HRTBT",
  8628. "HFI1_IB_CFG_OP_VLS",
  8629. "HFI1_IB_CFG_VL_HIGH_CAP",
  8630. "HFI1_IB_CFG_VL_LOW_CAP",
  8631. "HFI1_IB_CFG_OVERRUN_THRESH",
  8632. "HFI1_IB_CFG_PHYERR_THRESH",
  8633. "HFI1_IB_CFG_LINKDEFAULT",
  8634. "HFI1_IB_CFG_PKEYS",
  8635. "HFI1_IB_CFG_MTU",
  8636. "HFI1_IB_CFG_LSTATE",
  8637. "HFI1_IB_CFG_VL_HIGH_LIMIT",
  8638. "HFI1_IB_CFG_PMA_TICKS",
  8639. "HFI1_IB_CFG_PORT"
  8640. };
  8641. static const char *ib_cfg_name(int which)
  8642. {
  8643. if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
  8644. return "invalid";
  8645. return ib_cfg_name_strings[which];
  8646. }
  8647. int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
  8648. {
  8649. struct hfi1_devdata *dd = ppd->dd;
  8650. int val = 0;
  8651. switch (which) {
  8652. case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
  8653. val = ppd->link_width_enabled;
  8654. break;
  8655. case HFI1_IB_CFG_LWID: /* currently active Link-width */
  8656. val = ppd->link_width_active;
  8657. break;
  8658. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  8659. val = ppd->link_speed_enabled;
  8660. break;
  8661. case HFI1_IB_CFG_SPD: /* current Link speed */
  8662. val = ppd->link_speed_active;
  8663. break;
  8664. case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
  8665. case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
  8666. case HFI1_IB_CFG_LINKLATENCY:
  8667. goto unimplemented;
  8668. case HFI1_IB_CFG_OP_VLS:
  8669. val = ppd->actual_vls_operational;
  8670. break;
  8671. case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
  8672. val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
  8673. break;
  8674. case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
  8675. val = VL_ARB_LOW_PRIO_TABLE_SIZE;
  8676. break;
  8677. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  8678. val = ppd->overrun_threshold;
  8679. break;
  8680. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  8681. val = ppd->phy_error_threshold;
  8682. break;
  8683. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  8684. val = HLS_DEFAULT;
  8685. break;
  8686. case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
  8687. case HFI1_IB_CFG_PMA_TICKS:
  8688. default:
  8689. unimplemented:
  8690. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  8691. dd_dev_info(
  8692. dd,
  8693. "%s: which %s: not implemented\n",
  8694. __func__,
  8695. ib_cfg_name(which));
  8696. break;
  8697. }
  8698. return val;
  8699. }
  8700. /*
  8701. * The largest MAD packet size.
  8702. */
  8703. #define MAX_MAD_PACKET 2048
  8704. /*
  8705. * Return the maximum header bytes that can go on the _wire_
  8706. * for this device. This count includes the ICRC which is
  8707. * not part of the packet held in memory but it is appended
  8708. * by the HW.
  8709. * This is dependent on the device's receive header entry size.
  8710. * HFI allows this to be set per-receive context, but the
  8711. * driver presently enforces a global value.
  8712. */
  8713. u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
  8714. {
  8715. /*
  8716. * The maximum non-payload (MTU) bytes in LRH.PktLen are
  8717. * the Receive Header Entry Size minus the PBC (or RHF) size
  8718. * plus one DW for the ICRC appended by HW.
  8719. *
  8720. * dd->rcd[0].rcvhdrqentsize is in DW.
  8721. * We use rcd[0] as all context will have the same value. Also,
  8722. * the first kernel context would have been allocated by now so
  8723. * we are guaranteed a valid value.
  8724. */
  8725. return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
  8726. }
  8727. /*
  8728. * Set Send Length
  8729. * @ppd - per port data
  8730. *
  8731. * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
  8732. * registers compare against LRH.PktLen, so use the max bytes included
  8733. * in the LRH.
  8734. *
  8735. * This routine changes all VL values except VL15, which it maintains at
  8736. * the same value.
  8737. */
  8738. static void set_send_length(struct hfi1_pportdata *ppd)
  8739. {
  8740. struct hfi1_devdata *dd = ppd->dd;
  8741. u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
  8742. u32 maxvlmtu = dd->vld[15].mtu;
  8743. u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
  8744. & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
  8745. SEND_LEN_CHECK1_LEN_VL15_SHIFT;
  8746. int i, j;
  8747. u32 thres;
  8748. for (i = 0; i < ppd->vls_supported; i++) {
  8749. if (dd->vld[i].mtu > maxvlmtu)
  8750. maxvlmtu = dd->vld[i].mtu;
  8751. if (i <= 3)
  8752. len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8753. & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
  8754. ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
  8755. else
  8756. len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
  8757. & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
  8758. ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
  8759. }
  8760. write_csr(dd, SEND_LEN_CHECK0, len1);
  8761. write_csr(dd, SEND_LEN_CHECK1, len2);
  8762. /* adjust kernel credit return thresholds based on new MTUs */
  8763. /* all kernel receive contexts have the same hdrqentsize */
  8764. for (i = 0; i < ppd->vls_supported; i++) {
  8765. thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
  8766. sc_mtu_to_threshold(dd->vld[i].sc,
  8767. dd->vld[i].mtu,
  8768. dd->rcd[0]->rcvhdrqentsize));
  8769. for (j = 0; j < INIT_SC_PER_VL; j++)
  8770. sc_set_cr_threshold(
  8771. pio_select_send_context_vl(dd, j, i),
  8772. thres);
  8773. }
  8774. thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
  8775. sc_mtu_to_threshold(dd->vld[15].sc,
  8776. dd->vld[15].mtu,
  8777. dd->rcd[0]->rcvhdrqentsize));
  8778. sc_set_cr_threshold(dd->vld[15].sc, thres);
  8779. /* Adjust maximum MTU for the port in DC */
  8780. dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
  8781. (ilog2(maxvlmtu >> 8) + 1);
  8782. len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
  8783. len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
  8784. len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
  8785. DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
  8786. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
  8787. }
  8788. static void set_lidlmc(struct hfi1_pportdata *ppd)
  8789. {
  8790. int i;
  8791. u64 sreg = 0;
  8792. struct hfi1_devdata *dd = ppd->dd;
  8793. u32 mask = ~((1U << ppd->lmc) - 1);
  8794. u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
  8795. u32 lid;
  8796. /*
  8797. * Program 0 in CSR if port lid is extended. This prevents
  8798. * 9B packets being sent out for large lids.
  8799. */
  8800. lid = (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ? 0 : ppd->lid;
  8801. c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
  8802. | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
  8803. c1 |= ((lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
  8804. << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
  8805. ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
  8806. << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
  8807. write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
  8808. /*
  8809. * Iterate over all the send contexts and set their SLID check
  8810. */
  8811. sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
  8812. SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
  8813. (((lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
  8814. SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
  8815. for (i = 0; i < dd->chip_send_contexts; i++) {
  8816. hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
  8817. i, (u32)sreg);
  8818. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
  8819. }
  8820. /* Now we have to do the same thing for the sdma engines */
  8821. sdma_update_lmc(dd, mask, lid);
  8822. }
  8823. static const char *state_completed_string(u32 completed)
  8824. {
  8825. static const char * const state_completed[] = {
  8826. "EstablishComm",
  8827. "OptimizeEQ",
  8828. "VerifyCap"
  8829. };
  8830. if (completed < ARRAY_SIZE(state_completed))
  8831. return state_completed[completed];
  8832. return "unknown";
  8833. }
  8834. static const char all_lanes_dead_timeout_expired[] =
  8835. "All lanes were inactive – was the interconnect media removed?";
  8836. static const char tx_out_of_policy[] =
  8837. "Passing lanes on local port do not meet the local link width policy";
  8838. static const char no_state_complete[] =
  8839. "State timeout occurred before link partner completed the state";
  8840. static const char * const state_complete_reasons[] = {
  8841. [0x00] = "Reason unknown",
  8842. [0x01] = "Link was halted by driver, refer to LinkDownReason",
  8843. [0x02] = "Link partner reported failure",
  8844. [0x10] = "Unable to achieve frame sync on any lane",
  8845. [0x11] =
  8846. "Unable to find a common bit rate with the link partner",
  8847. [0x12] =
  8848. "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
  8849. [0x13] =
  8850. "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
  8851. [0x14] = no_state_complete,
  8852. [0x15] =
  8853. "State timeout occurred before link partner identified equalization presets",
  8854. [0x16] =
  8855. "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
  8856. [0x17] = tx_out_of_policy,
  8857. [0x20] = all_lanes_dead_timeout_expired,
  8858. [0x21] =
  8859. "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
  8860. [0x22] = no_state_complete,
  8861. [0x23] =
  8862. "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
  8863. [0x24] = tx_out_of_policy,
  8864. [0x30] = all_lanes_dead_timeout_expired,
  8865. [0x31] =
  8866. "State timeout occurred waiting for host to process received frames",
  8867. [0x32] = no_state_complete,
  8868. [0x33] =
  8869. "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
  8870. [0x34] = tx_out_of_policy,
  8871. [0x35] = "Negotiated link width is mutually exclusive",
  8872. [0x36] =
  8873. "Timed out before receiving verifycap frames in VerifyCap.Exchange",
  8874. [0x37] = "Unable to resolve secure data exchange",
  8875. };
  8876. static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
  8877. u32 code)
  8878. {
  8879. const char *str = NULL;
  8880. if (code < ARRAY_SIZE(state_complete_reasons))
  8881. str = state_complete_reasons[code];
  8882. if (str)
  8883. return str;
  8884. return "Reserved";
  8885. }
  8886. /* describe the given last state complete frame */
  8887. static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
  8888. const char *prefix)
  8889. {
  8890. struct hfi1_devdata *dd = ppd->dd;
  8891. u32 success;
  8892. u32 state;
  8893. u32 reason;
  8894. u32 lanes;
  8895. /*
  8896. * Decode frame:
  8897. * [ 0: 0] - success
  8898. * [ 3: 1] - state
  8899. * [ 7: 4] - next state timeout
  8900. * [15: 8] - reason code
  8901. * [31:16] - lanes
  8902. */
  8903. success = frame & 0x1;
  8904. state = (frame >> 1) & 0x7;
  8905. reason = (frame >> 8) & 0xff;
  8906. lanes = (frame >> 16) & 0xffff;
  8907. dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
  8908. prefix, frame);
  8909. dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
  8910. state_completed_string(state), state);
  8911. dd_dev_err(dd, " state successfully completed: %s\n",
  8912. success ? "yes" : "no");
  8913. dd_dev_err(dd, " fail reason 0x%x: %s\n",
  8914. reason, state_complete_reason_code_string(ppd, reason));
  8915. dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
  8916. }
  8917. /*
  8918. * Read the last state complete frames and explain them. This routine
  8919. * expects to be called if the link went down during link negotiation
  8920. * and initialization (LNI). That is, anywhere between polling and link up.
  8921. */
  8922. static void check_lni_states(struct hfi1_pportdata *ppd)
  8923. {
  8924. u32 last_local_state;
  8925. u32 last_remote_state;
  8926. read_last_local_state(ppd->dd, &last_local_state);
  8927. read_last_remote_state(ppd->dd, &last_remote_state);
  8928. /*
  8929. * Don't report anything if there is nothing to report. A value of
  8930. * 0 means the link was taken down while polling and there was no
  8931. * training in-process.
  8932. */
  8933. if (last_local_state == 0 && last_remote_state == 0)
  8934. return;
  8935. decode_state_complete(ppd, last_local_state, "transmitted");
  8936. decode_state_complete(ppd, last_remote_state, "received");
  8937. }
  8938. /* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
  8939. static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
  8940. {
  8941. u64 reg;
  8942. unsigned long timeout;
  8943. /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
  8944. timeout = jiffies + msecs_to_jiffies(wait_ms);
  8945. while (1) {
  8946. reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
  8947. if (reg)
  8948. break;
  8949. if (time_after(jiffies, timeout)) {
  8950. dd_dev_err(dd,
  8951. "timeout waiting for LINK_TRANSFER_ACTIVE\n");
  8952. return -ETIMEDOUT;
  8953. }
  8954. udelay(2);
  8955. }
  8956. return 0;
  8957. }
  8958. /* called when the logical link state is not down as it should be */
  8959. static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
  8960. {
  8961. struct hfi1_devdata *dd = ppd->dd;
  8962. /*
  8963. * Bring link up in LCB loopback
  8964. */
  8965. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  8966. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
  8967. DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
  8968. write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
  8969. write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
  8970. write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
  8971. write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
  8972. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
  8973. (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
  8974. udelay(3);
  8975. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
  8976. write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
  8977. wait_link_transfer_active(dd, 100);
  8978. /*
  8979. * Bring the link down again.
  8980. */
  8981. write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
  8982. write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
  8983. write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
  8984. dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
  8985. }
  8986. /*
  8987. * Helper for set_link_state(). Do not call except from that routine.
  8988. * Expects ppd->hls_mutex to be held.
  8989. *
  8990. * @rem_reason value to be sent to the neighbor
  8991. *
  8992. * LinkDownReasons only set if transition succeeds.
  8993. */
  8994. static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
  8995. {
  8996. struct hfi1_devdata *dd = ppd->dd;
  8997. u32 previous_state;
  8998. int offline_state_ret;
  8999. int ret;
  9000. update_lcb_cache(dd);
  9001. previous_state = ppd->host_link_state;
  9002. ppd->host_link_state = HLS_GOING_OFFLINE;
  9003. /* start offline transition */
  9004. ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
  9005. if (ret != HCMD_SUCCESS) {
  9006. dd_dev_err(dd,
  9007. "Failed to transition to Offline link state, return %d\n",
  9008. ret);
  9009. return -EINVAL;
  9010. }
  9011. if (ppd->offline_disabled_reason ==
  9012. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
  9013. ppd->offline_disabled_reason =
  9014. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
  9015. offline_state_ret = wait_phys_link_offline_substates(ppd, 10000);
  9016. if (offline_state_ret < 0)
  9017. return offline_state_ret;
  9018. /* Disabling AOC transmitters */
  9019. if (ppd->port_type == PORT_TYPE_QSFP &&
  9020. ppd->qsfp_info.limiting_active &&
  9021. qsfp_mod_present(ppd)) {
  9022. int ret;
  9023. ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
  9024. if (ret == 0) {
  9025. set_qsfp_tx(ppd, 0);
  9026. release_chip_resource(dd, qsfp_resource(dd));
  9027. } else {
  9028. /* not fatal, but should warn */
  9029. dd_dev_err(dd,
  9030. "Unable to acquire lock to turn off QSFP TX\n");
  9031. }
  9032. }
  9033. /*
  9034. * Wait for the offline.Quiet transition if it hasn't happened yet. It
  9035. * can take a while for the link to go down.
  9036. */
  9037. if (offline_state_ret != PLS_OFFLINE_QUIET) {
  9038. ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 30000);
  9039. if (ret < 0)
  9040. return ret;
  9041. }
  9042. /*
  9043. * Now in charge of LCB - must be after the physical state is
  9044. * offline.quiet and before host_link_state is changed.
  9045. */
  9046. set_host_lcb_access(dd);
  9047. write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
  9048. /* make sure the logical state is also down */
  9049. ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
  9050. if (ret)
  9051. force_logical_link_state_down(ppd);
  9052. ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
  9053. update_statusp(ppd, IB_PORT_DOWN);
  9054. /*
  9055. * The LNI has a mandatory wait time after the physical state
  9056. * moves to Offline.Quiet. The wait time may be different
  9057. * depending on how the link went down. The 8051 firmware
  9058. * will observe the needed wait time and only move to ready
  9059. * when that is completed. The largest of the quiet timeouts
  9060. * is 6s, so wait that long and then at least 0.5s more for
  9061. * other transitions, and another 0.5s for a buffer.
  9062. */
  9063. ret = wait_fm_ready(dd, 7000);
  9064. if (ret) {
  9065. dd_dev_err(dd,
  9066. "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
  9067. /* state is really offline, so make it so */
  9068. ppd->host_link_state = HLS_DN_OFFLINE;
  9069. return ret;
  9070. }
  9071. /*
  9072. * The state is now offline and the 8051 is ready to accept host
  9073. * requests.
  9074. * - change our state
  9075. * - notify others if we were previously in a linkup state
  9076. */
  9077. ppd->host_link_state = HLS_DN_OFFLINE;
  9078. if (previous_state & HLS_UP) {
  9079. /* went down while link was up */
  9080. handle_linkup_change(dd, 0);
  9081. } else if (previous_state
  9082. & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
  9083. /* went down while attempting link up */
  9084. check_lni_states(ppd);
  9085. /* The QSFP doesn't need to be reset on LNI failure */
  9086. ppd->qsfp_info.reset_needed = 0;
  9087. }
  9088. /* the active link width (downgrade) is 0 on link down */
  9089. ppd->link_width_active = 0;
  9090. ppd->link_width_downgrade_tx_active = 0;
  9091. ppd->link_width_downgrade_rx_active = 0;
  9092. ppd->current_egress_rate = 0;
  9093. return 0;
  9094. }
  9095. /* return the link state name */
  9096. static const char *link_state_name(u32 state)
  9097. {
  9098. const char *name;
  9099. int n = ilog2(state);
  9100. static const char * const names[] = {
  9101. [__HLS_UP_INIT_BP] = "INIT",
  9102. [__HLS_UP_ARMED_BP] = "ARMED",
  9103. [__HLS_UP_ACTIVE_BP] = "ACTIVE",
  9104. [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
  9105. [__HLS_DN_POLL_BP] = "POLL",
  9106. [__HLS_DN_DISABLE_BP] = "DISABLE",
  9107. [__HLS_DN_OFFLINE_BP] = "OFFLINE",
  9108. [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
  9109. [__HLS_GOING_UP_BP] = "GOING_UP",
  9110. [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
  9111. [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
  9112. };
  9113. name = n < ARRAY_SIZE(names) ? names[n] : NULL;
  9114. return name ? name : "unknown";
  9115. }
  9116. /* return the link state reason name */
  9117. static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
  9118. {
  9119. if (state == HLS_UP_INIT) {
  9120. switch (ppd->linkinit_reason) {
  9121. case OPA_LINKINIT_REASON_LINKUP:
  9122. return "(LINKUP)";
  9123. case OPA_LINKINIT_REASON_FLAPPING:
  9124. return "(FLAPPING)";
  9125. case OPA_LINKINIT_OUTSIDE_POLICY:
  9126. return "(OUTSIDE_POLICY)";
  9127. case OPA_LINKINIT_QUARANTINED:
  9128. return "(QUARANTINED)";
  9129. case OPA_LINKINIT_INSUFIC_CAPABILITY:
  9130. return "(INSUFIC_CAPABILITY)";
  9131. default:
  9132. break;
  9133. }
  9134. }
  9135. return "";
  9136. }
  9137. /*
  9138. * driver_pstate - convert the driver's notion of a port's
  9139. * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
  9140. * Return -1 (converted to a u32) to indicate error.
  9141. */
  9142. u32 driver_pstate(struct hfi1_pportdata *ppd)
  9143. {
  9144. switch (ppd->host_link_state) {
  9145. case HLS_UP_INIT:
  9146. case HLS_UP_ARMED:
  9147. case HLS_UP_ACTIVE:
  9148. return IB_PORTPHYSSTATE_LINKUP;
  9149. case HLS_DN_POLL:
  9150. return IB_PORTPHYSSTATE_POLLING;
  9151. case HLS_DN_DISABLE:
  9152. return IB_PORTPHYSSTATE_DISABLED;
  9153. case HLS_DN_OFFLINE:
  9154. return OPA_PORTPHYSSTATE_OFFLINE;
  9155. case HLS_VERIFY_CAP:
  9156. return IB_PORTPHYSSTATE_POLLING;
  9157. case HLS_GOING_UP:
  9158. return IB_PORTPHYSSTATE_POLLING;
  9159. case HLS_GOING_OFFLINE:
  9160. return OPA_PORTPHYSSTATE_OFFLINE;
  9161. case HLS_LINK_COOLDOWN:
  9162. return OPA_PORTPHYSSTATE_OFFLINE;
  9163. case HLS_DN_DOWNDEF:
  9164. default:
  9165. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9166. ppd->host_link_state);
  9167. return -1;
  9168. }
  9169. }
  9170. /*
  9171. * driver_lstate - convert the driver's notion of a port's
  9172. * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
  9173. * (converted to a u32) to indicate error.
  9174. */
  9175. u32 driver_lstate(struct hfi1_pportdata *ppd)
  9176. {
  9177. if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
  9178. return IB_PORT_DOWN;
  9179. switch (ppd->host_link_state & HLS_UP) {
  9180. case HLS_UP_INIT:
  9181. return IB_PORT_INIT;
  9182. case HLS_UP_ARMED:
  9183. return IB_PORT_ARMED;
  9184. case HLS_UP_ACTIVE:
  9185. return IB_PORT_ACTIVE;
  9186. default:
  9187. dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
  9188. ppd->host_link_state);
  9189. return -1;
  9190. }
  9191. }
  9192. void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
  9193. u8 neigh_reason, u8 rem_reason)
  9194. {
  9195. if (ppd->local_link_down_reason.latest == 0 &&
  9196. ppd->neigh_link_down_reason.latest == 0) {
  9197. ppd->local_link_down_reason.latest = lcl_reason;
  9198. ppd->neigh_link_down_reason.latest = neigh_reason;
  9199. ppd->remote_link_down_reason = rem_reason;
  9200. }
  9201. }
  9202. /*
  9203. * Verify if BCT for data VLs is non-zero.
  9204. */
  9205. static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
  9206. {
  9207. return !!ppd->actual_vls_operational;
  9208. }
  9209. /*
  9210. * Change the physical and/or logical link state.
  9211. *
  9212. * Do not call this routine while inside an interrupt. It contains
  9213. * calls to routines that can take multiple seconds to finish.
  9214. *
  9215. * Returns 0 on success, -errno on failure.
  9216. */
  9217. int set_link_state(struct hfi1_pportdata *ppd, u32 state)
  9218. {
  9219. struct hfi1_devdata *dd = ppd->dd;
  9220. struct ib_event event = {.device = NULL};
  9221. int ret1, ret = 0;
  9222. int orig_new_state, poll_bounce;
  9223. mutex_lock(&ppd->hls_lock);
  9224. orig_new_state = state;
  9225. if (state == HLS_DN_DOWNDEF)
  9226. state = HLS_DEFAULT;
  9227. /* interpret poll -> poll as a link bounce */
  9228. poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
  9229. state == HLS_DN_POLL;
  9230. dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
  9231. link_state_name(ppd->host_link_state),
  9232. link_state_name(orig_new_state),
  9233. poll_bounce ? "(bounce) " : "",
  9234. link_state_reason_name(ppd, state));
  9235. /*
  9236. * If we're going to a (HLS_*) link state that implies the logical
  9237. * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
  9238. * reset is_sm_config_started to 0.
  9239. */
  9240. if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
  9241. ppd->is_sm_config_started = 0;
  9242. /*
  9243. * Do nothing if the states match. Let a poll to poll link bounce
  9244. * go through.
  9245. */
  9246. if (ppd->host_link_state == state && !poll_bounce)
  9247. goto done;
  9248. switch (state) {
  9249. case HLS_UP_INIT:
  9250. if (ppd->host_link_state == HLS_DN_POLL &&
  9251. (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
  9252. /*
  9253. * Quick link up jumps from polling to here.
  9254. *
  9255. * Whether in normal or loopback mode, the
  9256. * simulator jumps from polling to link up.
  9257. * Accept that here.
  9258. */
  9259. /* OK */
  9260. } else if (ppd->host_link_state != HLS_GOING_UP) {
  9261. goto unexpected;
  9262. }
  9263. /*
  9264. * Wait for Link_Up physical state.
  9265. * Physical and Logical states should already be
  9266. * be transitioned to LinkUp and LinkInit respectively.
  9267. */
  9268. ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
  9269. if (ret) {
  9270. dd_dev_err(dd,
  9271. "%s: physical state did not change to LINK-UP\n",
  9272. __func__);
  9273. break;
  9274. }
  9275. ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
  9276. if (ret) {
  9277. dd_dev_err(dd,
  9278. "%s: logical state did not change to INIT\n",
  9279. __func__);
  9280. break;
  9281. }
  9282. /* clear old transient LINKINIT_REASON code */
  9283. if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
  9284. ppd->linkinit_reason =
  9285. OPA_LINKINIT_REASON_LINKUP;
  9286. /* enable the port */
  9287. add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
  9288. handle_linkup_change(dd, 1);
  9289. ppd->host_link_state = HLS_UP_INIT;
  9290. update_statusp(ppd, IB_PORT_INIT);
  9291. break;
  9292. case HLS_UP_ARMED:
  9293. if (ppd->host_link_state != HLS_UP_INIT)
  9294. goto unexpected;
  9295. if (!data_vls_operational(ppd)) {
  9296. dd_dev_err(dd,
  9297. "%s: data VLs not operational\n", __func__);
  9298. ret = -EINVAL;
  9299. break;
  9300. }
  9301. set_logical_state(dd, LSTATE_ARMED);
  9302. ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
  9303. if (ret) {
  9304. dd_dev_err(dd,
  9305. "%s: logical state did not change to ARMED\n",
  9306. __func__);
  9307. break;
  9308. }
  9309. ppd->host_link_state = HLS_UP_ARMED;
  9310. update_statusp(ppd, IB_PORT_ARMED);
  9311. /*
  9312. * The simulator does not currently implement SMA messages,
  9313. * so neighbor_normal is not set. Set it here when we first
  9314. * move to Armed.
  9315. */
  9316. if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
  9317. ppd->neighbor_normal = 1;
  9318. break;
  9319. case HLS_UP_ACTIVE:
  9320. if (ppd->host_link_state != HLS_UP_ARMED)
  9321. goto unexpected;
  9322. set_logical_state(dd, LSTATE_ACTIVE);
  9323. ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
  9324. if (ret) {
  9325. dd_dev_err(dd,
  9326. "%s: logical state did not change to ACTIVE\n",
  9327. __func__);
  9328. } else {
  9329. /* tell all engines to go running */
  9330. sdma_all_running(dd);
  9331. ppd->host_link_state = HLS_UP_ACTIVE;
  9332. update_statusp(ppd, IB_PORT_ACTIVE);
  9333. /* Signal the IB layer that the port has went active */
  9334. event.device = &dd->verbs_dev.rdi.ibdev;
  9335. event.element.port_num = ppd->port;
  9336. event.event = IB_EVENT_PORT_ACTIVE;
  9337. }
  9338. break;
  9339. case HLS_DN_POLL:
  9340. if ((ppd->host_link_state == HLS_DN_DISABLE ||
  9341. ppd->host_link_state == HLS_DN_OFFLINE) &&
  9342. dd->dc_shutdown)
  9343. dc_start(dd);
  9344. /* Hand LED control to the DC */
  9345. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  9346. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9347. u8 tmp = ppd->link_enabled;
  9348. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9349. if (ret) {
  9350. ppd->link_enabled = tmp;
  9351. break;
  9352. }
  9353. ppd->remote_link_down_reason = 0;
  9354. if (ppd->driver_link_ready)
  9355. ppd->link_enabled = 1;
  9356. }
  9357. set_all_slowpath(ppd->dd);
  9358. ret = set_local_link_attributes(ppd);
  9359. if (ret)
  9360. break;
  9361. ppd->port_error_action = 0;
  9362. ppd->host_link_state = HLS_DN_POLL;
  9363. if (quick_linkup) {
  9364. /* quick linkup does not go into polling */
  9365. ret = do_quick_linkup(dd);
  9366. } else {
  9367. ret1 = set_physical_link_state(dd, PLS_POLLING);
  9368. if (ret1 != HCMD_SUCCESS) {
  9369. dd_dev_err(dd,
  9370. "Failed to transition to Polling link state, return 0x%x\n",
  9371. ret1);
  9372. ret = -EINVAL;
  9373. }
  9374. }
  9375. ppd->offline_disabled_reason =
  9376. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  9377. /*
  9378. * If an error occurred above, go back to offline. The
  9379. * caller may reschedule another attempt.
  9380. */
  9381. if (ret)
  9382. goto_offline(ppd, 0);
  9383. else
  9384. log_physical_state(ppd, PLS_POLLING);
  9385. break;
  9386. case HLS_DN_DISABLE:
  9387. /* link is disabled */
  9388. ppd->link_enabled = 0;
  9389. /* allow any state to transition to disabled */
  9390. /* must transition to offline first */
  9391. if (ppd->host_link_state != HLS_DN_OFFLINE) {
  9392. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9393. if (ret)
  9394. break;
  9395. ppd->remote_link_down_reason = 0;
  9396. }
  9397. if (!dd->dc_shutdown) {
  9398. ret1 = set_physical_link_state(dd, PLS_DISABLED);
  9399. if (ret1 != HCMD_SUCCESS) {
  9400. dd_dev_err(dd,
  9401. "Failed to transition to Disabled link state, return 0x%x\n",
  9402. ret1);
  9403. ret = -EINVAL;
  9404. break;
  9405. }
  9406. ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
  9407. if (ret) {
  9408. dd_dev_err(dd,
  9409. "%s: physical state did not change to DISABLED\n",
  9410. __func__);
  9411. break;
  9412. }
  9413. dc_shutdown(dd);
  9414. }
  9415. ppd->host_link_state = HLS_DN_DISABLE;
  9416. break;
  9417. case HLS_DN_OFFLINE:
  9418. if (ppd->host_link_state == HLS_DN_DISABLE)
  9419. dc_start(dd);
  9420. /* allow any state to transition to offline */
  9421. ret = goto_offline(ppd, ppd->remote_link_down_reason);
  9422. if (!ret)
  9423. ppd->remote_link_down_reason = 0;
  9424. break;
  9425. case HLS_VERIFY_CAP:
  9426. if (ppd->host_link_state != HLS_DN_POLL)
  9427. goto unexpected;
  9428. ppd->host_link_state = HLS_VERIFY_CAP;
  9429. log_physical_state(ppd, PLS_CONFIGPHY_VERIFYCAP);
  9430. break;
  9431. case HLS_GOING_UP:
  9432. if (ppd->host_link_state != HLS_VERIFY_CAP)
  9433. goto unexpected;
  9434. ret1 = set_physical_link_state(dd, PLS_LINKUP);
  9435. if (ret1 != HCMD_SUCCESS) {
  9436. dd_dev_err(dd,
  9437. "Failed to transition to link up state, return 0x%x\n",
  9438. ret1);
  9439. ret = -EINVAL;
  9440. break;
  9441. }
  9442. ppd->host_link_state = HLS_GOING_UP;
  9443. break;
  9444. case HLS_GOING_OFFLINE: /* transient within goto_offline() */
  9445. case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
  9446. default:
  9447. dd_dev_info(dd, "%s: state 0x%x: not supported\n",
  9448. __func__, state);
  9449. ret = -EINVAL;
  9450. break;
  9451. }
  9452. goto done;
  9453. unexpected:
  9454. dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
  9455. __func__, link_state_name(ppd->host_link_state),
  9456. link_state_name(state));
  9457. ret = -EINVAL;
  9458. done:
  9459. mutex_unlock(&ppd->hls_lock);
  9460. if (event.device)
  9461. ib_dispatch_event(&event);
  9462. return ret;
  9463. }
  9464. int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
  9465. {
  9466. u64 reg;
  9467. int ret = 0;
  9468. switch (which) {
  9469. case HFI1_IB_CFG_LIDLMC:
  9470. set_lidlmc(ppd);
  9471. break;
  9472. case HFI1_IB_CFG_VL_HIGH_LIMIT:
  9473. /*
  9474. * The VL Arbitrator high limit is sent in units of 4k
  9475. * bytes, while HFI stores it in units of 64 bytes.
  9476. */
  9477. val *= 4096 / 64;
  9478. reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
  9479. << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
  9480. write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
  9481. break;
  9482. case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  9483. /* HFI only supports POLL as the default link down state */
  9484. if (val != HLS_DN_POLL)
  9485. ret = -EINVAL;
  9486. break;
  9487. case HFI1_IB_CFG_OP_VLS:
  9488. if (ppd->vls_operational != val) {
  9489. ppd->vls_operational = val;
  9490. if (!ppd->port)
  9491. ret = -EINVAL;
  9492. }
  9493. break;
  9494. /*
  9495. * For link width, link width downgrade, and speed enable, always AND
  9496. * the setting with what is actually supported. This has two benefits.
  9497. * First, enabled can't have unsupported values, no matter what the
  9498. * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
  9499. * "fill in with your supported value" have all the bits in the
  9500. * field set, so simply ANDing with supported has the desired result.
  9501. */
  9502. case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
  9503. ppd->link_width_enabled = val & ppd->link_width_supported;
  9504. break;
  9505. case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
  9506. ppd->link_width_downgrade_enabled =
  9507. val & ppd->link_width_downgrade_supported;
  9508. break;
  9509. case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
  9510. ppd->link_speed_enabled = val & ppd->link_speed_supported;
  9511. break;
  9512. case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  9513. /*
  9514. * HFI does not follow IB specs, save this value
  9515. * so we can report it, if asked.
  9516. */
  9517. ppd->overrun_threshold = val;
  9518. break;
  9519. case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  9520. /*
  9521. * HFI does not follow IB specs, save this value
  9522. * so we can report it, if asked.
  9523. */
  9524. ppd->phy_error_threshold = val;
  9525. break;
  9526. case HFI1_IB_CFG_MTU:
  9527. set_send_length(ppd);
  9528. break;
  9529. case HFI1_IB_CFG_PKEYS:
  9530. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  9531. set_partition_keys(ppd);
  9532. break;
  9533. default:
  9534. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  9535. dd_dev_info(ppd->dd,
  9536. "%s: which %s, val 0x%x: not implemented\n",
  9537. __func__, ib_cfg_name(which), val);
  9538. break;
  9539. }
  9540. return ret;
  9541. }
  9542. /* begin functions related to vl arbitration table caching */
  9543. static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
  9544. {
  9545. int i;
  9546. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9547. VL_ARB_LOW_PRIO_TABLE_SIZE);
  9548. BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
  9549. VL_ARB_HIGH_PRIO_TABLE_SIZE);
  9550. /*
  9551. * Note that we always return values directly from the
  9552. * 'vl_arb_cache' (and do no CSR reads) in response to a
  9553. * 'Get(VLArbTable)'. This is obviously correct after a
  9554. * 'Set(VLArbTable)', since the cache will then be up to
  9555. * date. But it's also correct prior to any 'Set(VLArbTable)'
  9556. * since then both the cache, and the relevant h/w registers
  9557. * will be zeroed.
  9558. */
  9559. for (i = 0; i < MAX_PRIO_TABLE; i++)
  9560. spin_lock_init(&ppd->vl_arb_cache[i].lock);
  9561. }
  9562. /*
  9563. * vl_arb_lock_cache
  9564. *
  9565. * All other vl_arb_* functions should be called only after locking
  9566. * the cache.
  9567. */
  9568. static inline struct vl_arb_cache *
  9569. vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
  9570. {
  9571. if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
  9572. return NULL;
  9573. spin_lock(&ppd->vl_arb_cache[idx].lock);
  9574. return &ppd->vl_arb_cache[idx];
  9575. }
  9576. static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
  9577. {
  9578. spin_unlock(&ppd->vl_arb_cache[idx].lock);
  9579. }
  9580. static void vl_arb_get_cache(struct vl_arb_cache *cache,
  9581. struct ib_vl_weight_elem *vl)
  9582. {
  9583. memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9584. }
  9585. static void vl_arb_set_cache(struct vl_arb_cache *cache,
  9586. struct ib_vl_weight_elem *vl)
  9587. {
  9588. memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9589. }
  9590. static int vl_arb_match_cache(struct vl_arb_cache *cache,
  9591. struct ib_vl_weight_elem *vl)
  9592. {
  9593. return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
  9594. }
  9595. /* end functions related to vl arbitration table caching */
  9596. static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
  9597. u32 size, struct ib_vl_weight_elem *vl)
  9598. {
  9599. struct hfi1_devdata *dd = ppd->dd;
  9600. u64 reg;
  9601. unsigned int i, is_up = 0;
  9602. int drain, ret = 0;
  9603. mutex_lock(&ppd->hls_lock);
  9604. if (ppd->host_link_state & HLS_UP)
  9605. is_up = 1;
  9606. drain = !is_ax(dd) && is_up;
  9607. if (drain)
  9608. /*
  9609. * Before adjusting VL arbitration weights, empty per-VL
  9610. * FIFOs, otherwise a packet whose VL weight is being
  9611. * set to 0 could get stuck in a FIFO with no chance to
  9612. * egress.
  9613. */
  9614. ret = stop_drain_data_vls(dd);
  9615. if (ret) {
  9616. dd_dev_err(
  9617. dd,
  9618. "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
  9619. __func__);
  9620. goto err;
  9621. }
  9622. for (i = 0; i < size; i++, vl++) {
  9623. /*
  9624. * NOTE: The low priority shift and mask are used here, but
  9625. * they are the same for both the low and high registers.
  9626. */
  9627. reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
  9628. << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
  9629. | (((u64)vl->weight
  9630. & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
  9631. << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
  9632. write_csr(dd, target + (i * 8), reg);
  9633. }
  9634. pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
  9635. if (drain)
  9636. open_fill_data_vls(dd); /* reopen all VLs */
  9637. err:
  9638. mutex_unlock(&ppd->hls_lock);
  9639. return ret;
  9640. }
  9641. /*
  9642. * Read one credit merge VL register.
  9643. */
  9644. static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
  9645. struct vl_limit *vll)
  9646. {
  9647. u64 reg = read_csr(dd, csr);
  9648. vll->dedicated = cpu_to_be16(
  9649. (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
  9650. & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
  9651. vll->shared = cpu_to_be16(
  9652. (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
  9653. & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
  9654. }
  9655. /*
  9656. * Read the current credit merge limits.
  9657. */
  9658. static int get_buffer_control(struct hfi1_devdata *dd,
  9659. struct buffer_control *bc, u16 *overall_limit)
  9660. {
  9661. u64 reg;
  9662. int i;
  9663. /* not all entries are filled in */
  9664. memset(bc, 0, sizeof(*bc));
  9665. /* OPA and HFI have a 1-1 mapping */
  9666. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  9667. read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
  9668. /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
  9669. read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
  9670. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9671. bc->overall_shared_limit = cpu_to_be16(
  9672. (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
  9673. & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
  9674. if (overall_limit)
  9675. *overall_limit = (reg
  9676. >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
  9677. & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
  9678. return sizeof(struct buffer_control);
  9679. }
  9680. static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9681. {
  9682. u64 reg;
  9683. int i;
  9684. /* each register contains 16 SC->VLnt mappings, 4 bits each */
  9685. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
  9686. for (i = 0; i < sizeof(u64); i++) {
  9687. u8 byte = *(((u8 *)&reg) + i);
  9688. dp->vlnt[2 * i] = byte & 0xf;
  9689. dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
  9690. }
  9691. reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
  9692. for (i = 0; i < sizeof(u64); i++) {
  9693. u8 byte = *(((u8 *)&reg) + i);
  9694. dp->vlnt[16 + (2 * i)] = byte & 0xf;
  9695. dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
  9696. }
  9697. return sizeof(struct sc2vlnt);
  9698. }
  9699. static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
  9700. struct ib_vl_weight_elem *vl)
  9701. {
  9702. unsigned int i;
  9703. for (i = 0; i < nelems; i++, vl++) {
  9704. vl->vl = 0xf;
  9705. vl->weight = 0;
  9706. }
  9707. }
  9708. static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
  9709. {
  9710. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
  9711. DC_SC_VL_VAL(15_0,
  9712. 0, dp->vlnt[0] & 0xf,
  9713. 1, dp->vlnt[1] & 0xf,
  9714. 2, dp->vlnt[2] & 0xf,
  9715. 3, dp->vlnt[3] & 0xf,
  9716. 4, dp->vlnt[4] & 0xf,
  9717. 5, dp->vlnt[5] & 0xf,
  9718. 6, dp->vlnt[6] & 0xf,
  9719. 7, dp->vlnt[7] & 0xf,
  9720. 8, dp->vlnt[8] & 0xf,
  9721. 9, dp->vlnt[9] & 0xf,
  9722. 10, dp->vlnt[10] & 0xf,
  9723. 11, dp->vlnt[11] & 0xf,
  9724. 12, dp->vlnt[12] & 0xf,
  9725. 13, dp->vlnt[13] & 0xf,
  9726. 14, dp->vlnt[14] & 0xf,
  9727. 15, dp->vlnt[15] & 0xf));
  9728. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
  9729. DC_SC_VL_VAL(31_16,
  9730. 16, dp->vlnt[16] & 0xf,
  9731. 17, dp->vlnt[17] & 0xf,
  9732. 18, dp->vlnt[18] & 0xf,
  9733. 19, dp->vlnt[19] & 0xf,
  9734. 20, dp->vlnt[20] & 0xf,
  9735. 21, dp->vlnt[21] & 0xf,
  9736. 22, dp->vlnt[22] & 0xf,
  9737. 23, dp->vlnt[23] & 0xf,
  9738. 24, dp->vlnt[24] & 0xf,
  9739. 25, dp->vlnt[25] & 0xf,
  9740. 26, dp->vlnt[26] & 0xf,
  9741. 27, dp->vlnt[27] & 0xf,
  9742. 28, dp->vlnt[28] & 0xf,
  9743. 29, dp->vlnt[29] & 0xf,
  9744. 30, dp->vlnt[30] & 0xf,
  9745. 31, dp->vlnt[31] & 0xf));
  9746. }
  9747. static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
  9748. u16 limit)
  9749. {
  9750. if (limit != 0)
  9751. dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
  9752. what, (int)limit, idx);
  9753. }
  9754. /* change only the shared limit portion of SendCmGLobalCredit */
  9755. static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
  9756. {
  9757. u64 reg;
  9758. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9759. reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
  9760. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
  9761. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9762. }
  9763. /* change only the total credit limit portion of SendCmGLobalCredit */
  9764. static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
  9765. {
  9766. u64 reg;
  9767. reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
  9768. reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
  9769. reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
  9770. write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
  9771. }
  9772. /* set the given per-VL shared limit */
  9773. static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
  9774. {
  9775. u64 reg;
  9776. u32 addr;
  9777. if (vl < TXE_NUM_DATA_VL)
  9778. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9779. else
  9780. addr = SEND_CM_CREDIT_VL15;
  9781. reg = read_csr(dd, addr);
  9782. reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
  9783. reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
  9784. write_csr(dd, addr, reg);
  9785. }
  9786. /* set the given per-VL dedicated limit */
  9787. static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
  9788. {
  9789. u64 reg;
  9790. u32 addr;
  9791. if (vl < TXE_NUM_DATA_VL)
  9792. addr = SEND_CM_CREDIT_VL + (8 * vl);
  9793. else
  9794. addr = SEND_CM_CREDIT_VL15;
  9795. reg = read_csr(dd, addr);
  9796. reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
  9797. reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
  9798. write_csr(dd, addr, reg);
  9799. }
  9800. /* spin until the given per-VL status mask bits clear */
  9801. static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
  9802. const char *which)
  9803. {
  9804. unsigned long timeout;
  9805. u64 reg;
  9806. timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
  9807. while (1) {
  9808. reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
  9809. if (reg == 0)
  9810. return; /* success */
  9811. if (time_after(jiffies, timeout))
  9812. break; /* timed out */
  9813. udelay(1);
  9814. }
  9815. dd_dev_err(dd,
  9816. "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
  9817. which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
  9818. /*
  9819. * If this occurs, it is likely there was a credit loss on the link.
  9820. * The only recovery from that is a link bounce.
  9821. */
  9822. dd_dev_err(dd,
  9823. "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
  9824. }
  9825. /*
  9826. * The number of credits on the VLs may be changed while everything
  9827. * is "live", but the following algorithm must be followed due to
  9828. * how the hardware is actually implemented. In particular,
  9829. * Return_Credit_Status[] is the only correct status check.
  9830. *
  9831. * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
  9832. * set Global_Shared_Credit_Limit = 0
  9833. * use_all_vl = 1
  9834. * mask0 = all VLs that are changing either dedicated or shared limits
  9835. * set Shared_Limit[mask0] = 0
  9836. * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
  9837. * if (changing any dedicated limit)
  9838. * mask1 = all VLs that are lowering dedicated limits
  9839. * lower Dedicated_Limit[mask1]
  9840. * spin until Return_Credit_Status[mask1] == 0
  9841. * raise Dedicated_Limits
  9842. * raise Shared_Limits
  9843. * raise Global_Shared_Credit_Limit
  9844. *
  9845. * lower = if the new limit is lower, set the limit to the new value
  9846. * raise = if the new limit is higher than the current value (may be changed
  9847. * earlier in the algorithm), set the new limit to the new value
  9848. */
  9849. int set_buffer_control(struct hfi1_pportdata *ppd,
  9850. struct buffer_control *new_bc)
  9851. {
  9852. struct hfi1_devdata *dd = ppd->dd;
  9853. u64 changing_mask, ld_mask, stat_mask;
  9854. int change_count;
  9855. int i, use_all_mask;
  9856. int this_shared_changing;
  9857. int vl_count = 0, ret;
  9858. /*
  9859. * A0: add the variable any_shared_limit_changing below and in the
  9860. * algorithm above. If removing A0 support, it can be removed.
  9861. */
  9862. int any_shared_limit_changing;
  9863. struct buffer_control cur_bc;
  9864. u8 changing[OPA_MAX_VLS];
  9865. u8 lowering_dedicated[OPA_MAX_VLS];
  9866. u16 cur_total;
  9867. u32 new_total = 0;
  9868. const u64 all_mask =
  9869. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
  9870. | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
  9871. | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
  9872. | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
  9873. | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
  9874. | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
  9875. | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
  9876. | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
  9877. | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
  9878. #define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
  9879. #define NUM_USABLE_VLS 16 /* look at VL15 and less */
  9880. /* find the new total credits, do sanity check on unused VLs */
  9881. for (i = 0; i < OPA_MAX_VLS; i++) {
  9882. if (valid_vl(i)) {
  9883. new_total += be16_to_cpu(new_bc->vl[i].dedicated);
  9884. continue;
  9885. }
  9886. nonzero_msg(dd, i, "dedicated",
  9887. be16_to_cpu(new_bc->vl[i].dedicated));
  9888. nonzero_msg(dd, i, "shared",
  9889. be16_to_cpu(new_bc->vl[i].shared));
  9890. new_bc->vl[i].dedicated = 0;
  9891. new_bc->vl[i].shared = 0;
  9892. }
  9893. new_total += be16_to_cpu(new_bc->overall_shared_limit);
  9894. /* fetch the current values */
  9895. get_buffer_control(dd, &cur_bc, &cur_total);
  9896. /*
  9897. * Create the masks we will use.
  9898. */
  9899. memset(changing, 0, sizeof(changing));
  9900. memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
  9901. /*
  9902. * NOTE: Assumes that the individual VL bits are adjacent and in
  9903. * increasing order
  9904. */
  9905. stat_mask =
  9906. SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
  9907. changing_mask = 0;
  9908. ld_mask = 0;
  9909. change_count = 0;
  9910. any_shared_limit_changing = 0;
  9911. for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
  9912. if (!valid_vl(i))
  9913. continue;
  9914. this_shared_changing = new_bc->vl[i].shared
  9915. != cur_bc.vl[i].shared;
  9916. if (this_shared_changing)
  9917. any_shared_limit_changing = 1;
  9918. if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
  9919. this_shared_changing) {
  9920. changing[i] = 1;
  9921. changing_mask |= stat_mask;
  9922. change_count++;
  9923. }
  9924. if (be16_to_cpu(new_bc->vl[i].dedicated) <
  9925. be16_to_cpu(cur_bc.vl[i].dedicated)) {
  9926. lowering_dedicated[i] = 1;
  9927. ld_mask |= stat_mask;
  9928. }
  9929. }
  9930. /* bracket the credit change with a total adjustment */
  9931. if (new_total > cur_total)
  9932. set_global_limit(dd, new_total);
  9933. /*
  9934. * Start the credit change algorithm.
  9935. */
  9936. use_all_mask = 0;
  9937. if ((be16_to_cpu(new_bc->overall_shared_limit) <
  9938. be16_to_cpu(cur_bc.overall_shared_limit)) ||
  9939. (is_ax(dd) && any_shared_limit_changing)) {
  9940. set_global_shared(dd, 0);
  9941. cur_bc.overall_shared_limit = 0;
  9942. use_all_mask = 1;
  9943. }
  9944. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9945. if (!valid_vl(i))
  9946. continue;
  9947. if (changing[i]) {
  9948. set_vl_shared(dd, i, 0);
  9949. cur_bc.vl[i].shared = 0;
  9950. }
  9951. }
  9952. wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
  9953. "shared");
  9954. if (change_count > 0) {
  9955. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9956. if (!valid_vl(i))
  9957. continue;
  9958. if (lowering_dedicated[i]) {
  9959. set_vl_dedicated(dd, i,
  9960. be16_to_cpu(new_bc->
  9961. vl[i].dedicated));
  9962. cur_bc.vl[i].dedicated =
  9963. new_bc->vl[i].dedicated;
  9964. }
  9965. }
  9966. wait_for_vl_status_clear(dd, ld_mask, "dedicated");
  9967. /* now raise all dedicated that are going up */
  9968. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9969. if (!valid_vl(i))
  9970. continue;
  9971. if (be16_to_cpu(new_bc->vl[i].dedicated) >
  9972. be16_to_cpu(cur_bc.vl[i].dedicated))
  9973. set_vl_dedicated(dd, i,
  9974. be16_to_cpu(new_bc->
  9975. vl[i].dedicated));
  9976. }
  9977. }
  9978. /* next raise all shared that are going up */
  9979. for (i = 0; i < NUM_USABLE_VLS; i++) {
  9980. if (!valid_vl(i))
  9981. continue;
  9982. if (be16_to_cpu(new_bc->vl[i].shared) >
  9983. be16_to_cpu(cur_bc.vl[i].shared))
  9984. set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
  9985. }
  9986. /* finally raise the global shared */
  9987. if (be16_to_cpu(new_bc->overall_shared_limit) >
  9988. be16_to_cpu(cur_bc.overall_shared_limit))
  9989. set_global_shared(dd,
  9990. be16_to_cpu(new_bc->overall_shared_limit));
  9991. /* bracket the credit change with a total adjustment */
  9992. if (new_total < cur_total)
  9993. set_global_limit(dd, new_total);
  9994. /*
  9995. * Determine the actual number of operational VLS using the number of
  9996. * dedicated and shared credits for each VL.
  9997. */
  9998. if (change_count > 0) {
  9999. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  10000. if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
  10001. be16_to_cpu(new_bc->vl[i].shared) > 0)
  10002. vl_count++;
  10003. ppd->actual_vls_operational = vl_count;
  10004. ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
  10005. ppd->actual_vls_operational :
  10006. ppd->vls_operational,
  10007. NULL);
  10008. if (ret == 0)
  10009. ret = pio_map_init(dd, ppd->port - 1, vl_count ?
  10010. ppd->actual_vls_operational :
  10011. ppd->vls_operational, NULL);
  10012. if (ret)
  10013. return ret;
  10014. }
  10015. return 0;
  10016. }
  10017. /*
  10018. * Read the given fabric manager table. Return the size of the
  10019. * table (in bytes) on success, and a negative error code on
  10020. * failure.
  10021. */
  10022. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
  10023. {
  10024. int size;
  10025. struct vl_arb_cache *vlc;
  10026. switch (which) {
  10027. case FM_TBL_VL_HIGH_ARB:
  10028. size = 256;
  10029. /*
  10030. * OPA specifies 128 elements (of 2 bytes each), though
  10031. * HFI supports only 16 elements in h/w.
  10032. */
  10033. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10034. vl_arb_get_cache(vlc, t);
  10035. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10036. break;
  10037. case FM_TBL_VL_LOW_ARB:
  10038. size = 256;
  10039. /*
  10040. * OPA specifies 128 elements (of 2 bytes each), though
  10041. * HFI supports only 16 elements in h/w.
  10042. */
  10043. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10044. vl_arb_get_cache(vlc, t);
  10045. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10046. break;
  10047. case FM_TBL_BUFFER_CONTROL:
  10048. size = get_buffer_control(ppd->dd, t, NULL);
  10049. break;
  10050. case FM_TBL_SC2VLNT:
  10051. size = get_sc2vlnt(ppd->dd, t);
  10052. break;
  10053. case FM_TBL_VL_PREEMPT_ELEMS:
  10054. size = 256;
  10055. /* OPA specifies 128 elements, of 2 bytes each */
  10056. get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
  10057. break;
  10058. case FM_TBL_VL_PREEMPT_MATRIX:
  10059. size = 256;
  10060. /*
  10061. * OPA specifies that this is the same size as the VL
  10062. * arbitration tables (i.e., 256 bytes).
  10063. */
  10064. break;
  10065. default:
  10066. return -EINVAL;
  10067. }
  10068. return size;
  10069. }
  10070. /*
  10071. * Write the given fabric manager table.
  10072. */
  10073. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
  10074. {
  10075. int ret = 0;
  10076. struct vl_arb_cache *vlc;
  10077. switch (which) {
  10078. case FM_TBL_VL_HIGH_ARB:
  10079. vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
  10080. if (vl_arb_match_cache(vlc, t)) {
  10081. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10082. break;
  10083. }
  10084. vl_arb_set_cache(vlc, t);
  10085. vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
  10086. ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
  10087. VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
  10088. break;
  10089. case FM_TBL_VL_LOW_ARB:
  10090. vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
  10091. if (vl_arb_match_cache(vlc, t)) {
  10092. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10093. break;
  10094. }
  10095. vl_arb_set_cache(vlc, t);
  10096. vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
  10097. ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
  10098. VL_ARB_LOW_PRIO_TABLE_SIZE, t);
  10099. break;
  10100. case FM_TBL_BUFFER_CONTROL:
  10101. ret = set_buffer_control(ppd, t);
  10102. break;
  10103. case FM_TBL_SC2VLNT:
  10104. set_sc2vlnt(ppd->dd, t);
  10105. break;
  10106. default:
  10107. ret = -EINVAL;
  10108. }
  10109. return ret;
  10110. }
  10111. /*
  10112. * Disable all data VLs.
  10113. *
  10114. * Return 0 if disabled, non-zero if the VLs cannot be disabled.
  10115. */
  10116. static int disable_data_vls(struct hfi1_devdata *dd)
  10117. {
  10118. if (is_ax(dd))
  10119. return 1;
  10120. pio_send_control(dd, PSC_DATA_VL_DISABLE);
  10121. return 0;
  10122. }
  10123. /*
  10124. * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
  10125. * Just re-enables all data VLs (the "fill" part happens
  10126. * automatically - the name was chosen for symmetry with
  10127. * stop_drain_data_vls()).
  10128. *
  10129. * Return 0 if successful, non-zero if the VLs cannot be enabled.
  10130. */
  10131. int open_fill_data_vls(struct hfi1_devdata *dd)
  10132. {
  10133. if (is_ax(dd))
  10134. return 1;
  10135. pio_send_control(dd, PSC_DATA_VL_ENABLE);
  10136. return 0;
  10137. }
  10138. /*
  10139. * drain_data_vls() - assumes that disable_data_vls() has been called,
  10140. * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
  10141. * engines to drop to 0.
  10142. */
  10143. static void drain_data_vls(struct hfi1_devdata *dd)
  10144. {
  10145. sc_wait(dd);
  10146. sdma_wait(dd);
  10147. pause_for_credit_return(dd);
  10148. }
  10149. /*
  10150. * stop_drain_data_vls() - disable, then drain all per-VL fifos.
  10151. *
  10152. * Use open_fill_data_vls() to resume using data VLs. This pair is
  10153. * meant to be used like this:
  10154. *
  10155. * stop_drain_data_vls(dd);
  10156. * // do things with per-VL resources
  10157. * open_fill_data_vls(dd);
  10158. */
  10159. int stop_drain_data_vls(struct hfi1_devdata *dd)
  10160. {
  10161. int ret;
  10162. ret = disable_data_vls(dd);
  10163. if (ret == 0)
  10164. drain_data_vls(dd);
  10165. return ret;
  10166. }
  10167. /*
  10168. * Convert a nanosecond time to a cclock count. No matter how slow
  10169. * the cclock, a non-zero ns will always have a non-zero result.
  10170. */
  10171. u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
  10172. {
  10173. u32 cclocks;
  10174. if (dd->icode == ICODE_FPGA_EMULATION)
  10175. cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
  10176. else /* simulation pretends to be ASIC */
  10177. cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
  10178. if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
  10179. cclocks = 1;
  10180. return cclocks;
  10181. }
  10182. /*
  10183. * Convert a cclock count to nanoseconds. Not matter how slow
  10184. * the cclock, a non-zero cclocks will always have a non-zero result.
  10185. */
  10186. u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
  10187. {
  10188. u32 ns;
  10189. if (dd->icode == ICODE_FPGA_EMULATION)
  10190. ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
  10191. else /* simulation pretends to be ASIC */
  10192. ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
  10193. if (cclocks && !ns)
  10194. ns = 1;
  10195. return ns;
  10196. }
  10197. /*
  10198. * Dynamically adjust the receive interrupt timeout for a context based on
  10199. * incoming packet rate.
  10200. *
  10201. * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
  10202. */
  10203. static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
  10204. {
  10205. struct hfi1_devdata *dd = rcd->dd;
  10206. u32 timeout = rcd->rcvavail_timeout;
  10207. /*
  10208. * This algorithm doubles or halves the timeout depending on whether
  10209. * the number of packets received in this interrupt were less than or
  10210. * greater equal the interrupt count.
  10211. *
  10212. * The calculations below do not allow a steady state to be achieved.
  10213. * Only at the endpoints it is possible to have an unchanging
  10214. * timeout.
  10215. */
  10216. if (npkts < rcv_intr_count) {
  10217. /*
  10218. * Not enough packets arrived before the timeout, adjust
  10219. * timeout downward.
  10220. */
  10221. if (timeout < 2) /* already at minimum? */
  10222. return;
  10223. timeout >>= 1;
  10224. } else {
  10225. /*
  10226. * More than enough packets arrived before the timeout, adjust
  10227. * timeout upward.
  10228. */
  10229. if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
  10230. return;
  10231. timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
  10232. }
  10233. rcd->rcvavail_timeout = timeout;
  10234. /*
  10235. * timeout cannot be larger than rcv_intr_timeout_csr which has already
  10236. * been verified to be in range
  10237. */
  10238. write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
  10239. (u64)timeout <<
  10240. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10241. }
  10242. void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
  10243. u32 intr_adjust, u32 npkts)
  10244. {
  10245. struct hfi1_devdata *dd = rcd->dd;
  10246. u64 reg;
  10247. u32 ctxt = rcd->ctxt;
  10248. /*
  10249. * Need to write timeout register before updating RcvHdrHead to ensure
  10250. * that a new value is used when the HW decides to restart counting.
  10251. */
  10252. if (intr_adjust)
  10253. adjust_rcv_timeout(rcd, npkts);
  10254. if (updegr) {
  10255. reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
  10256. << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
  10257. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
  10258. }
  10259. mmiowb();
  10260. reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
  10261. (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
  10262. << RCV_HDR_HEAD_HEAD_SHIFT);
  10263. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10264. mmiowb();
  10265. }
  10266. u32 hdrqempty(struct hfi1_ctxtdata *rcd)
  10267. {
  10268. u32 head, tail;
  10269. head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
  10270. & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
  10271. if (rcd->rcvhdrtail_kvaddr)
  10272. tail = get_rcvhdrtail(rcd);
  10273. else
  10274. tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
  10275. return head == tail;
  10276. }
  10277. /*
  10278. * Context Control and Receive Array encoding for buffer size:
  10279. * 0x0 invalid
  10280. * 0x1 4 KB
  10281. * 0x2 8 KB
  10282. * 0x3 16 KB
  10283. * 0x4 32 KB
  10284. * 0x5 64 KB
  10285. * 0x6 128 KB
  10286. * 0x7 256 KB
  10287. * 0x8 512 KB (Receive Array only)
  10288. * 0x9 1 MB (Receive Array only)
  10289. * 0xa 2 MB (Receive Array only)
  10290. *
  10291. * 0xB-0xF - reserved (Receive Array only)
  10292. *
  10293. *
  10294. * This routine assumes that the value has already been sanity checked.
  10295. */
  10296. static u32 encoded_size(u32 size)
  10297. {
  10298. switch (size) {
  10299. case 4 * 1024: return 0x1;
  10300. case 8 * 1024: return 0x2;
  10301. case 16 * 1024: return 0x3;
  10302. case 32 * 1024: return 0x4;
  10303. case 64 * 1024: return 0x5;
  10304. case 128 * 1024: return 0x6;
  10305. case 256 * 1024: return 0x7;
  10306. case 512 * 1024: return 0x8;
  10307. case 1 * 1024 * 1024: return 0x9;
  10308. case 2 * 1024 * 1024: return 0xa;
  10309. }
  10310. return 0x1; /* if invalid, go with the minimum size */
  10311. }
  10312. void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
  10313. struct hfi1_ctxtdata *rcd)
  10314. {
  10315. u64 rcvctrl, reg;
  10316. int did_enable = 0;
  10317. u16 ctxt;
  10318. if (!rcd)
  10319. return;
  10320. ctxt = rcd->ctxt;
  10321. hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
  10322. rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
  10323. /* if the context already enabled, don't do the extra steps */
  10324. if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
  10325. !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
  10326. /* reset the tail and hdr addresses, and sequence count */
  10327. write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
  10328. rcd->rcvhdrq_dma);
  10329. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  10330. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10331. rcd->rcvhdrqtailaddr_dma);
  10332. rcd->seq_cnt = 1;
  10333. /* reset the cached receive header queue head value */
  10334. rcd->head = 0;
  10335. /*
  10336. * Zero the receive header queue so we don't get false
  10337. * positives when checking the sequence number. The
  10338. * sequence numbers could land exactly on the same spot.
  10339. * E.g. a rcd restart before the receive header wrapped.
  10340. */
  10341. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  10342. /* starting timeout */
  10343. rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
  10344. /* enable the context */
  10345. rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
  10346. /* clean the egr buffer size first */
  10347. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10348. rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
  10349. & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
  10350. << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
  10351. /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
  10352. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
  10353. did_enable = 1;
  10354. /* zero RcvEgrIndexHead */
  10355. write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
  10356. /* set eager count and base index */
  10357. reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
  10358. & RCV_EGR_CTRL_EGR_CNT_MASK)
  10359. << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
  10360. (((rcd->eager_base >> RCV_SHIFT)
  10361. & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
  10362. << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
  10363. write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
  10364. /*
  10365. * Set TID (expected) count and base index.
  10366. * rcd->expected_count is set to individual RcvArray entries,
  10367. * not pairs, and the CSR takes a pair-count in groups of
  10368. * four, so divide by 8.
  10369. */
  10370. reg = (((rcd->expected_count >> RCV_SHIFT)
  10371. & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
  10372. << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
  10373. (((rcd->expected_base >> RCV_SHIFT)
  10374. & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
  10375. << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
  10376. write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
  10377. if (ctxt == HFI1_CTRL_CTXT)
  10378. write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
  10379. }
  10380. if (op & HFI1_RCVCTRL_CTXT_DIS) {
  10381. write_csr(dd, RCV_VL15, 0);
  10382. /*
  10383. * When receive context is being disabled turn on tail
  10384. * update with a dummy tail address and then disable
  10385. * receive context.
  10386. */
  10387. if (dd->rcvhdrtail_dummy_dma) {
  10388. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10389. dd->rcvhdrtail_dummy_dma);
  10390. /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
  10391. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10392. }
  10393. rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
  10394. }
  10395. if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
  10396. rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10397. if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
  10398. rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
  10399. if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
  10400. rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10401. if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
  10402. /* See comment on RcvCtxtCtrl.TailUpd above */
  10403. if (!(op & HFI1_RCVCTRL_CTXT_DIS))
  10404. rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
  10405. }
  10406. if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
  10407. rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10408. if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
  10409. rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
  10410. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
  10411. /*
  10412. * In one-packet-per-eager mode, the size comes from
  10413. * the RcvArray entry.
  10414. */
  10415. rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
  10416. rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10417. }
  10418. if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
  10419. rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
  10420. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
  10421. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10422. if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
  10423. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
  10424. if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
  10425. rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10426. if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
  10427. rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
  10428. rcd->rcvctrl = rcvctrl;
  10429. hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
  10430. write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
  10431. /* work around sticky RcvCtxtStatus.BlockedRHQFull */
  10432. if (did_enable &&
  10433. (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
  10434. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10435. if (reg != 0) {
  10436. dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
  10437. ctxt, reg);
  10438. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10439. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
  10440. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
  10441. read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
  10442. reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
  10443. dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
  10444. ctxt, reg, reg == 0 ? "not" : "still");
  10445. }
  10446. }
  10447. if (did_enable) {
  10448. /*
  10449. * The interrupt timeout and count must be set after
  10450. * the context is enabled to take effect.
  10451. */
  10452. /* set interrupt timeout */
  10453. write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
  10454. (u64)rcd->rcvavail_timeout <<
  10455. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
  10456. /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
  10457. reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
  10458. write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
  10459. }
  10460. if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
  10461. /*
  10462. * If the context has been disabled and the Tail Update has
  10463. * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
  10464. * so it doesn't contain an address that is invalid.
  10465. */
  10466. write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
  10467. dd->rcvhdrtail_dummy_dma);
  10468. }
  10469. u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
  10470. {
  10471. int ret;
  10472. u64 val = 0;
  10473. if (namep) {
  10474. ret = dd->cntrnameslen;
  10475. *namep = dd->cntrnames;
  10476. } else {
  10477. const struct cntr_entry *entry;
  10478. int i, j;
  10479. ret = (dd->ndevcntrs) * sizeof(u64);
  10480. /* Get the start of the block of counters */
  10481. *cntrp = dd->cntrs;
  10482. /*
  10483. * Now go and fill in each counter in the block.
  10484. */
  10485. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10486. entry = &dev_cntrs[i];
  10487. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10488. if (entry->flags & CNTR_DISABLED) {
  10489. /* Nothing */
  10490. hfi1_cdbg(CNTR, "\tDisabled\n");
  10491. } else {
  10492. if (entry->flags & CNTR_VL) {
  10493. hfi1_cdbg(CNTR, "\tPer VL\n");
  10494. for (j = 0; j < C_VL_COUNT; j++) {
  10495. val = entry->rw_cntr(entry,
  10496. dd, j,
  10497. CNTR_MODE_R,
  10498. 0);
  10499. hfi1_cdbg(
  10500. CNTR,
  10501. "\t\tRead 0x%llx for %d\n",
  10502. val, j);
  10503. dd->cntrs[entry->offset + j] =
  10504. val;
  10505. }
  10506. } else if (entry->flags & CNTR_SDMA) {
  10507. hfi1_cdbg(CNTR,
  10508. "\t Per SDMA Engine\n");
  10509. for (j = 0; j < dd->chip_sdma_engines;
  10510. j++) {
  10511. val =
  10512. entry->rw_cntr(entry, dd, j,
  10513. CNTR_MODE_R, 0);
  10514. hfi1_cdbg(CNTR,
  10515. "\t\tRead 0x%llx for %d\n",
  10516. val, j);
  10517. dd->cntrs[entry->offset + j] =
  10518. val;
  10519. }
  10520. } else {
  10521. val = entry->rw_cntr(entry, dd,
  10522. CNTR_INVALID_VL,
  10523. CNTR_MODE_R, 0);
  10524. dd->cntrs[entry->offset] = val;
  10525. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10526. }
  10527. }
  10528. }
  10529. }
  10530. return ret;
  10531. }
  10532. /*
  10533. * Used by sysfs to create files for hfi stats to read
  10534. */
  10535. u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
  10536. {
  10537. int ret;
  10538. u64 val = 0;
  10539. if (namep) {
  10540. ret = ppd->dd->portcntrnameslen;
  10541. *namep = ppd->dd->portcntrnames;
  10542. } else {
  10543. const struct cntr_entry *entry;
  10544. int i, j;
  10545. ret = ppd->dd->nportcntrs * sizeof(u64);
  10546. *cntrp = ppd->cntrs;
  10547. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10548. entry = &port_cntrs[i];
  10549. hfi1_cdbg(CNTR, "reading %s", entry->name);
  10550. if (entry->flags & CNTR_DISABLED) {
  10551. /* Nothing */
  10552. hfi1_cdbg(CNTR, "\tDisabled\n");
  10553. continue;
  10554. }
  10555. if (entry->flags & CNTR_VL) {
  10556. hfi1_cdbg(CNTR, "\tPer VL");
  10557. for (j = 0; j < C_VL_COUNT; j++) {
  10558. val = entry->rw_cntr(entry, ppd, j,
  10559. CNTR_MODE_R,
  10560. 0);
  10561. hfi1_cdbg(
  10562. CNTR,
  10563. "\t\tRead 0x%llx for %d",
  10564. val, j);
  10565. ppd->cntrs[entry->offset + j] = val;
  10566. }
  10567. } else {
  10568. val = entry->rw_cntr(entry, ppd,
  10569. CNTR_INVALID_VL,
  10570. CNTR_MODE_R,
  10571. 0);
  10572. ppd->cntrs[entry->offset] = val;
  10573. hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
  10574. }
  10575. }
  10576. }
  10577. return ret;
  10578. }
  10579. static void free_cntrs(struct hfi1_devdata *dd)
  10580. {
  10581. struct hfi1_pportdata *ppd;
  10582. int i;
  10583. if (dd->synth_stats_timer.function)
  10584. del_timer_sync(&dd->synth_stats_timer);
  10585. ppd = (struct hfi1_pportdata *)(dd + 1);
  10586. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10587. kfree(ppd->cntrs);
  10588. kfree(ppd->scntrs);
  10589. free_percpu(ppd->ibport_data.rvp.rc_acks);
  10590. free_percpu(ppd->ibport_data.rvp.rc_qacks);
  10591. free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
  10592. ppd->cntrs = NULL;
  10593. ppd->scntrs = NULL;
  10594. ppd->ibport_data.rvp.rc_acks = NULL;
  10595. ppd->ibport_data.rvp.rc_qacks = NULL;
  10596. ppd->ibport_data.rvp.rc_delayed_comp = NULL;
  10597. }
  10598. kfree(dd->portcntrnames);
  10599. dd->portcntrnames = NULL;
  10600. kfree(dd->cntrs);
  10601. dd->cntrs = NULL;
  10602. kfree(dd->scntrs);
  10603. dd->scntrs = NULL;
  10604. kfree(dd->cntrnames);
  10605. dd->cntrnames = NULL;
  10606. if (dd->update_cntr_wq) {
  10607. destroy_workqueue(dd->update_cntr_wq);
  10608. dd->update_cntr_wq = NULL;
  10609. }
  10610. }
  10611. static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
  10612. u64 *psval, void *context, int vl)
  10613. {
  10614. u64 val;
  10615. u64 sval = *psval;
  10616. if (entry->flags & CNTR_DISABLED) {
  10617. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10618. return 0;
  10619. }
  10620. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10621. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
  10622. /* If its a synthetic counter there is more work we need to do */
  10623. if (entry->flags & CNTR_SYNTH) {
  10624. if (sval == CNTR_MAX) {
  10625. /* No need to read already saturated */
  10626. return CNTR_MAX;
  10627. }
  10628. if (entry->flags & CNTR_32BIT) {
  10629. /* 32bit counters can wrap multiple times */
  10630. u64 upper = sval >> 32;
  10631. u64 lower = (sval << 32) >> 32;
  10632. if (lower > val) { /* hw wrapped */
  10633. if (upper == CNTR_32BIT_MAX)
  10634. val = CNTR_MAX;
  10635. else
  10636. upper++;
  10637. }
  10638. if (val != CNTR_MAX)
  10639. val = (upper << 32) | val;
  10640. } else {
  10641. /* If we rolled we are saturated */
  10642. if ((val < sval) || (val > CNTR_MAX))
  10643. val = CNTR_MAX;
  10644. }
  10645. }
  10646. *psval = val;
  10647. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10648. return val;
  10649. }
  10650. static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
  10651. struct cntr_entry *entry,
  10652. u64 *psval, void *context, int vl, u64 data)
  10653. {
  10654. u64 val;
  10655. if (entry->flags & CNTR_DISABLED) {
  10656. dd_dev_err(dd, "Counter %s not enabled", entry->name);
  10657. return 0;
  10658. }
  10659. hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
  10660. if (entry->flags & CNTR_SYNTH) {
  10661. *psval = data;
  10662. if (entry->flags & CNTR_32BIT) {
  10663. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10664. (data << 32) >> 32);
  10665. val = data; /* return the full 64bit value */
  10666. } else {
  10667. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
  10668. data);
  10669. }
  10670. } else {
  10671. val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
  10672. }
  10673. *psval = val;
  10674. hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
  10675. return val;
  10676. }
  10677. u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
  10678. {
  10679. struct cntr_entry *entry;
  10680. u64 *sval;
  10681. entry = &dev_cntrs[index];
  10682. sval = dd->scntrs + entry->offset;
  10683. if (vl != CNTR_INVALID_VL)
  10684. sval += vl;
  10685. return read_dev_port_cntr(dd, entry, sval, dd, vl);
  10686. }
  10687. u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
  10688. {
  10689. struct cntr_entry *entry;
  10690. u64 *sval;
  10691. entry = &dev_cntrs[index];
  10692. sval = dd->scntrs + entry->offset;
  10693. if (vl != CNTR_INVALID_VL)
  10694. sval += vl;
  10695. return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
  10696. }
  10697. u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
  10698. {
  10699. struct cntr_entry *entry;
  10700. u64 *sval;
  10701. entry = &port_cntrs[index];
  10702. sval = ppd->scntrs + entry->offset;
  10703. if (vl != CNTR_INVALID_VL)
  10704. sval += vl;
  10705. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10706. (index <= C_RCV_HDR_OVF_LAST)) {
  10707. /* We do not want to bother for disabled contexts */
  10708. return 0;
  10709. }
  10710. return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
  10711. }
  10712. u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
  10713. {
  10714. struct cntr_entry *entry;
  10715. u64 *sval;
  10716. entry = &port_cntrs[index];
  10717. sval = ppd->scntrs + entry->offset;
  10718. if (vl != CNTR_INVALID_VL)
  10719. sval += vl;
  10720. if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
  10721. (index <= C_RCV_HDR_OVF_LAST)) {
  10722. /* We do not want to bother for disabled contexts */
  10723. return 0;
  10724. }
  10725. return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
  10726. }
  10727. static void do_update_synth_timer(struct work_struct *work)
  10728. {
  10729. u64 cur_tx;
  10730. u64 cur_rx;
  10731. u64 total_flits;
  10732. u8 update = 0;
  10733. int i, j, vl;
  10734. struct hfi1_pportdata *ppd;
  10735. struct cntr_entry *entry;
  10736. struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
  10737. update_cntr_work);
  10738. /*
  10739. * Rather than keep beating on the CSRs pick a minimal set that we can
  10740. * check to watch for potential roll over. We can do this by looking at
  10741. * the number of flits sent/recv. If the total flits exceeds 32bits then
  10742. * we have to iterate all the counters and update.
  10743. */
  10744. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10745. cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10746. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10747. cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
  10748. hfi1_cdbg(
  10749. CNTR,
  10750. "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
  10751. dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
  10752. if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
  10753. /*
  10754. * May not be strictly necessary to update but it won't hurt and
  10755. * simplifies the logic here.
  10756. */
  10757. update = 1;
  10758. hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
  10759. dd->unit);
  10760. } else {
  10761. total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
  10762. hfi1_cdbg(CNTR,
  10763. "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
  10764. total_flits, (u64)CNTR_32BIT_MAX);
  10765. if (total_flits >= CNTR_32BIT_MAX) {
  10766. hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
  10767. dd->unit);
  10768. update = 1;
  10769. }
  10770. }
  10771. if (update) {
  10772. hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
  10773. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10774. entry = &dev_cntrs[i];
  10775. if (entry->flags & CNTR_VL) {
  10776. for (vl = 0; vl < C_VL_COUNT; vl++)
  10777. read_dev_cntr(dd, i, vl);
  10778. } else {
  10779. read_dev_cntr(dd, i, CNTR_INVALID_VL);
  10780. }
  10781. }
  10782. ppd = (struct hfi1_pportdata *)(dd + 1);
  10783. for (i = 0; i < dd->num_pports; i++, ppd++) {
  10784. for (j = 0; j < PORT_CNTR_LAST; j++) {
  10785. entry = &port_cntrs[j];
  10786. if (entry->flags & CNTR_VL) {
  10787. for (vl = 0; vl < C_VL_COUNT; vl++)
  10788. read_port_cntr(ppd, j, vl);
  10789. } else {
  10790. read_port_cntr(ppd, j, CNTR_INVALID_VL);
  10791. }
  10792. }
  10793. }
  10794. /*
  10795. * We want the value in the register. The goal is to keep track
  10796. * of the number of "ticks" not the counter value. In other
  10797. * words if the register rolls we want to notice it and go ahead
  10798. * and force an update.
  10799. */
  10800. entry = &dev_cntrs[C_DC_XMIT_FLITS];
  10801. dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10802. CNTR_MODE_R, 0);
  10803. entry = &dev_cntrs[C_DC_RCV_FLITS];
  10804. dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
  10805. CNTR_MODE_R, 0);
  10806. hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
  10807. dd->unit, dd->last_tx, dd->last_rx);
  10808. } else {
  10809. hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
  10810. }
  10811. }
  10812. static void update_synth_timer(struct timer_list *t)
  10813. {
  10814. struct hfi1_devdata *dd = from_timer(dd, t, synth_stats_timer);
  10815. queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
  10816. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  10817. }
  10818. #define C_MAX_NAME 16 /* 15 chars + one for /0 */
  10819. static int init_cntrs(struct hfi1_devdata *dd)
  10820. {
  10821. int i, rcv_ctxts, j;
  10822. size_t sz;
  10823. char *p;
  10824. char name[C_MAX_NAME];
  10825. struct hfi1_pportdata *ppd;
  10826. const char *bit_type_32 = ",32";
  10827. const int bit_type_32_sz = strlen(bit_type_32);
  10828. /* set up the stats timer; the add_timer is done at the end */
  10829. timer_setup(&dd->synth_stats_timer, update_synth_timer, 0);
  10830. /***********************/
  10831. /* per device counters */
  10832. /***********************/
  10833. /* size names and determine how many we have*/
  10834. dd->ndevcntrs = 0;
  10835. sz = 0;
  10836. for (i = 0; i < DEV_CNTR_LAST; i++) {
  10837. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10838. hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
  10839. continue;
  10840. }
  10841. if (dev_cntrs[i].flags & CNTR_VL) {
  10842. dev_cntrs[i].offset = dd->ndevcntrs;
  10843. for (j = 0; j < C_VL_COUNT; j++) {
  10844. snprintf(name, C_MAX_NAME, "%s%d",
  10845. dev_cntrs[i].name, vl_from_idx(j));
  10846. sz += strlen(name);
  10847. /* Add ",32" for 32-bit counters */
  10848. if (dev_cntrs[i].flags & CNTR_32BIT)
  10849. sz += bit_type_32_sz;
  10850. sz++;
  10851. dd->ndevcntrs++;
  10852. }
  10853. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10854. dev_cntrs[i].offset = dd->ndevcntrs;
  10855. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10856. snprintf(name, C_MAX_NAME, "%s%d",
  10857. dev_cntrs[i].name, j);
  10858. sz += strlen(name);
  10859. /* Add ",32" for 32-bit counters */
  10860. if (dev_cntrs[i].flags & CNTR_32BIT)
  10861. sz += bit_type_32_sz;
  10862. sz++;
  10863. dd->ndevcntrs++;
  10864. }
  10865. } else {
  10866. /* +1 for newline. */
  10867. sz += strlen(dev_cntrs[i].name) + 1;
  10868. /* Add ",32" for 32-bit counters */
  10869. if (dev_cntrs[i].flags & CNTR_32BIT)
  10870. sz += bit_type_32_sz;
  10871. dev_cntrs[i].offset = dd->ndevcntrs;
  10872. dd->ndevcntrs++;
  10873. }
  10874. }
  10875. /* allocate space for the counter values */
  10876. dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10877. if (!dd->cntrs)
  10878. goto bail;
  10879. dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
  10880. if (!dd->scntrs)
  10881. goto bail;
  10882. /* allocate space for the counter names */
  10883. dd->cntrnameslen = sz;
  10884. dd->cntrnames = kmalloc(sz, GFP_KERNEL);
  10885. if (!dd->cntrnames)
  10886. goto bail;
  10887. /* fill in the names */
  10888. for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
  10889. if (dev_cntrs[i].flags & CNTR_DISABLED) {
  10890. /* Nothing */
  10891. } else if (dev_cntrs[i].flags & CNTR_VL) {
  10892. for (j = 0; j < C_VL_COUNT; j++) {
  10893. snprintf(name, C_MAX_NAME, "%s%d",
  10894. dev_cntrs[i].name,
  10895. vl_from_idx(j));
  10896. memcpy(p, name, strlen(name));
  10897. p += strlen(name);
  10898. /* Counter is 32 bits */
  10899. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10900. memcpy(p, bit_type_32, bit_type_32_sz);
  10901. p += bit_type_32_sz;
  10902. }
  10903. *p++ = '\n';
  10904. }
  10905. } else if (dev_cntrs[i].flags & CNTR_SDMA) {
  10906. for (j = 0; j < dd->chip_sdma_engines; j++) {
  10907. snprintf(name, C_MAX_NAME, "%s%d",
  10908. dev_cntrs[i].name, j);
  10909. memcpy(p, name, strlen(name));
  10910. p += strlen(name);
  10911. /* Counter is 32 bits */
  10912. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10913. memcpy(p, bit_type_32, bit_type_32_sz);
  10914. p += bit_type_32_sz;
  10915. }
  10916. *p++ = '\n';
  10917. }
  10918. } else {
  10919. memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
  10920. p += strlen(dev_cntrs[i].name);
  10921. /* Counter is 32 bits */
  10922. if (dev_cntrs[i].flags & CNTR_32BIT) {
  10923. memcpy(p, bit_type_32, bit_type_32_sz);
  10924. p += bit_type_32_sz;
  10925. }
  10926. *p++ = '\n';
  10927. }
  10928. }
  10929. /*********************/
  10930. /* per port counters */
  10931. /*********************/
  10932. /*
  10933. * Go through the counters for the overflows and disable the ones we
  10934. * don't need. This varies based on platform so we need to do it
  10935. * dynamically here.
  10936. */
  10937. rcv_ctxts = dd->num_rcv_contexts;
  10938. for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
  10939. i <= C_RCV_HDR_OVF_LAST; i++) {
  10940. port_cntrs[i].flags |= CNTR_DISABLED;
  10941. }
  10942. /* size port counter names and determine how many we have*/
  10943. sz = 0;
  10944. dd->nportcntrs = 0;
  10945. for (i = 0; i < PORT_CNTR_LAST; i++) {
  10946. if (port_cntrs[i].flags & CNTR_DISABLED) {
  10947. hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
  10948. continue;
  10949. }
  10950. if (port_cntrs[i].flags & CNTR_VL) {
  10951. port_cntrs[i].offset = dd->nportcntrs;
  10952. for (j = 0; j < C_VL_COUNT; j++) {
  10953. snprintf(name, C_MAX_NAME, "%s%d",
  10954. port_cntrs[i].name, vl_from_idx(j));
  10955. sz += strlen(name);
  10956. /* Add ",32" for 32-bit counters */
  10957. if (port_cntrs[i].flags & CNTR_32BIT)
  10958. sz += bit_type_32_sz;
  10959. sz++;
  10960. dd->nportcntrs++;
  10961. }
  10962. } else {
  10963. /* +1 for newline */
  10964. sz += strlen(port_cntrs[i].name) + 1;
  10965. /* Add ",32" for 32-bit counters */
  10966. if (port_cntrs[i].flags & CNTR_32BIT)
  10967. sz += bit_type_32_sz;
  10968. port_cntrs[i].offset = dd->nportcntrs;
  10969. dd->nportcntrs++;
  10970. }
  10971. }
  10972. /* allocate space for the counter names */
  10973. dd->portcntrnameslen = sz;
  10974. dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
  10975. if (!dd->portcntrnames)
  10976. goto bail;
  10977. /* fill in port cntr names */
  10978. for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
  10979. if (port_cntrs[i].flags & CNTR_DISABLED)
  10980. continue;
  10981. if (port_cntrs[i].flags & CNTR_VL) {
  10982. for (j = 0; j < C_VL_COUNT; j++) {
  10983. snprintf(name, C_MAX_NAME, "%s%d",
  10984. port_cntrs[i].name, vl_from_idx(j));
  10985. memcpy(p, name, strlen(name));
  10986. p += strlen(name);
  10987. /* Counter is 32 bits */
  10988. if (port_cntrs[i].flags & CNTR_32BIT) {
  10989. memcpy(p, bit_type_32, bit_type_32_sz);
  10990. p += bit_type_32_sz;
  10991. }
  10992. *p++ = '\n';
  10993. }
  10994. } else {
  10995. memcpy(p, port_cntrs[i].name,
  10996. strlen(port_cntrs[i].name));
  10997. p += strlen(port_cntrs[i].name);
  10998. /* Counter is 32 bits */
  10999. if (port_cntrs[i].flags & CNTR_32BIT) {
  11000. memcpy(p, bit_type_32, bit_type_32_sz);
  11001. p += bit_type_32_sz;
  11002. }
  11003. *p++ = '\n';
  11004. }
  11005. }
  11006. /* allocate per port storage for counter values */
  11007. ppd = (struct hfi1_pportdata *)(dd + 1);
  11008. for (i = 0; i < dd->num_pports; i++, ppd++) {
  11009. ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11010. if (!ppd->cntrs)
  11011. goto bail;
  11012. ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
  11013. if (!ppd->scntrs)
  11014. goto bail;
  11015. }
  11016. /* CPU counters need to be allocated and zeroed */
  11017. if (init_cpu_counters(dd))
  11018. goto bail;
  11019. dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
  11020. WQ_MEM_RECLAIM, dd->unit);
  11021. if (!dd->update_cntr_wq)
  11022. goto bail;
  11023. INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
  11024. mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
  11025. return 0;
  11026. bail:
  11027. free_cntrs(dd);
  11028. return -ENOMEM;
  11029. }
  11030. static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
  11031. {
  11032. switch (chip_lstate) {
  11033. default:
  11034. dd_dev_err(dd,
  11035. "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
  11036. chip_lstate);
  11037. /* fall through */
  11038. case LSTATE_DOWN:
  11039. return IB_PORT_DOWN;
  11040. case LSTATE_INIT:
  11041. return IB_PORT_INIT;
  11042. case LSTATE_ARMED:
  11043. return IB_PORT_ARMED;
  11044. case LSTATE_ACTIVE:
  11045. return IB_PORT_ACTIVE;
  11046. }
  11047. }
  11048. u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
  11049. {
  11050. /* look at the HFI meta-states only */
  11051. switch (chip_pstate & 0xf0) {
  11052. default:
  11053. dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
  11054. chip_pstate);
  11055. /* fall through */
  11056. case PLS_DISABLED:
  11057. return IB_PORTPHYSSTATE_DISABLED;
  11058. case PLS_OFFLINE:
  11059. return OPA_PORTPHYSSTATE_OFFLINE;
  11060. case PLS_POLLING:
  11061. return IB_PORTPHYSSTATE_POLLING;
  11062. case PLS_CONFIGPHY:
  11063. return IB_PORTPHYSSTATE_TRAINING;
  11064. case PLS_LINKUP:
  11065. return IB_PORTPHYSSTATE_LINKUP;
  11066. case PLS_PHYTEST:
  11067. return IB_PORTPHYSSTATE_PHY_TEST;
  11068. }
  11069. }
  11070. /* return the OPA port logical state name */
  11071. const char *opa_lstate_name(u32 lstate)
  11072. {
  11073. static const char * const port_logical_names[] = {
  11074. "PORT_NOP",
  11075. "PORT_DOWN",
  11076. "PORT_INIT",
  11077. "PORT_ARMED",
  11078. "PORT_ACTIVE",
  11079. "PORT_ACTIVE_DEFER",
  11080. };
  11081. if (lstate < ARRAY_SIZE(port_logical_names))
  11082. return port_logical_names[lstate];
  11083. return "unknown";
  11084. }
  11085. /* return the OPA port physical state name */
  11086. const char *opa_pstate_name(u32 pstate)
  11087. {
  11088. static const char * const port_physical_names[] = {
  11089. "PHYS_NOP",
  11090. "reserved1",
  11091. "PHYS_POLL",
  11092. "PHYS_DISABLED",
  11093. "PHYS_TRAINING",
  11094. "PHYS_LINKUP",
  11095. "PHYS_LINK_ERR_RECOVER",
  11096. "PHYS_PHY_TEST",
  11097. "reserved8",
  11098. "PHYS_OFFLINE",
  11099. "PHYS_GANGED",
  11100. "PHYS_TEST",
  11101. };
  11102. if (pstate < ARRAY_SIZE(port_physical_names))
  11103. return port_physical_names[pstate];
  11104. return "unknown";
  11105. }
  11106. /**
  11107. * update_statusp - Update userspace status flag
  11108. * @ppd: Port data structure
  11109. * @state: port state information
  11110. *
  11111. * Actual port status is determined by the host_link_state value
  11112. * in the ppd.
  11113. *
  11114. * host_link_state MUST be updated before updating the user space
  11115. * statusp.
  11116. */
  11117. static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
  11118. {
  11119. /*
  11120. * Set port status flags in the page mapped into userspace
  11121. * memory. Do it here to ensure a reliable state - this is
  11122. * the only function called by all state handling code.
  11123. * Always set the flags due to the fact that the cache value
  11124. * might have been changed explicitly outside of this
  11125. * function.
  11126. */
  11127. if (ppd->statusp) {
  11128. switch (state) {
  11129. case IB_PORT_DOWN:
  11130. case IB_PORT_INIT:
  11131. *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
  11132. HFI1_STATUS_IB_READY);
  11133. break;
  11134. case IB_PORT_ARMED:
  11135. *ppd->statusp |= HFI1_STATUS_IB_CONF;
  11136. break;
  11137. case IB_PORT_ACTIVE:
  11138. *ppd->statusp |= HFI1_STATUS_IB_READY;
  11139. break;
  11140. }
  11141. }
  11142. dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
  11143. opa_lstate_name(state), state);
  11144. }
  11145. /**
  11146. * wait_logical_linkstate - wait for an IB link state change to occur
  11147. * @ppd: port device
  11148. * @state: the state to wait for
  11149. * @msecs: the number of milliseconds to wait
  11150. *
  11151. * Wait up to msecs milliseconds for IB link state change to occur.
  11152. * For now, take the easy polling route.
  11153. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11154. */
  11155. static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11156. int msecs)
  11157. {
  11158. unsigned long timeout;
  11159. u32 new_state;
  11160. timeout = jiffies + msecs_to_jiffies(msecs);
  11161. while (1) {
  11162. new_state = chip_to_opa_lstate(ppd->dd,
  11163. read_logical_state(ppd->dd));
  11164. if (new_state == state)
  11165. break;
  11166. if (time_after(jiffies, timeout)) {
  11167. dd_dev_err(ppd->dd,
  11168. "timeout waiting for link state 0x%x\n",
  11169. state);
  11170. return -ETIMEDOUT;
  11171. }
  11172. msleep(20);
  11173. }
  11174. return 0;
  11175. }
  11176. static void log_state_transition(struct hfi1_pportdata *ppd, u32 state)
  11177. {
  11178. u32 ib_pstate = chip_to_opa_pstate(ppd->dd, state);
  11179. dd_dev_info(ppd->dd,
  11180. "physical state changed to %s (0x%x), phy 0x%x\n",
  11181. opa_pstate_name(ib_pstate), ib_pstate, state);
  11182. }
  11183. /*
  11184. * Read the physical hardware link state and check if it matches host
  11185. * drivers anticipated state.
  11186. */
  11187. static void log_physical_state(struct hfi1_pportdata *ppd, u32 state)
  11188. {
  11189. u32 read_state = read_physical_state(ppd->dd);
  11190. if (read_state == state) {
  11191. log_state_transition(ppd, state);
  11192. } else {
  11193. dd_dev_err(ppd->dd,
  11194. "anticipated phy link state 0x%x, read 0x%x\n",
  11195. state, read_state);
  11196. }
  11197. }
  11198. /*
  11199. * wait_physical_linkstate - wait for an physical link state change to occur
  11200. * @ppd: port device
  11201. * @state: the state to wait for
  11202. * @msecs: the number of milliseconds to wait
  11203. *
  11204. * Wait up to msecs milliseconds for physical link state change to occur.
  11205. * Returns 0 if state reached, otherwise -ETIMEDOUT.
  11206. */
  11207. static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
  11208. int msecs)
  11209. {
  11210. u32 read_state;
  11211. unsigned long timeout;
  11212. timeout = jiffies + msecs_to_jiffies(msecs);
  11213. while (1) {
  11214. read_state = read_physical_state(ppd->dd);
  11215. if (read_state == state)
  11216. break;
  11217. if (time_after(jiffies, timeout)) {
  11218. dd_dev_err(ppd->dd,
  11219. "timeout waiting for phy link state 0x%x\n",
  11220. state);
  11221. return -ETIMEDOUT;
  11222. }
  11223. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11224. }
  11225. log_state_transition(ppd, state);
  11226. return 0;
  11227. }
  11228. /*
  11229. * wait_phys_link_offline_quiet_substates - wait for any offline substate
  11230. * @ppd: port device
  11231. * @msecs: the number of milliseconds to wait
  11232. *
  11233. * Wait up to msecs milliseconds for any offline physical link
  11234. * state change to occur.
  11235. * Returns 0 if at least one state is reached, otherwise -ETIMEDOUT.
  11236. */
  11237. static int wait_phys_link_offline_substates(struct hfi1_pportdata *ppd,
  11238. int msecs)
  11239. {
  11240. u32 read_state;
  11241. unsigned long timeout;
  11242. timeout = jiffies + msecs_to_jiffies(msecs);
  11243. while (1) {
  11244. read_state = read_physical_state(ppd->dd);
  11245. if ((read_state & 0xF0) == PLS_OFFLINE)
  11246. break;
  11247. if (time_after(jiffies, timeout)) {
  11248. dd_dev_err(ppd->dd,
  11249. "timeout waiting for phy link offline.quiet substates. Read state 0x%x, %dms\n",
  11250. read_state, msecs);
  11251. return -ETIMEDOUT;
  11252. }
  11253. usleep_range(1950, 2050); /* sleep 2ms-ish */
  11254. }
  11255. log_state_transition(ppd, read_state);
  11256. return read_state;
  11257. }
  11258. #define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
  11259. (r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11260. #define SET_STATIC_RATE_CONTROL_SMASK(r) \
  11261. (r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
  11262. void hfi1_init_ctxt(struct send_context *sc)
  11263. {
  11264. if (sc) {
  11265. struct hfi1_devdata *dd = sc->dd;
  11266. u64 reg;
  11267. u8 set = (sc->type == SC_USER ?
  11268. HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
  11269. HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
  11270. reg = read_kctxt_csr(dd, sc->hw_context,
  11271. SEND_CTXT_CHECK_ENABLE);
  11272. if (set)
  11273. CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
  11274. else
  11275. SET_STATIC_RATE_CONTROL_SMASK(reg);
  11276. write_kctxt_csr(dd, sc->hw_context,
  11277. SEND_CTXT_CHECK_ENABLE, reg);
  11278. }
  11279. }
  11280. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
  11281. {
  11282. int ret = 0;
  11283. u64 reg;
  11284. if (dd->icode != ICODE_RTL_SILICON) {
  11285. if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
  11286. dd_dev_info(dd, "%s: tempsense not supported by HW\n",
  11287. __func__);
  11288. return -EINVAL;
  11289. }
  11290. reg = read_csr(dd, ASIC_STS_THERM);
  11291. temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
  11292. ASIC_STS_THERM_CURR_TEMP_MASK);
  11293. temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
  11294. ASIC_STS_THERM_LO_TEMP_MASK);
  11295. temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
  11296. ASIC_STS_THERM_HI_TEMP_MASK);
  11297. temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
  11298. ASIC_STS_THERM_CRIT_TEMP_MASK);
  11299. /* triggers is a 3-bit value - 1 bit per trigger. */
  11300. temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
  11301. return ret;
  11302. }
  11303. /**
  11304. * get_int_mask - get 64 bit int mask
  11305. * @dd - the devdata
  11306. * @i - the csr (relative to CCE_INT_MASK)
  11307. *
  11308. * Returns the mask with the urgent interrupt mask
  11309. * bit clear for kernel receive contexts.
  11310. */
  11311. static u64 get_int_mask(struct hfi1_devdata *dd, u32 i)
  11312. {
  11313. u64 mask = U64_MAX; /* default to no change */
  11314. if (i >= (IS_RCVURGENT_START / 64) && i < (IS_RCVURGENT_END / 64)) {
  11315. int j = (i - (IS_RCVURGENT_START / 64)) * 64;
  11316. int k = !j ? IS_RCVURGENT_START % 64 : 0;
  11317. if (j)
  11318. j -= IS_RCVURGENT_START % 64;
  11319. /* j = 0..dd->first_dyn_alloc_ctxt - 1,k = 0..63 */
  11320. for (; j < dd->first_dyn_alloc_ctxt && k < 64; j++, k++)
  11321. /* convert to bit in mask and clear */
  11322. mask &= ~BIT_ULL(k);
  11323. }
  11324. return mask;
  11325. }
  11326. /* ========================================================================= */
  11327. /*
  11328. * Enable/disable chip from delivering interrupts.
  11329. */
  11330. void set_intr_state(struct hfi1_devdata *dd, u32 enable)
  11331. {
  11332. int i;
  11333. /*
  11334. * In HFI, the mask needs to be 1 to allow interrupts.
  11335. */
  11336. if (enable) {
  11337. /* enable all interrupts but urgent on kernel contexts */
  11338. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11339. u64 mask = get_int_mask(dd, i);
  11340. write_csr(dd, CCE_INT_MASK + (8 * i), mask);
  11341. }
  11342. init_qsfp_int(dd);
  11343. } else {
  11344. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11345. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  11346. }
  11347. }
  11348. /*
  11349. * Clear all interrupt sources on the chip.
  11350. */
  11351. static void clear_all_interrupts(struct hfi1_devdata *dd)
  11352. {
  11353. int i;
  11354. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11355. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
  11356. write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
  11357. write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
  11358. write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
  11359. write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
  11360. write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
  11361. write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
  11362. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
  11363. for (i = 0; i < dd->chip_send_contexts; i++)
  11364. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
  11365. for (i = 0; i < dd->chip_sdma_engines; i++)
  11366. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
  11367. write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
  11368. write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
  11369. write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
  11370. }
  11371. /* Move to pcie.c? */
  11372. static void disable_intx(struct pci_dev *pdev)
  11373. {
  11374. pci_intx(pdev, 0);
  11375. }
  11376. static void clean_up_interrupts(struct hfi1_devdata *dd)
  11377. {
  11378. int i;
  11379. /* remove irqs - must happen before disabling/turning off */
  11380. if (dd->num_msix_entries) {
  11381. /* MSI-X */
  11382. struct hfi1_msix_entry *me = dd->msix_entries;
  11383. for (i = 0; i < dd->num_msix_entries; i++, me++) {
  11384. if (!me->arg) /* => no irq, no affinity */
  11385. continue;
  11386. hfi1_put_irq_affinity(dd, me);
  11387. pci_free_irq(dd->pcidev, i, me->arg);
  11388. }
  11389. /* clean structures */
  11390. kfree(dd->msix_entries);
  11391. dd->msix_entries = NULL;
  11392. dd->num_msix_entries = 0;
  11393. } else {
  11394. /* INTx */
  11395. if (dd->requested_intx_irq) {
  11396. pci_free_irq(dd->pcidev, 0, dd);
  11397. dd->requested_intx_irq = 0;
  11398. }
  11399. disable_intx(dd->pcidev);
  11400. }
  11401. pci_free_irq_vectors(dd->pcidev);
  11402. }
  11403. /*
  11404. * Remap the interrupt source from the general handler to the given MSI-X
  11405. * interrupt.
  11406. */
  11407. static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
  11408. {
  11409. u64 reg;
  11410. int m, n;
  11411. /* clear from the handled mask of the general interrupt */
  11412. m = isrc / 64;
  11413. n = isrc % 64;
  11414. if (likely(m < CCE_NUM_INT_CSRS)) {
  11415. dd->gi_mask[m] &= ~((u64)1 << n);
  11416. } else {
  11417. dd_dev_err(dd, "remap interrupt err\n");
  11418. return;
  11419. }
  11420. /* direct the chip source to the given MSI-X interrupt */
  11421. m = isrc / 8;
  11422. n = isrc % 8;
  11423. reg = read_csr(dd, CCE_INT_MAP + (8 * m));
  11424. reg &= ~((u64)0xff << (8 * n));
  11425. reg |= ((u64)msix_intr & 0xff) << (8 * n);
  11426. write_csr(dd, CCE_INT_MAP + (8 * m), reg);
  11427. }
  11428. static void remap_sdma_interrupts(struct hfi1_devdata *dd,
  11429. int engine, int msix_intr)
  11430. {
  11431. /*
  11432. * SDMA engine interrupt sources grouped by type, rather than
  11433. * engine. Per-engine interrupts are as follows:
  11434. * SDMA
  11435. * SDMAProgress
  11436. * SDMAIdle
  11437. */
  11438. remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
  11439. msix_intr);
  11440. remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
  11441. msix_intr);
  11442. remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
  11443. msix_intr);
  11444. }
  11445. static int request_intx_irq(struct hfi1_devdata *dd)
  11446. {
  11447. int ret;
  11448. ret = pci_request_irq(dd->pcidev, 0, general_interrupt, NULL, dd,
  11449. DRIVER_NAME "_%d", dd->unit);
  11450. if (ret)
  11451. dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
  11452. ret);
  11453. else
  11454. dd->requested_intx_irq = 1;
  11455. return ret;
  11456. }
  11457. static int request_msix_irqs(struct hfi1_devdata *dd)
  11458. {
  11459. int first_general, last_general;
  11460. int first_sdma, last_sdma;
  11461. int first_rx, last_rx;
  11462. int i, ret = 0;
  11463. /* calculate the ranges we are going to use */
  11464. first_general = 0;
  11465. last_general = first_general + 1;
  11466. first_sdma = last_general;
  11467. last_sdma = first_sdma + dd->num_sdma;
  11468. first_rx = last_sdma;
  11469. last_rx = first_rx + dd->n_krcv_queues + dd->num_vnic_contexts;
  11470. /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
  11471. dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
  11472. /*
  11473. * Sanity check - the code expects all SDMA chip source
  11474. * interrupts to be in the same CSR, starting at bit 0. Verify
  11475. * that this is true by checking the bit location of the start.
  11476. */
  11477. BUILD_BUG_ON(IS_SDMA_START % 64);
  11478. for (i = 0; i < dd->num_msix_entries; i++) {
  11479. struct hfi1_msix_entry *me = &dd->msix_entries[i];
  11480. const char *err_info;
  11481. irq_handler_t handler;
  11482. irq_handler_t thread = NULL;
  11483. void *arg = NULL;
  11484. int idx;
  11485. struct hfi1_ctxtdata *rcd = NULL;
  11486. struct sdma_engine *sde = NULL;
  11487. char name[MAX_NAME_SIZE];
  11488. /* obtain the arguments to pci_request_irq */
  11489. if (first_general <= i && i < last_general) {
  11490. idx = i - first_general;
  11491. handler = general_interrupt;
  11492. arg = dd;
  11493. snprintf(name, sizeof(name),
  11494. DRIVER_NAME "_%d", dd->unit);
  11495. err_info = "general";
  11496. me->type = IRQ_GENERAL;
  11497. } else if (first_sdma <= i && i < last_sdma) {
  11498. idx = i - first_sdma;
  11499. sde = &dd->per_sdma[idx];
  11500. handler = sdma_interrupt;
  11501. arg = sde;
  11502. snprintf(name, sizeof(name),
  11503. DRIVER_NAME "_%d sdma%d", dd->unit, idx);
  11504. err_info = "sdma";
  11505. remap_sdma_interrupts(dd, idx, i);
  11506. me->type = IRQ_SDMA;
  11507. } else if (first_rx <= i && i < last_rx) {
  11508. idx = i - first_rx;
  11509. rcd = hfi1_rcd_get_by_index_safe(dd, idx);
  11510. if (rcd) {
  11511. /*
  11512. * Set the interrupt register and mask for this
  11513. * context's interrupt.
  11514. */
  11515. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11516. rcd->imask = ((u64)1) <<
  11517. ((IS_RCVAVAIL_START + idx) % 64);
  11518. handler = receive_context_interrupt;
  11519. thread = receive_context_thread;
  11520. arg = rcd;
  11521. snprintf(name, sizeof(name),
  11522. DRIVER_NAME "_%d kctxt%d",
  11523. dd->unit, idx);
  11524. err_info = "receive context";
  11525. remap_intr(dd, IS_RCVAVAIL_START + idx, i);
  11526. me->type = IRQ_RCVCTXT;
  11527. rcd->msix_intr = i;
  11528. hfi1_rcd_put(rcd);
  11529. }
  11530. } else {
  11531. /* not in our expected range - complain, then
  11532. * ignore it
  11533. */
  11534. dd_dev_err(dd,
  11535. "Unexpected extra MSI-X interrupt %d\n", i);
  11536. continue;
  11537. }
  11538. /* no argument, no interrupt */
  11539. if (!arg)
  11540. continue;
  11541. /* make sure the name is terminated */
  11542. name[sizeof(name) - 1] = 0;
  11543. me->irq = pci_irq_vector(dd->pcidev, i);
  11544. ret = pci_request_irq(dd->pcidev, i, handler, thread, arg,
  11545. name);
  11546. if (ret) {
  11547. dd_dev_err(dd,
  11548. "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
  11549. err_info, me->irq, idx, ret);
  11550. return ret;
  11551. }
  11552. /*
  11553. * assign arg after pci_request_irq call, so it will be
  11554. * cleaned up
  11555. */
  11556. me->arg = arg;
  11557. ret = hfi1_get_irq_affinity(dd, me);
  11558. if (ret)
  11559. dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
  11560. }
  11561. return ret;
  11562. }
  11563. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
  11564. {
  11565. int i;
  11566. if (!dd->num_msix_entries) {
  11567. synchronize_irq(pci_irq_vector(dd->pcidev, 0));
  11568. return;
  11569. }
  11570. for (i = 0; i < dd->vnic.num_ctxt; i++) {
  11571. struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
  11572. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11573. synchronize_irq(me->irq);
  11574. }
  11575. }
  11576. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11577. {
  11578. struct hfi1_devdata *dd = rcd->dd;
  11579. struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
  11580. if (!me->arg) /* => no irq, no affinity */
  11581. return;
  11582. hfi1_put_irq_affinity(dd, me);
  11583. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11584. me->arg = NULL;
  11585. }
  11586. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
  11587. {
  11588. struct hfi1_devdata *dd = rcd->dd;
  11589. struct hfi1_msix_entry *me;
  11590. int idx = rcd->ctxt;
  11591. void *arg = rcd;
  11592. int ret;
  11593. rcd->msix_intr = dd->vnic.msix_idx++;
  11594. me = &dd->msix_entries[rcd->msix_intr];
  11595. /*
  11596. * Set the interrupt register and mask for this
  11597. * context's interrupt.
  11598. */
  11599. rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
  11600. rcd->imask = ((u64)1) <<
  11601. ((IS_RCVAVAIL_START + idx) % 64);
  11602. me->type = IRQ_RCVCTXT;
  11603. me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
  11604. remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
  11605. ret = pci_request_irq(dd->pcidev, rcd->msix_intr,
  11606. receive_context_interrupt,
  11607. receive_context_thread, arg,
  11608. DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
  11609. if (ret) {
  11610. dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
  11611. me->irq, idx, ret);
  11612. return;
  11613. }
  11614. /*
  11615. * assign arg after pci_request_irq call, so it will be
  11616. * cleaned up
  11617. */
  11618. me->arg = arg;
  11619. ret = hfi1_get_irq_affinity(dd, me);
  11620. if (ret) {
  11621. dd_dev_err(dd,
  11622. "unable to pin IRQ %d\n", ret);
  11623. pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
  11624. }
  11625. }
  11626. /*
  11627. * Set the general handler to accept all interrupts, remap all
  11628. * chip interrupts back to MSI-X 0.
  11629. */
  11630. static void reset_interrupts(struct hfi1_devdata *dd)
  11631. {
  11632. int i;
  11633. /* all interrupts handled by the general handler */
  11634. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  11635. dd->gi_mask[i] = ~(u64)0;
  11636. /* all chip interrupts map to MSI-X 0 */
  11637. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11638. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11639. }
  11640. static int set_up_interrupts(struct hfi1_devdata *dd)
  11641. {
  11642. u32 total;
  11643. int ret, request;
  11644. int single_interrupt = 0; /* we expect to have all the interrupts */
  11645. /*
  11646. * Interrupt count:
  11647. * 1 general, "slow path" interrupt (includes the SDMA engines
  11648. * slow source, SDMACleanupDone)
  11649. * N interrupts - one per used SDMA engine
  11650. * M interrupt - one per kernel receive context
  11651. * V interrupt - one for each VNIC context
  11652. */
  11653. total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
  11654. /* ask for MSI-X interrupts */
  11655. request = request_msix(dd, total);
  11656. if (request < 0) {
  11657. ret = request;
  11658. goto fail;
  11659. } else if (request == 0) {
  11660. /* using INTx */
  11661. /* dd->num_msix_entries already zero */
  11662. single_interrupt = 1;
  11663. dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
  11664. } else if (request < total) {
  11665. /* using MSI-X, with reduced interrupts */
  11666. dd_dev_err(dd, "reduced interrupt found, wanted %u, got %u\n",
  11667. total, request);
  11668. ret = -EINVAL;
  11669. goto fail;
  11670. } else {
  11671. dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
  11672. GFP_KERNEL);
  11673. if (!dd->msix_entries) {
  11674. ret = -ENOMEM;
  11675. goto fail;
  11676. }
  11677. /* using MSI-X */
  11678. dd->num_msix_entries = total;
  11679. dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
  11680. }
  11681. /* mask all interrupts */
  11682. set_intr_state(dd, 0);
  11683. /* clear all pending interrupts */
  11684. clear_all_interrupts(dd);
  11685. /* reset general handler mask, chip MSI-X mappings */
  11686. reset_interrupts(dd);
  11687. if (single_interrupt)
  11688. ret = request_intx_irq(dd);
  11689. else
  11690. ret = request_msix_irqs(dd);
  11691. if (ret)
  11692. goto fail;
  11693. return 0;
  11694. fail:
  11695. clean_up_interrupts(dd);
  11696. return ret;
  11697. }
  11698. /*
  11699. * Set up context values in dd. Sets:
  11700. *
  11701. * num_rcv_contexts - number of contexts being used
  11702. * n_krcv_queues - number of kernel contexts
  11703. * first_dyn_alloc_ctxt - first dynamically allocated context
  11704. * in array of contexts
  11705. * freectxts - number of free user contexts
  11706. * num_send_contexts - number of PIO send contexts being used
  11707. * num_vnic_contexts - number of contexts reserved for VNIC
  11708. */
  11709. static int set_up_context_variables(struct hfi1_devdata *dd)
  11710. {
  11711. unsigned long num_kernel_contexts;
  11712. u16 num_vnic_contexts = HFI1_NUM_VNIC_CTXT;
  11713. int total_contexts;
  11714. int ret;
  11715. unsigned ngroups;
  11716. int qos_rmt_count;
  11717. int user_rmt_reduced;
  11718. u32 n_usr_ctxts;
  11719. /*
  11720. * Kernel receive contexts:
  11721. * - Context 0 - control context (VL15/multicast/error)
  11722. * - Context 1 - first kernel context
  11723. * - Context 2 - second kernel context
  11724. * ...
  11725. */
  11726. if (n_krcvqs)
  11727. /*
  11728. * n_krcvqs is the sum of module parameter kernel receive
  11729. * contexts, krcvqs[]. It does not include the control
  11730. * context, so add that.
  11731. */
  11732. num_kernel_contexts = n_krcvqs + 1;
  11733. else
  11734. num_kernel_contexts = DEFAULT_KRCVQS + 1;
  11735. /*
  11736. * Every kernel receive context needs an ACK send context.
  11737. * one send context is allocated for each VL{0-7} and VL15
  11738. */
  11739. if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
  11740. dd_dev_err(dd,
  11741. "Reducing # kernel rcv contexts to: %d, from %lu\n",
  11742. (int)(dd->chip_send_contexts - num_vls - 1),
  11743. num_kernel_contexts);
  11744. num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
  11745. }
  11746. /* Accommodate VNIC contexts if possible */
  11747. if ((num_kernel_contexts + num_vnic_contexts) > dd->chip_rcv_contexts) {
  11748. dd_dev_err(dd, "No receive contexts available for VNIC\n");
  11749. num_vnic_contexts = 0;
  11750. }
  11751. total_contexts = num_kernel_contexts + num_vnic_contexts;
  11752. /*
  11753. * User contexts:
  11754. * - default to 1 user context per real (non-HT) CPU core if
  11755. * num_user_contexts is negative
  11756. */
  11757. if (num_user_contexts < 0)
  11758. n_usr_ctxts = cpumask_weight(&node_affinity.real_cpu_mask);
  11759. else
  11760. n_usr_ctxts = num_user_contexts;
  11761. /*
  11762. * Adjust the counts given a global max.
  11763. */
  11764. if (total_contexts + n_usr_ctxts > dd->chip_rcv_contexts) {
  11765. dd_dev_err(dd,
  11766. "Reducing # user receive contexts to: %d, from %u\n",
  11767. (int)(dd->chip_rcv_contexts - total_contexts),
  11768. n_usr_ctxts);
  11769. /* recalculate */
  11770. n_usr_ctxts = dd->chip_rcv_contexts - total_contexts;
  11771. }
  11772. /* each user context requires an entry in the RMT */
  11773. qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
  11774. if (qos_rmt_count + n_usr_ctxts > NUM_MAP_ENTRIES) {
  11775. user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
  11776. dd_dev_err(dd,
  11777. "RMT size is reducing the number of user receive contexts from %u to %d\n",
  11778. n_usr_ctxts,
  11779. user_rmt_reduced);
  11780. /* recalculate */
  11781. n_usr_ctxts = user_rmt_reduced;
  11782. }
  11783. total_contexts += n_usr_ctxts;
  11784. /* the first N are kernel contexts, the rest are user/vnic contexts */
  11785. dd->num_rcv_contexts = total_contexts;
  11786. dd->n_krcv_queues = num_kernel_contexts;
  11787. dd->first_dyn_alloc_ctxt = num_kernel_contexts;
  11788. dd->num_vnic_contexts = num_vnic_contexts;
  11789. dd->num_user_contexts = n_usr_ctxts;
  11790. dd->freectxts = n_usr_ctxts;
  11791. dd_dev_info(dd,
  11792. "rcv contexts: chip %d, used %d (kernel %d, vnic %u, user %u)\n",
  11793. (int)dd->chip_rcv_contexts,
  11794. (int)dd->num_rcv_contexts,
  11795. (int)dd->n_krcv_queues,
  11796. dd->num_vnic_contexts,
  11797. dd->num_user_contexts);
  11798. /*
  11799. * Receive array allocation:
  11800. * All RcvArray entries are divided into groups of 8. This
  11801. * is required by the hardware and will speed up writes to
  11802. * consecutive entries by using write-combining of the entire
  11803. * cacheline.
  11804. *
  11805. * The number of groups are evenly divided among all contexts.
  11806. * any left over groups will be given to the first N user
  11807. * contexts.
  11808. */
  11809. dd->rcv_entries.group_size = RCV_INCREMENT;
  11810. ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
  11811. dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
  11812. dd->rcv_entries.nctxt_extra = ngroups -
  11813. (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
  11814. dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
  11815. dd->rcv_entries.ngroups,
  11816. dd->rcv_entries.nctxt_extra);
  11817. if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
  11818. MAX_EAGER_ENTRIES * 2) {
  11819. dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
  11820. dd->rcv_entries.group_size;
  11821. dd_dev_info(dd,
  11822. "RcvArray group count too high, change to %u\n",
  11823. dd->rcv_entries.ngroups);
  11824. dd->rcv_entries.nctxt_extra = 0;
  11825. }
  11826. /*
  11827. * PIO send contexts
  11828. */
  11829. ret = init_sc_pools_and_sizes(dd);
  11830. if (ret >= 0) { /* success */
  11831. dd->num_send_contexts = ret;
  11832. dd_dev_info(
  11833. dd,
  11834. "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
  11835. dd->chip_send_contexts,
  11836. dd->num_send_contexts,
  11837. dd->sc_sizes[SC_KERNEL].count,
  11838. dd->sc_sizes[SC_ACK].count,
  11839. dd->sc_sizes[SC_USER].count,
  11840. dd->sc_sizes[SC_VL15].count);
  11841. ret = 0; /* success */
  11842. }
  11843. return ret;
  11844. }
  11845. /*
  11846. * Set the device/port partition key table. The MAD code
  11847. * will ensure that, at least, the partial management
  11848. * partition key is present in the table.
  11849. */
  11850. static void set_partition_keys(struct hfi1_pportdata *ppd)
  11851. {
  11852. struct hfi1_devdata *dd = ppd->dd;
  11853. u64 reg = 0;
  11854. int i;
  11855. dd_dev_info(dd, "Setting partition keys\n");
  11856. for (i = 0; i < hfi1_get_npkeys(dd); i++) {
  11857. reg |= (ppd->pkeys[i] &
  11858. RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
  11859. ((i % 4) *
  11860. RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
  11861. /* Each register holds 4 PKey values. */
  11862. if ((i % 4) == 3) {
  11863. write_csr(dd, RCV_PARTITION_KEY +
  11864. ((i - 3) * 2), reg);
  11865. reg = 0;
  11866. }
  11867. }
  11868. /* Always enable HW pkeys check when pkeys table is set */
  11869. add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
  11870. }
  11871. /*
  11872. * These CSRs and memories are uninitialized on reset and must be
  11873. * written before reading to set the ECC/parity bits.
  11874. *
  11875. * NOTE: All user context CSRs that are not mmaped write-only
  11876. * (e.g. the TID flows) must be initialized even if the driver never
  11877. * reads them.
  11878. */
  11879. static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
  11880. {
  11881. int i, j;
  11882. /* CceIntMap */
  11883. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11884. write_csr(dd, CCE_INT_MAP + (8 * i), 0);
  11885. /* SendCtxtCreditReturnAddr */
  11886. for (i = 0; i < dd->chip_send_contexts; i++)
  11887. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  11888. /* PIO Send buffers */
  11889. /* SDMA Send buffers */
  11890. /*
  11891. * These are not normally read, and (presently) have no method
  11892. * to be read, so are not pre-initialized
  11893. */
  11894. /* RcvHdrAddr */
  11895. /* RcvHdrTailAddr */
  11896. /* RcvTidFlowTable */
  11897. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  11898. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  11899. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  11900. for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
  11901. write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
  11902. }
  11903. /* RcvArray */
  11904. for (i = 0; i < dd->chip_rcv_array_count; i++)
  11905. hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
  11906. /* RcvQPMapTable */
  11907. for (i = 0; i < 32; i++)
  11908. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  11909. }
  11910. /*
  11911. * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
  11912. */
  11913. static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
  11914. u64 ctrl_bits)
  11915. {
  11916. unsigned long timeout;
  11917. u64 reg;
  11918. /* is the condition present? */
  11919. reg = read_csr(dd, CCE_STATUS);
  11920. if ((reg & status_bits) == 0)
  11921. return;
  11922. /* clear the condition */
  11923. write_csr(dd, CCE_CTRL, ctrl_bits);
  11924. /* wait for the condition to clear */
  11925. timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
  11926. while (1) {
  11927. reg = read_csr(dd, CCE_STATUS);
  11928. if ((reg & status_bits) == 0)
  11929. return;
  11930. if (time_after(jiffies, timeout)) {
  11931. dd_dev_err(dd,
  11932. "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
  11933. status_bits, reg & status_bits);
  11934. return;
  11935. }
  11936. udelay(1);
  11937. }
  11938. }
  11939. /* set CCE CSRs to chip reset defaults */
  11940. static void reset_cce_csrs(struct hfi1_devdata *dd)
  11941. {
  11942. int i;
  11943. /* CCE_REVISION read-only */
  11944. /* CCE_REVISION2 read-only */
  11945. /* CCE_CTRL - bits clear automatically */
  11946. /* CCE_STATUS read-only, use CceCtrl to clear */
  11947. clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
  11948. clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
  11949. clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
  11950. for (i = 0; i < CCE_NUM_SCRATCH; i++)
  11951. write_csr(dd, CCE_SCRATCH + (8 * i), 0);
  11952. /* CCE_ERR_STATUS read-only */
  11953. write_csr(dd, CCE_ERR_MASK, 0);
  11954. write_csr(dd, CCE_ERR_CLEAR, ~0ull);
  11955. /* CCE_ERR_FORCE leave alone */
  11956. for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
  11957. write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
  11958. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
  11959. /* CCE_PCIE_CTRL leave alone */
  11960. for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
  11961. write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
  11962. write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
  11963. CCE_MSIX_TABLE_UPPER_RESETCSR);
  11964. }
  11965. for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
  11966. /* CCE_MSIX_PBA read-only */
  11967. write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
  11968. write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
  11969. }
  11970. for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
  11971. write_csr(dd, CCE_INT_MAP, 0);
  11972. for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
  11973. /* CCE_INT_STATUS read-only */
  11974. write_csr(dd, CCE_INT_MASK + (8 * i), 0);
  11975. write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
  11976. /* CCE_INT_FORCE leave alone */
  11977. /* CCE_INT_BLOCKED read-only */
  11978. }
  11979. for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
  11980. write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
  11981. }
  11982. /* set MISC CSRs to chip reset defaults */
  11983. static void reset_misc_csrs(struct hfi1_devdata *dd)
  11984. {
  11985. int i;
  11986. for (i = 0; i < 32; i++) {
  11987. write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
  11988. write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
  11989. write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
  11990. }
  11991. /*
  11992. * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
  11993. * only be written 128-byte chunks
  11994. */
  11995. /* init RSA engine to clear lingering errors */
  11996. write_csr(dd, MISC_CFG_RSA_CMD, 1);
  11997. write_csr(dd, MISC_CFG_RSA_MU, 0);
  11998. write_csr(dd, MISC_CFG_FW_CTRL, 0);
  11999. /* MISC_STS_8051_DIGEST read-only */
  12000. /* MISC_STS_SBM_DIGEST read-only */
  12001. /* MISC_STS_PCIE_DIGEST read-only */
  12002. /* MISC_STS_FAB_DIGEST read-only */
  12003. /* MISC_ERR_STATUS read-only */
  12004. write_csr(dd, MISC_ERR_MASK, 0);
  12005. write_csr(dd, MISC_ERR_CLEAR, ~0ull);
  12006. /* MISC_ERR_FORCE leave alone */
  12007. }
  12008. /* set TXE CSRs to chip reset defaults */
  12009. static void reset_txe_csrs(struct hfi1_devdata *dd)
  12010. {
  12011. int i;
  12012. /*
  12013. * TXE Kernel CSRs
  12014. */
  12015. write_csr(dd, SEND_CTRL, 0);
  12016. __cm_reset(dd, 0); /* reset CM internal state */
  12017. /* SEND_CONTEXTS read-only */
  12018. /* SEND_DMA_ENGINES read-only */
  12019. /* SEND_PIO_MEM_SIZE read-only */
  12020. /* SEND_DMA_MEM_SIZE read-only */
  12021. write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
  12022. pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
  12023. /* SEND_PIO_ERR_STATUS read-only */
  12024. write_csr(dd, SEND_PIO_ERR_MASK, 0);
  12025. write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
  12026. /* SEND_PIO_ERR_FORCE leave alone */
  12027. /* SEND_DMA_ERR_STATUS read-only */
  12028. write_csr(dd, SEND_DMA_ERR_MASK, 0);
  12029. write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
  12030. /* SEND_DMA_ERR_FORCE leave alone */
  12031. /* SEND_EGRESS_ERR_STATUS read-only */
  12032. write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
  12033. write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
  12034. /* SEND_EGRESS_ERR_FORCE leave alone */
  12035. write_csr(dd, SEND_BTH_QP, 0);
  12036. write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
  12037. write_csr(dd, SEND_SC2VLT0, 0);
  12038. write_csr(dd, SEND_SC2VLT1, 0);
  12039. write_csr(dd, SEND_SC2VLT2, 0);
  12040. write_csr(dd, SEND_SC2VLT3, 0);
  12041. write_csr(dd, SEND_LEN_CHECK0, 0);
  12042. write_csr(dd, SEND_LEN_CHECK1, 0);
  12043. /* SEND_ERR_STATUS read-only */
  12044. write_csr(dd, SEND_ERR_MASK, 0);
  12045. write_csr(dd, SEND_ERR_CLEAR, ~0ull);
  12046. /* SEND_ERR_FORCE read-only */
  12047. for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
  12048. write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
  12049. for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
  12050. write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
  12051. for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
  12052. write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
  12053. for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
  12054. write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
  12055. for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
  12056. write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
  12057. write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
  12058. write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
  12059. /* SEND_CM_CREDIT_USED_STATUS read-only */
  12060. write_csr(dd, SEND_CM_TIMER_CTRL, 0);
  12061. write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
  12062. write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
  12063. write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
  12064. write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
  12065. for (i = 0; i < TXE_NUM_DATA_VL; i++)
  12066. write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
  12067. write_csr(dd, SEND_CM_CREDIT_VL15, 0);
  12068. /* SEND_CM_CREDIT_USED_VL read-only */
  12069. /* SEND_CM_CREDIT_USED_VL15 read-only */
  12070. /* SEND_EGRESS_CTXT_STATUS read-only */
  12071. /* SEND_EGRESS_SEND_DMA_STATUS read-only */
  12072. write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
  12073. /* SEND_EGRESS_ERR_INFO read-only */
  12074. /* SEND_EGRESS_ERR_SOURCE read-only */
  12075. /*
  12076. * TXE Per-Context CSRs
  12077. */
  12078. for (i = 0; i < dd->chip_send_contexts; i++) {
  12079. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12080. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
  12081. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
  12082. write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
  12083. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
  12084. write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
  12085. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
  12086. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
  12087. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
  12088. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12089. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
  12090. write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
  12091. }
  12092. /*
  12093. * TXE Per-SDMA CSRs
  12094. */
  12095. for (i = 0; i < dd->chip_sdma_engines; i++) {
  12096. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12097. /* SEND_DMA_STATUS read-only */
  12098. write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
  12099. write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
  12100. write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
  12101. /* SEND_DMA_HEAD read-only */
  12102. write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
  12103. write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
  12104. /* SEND_DMA_IDLE_CNT read-only */
  12105. write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
  12106. write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
  12107. /* SEND_DMA_DESC_FETCHED_CNT read-only */
  12108. /* SEND_DMA_ENG_ERR_STATUS read-only */
  12109. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
  12110. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
  12111. /* SEND_DMA_ENG_ERR_FORCE leave alone */
  12112. write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
  12113. write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
  12114. write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
  12115. write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
  12116. write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
  12117. write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
  12118. write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
  12119. }
  12120. }
  12121. /*
  12122. * Expect on entry:
  12123. * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
  12124. */
  12125. static void init_rbufs(struct hfi1_devdata *dd)
  12126. {
  12127. u64 reg;
  12128. int count;
  12129. /*
  12130. * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
  12131. * clear.
  12132. */
  12133. count = 0;
  12134. while (1) {
  12135. reg = read_csr(dd, RCV_STATUS);
  12136. if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
  12137. | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
  12138. break;
  12139. /*
  12140. * Give up after 1ms - maximum wait time.
  12141. *
  12142. * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
  12143. * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
  12144. * 136 KB / (66% * 250MB/s) = 844us
  12145. */
  12146. if (count++ > 500) {
  12147. dd_dev_err(dd,
  12148. "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
  12149. __func__, reg);
  12150. break;
  12151. }
  12152. udelay(2); /* do not busy-wait the CSR */
  12153. }
  12154. /* start the init - expect RcvCtrl to be 0 */
  12155. write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
  12156. /*
  12157. * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
  12158. * period after the write before RcvStatus.RxRbufInitDone is valid.
  12159. * The delay in the first run through the loop below is sufficient and
  12160. * required before the first read of RcvStatus.RxRbufInintDone.
  12161. */
  12162. read_csr(dd, RCV_CTRL);
  12163. /* wait for the init to finish */
  12164. count = 0;
  12165. while (1) {
  12166. /* delay is required first time through - see above */
  12167. udelay(2); /* do not busy-wait the CSR */
  12168. reg = read_csr(dd, RCV_STATUS);
  12169. if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
  12170. break;
  12171. /* give up after 100us - slowest possible at 33MHz is 73us */
  12172. if (count++ > 50) {
  12173. dd_dev_err(dd,
  12174. "%s: RcvStatus.RxRbufInit not set, continuing\n",
  12175. __func__);
  12176. break;
  12177. }
  12178. }
  12179. }
  12180. /* set RXE CSRs to chip reset defaults */
  12181. static void reset_rxe_csrs(struct hfi1_devdata *dd)
  12182. {
  12183. int i, j;
  12184. /*
  12185. * RXE Kernel CSRs
  12186. */
  12187. write_csr(dd, RCV_CTRL, 0);
  12188. init_rbufs(dd);
  12189. /* RCV_STATUS read-only */
  12190. /* RCV_CONTEXTS read-only */
  12191. /* RCV_ARRAY_CNT read-only */
  12192. /* RCV_BUF_SIZE read-only */
  12193. write_csr(dd, RCV_BTH_QP, 0);
  12194. write_csr(dd, RCV_MULTICAST, 0);
  12195. write_csr(dd, RCV_BYPASS, 0);
  12196. write_csr(dd, RCV_VL15, 0);
  12197. /* this is a clear-down */
  12198. write_csr(dd, RCV_ERR_INFO,
  12199. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  12200. /* RCV_ERR_STATUS read-only */
  12201. write_csr(dd, RCV_ERR_MASK, 0);
  12202. write_csr(dd, RCV_ERR_CLEAR, ~0ull);
  12203. /* RCV_ERR_FORCE leave alone */
  12204. for (i = 0; i < 32; i++)
  12205. write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
  12206. for (i = 0; i < 4; i++)
  12207. write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
  12208. for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
  12209. write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
  12210. for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
  12211. write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
  12212. for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
  12213. clear_rsm_rule(dd, i);
  12214. for (i = 0; i < 32; i++)
  12215. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
  12216. /*
  12217. * RXE Kernel and User Per-Context CSRs
  12218. */
  12219. for (i = 0; i < dd->chip_rcv_contexts; i++) {
  12220. /* kernel */
  12221. write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
  12222. /* RCV_CTXT_STATUS read-only */
  12223. write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
  12224. write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
  12225. write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
  12226. write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
  12227. write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
  12228. write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
  12229. write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
  12230. write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
  12231. write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
  12232. write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
  12233. /* user */
  12234. /* RCV_HDR_TAIL read-only */
  12235. write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
  12236. /* RCV_EGR_INDEX_TAIL read-only */
  12237. write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
  12238. /* RCV_EGR_OFFSET_TAIL read-only */
  12239. for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
  12240. write_uctxt_csr(dd, i,
  12241. RCV_TID_FLOW_TABLE + (8 * j), 0);
  12242. }
  12243. }
  12244. }
  12245. /*
  12246. * Set sc2vl tables.
  12247. *
  12248. * They power on to zeros, so to avoid send context errors
  12249. * they need to be set:
  12250. *
  12251. * SC 0-7 -> VL 0-7 (respectively)
  12252. * SC 15 -> VL 15
  12253. * otherwise
  12254. * -> VL 0
  12255. */
  12256. static void init_sc2vl_tables(struct hfi1_devdata *dd)
  12257. {
  12258. int i;
  12259. /* init per architecture spec, constrained by hardware capability */
  12260. /* HFI maps sent packets */
  12261. write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
  12262. 0,
  12263. 0, 0, 1, 1,
  12264. 2, 2, 3, 3,
  12265. 4, 4, 5, 5,
  12266. 6, 6, 7, 7));
  12267. write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
  12268. 1,
  12269. 8, 0, 9, 0,
  12270. 10, 0, 11, 0,
  12271. 12, 0, 13, 0,
  12272. 14, 0, 15, 15));
  12273. write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
  12274. 2,
  12275. 16, 0, 17, 0,
  12276. 18, 0, 19, 0,
  12277. 20, 0, 21, 0,
  12278. 22, 0, 23, 0));
  12279. write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
  12280. 3,
  12281. 24, 0, 25, 0,
  12282. 26, 0, 27, 0,
  12283. 28, 0, 29, 0,
  12284. 30, 0, 31, 0));
  12285. /* DC maps received packets */
  12286. write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
  12287. 15_0,
  12288. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  12289. 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
  12290. write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
  12291. 31_16,
  12292. 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
  12293. 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
  12294. /* initialize the cached sc2vl values consistently with h/w */
  12295. for (i = 0; i < 32; i++) {
  12296. if (i < 8 || i == 15)
  12297. *((u8 *)(dd->sc2vl) + i) = (u8)i;
  12298. else
  12299. *((u8 *)(dd->sc2vl) + i) = 0;
  12300. }
  12301. }
  12302. /*
  12303. * Read chip sizes and then reset parts to sane, disabled, values. We cannot
  12304. * depend on the chip going through a power-on reset - a driver may be loaded
  12305. * and unloaded many times.
  12306. *
  12307. * Do not write any CSR values to the chip in this routine - there may be
  12308. * a reset following the (possible) FLR in this routine.
  12309. *
  12310. */
  12311. static int init_chip(struct hfi1_devdata *dd)
  12312. {
  12313. int i;
  12314. int ret = 0;
  12315. /*
  12316. * Put the HFI CSRs in a known state.
  12317. * Combine this with a DC reset.
  12318. *
  12319. * Stop the device from doing anything while we do a
  12320. * reset. We know there are no other active users of
  12321. * the device since we are now in charge. Turn off
  12322. * off all outbound and inbound traffic and make sure
  12323. * the device does not generate any interrupts.
  12324. */
  12325. /* disable send contexts and SDMA engines */
  12326. write_csr(dd, SEND_CTRL, 0);
  12327. for (i = 0; i < dd->chip_send_contexts; i++)
  12328. write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
  12329. for (i = 0; i < dd->chip_sdma_engines; i++)
  12330. write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
  12331. /* disable port (turn off RXE inbound traffic) and contexts */
  12332. write_csr(dd, RCV_CTRL, 0);
  12333. for (i = 0; i < dd->chip_rcv_contexts; i++)
  12334. write_csr(dd, RCV_CTXT_CTRL, 0);
  12335. /* mask all interrupt sources */
  12336. for (i = 0; i < CCE_NUM_INT_CSRS; i++)
  12337. write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
  12338. /*
  12339. * DC Reset: do a full DC reset before the register clear.
  12340. * A recommended length of time to hold is one CSR read,
  12341. * so reread the CceDcCtrl. Then, hold the DC in reset
  12342. * across the clear.
  12343. */
  12344. write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
  12345. (void)read_csr(dd, CCE_DC_CTRL);
  12346. if (use_flr) {
  12347. /*
  12348. * A FLR will reset the SPC core and part of the PCIe.
  12349. * The parts that need to be restored have already been
  12350. * saved.
  12351. */
  12352. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12353. /* do the FLR, the DC reset will remain */
  12354. pcie_flr(dd->pcidev);
  12355. /* restore command and BARs */
  12356. ret = restore_pci_variables(dd);
  12357. if (ret) {
  12358. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12359. __func__);
  12360. return ret;
  12361. }
  12362. if (is_ax(dd)) {
  12363. dd_dev_info(dd, "Resetting CSRs with FLR\n");
  12364. pcie_flr(dd->pcidev);
  12365. ret = restore_pci_variables(dd);
  12366. if (ret) {
  12367. dd_dev_err(dd, "%s: Could not restore PCI variables\n",
  12368. __func__);
  12369. return ret;
  12370. }
  12371. }
  12372. } else {
  12373. dd_dev_info(dd, "Resetting CSRs with writes\n");
  12374. reset_cce_csrs(dd);
  12375. reset_txe_csrs(dd);
  12376. reset_rxe_csrs(dd);
  12377. reset_misc_csrs(dd);
  12378. }
  12379. /* clear the DC reset */
  12380. write_csr(dd, CCE_DC_CTRL, 0);
  12381. /* Set the LED off */
  12382. setextled(dd, 0);
  12383. /*
  12384. * Clear the QSFP reset.
  12385. * An FLR enforces a 0 on all out pins. The driver does not touch
  12386. * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
  12387. * anything plugged constantly in reset, if it pays attention
  12388. * to RESET_N.
  12389. * Prime examples of this are optical cables. Set all pins high.
  12390. * I2CCLK and I2CDAT will change per direction, and INT_N and
  12391. * MODPRS_N are input only and their value is ignored.
  12392. */
  12393. write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
  12394. write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
  12395. init_chip_resources(dd);
  12396. return ret;
  12397. }
  12398. static void init_early_variables(struct hfi1_devdata *dd)
  12399. {
  12400. int i;
  12401. /* assign link credit variables */
  12402. dd->vau = CM_VAU;
  12403. dd->link_credits = CM_GLOBAL_CREDITS;
  12404. if (is_ax(dd))
  12405. dd->link_credits--;
  12406. dd->vcu = cu_to_vcu(hfi1_cu);
  12407. /* enough room for 8 MAD packets plus header - 17K */
  12408. dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
  12409. if (dd->vl15_init > dd->link_credits)
  12410. dd->vl15_init = dd->link_credits;
  12411. write_uninitialized_csrs_and_memories(dd);
  12412. if (HFI1_CAP_IS_KSET(PKEY_CHECK))
  12413. for (i = 0; i < dd->num_pports; i++) {
  12414. struct hfi1_pportdata *ppd = &dd->pport[i];
  12415. set_partition_keys(ppd);
  12416. }
  12417. init_sc2vl_tables(dd);
  12418. }
  12419. static void init_kdeth_qp(struct hfi1_devdata *dd)
  12420. {
  12421. /* user changed the KDETH_QP */
  12422. if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
  12423. /* out of range or illegal value */
  12424. dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
  12425. kdeth_qp = 0;
  12426. }
  12427. if (kdeth_qp == 0) /* not set, or failed range check */
  12428. kdeth_qp = DEFAULT_KDETH_QP;
  12429. write_csr(dd, SEND_BTH_QP,
  12430. (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
  12431. SEND_BTH_QP_KDETH_QP_SHIFT);
  12432. write_csr(dd, RCV_BTH_QP,
  12433. (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
  12434. RCV_BTH_QP_KDETH_QP_SHIFT);
  12435. }
  12436. /**
  12437. * init_qpmap_table
  12438. * @dd - device data
  12439. * @first_ctxt - first context
  12440. * @last_ctxt - first context
  12441. *
  12442. * This return sets the qpn mapping table that
  12443. * is indexed by qpn[8:1].
  12444. *
  12445. * The routine will round robin the 256 settings
  12446. * from first_ctxt to last_ctxt.
  12447. *
  12448. * The first/last looks ahead to having specialized
  12449. * receive contexts for mgmt and bypass. Normal
  12450. * verbs traffic will assumed to be on a range
  12451. * of receive contexts.
  12452. */
  12453. static void init_qpmap_table(struct hfi1_devdata *dd,
  12454. u32 first_ctxt,
  12455. u32 last_ctxt)
  12456. {
  12457. u64 reg = 0;
  12458. u64 regno = RCV_QP_MAP_TABLE;
  12459. int i;
  12460. u64 ctxt = first_ctxt;
  12461. for (i = 0; i < 256; i++) {
  12462. reg |= ctxt << (8 * (i % 8));
  12463. ctxt++;
  12464. if (ctxt > last_ctxt)
  12465. ctxt = first_ctxt;
  12466. if (i % 8 == 7) {
  12467. write_csr(dd, regno, reg);
  12468. reg = 0;
  12469. regno += 8;
  12470. }
  12471. }
  12472. add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
  12473. | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
  12474. }
  12475. struct rsm_map_table {
  12476. u64 map[NUM_MAP_REGS];
  12477. unsigned int used;
  12478. };
  12479. struct rsm_rule_data {
  12480. u8 offset;
  12481. u8 pkt_type;
  12482. u32 field1_off;
  12483. u32 field2_off;
  12484. u32 index1_off;
  12485. u32 index1_width;
  12486. u32 index2_off;
  12487. u32 index2_width;
  12488. u32 mask1;
  12489. u32 value1;
  12490. u32 mask2;
  12491. u32 value2;
  12492. };
  12493. /*
  12494. * Return an initialized RMT map table for users to fill in. OK if it
  12495. * returns NULL, indicating no table.
  12496. */
  12497. static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
  12498. {
  12499. struct rsm_map_table *rmt;
  12500. u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
  12501. rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
  12502. if (rmt) {
  12503. memset(rmt->map, rxcontext, sizeof(rmt->map));
  12504. rmt->used = 0;
  12505. }
  12506. return rmt;
  12507. }
  12508. /*
  12509. * Write the final RMT map table to the chip and free the table. OK if
  12510. * table is NULL.
  12511. */
  12512. static void complete_rsm_map_table(struct hfi1_devdata *dd,
  12513. struct rsm_map_table *rmt)
  12514. {
  12515. int i;
  12516. if (rmt) {
  12517. /* write table to chip */
  12518. for (i = 0; i < NUM_MAP_REGS; i++)
  12519. write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
  12520. /* enable RSM */
  12521. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12522. }
  12523. }
  12524. /*
  12525. * Add a receive side mapping rule.
  12526. */
  12527. static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
  12528. struct rsm_rule_data *rrd)
  12529. {
  12530. write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
  12531. (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
  12532. 1ull << rule_index | /* enable bit */
  12533. (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
  12534. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
  12535. (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
  12536. (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
  12537. (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
  12538. (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
  12539. (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
  12540. (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
  12541. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
  12542. (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
  12543. (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
  12544. (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
  12545. (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
  12546. }
  12547. /*
  12548. * Clear a receive side mapping rule.
  12549. */
  12550. static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
  12551. {
  12552. write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
  12553. write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
  12554. write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
  12555. }
  12556. /* return the number of RSM map table entries that will be used for QOS */
  12557. static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
  12558. unsigned int *np)
  12559. {
  12560. int i;
  12561. unsigned int m, n;
  12562. u8 max_by_vl = 0;
  12563. /* is QOS active at all? */
  12564. if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
  12565. num_vls == 1 ||
  12566. krcvqsset <= 1)
  12567. goto no_qos;
  12568. /* determine bits for qpn */
  12569. for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
  12570. if (krcvqs[i] > max_by_vl)
  12571. max_by_vl = krcvqs[i];
  12572. if (max_by_vl > 32)
  12573. goto no_qos;
  12574. m = ilog2(__roundup_pow_of_two(max_by_vl));
  12575. /* determine bits for vl */
  12576. n = ilog2(__roundup_pow_of_two(num_vls));
  12577. /* reject if too much is used */
  12578. if ((m + n) > 7)
  12579. goto no_qos;
  12580. if (mp)
  12581. *mp = m;
  12582. if (np)
  12583. *np = n;
  12584. return 1 << (m + n);
  12585. no_qos:
  12586. if (mp)
  12587. *mp = 0;
  12588. if (np)
  12589. *np = 0;
  12590. return 0;
  12591. }
  12592. /**
  12593. * init_qos - init RX qos
  12594. * @dd - device data
  12595. * @rmt - RSM map table
  12596. *
  12597. * This routine initializes Rule 0 and the RSM map table to implement
  12598. * quality of service (qos).
  12599. *
  12600. * If all of the limit tests succeed, qos is applied based on the array
  12601. * interpretation of krcvqs where entry 0 is VL0.
  12602. *
  12603. * The number of vl bits (n) and the number of qpn bits (m) are computed to
  12604. * feed both the RSM map table and the single rule.
  12605. */
  12606. static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
  12607. {
  12608. struct rsm_rule_data rrd;
  12609. unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
  12610. unsigned int rmt_entries;
  12611. u64 reg;
  12612. if (!rmt)
  12613. goto bail;
  12614. rmt_entries = qos_rmt_entries(dd, &m, &n);
  12615. if (rmt_entries == 0)
  12616. goto bail;
  12617. qpns_per_vl = 1 << m;
  12618. /* enough room in the map table? */
  12619. rmt_entries = 1 << (m + n);
  12620. if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
  12621. goto bail;
  12622. /* add qos entries to the the RSM map table */
  12623. for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
  12624. unsigned tctxt;
  12625. for (qpn = 0, tctxt = ctxt;
  12626. krcvqs[i] && qpn < qpns_per_vl; qpn++) {
  12627. unsigned idx, regoff, regidx;
  12628. /* generate the index the hardware will produce */
  12629. idx = rmt->used + ((qpn << n) ^ i);
  12630. regoff = (idx % 8) * 8;
  12631. regidx = idx / 8;
  12632. /* replace default with context number */
  12633. reg = rmt->map[regidx];
  12634. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
  12635. << regoff);
  12636. reg |= (u64)(tctxt++) << regoff;
  12637. rmt->map[regidx] = reg;
  12638. if (tctxt == ctxt + krcvqs[i])
  12639. tctxt = ctxt;
  12640. }
  12641. ctxt += krcvqs[i];
  12642. }
  12643. rrd.offset = rmt->used;
  12644. rrd.pkt_type = 2;
  12645. rrd.field1_off = LRH_BTH_MATCH_OFFSET;
  12646. rrd.field2_off = LRH_SC_MATCH_OFFSET;
  12647. rrd.index1_off = LRH_SC_SELECT_OFFSET;
  12648. rrd.index1_width = n;
  12649. rrd.index2_off = QPN_SELECT_OFFSET;
  12650. rrd.index2_width = m + n;
  12651. rrd.mask1 = LRH_BTH_MASK;
  12652. rrd.value1 = LRH_BTH_VALUE;
  12653. rrd.mask2 = LRH_SC_MASK;
  12654. rrd.value2 = LRH_SC_VALUE;
  12655. /* add rule 0 */
  12656. add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
  12657. /* mark RSM map entries as used */
  12658. rmt->used += rmt_entries;
  12659. /* map everything else to the mcast/err/vl15 context */
  12660. init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
  12661. dd->qos_shift = n + 1;
  12662. return;
  12663. bail:
  12664. dd->qos_shift = 1;
  12665. init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
  12666. }
  12667. static void init_user_fecn_handling(struct hfi1_devdata *dd,
  12668. struct rsm_map_table *rmt)
  12669. {
  12670. struct rsm_rule_data rrd;
  12671. u64 reg;
  12672. int i, idx, regoff, regidx;
  12673. u8 offset;
  12674. /* there needs to be enough room in the map table */
  12675. if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
  12676. dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
  12677. return;
  12678. }
  12679. /*
  12680. * RSM will extract the destination context as an index into the
  12681. * map table. The destination contexts are a sequential block
  12682. * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
  12683. * Map entries are accessed as offset + extracted value. Adjust
  12684. * the added offset so this sequence can be placed anywhere in
  12685. * the table - as long as the entries themselves do not wrap.
  12686. * There are only enough bits in offset for the table size, so
  12687. * start with that to allow for a "negative" offset.
  12688. */
  12689. offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
  12690. (int)dd->first_dyn_alloc_ctxt);
  12691. for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
  12692. i < dd->num_rcv_contexts; i++, idx++) {
  12693. /* replace with identity mapping */
  12694. regoff = (idx % 8) * 8;
  12695. regidx = idx / 8;
  12696. reg = rmt->map[regidx];
  12697. reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
  12698. reg |= (u64)i << regoff;
  12699. rmt->map[regidx] = reg;
  12700. }
  12701. /*
  12702. * For RSM intercept of Expected FECN packets:
  12703. * o packet type 0 - expected
  12704. * o match on F (bit 95), using select/match 1, and
  12705. * o match on SH (bit 133), using select/match 2.
  12706. *
  12707. * Use index 1 to extract the 8-bit receive context from DestQP
  12708. * (start at bit 64). Use that as the RSM map table index.
  12709. */
  12710. rrd.offset = offset;
  12711. rrd.pkt_type = 0;
  12712. rrd.field1_off = 95;
  12713. rrd.field2_off = 133;
  12714. rrd.index1_off = 64;
  12715. rrd.index1_width = 8;
  12716. rrd.index2_off = 0;
  12717. rrd.index2_width = 0;
  12718. rrd.mask1 = 1;
  12719. rrd.value1 = 1;
  12720. rrd.mask2 = 1;
  12721. rrd.value2 = 1;
  12722. /* add rule 1 */
  12723. add_rsm_rule(dd, RSM_INS_FECN, &rrd);
  12724. rmt->used += dd->num_user_contexts;
  12725. }
  12726. /* Initialize RSM for VNIC */
  12727. void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
  12728. {
  12729. u8 i, j;
  12730. u8 ctx_id = 0;
  12731. u64 reg;
  12732. u32 regoff;
  12733. struct rsm_rule_data rrd;
  12734. if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
  12735. dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
  12736. dd->vnic.rmt_start);
  12737. return;
  12738. }
  12739. dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
  12740. dd->vnic.rmt_start,
  12741. dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
  12742. /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
  12743. regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
  12744. reg = read_csr(dd, regoff);
  12745. for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
  12746. /* Update map register with vnic context */
  12747. j = (dd->vnic.rmt_start + i) % 8;
  12748. reg &= ~(0xffllu << (j * 8));
  12749. reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
  12750. /* Wrap up vnic ctx index */
  12751. ctx_id %= dd->vnic.num_ctxt;
  12752. /* Write back map register */
  12753. if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
  12754. dev_dbg(&(dd)->pcidev->dev,
  12755. "Vnic rsm map reg[%d] =0x%llx\n",
  12756. regoff - RCV_RSM_MAP_TABLE, reg);
  12757. write_csr(dd, regoff, reg);
  12758. regoff += 8;
  12759. if (i < (NUM_VNIC_MAP_ENTRIES - 1))
  12760. reg = read_csr(dd, regoff);
  12761. }
  12762. }
  12763. /* Add rule for vnic */
  12764. rrd.offset = dd->vnic.rmt_start;
  12765. rrd.pkt_type = 4;
  12766. /* Match 16B packets */
  12767. rrd.field1_off = L2_TYPE_MATCH_OFFSET;
  12768. rrd.mask1 = L2_TYPE_MASK;
  12769. rrd.value1 = L2_16B_VALUE;
  12770. /* Match ETH L4 packets */
  12771. rrd.field2_off = L4_TYPE_MATCH_OFFSET;
  12772. rrd.mask2 = L4_16B_TYPE_MASK;
  12773. rrd.value2 = L4_16B_ETH_VALUE;
  12774. /* Calc context from veswid and entropy */
  12775. rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
  12776. rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12777. rrd.index2_off = L2_16B_ENTROPY_OFFSET;
  12778. rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
  12779. add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
  12780. /* Enable RSM if not already enabled */
  12781. add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12782. }
  12783. void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
  12784. {
  12785. clear_rsm_rule(dd, RSM_INS_VNIC);
  12786. /* Disable RSM if used only by vnic */
  12787. if (dd->vnic.rmt_start == 0)
  12788. clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
  12789. }
  12790. static void init_rxe(struct hfi1_devdata *dd)
  12791. {
  12792. struct rsm_map_table *rmt;
  12793. u64 val;
  12794. /* enable all receive errors */
  12795. write_csr(dd, RCV_ERR_MASK, ~0ull);
  12796. rmt = alloc_rsm_map_table(dd);
  12797. /* set up QOS, including the QPN map table */
  12798. init_qos(dd, rmt);
  12799. init_user_fecn_handling(dd, rmt);
  12800. complete_rsm_map_table(dd, rmt);
  12801. /* record number of used rsm map entries for vnic */
  12802. dd->vnic.rmt_start = rmt->used;
  12803. kfree(rmt);
  12804. /*
  12805. * make sure RcvCtrl.RcvWcb <= PCIe Device Control
  12806. * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
  12807. * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
  12808. * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
  12809. * Max_PayLoad_Size set to its minimum of 128.
  12810. *
  12811. * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
  12812. * (64 bytes). Max_Payload_Size is possibly modified upward in
  12813. * tune_pcie_caps() which is called after this routine.
  12814. */
  12815. /* Have 16 bytes (4DW) of bypass header available in header queue */
  12816. val = read_csr(dd, RCV_BYPASS);
  12817. val |= (4ull << 16);
  12818. write_csr(dd, RCV_BYPASS, val);
  12819. }
  12820. static void init_other(struct hfi1_devdata *dd)
  12821. {
  12822. /* enable all CCE errors */
  12823. write_csr(dd, CCE_ERR_MASK, ~0ull);
  12824. /* enable *some* Misc errors */
  12825. write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
  12826. /* enable all DC errors, except LCB */
  12827. write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
  12828. write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
  12829. }
  12830. /*
  12831. * Fill out the given AU table using the given CU. A CU is defined in terms
  12832. * AUs. The table is a an encoding: given the index, how many AUs does that
  12833. * represent?
  12834. *
  12835. * NOTE: Assumes that the register layout is the same for the
  12836. * local and remote tables.
  12837. */
  12838. static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
  12839. u32 csr0to3, u32 csr4to7)
  12840. {
  12841. write_csr(dd, csr0to3,
  12842. 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
  12843. 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
  12844. 2ull * cu <<
  12845. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
  12846. 4ull * cu <<
  12847. SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
  12848. write_csr(dd, csr4to7,
  12849. 8ull * cu <<
  12850. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
  12851. 16ull * cu <<
  12852. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
  12853. 32ull * cu <<
  12854. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
  12855. 64ull * cu <<
  12856. SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
  12857. }
  12858. static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12859. {
  12860. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
  12861. SEND_CM_LOCAL_AU_TABLE4_TO7);
  12862. }
  12863. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
  12864. {
  12865. assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
  12866. SEND_CM_REMOTE_AU_TABLE4_TO7);
  12867. }
  12868. static void init_txe(struct hfi1_devdata *dd)
  12869. {
  12870. int i;
  12871. /* enable all PIO, SDMA, general, and Egress errors */
  12872. write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
  12873. write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
  12874. write_csr(dd, SEND_ERR_MASK, ~0ull);
  12875. write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
  12876. /* enable all per-context and per-SDMA engine errors */
  12877. for (i = 0; i < dd->chip_send_contexts; i++)
  12878. write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
  12879. for (i = 0; i < dd->chip_sdma_engines; i++)
  12880. write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
  12881. /* set the local CU to AU mapping */
  12882. assign_local_cm_au_table(dd, dd->vcu);
  12883. /*
  12884. * Set reasonable default for Credit Return Timer
  12885. * Don't set on Simulator - causes it to choke.
  12886. */
  12887. if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
  12888. write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
  12889. }
  12890. int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12891. u16 jkey)
  12892. {
  12893. u8 hw_ctxt;
  12894. u64 reg;
  12895. if (!rcd || !rcd->sc)
  12896. return -EINVAL;
  12897. hw_ctxt = rcd->sc->hw_context;
  12898. reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
  12899. ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
  12900. SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
  12901. /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
  12902. if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
  12903. reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
  12904. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
  12905. /*
  12906. * Enable send-side J_KEY integrity check, unless this is A0 h/w
  12907. */
  12908. if (!is_ax(dd)) {
  12909. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12910. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12911. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12912. }
  12913. /* Enable J_KEY check on receive context. */
  12914. reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
  12915. ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
  12916. RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
  12917. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
  12918. return 0;
  12919. }
  12920. int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
  12921. {
  12922. u8 hw_ctxt;
  12923. u64 reg;
  12924. if (!rcd || !rcd->sc)
  12925. return -EINVAL;
  12926. hw_ctxt = rcd->sc->hw_context;
  12927. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
  12928. /*
  12929. * Disable send-side J_KEY integrity check, unless this is A0 h/w.
  12930. * This check would not have been enabled for A0 h/w, see
  12931. * set_ctxt_jkey().
  12932. */
  12933. if (!is_ax(dd)) {
  12934. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12935. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  12936. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12937. }
  12938. /* Turn off the J_KEY on the receive side */
  12939. write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
  12940. return 0;
  12941. }
  12942. int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
  12943. u16 pkey)
  12944. {
  12945. u8 hw_ctxt;
  12946. u64 reg;
  12947. if (!rcd || !rcd->sc)
  12948. return -EINVAL;
  12949. hw_ctxt = rcd->sc->hw_context;
  12950. reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
  12951. SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
  12952. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
  12953. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12954. reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12955. reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
  12956. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12957. return 0;
  12958. }
  12959. int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
  12960. {
  12961. u8 hw_ctxt;
  12962. u64 reg;
  12963. if (!ctxt || !ctxt->sc)
  12964. return -EINVAL;
  12965. hw_ctxt = ctxt->sc->hw_context;
  12966. reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
  12967. reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
  12968. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
  12969. write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
  12970. return 0;
  12971. }
  12972. /*
  12973. * Start doing the clean up the the chip. Our clean up happens in multiple
  12974. * stages and this is just the first.
  12975. */
  12976. void hfi1_start_cleanup(struct hfi1_devdata *dd)
  12977. {
  12978. aspm_exit(dd);
  12979. free_cntrs(dd);
  12980. free_rcverr(dd);
  12981. clean_up_interrupts(dd);
  12982. finish_chip_resources(dd);
  12983. }
  12984. #define HFI_BASE_GUID(dev) \
  12985. ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
  12986. /*
  12987. * Information can be shared between the two HFIs on the same ASIC
  12988. * in the same OS. This function finds the peer device and sets
  12989. * up a shared structure.
  12990. */
  12991. static int init_asic_data(struct hfi1_devdata *dd)
  12992. {
  12993. unsigned long flags;
  12994. struct hfi1_devdata *tmp, *peer = NULL;
  12995. struct hfi1_asic_data *asic_data;
  12996. int ret = 0;
  12997. /* pre-allocate the asic structure in case we are the first device */
  12998. asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
  12999. if (!asic_data)
  13000. return -ENOMEM;
  13001. spin_lock_irqsave(&hfi1_devs_lock, flags);
  13002. /* Find our peer device */
  13003. list_for_each_entry(tmp, &hfi1_dev_list, list) {
  13004. if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
  13005. dd->unit != tmp->unit) {
  13006. peer = tmp;
  13007. break;
  13008. }
  13009. }
  13010. if (peer) {
  13011. /* use already allocated structure */
  13012. dd->asic_data = peer->asic_data;
  13013. kfree(asic_data);
  13014. } else {
  13015. dd->asic_data = asic_data;
  13016. mutex_init(&dd->asic_data->asic_resource_mutex);
  13017. }
  13018. dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
  13019. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  13020. /* first one through - set up i2c devices */
  13021. if (!peer)
  13022. ret = set_up_i2c(dd, dd->asic_data);
  13023. return ret;
  13024. }
  13025. /*
  13026. * Set dd->boardname. Use a generic name if a name is not returned from
  13027. * EFI variable space.
  13028. *
  13029. * Return 0 on success, -ENOMEM if space could not be allocated.
  13030. */
  13031. static int obtain_boardname(struct hfi1_devdata *dd)
  13032. {
  13033. /* generic board description */
  13034. const char generic[] =
  13035. "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
  13036. unsigned long size;
  13037. int ret;
  13038. ret = read_hfi1_efi_var(dd, "description", &size,
  13039. (void **)&dd->boardname);
  13040. if (ret) {
  13041. dd_dev_info(dd, "Board description not found\n");
  13042. /* use generic description */
  13043. dd->boardname = kstrdup(generic, GFP_KERNEL);
  13044. if (!dd->boardname)
  13045. return -ENOMEM;
  13046. }
  13047. return 0;
  13048. }
  13049. /*
  13050. * Check the interrupt registers to make sure that they are mapped correctly.
  13051. * It is intended to help user identify any mismapping by VMM when the driver
  13052. * is running in a VM. This function should only be called before interrupt
  13053. * is set up properly.
  13054. *
  13055. * Return 0 on success, -EINVAL on failure.
  13056. */
  13057. static int check_int_registers(struct hfi1_devdata *dd)
  13058. {
  13059. u64 reg;
  13060. u64 all_bits = ~(u64)0;
  13061. u64 mask;
  13062. /* Clear CceIntMask[0] to avoid raising any interrupts */
  13063. mask = read_csr(dd, CCE_INT_MASK);
  13064. write_csr(dd, CCE_INT_MASK, 0ull);
  13065. reg = read_csr(dd, CCE_INT_MASK);
  13066. if (reg)
  13067. goto err_exit;
  13068. /* Clear all interrupt status bits */
  13069. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13070. reg = read_csr(dd, CCE_INT_STATUS);
  13071. if (reg)
  13072. goto err_exit;
  13073. /* Set all interrupt status bits */
  13074. write_csr(dd, CCE_INT_FORCE, all_bits);
  13075. reg = read_csr(dd, CCE_INT_STATUS);
  13076. if (reg != all_bits)
  13077. goto err_exit;
  13078. /* Restore the interrupt mask */
  13079. write_csr(dd, CCE_INT_CLEAR, all_bits);
  13080. write_csr(dd, CCE_INT_MASK, mask);
  13081. return 0;
  13082. err_exit:
  13083. write_csr(dd, CCE_INT_MASK, mask);
  13084. dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
  13085. return -EINVAL;
  13086. }
  13087. /**
  13088. * Allocate and initialize the device structure for the hfi.
  13089. * @dev: the pci_dev for hfi1_ib device
  13090. * @ent: pci_device_id struct for this dev
  13091. *
  13092. * Also allocates, initializes, and returns the devdata struct for this
  13093. * device instance
  13094. *
  13095. * This is global, and is called directly at init to set up the
  13096. * chip-specific function pointers for later use.
  13097. */
  13098. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  13099. const struct pci_device_id *ent)
  13100. {
  13101. struct hfi1_devdata *dd;
  13102. struct hfi1_pportdata *ppd;
  13103. u64 reg;
  13104. int i, ret;
  13105. static const char * const inames[] = { /* implementation names */
  13106. "RTL silicon",
  13107. "RTL VCS simulation",
  13108. "RTL FPGA emulation",
  13109. "Functional simulator"
  13110. };
  13111. struct pci_dev *parent = pdev->bus->self;
  13112. dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
  13113. sizeof(struct hfi1_pportdata));
  13114. if (IS_ERR(dd))
  13115. goto bail;
  13116. ppd = dd->pport;
  13117. for (i = 0; i < dd->num_pports; i++, ppd++) {
  13118. int vl;
  13119. /* init common fields */
  13120. hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
  13121. /* DC supports 4 link widths */
  13122. ppd->link_width_supported =
  13123. OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
  13124. OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
  13125. ppd->link_width_downgrade_supported =
  13126. ppd->link_width_supported;
  13127. /* start out enabling only 4X */
  13128. ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
  13129. ppd->link_width_downgrade_enabled =
  13130. ppd->link_width_downgrade_supported;
  13131. /* link width active is 0 when link is down */
  13132. /* link width downgrade active is 0 when link is down */
  13133. if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
  13134. num_vls > HFI1_MAX_VLS_SUPPORTED) {
  13135. hfi1_early_err(&pdev->dev,
  13136. "Invalid num_vls %u, using %u VLs\n",
  13137. num_vls, HFI1_MAX_VLS_SUPPORTED);
  13138. num_vls = HFI1_MAX_VLS_SUPPORTED;
  13139. }
  13140. ppd->vls_supported = num_vls;
  13141. ppd->vls_operational = ppd->vls_supported;
  13142. /* Set the default MTU. */
  13143. for (vl = 0; vl < num_vls; vl++)
  13144. dd->vld[vl].mtu = hfi1_max_mtu;
  13145. dd->vld[15].mtu = MAX_MAD_PACKET;
  13146. /*
  13147. * Set the initial values to reasonable default, will be set
  13148. * for real when link is up.
  13149. */
  13150. ppd->overrun_threshold = 0x4;
  13151. ppd->phy_error_threshold = 0xf;
  13152. ppd->port_crc_mode_enabled = link_crc_mask;
  13153. /* initialize supported LTP CRC mode */
  13154. ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
  13155. /* initialize enabled LTP CRC mode */
  13156. ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
  13157. /* start in offline */
  13158. ppd->host_link_state = HLS_DN_OFFLINE;
  13159. init_vl_arb_caches(ppd);
  13160. }
  13161. /*
  13162. * Do remaining PCIe setup and save PCIe values in dd.
  13163. * Any error printing is already done by the init code.
  13164. * On return, we have the chip mapped.
  13165. */
  13166. ret = hfi1_pcie_ddinit(dd, pdev);
  13167. if (ret < 0)
  13168. goto bail_free;
  13169. /* Save PCI space registers to rewrite after device reset */
  13170. ret = save_pci_variables(dd);
  13171. if (ret < 0)
  13172. goto bail_cleanup;
  13173. /* verify that reads actually work, save revision for reset check */
  13174. dd->revision = read_csr(dd, CCE_REVISION);
  13175. if (dd->revision == ~(u64)0) {
  13176. dd_dev_err(dd, "cannot read chip CSRs\n");
  13177. ret = -EINVAL;
  13178. goto bail_cleanup;
  13179. }
  13180. dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
  13181. & CCE_REVISION_CHIP_REV_MAJOR_MASK;
  13182. dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
  13183. & CCE_REVISION_CHIP_REV_MINOR_MASK;
  13184. /*
  13185. * Check interrupt registers mapping if the driver has no access to
  13186. * the upstream component. In this case, it is likely that the driver
  13187. * is running in a VM.
  13188. */
  13189. if (!parent) {
  13190. ret = check_int_registers(dd);
  13191. if (ret)
  13192. goto bail_cleanup;
  13193. }
  13194. /*
  13195. * obtain the hardware ID - NOT related to unit, which is a
  13196. * software enumeration
  13197. */
  13198. reg = read_csr(dd, CCE_REVISION2);
  13199. dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
  13200. & CCE_REVISION2_HFI_ID_MASK;
  13201. /* the variable size will remove unwanted bits */
  13202. dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
  13203. dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
  13204. dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
  13205. dd->icode < ARRAY_SIZE(inames) ?
  13206. inames[dd->icode] : "unknown", (int)dd->irev);
  13207. /* speeds the hardware can support */
  13208. dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
  13209. /* speeds allowed to run at */
  13210. dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
  13211. /* give a reasonable active value, will be set on link up */
  13212. dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
  13213. dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
  13214. dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
  13215. dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
  13216. dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
  13217. dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
  13218. /* fix up link widths for emulation _p */
  13219. ppd = dd->pport;
  13220. if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
  13221. ppd->link_width_supported =
  13222. ppd->link_width_enabled =
  13223. ppd->link_width_downgrade_supported =
  13224. ppd->link_width_downgrade_enabled =
  13225. OPA_LINK_WIDTH_1X;
  13226. }
  13227. /* insure num_vls isn't larger than number of sdma engines */
  13228. if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
  13229. dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
  13230. num_vls, dd->chip_sdma_engines);
  13231. num_vls = dd->chip_sdma_engines;
  13232. ppd->vls_supported = dd->chip_sdma_engines;
  13233. ppd->vls_operational = ppd->vls_supported;
  13234. }
  13235. /*
  13236. * Convert the ns parameter to the 64 * cclocks used in the CSR.
  13237. * Limit the max if larger than the field holds. If timeout is
  13238. * non-zero, then the calculated field will be at least 1.
  13239. *
  13240. * Must be after icode is set up - the cclock rate depends
  13241. * on knowing the hardware being used.
  13242. */
  13243. dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
  13244. if (dd->rcv_intr_timeout_csr >
  13245. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
  13246. dd->rcv_intr_timeout_csr =
  13247. RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
  13248. else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
  13249. dd->rcv_intr_timeout_csr = 1;
  13250. /* needs to be done before we look for the peer device */
  13251. read_guid(dd);
  13252. /* set up shared ASIC data with peer device */
  13253. ret = init_asic_data(dd);
  13254. if (ret)
  13255. goto bail_cleanup;
  13256. /* obtain chip sizes, reset chip CSRs */
  13257. ret = init_chip(dd);
  13258. if (ret)
  13259. goto bail_cleanup;
  13260. /* read in the PCIe link speed information */
  13261. ret = pcie_speeds(dd);
  13262. if (ret)
  13263. goto bail_cleanup;
  13264. /* call before get_platform_config(), after init_chip_resources() */
  13265. ret = eprom_init(dd);
  13266. if (ret)
  13267. goto bail_free_rcverr;
  13268. /* Needs to be called before hfi1_firmware_init */
  13269. get_platform_config(dd);
  13270. /* read in firmware */
  13271. ret = hfi1_firmware_init(dd);
  13272. if (ret)
  13273. goto bail_cleanup;
  13274. /*
  13275. * In general, the PCIe Gen3 transition must occur after the
  13276. * chip has been idled (so it won't initiate any PCIe transactions
  13277. * e.g. an interrupt) and before the driver changes any registers
  13278. * (the transition will reset the registers).
  13279. *
  13280. * In particular, place this call after:
  13281. * - init_chip() - the chip will not initiate any PCIe transactions
  13282. * - pcie_speeds() - reads the current link speed
  13283. * - hfi1_firmware_init() - the needed firmware is ready to be
  13284. * downloaded
  13285. */
  13286. ret = do_pcie_gen3_transition(dd);
  13287. if (ret)
  13288. goto bail_cleanup;
  13289. /* start setting dd values and adjusting CSRs */
  13290. init_early_variables(dd);
  13291. parse_platform_config(dd);
  13292. ret = obtain_boardname(dd);
  13293. if (ret)
  13294. goto bail_cleanup;
  13295. snprintf(dd->boardversion, BOARD_VERS_MAX,
  13296. "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
  13297. HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
  13298. (u32)dd->majrev,
  13299. (u32)dd->minrev,
  13300. (dd->revision >> CCE_REVISION_SW_SHIFT)
  13301. & CCE_REVISION_SW_MASK);
  13302. ret = set_up_context_variables(dd);
  13303. if (ret)
  13304. goto bail_cleanup;
  13305. /* set initial RXE CSRs */
  13306. init_rxe(dd);
  13307. /* set initial TXE CSRs */
  13308. init_txe(dd);
  13309. /* set initial non-RXE, non-TXE CSRs */
  13310. init_other(dd);
  13311. /* set up KDETH QP prefix in both RX and TX CSRs */
  13312. init_kdeth_qp(dd);
  13313. ret = hfi1_dev_affinity_init(dd);
  13314. if (ret)
  13315. goto bail_cleanup;
  13316. /* send contexts must be set up before receive contexts */
  13317. ret = init_send_contexts(dd);
  13318. if (ret)
  13319. goto bail_cleanup;
  13320. ret = hfi1_create_kctxts(dd);
  13321. if (ret)
  13322. goto bail_cleanup;
  13323. /*
  13324. * Initialize aspm, to be done after gen3 transition and setting up
  13325. * contexts and before enabling interrupts
  13326. */
  13327. aspm_init(dd);
  13328. dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
  13329. /*
  13330. * rcd[0] is guaranteed to be valid by this point. Also, all
  13331. * context are using the same value, as per the module parameter.
  13332. */
  13333. dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
  13334. ret = init_pervl_scs(dd);
  13335. if (ret)
  13336. goto bail_cleanup;
  13337. /* sdma init */
  13338. for (i = 0; i < dd->num_pports; ++i) {
  13339. ret = sdma_init(dd, i);
  13340. if (ret)
  13341. goto bail_cleanup;
  13342. }
  13343. /* use contexts created by hfi1_create_kctxts */
  13344. ret = set_up_interrupts(dd);
  13345. if (ret)
  13346. goto bail_cleanup;
  13347. /* set up LCB access - must be after set_up_interrupts() */
  13348. init_lcb_access(dd);
  13349. /*
  13350. * Serial number is created from the base guid:
  13351. * [27:24] = base guid [38:35]
  13352. * [23: 0] = base guid [23: 0]
  13353. */
  13354. snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
  13355. (dd->base_guid & 0xFFFFFF) |
  13356. ((dd->base_guid >> 11) & 0xF000000));
  13357. dd->oui1 = dd->base_guid >> 56 & 0xFF;
  13358. dd->oui2 = dd->base_guid >> 48 & 0xFF;
  13359. dd->oui3 = dd->base_guid >> 40 & 0xFF;
  13360. ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
  13361. if (ret)
  13362. goto bail_clear_intr;
  13363. thermal_init(dd);
  13364. ret = init_cntrs(dd);
  13365. if (ret)
  13366. goto bail_clear_intr;
  13367. ret = init_rcverr(dd);
  13368. if (ret)
  13369. goto bail_free_cntrs;
  13370. init_completion(&dd->user_comp);
  13371. /* The user refcount starts with one to inidicate an active device */
  13372. atomic_set(&dd->user_refcount, 1);
  13373. goto bail;
  13374. bail_free_rcverr:
  13375. free_rcverr(dd);
  13376. bail_free_cntrs:
  13377. free_cntrs(dd);
  13378. bail_clear_intr:
  13379. clean_up_interrupts(dd);
  13380. bail_cleanup:
  13381. hfi1_pcie_ddcleanup(dd);
  13382. bail_free:
  13383. hfi1_free_devdata(dd);
  13384. dd = ERR_PTR(ret);
  13385. bail:
  13386. return dd;
  13387. }
  13388. static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
  13389. u32 dw_len)
  13390. {
  13391. u32 delta_cycles;
  13392. u32 current_egress_rate = ppd->current_egress_rate;
  13393. /* rates here are in units of 10^6 bits/sec */
  13394. if (desired_egress_rate == -1)
  13395. return 0; /* shouldn't happen */
  13396. if (desired_egress_rate >= current_egress_rate)
  13397. return 0; /* we can't help go faster, only slower */
  13398. delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
  13399. egress_cycles(dw_len * 4, current_egress_rate);
  13400. return (u16)delta_cycles;
  13401. }
  13402. /**
  13403. * create_pbc - build a pbc for transmission
  13404. * @flags: special case flags or-ed in built pbc
  13405. * @srate: static rate
  13406. * @vl: vl
  13407. * @dwlen: dword length (header words + data words + pbc words)
  13408. *
  13409. * Create a PBC with the given flags, rate, VL, and length.
  13410. *
  13411. * NOTE: The PBC created will not insert any HCRC - all callers but one are
  13412. * for verbs, which does not use this PSM feature. The lone other caller
  13413. * is for the diagnostic interface which calls this if the user does not
  13414. * supply their own PBC.
  13415. */
  13416. u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
  13417. u32 dw_len)
  13418. {
  13419. u64 pbc, delay = 0;
  13420. if (unlikely(srate_mbs))
  13421. delay = delay_cycles(ppd, srate_mbs, dw_len);
  13422. pbc = flags
  13423. | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
  13424. | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
  13425. | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
  13426. | (dw_len & PBC_LENGTH_DWS_MASK)
  13427. << PBC_LENGTH_DWS_SHIFT;
  13428. return pbc;
  13429. }
  13430. #define SBUS_THERMAL 0x4f
  13431. #define SBUS_THERM_MONITOR_MODE 0x1
  13432. #define THERM_FAILURE(dev, ret, reason) \
  13433. dd_dev_err((dd), \
  13434. "Thermal sensor initialization failed: %s (%d)\n", \
  13435. (reason), (ret))
  13436. /*
  13437. * Initialize the thermal sensor.
  13438. *
  13439. * After initialization, enable polling of thermal sensor through
  13440. * SBus interface. In order for this to work, the SBus Master
  13441. * firmware has to be loaded due to the fact that the HW polling
  13442. * logic uses SBus interrupts, which are not supported with
  13443. * default firmware. Otherwise, no data will be returned through
  13444. * the ASIC_STS_THERM CSR.
  13445. */
  13446. static int thermal_init(struct hfi1_devdata *dd)
  13447. {
  13448. int ret = 0;
  13449. if (dd->icode != ICODE_RTL_SILICON ||
  13450. check_chip_resource(dd, CR_THERM_INIT, NULL))
  13451. return ret;
  13452. ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
  13453. if (ret) {
  13454. THERM_FAILURE(dd, ret, "Acquire SBus");
  13455. return ret;
  13456. }
  13457. dd_dev_info(dd, "Initializing thermal sensor\n");
  13458. /* Disable polling of thermal readings */
  13459. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
  13460. msleep(100);
  13461. /* Thermal Sensor Initialization */
  13462. /* Step 1: Reset the Thermal SBus Receiver */
  13463. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13464. RESET_SBUS_RECEIVER, 0);
  13465. if (ret) {
  13466. THERM_FAILURE(dd, ret, "Bus Reset");
  13467. goto done;
  13468. }
  13469. /* Step 2: Set Reset bit in Thermal block */
  13470. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13471. WRITE_SBUS_RECEIVER, 0x1);
  13472. if (ret) {
  13473. THERM_FAILURE(dd, ret, "Therm Block Reset");
  13474. goto done;
  13475. }
  13476. /* Step 3: Write clock divider value (100MHz -> 2MHz) */
  13477. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
  13478. WRITE_SBUS_RECEIVER, 0x32);
  13479. if (ret) {
  13480. THERM_FAILURE(dd, ret, "Write Clock Div");
  13481. goto done;
  13482. }
  13483. /* Step 4: Select temperature mode */
  13484. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
  13485. WRITE_SBUS_RECEIVER,
  13486. SBUS_THERM_MONITOR_MODE);
  13487. if (ret) {
  13488. THERM_FAILURE(dd, ret, "Write Mode Sel");
  13489. goto done;
  13490. }
  13491. /* Step 5: De-assert block reset and start conversion */
  13492. ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
  13493. WRITE_SBUS_RECEIVER, 0x2);
  13494. if (ret) {
  13495. THERM_FAILURE(dd, ret, "Write Reset Deassert");
  13496. goto done;
  13497. }
  13498. /* Step 5.1: Wait for first conversion (21.5ms per spec) */
  13499. msleep(22);
  13500. /* Enable polling of thermal readings */
  13501. write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
  13502. /* Set initialized flag */
  13503. ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
  13504. if (ret)
  13505. THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
  13506. done:
  13507. release_chip_resource(dd, CR_SBUS);
  13508. return ret;
  13509. }
  13510. static void handle_temp_err(struct hfi1_devdata *dd)
  13511. {
  13512. struct hfi1_pportdata *ppd = &dd->pport[0];
  13513. /*
  13514. * Thermal Critical Interrupt
  13515. * Put the device into forced freeze mode, take link down to
  13516. * offline, and put DC into reset.
  13517. */
  13518. dd_dev_emerg(dd,
  13519. "Critical temperature reached! Forcing device into freeze mode!\n");
  13520. dd->flags |= HFI1_FORCED_FREEZE;
  13521. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
  13522. /*
  13523. * Shut DC down as much and as quickly as possible.
  13524. *
  13525. * Step 1: Take the link down to OFFLINE. This will cause the
  13526. * 8051 to put the Serdes in reset. However, we don't want to
  13527. * go through the entire link state machine since we want to
  13528. * shutdown ASAP. Furthermore, this is not a graceful shutdown
  13529. * but rather an attempt to save the chip.
  13530. * Code below is almost the same as quiet_serdes() but avoids
  13531. * all the extra work and the sleeps.
  13532. */
  13533. ppd->driver_link_ready = 0;
  13534. ppd->link_enabled = 0;
  13535. set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
  13536. PLS_OFFLINE);
  13537. /*
  13538. * Step 2: Shutdown LCB and 8051
  13539. * After shutdown, do not restore DC_CFG_RESET value.
  13540. */
  13541. dc_shutdown(dd);
  13542. }