t4_hw.c 239 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/delay.h>
  35. #include "cxgb4.h"
  36. #include "t4_regs.h"
  37. #include "t4_values.h"
  38. #include "t4fw_api.h"
  39. #include "t4fw_version.h"
  40. /**
  41. * t4_wait_op_done_val - wait until an operation is completed
  42. * @adapter: the adapter performing the operation
  43. * @reg: the register to check for completion
  44. * @mask: a single-bit field within @reg that indicates completion
  45. * @polarity: the value of the field when the operation is completed
  46. * @attempts: number of check iterations
  47. * @delay: delay in usecs between iterations
  48. * @valp: where to store the value of the register at completion time
  49. *
  50. * Wait until an operation is completed by checking a bit in a register
  51. * up to @attempts times. If @valp is not NULL the value of the register
  52. * at the time it indicated completion is stored there. Returns 0 if the
  53. * operation completes and -EAGAIN otherwise.
  54. */
  55. static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
  56. int polarity, int attempts, int delay, u32 *valp)
  57. {
  58. while (1) {
  59. u32 val = t4_read_reg(adapter, reg);
  60. if (!!(val & mask) == polarity) {
  61. if (valp)
  62. *valp = val;
  63. return 0;
  64. }
  65. if (--attempts == 0)
  66. return -EAGAIN;
  67. if (delay)
  68. udelay(delay);
  69. }
  70. }
  71. static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
  72. int polarity, int attempts, int delay)
  73. {
  74. return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
  75. delay, NULL);
  76. }
  77. /**
  78. * t4_set_reg_field - set a register field to a value
  79. * @adapter: the adapter to program
  80. * @addr: the register address
  81. * @mask: specifies the portion of the register to modify
  82. * @val: the new value for the register field
  83. *
  84. * Sets a register field specified by the supplied mask to the
  85. * given value.
  86. */
  87. void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
  88. u32 val)
  89. {
  90. u32 v = t4_read_reg(adapter, addr) & ~mask;
  91. t4_write_reg(adapter, addr, v | val);
  92. (void) t4_read_reg(adapter, addr); /* flush */
  93. }
  94. /**
  95. * t4_read_indirect - read indirectly addressed registers
  96. * @adap: the adapter
  97. * @addr_reg: register holding the indirect address
  98. * @data_reg: register holding the value of the indirect register
  99. * @vals: where the read register values are stored
  100. * @nregs: how many indirect registers to read
  101. * @start_idx: index of first indirect register to read
  102. *
  103. * Reads registers that are accessed indirectly through an address/data
  104. * register pair.
  105. */
  106. void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  107. unsigned int data_reg, u32 *vals,
  108. unsigned int nregs, unsigned int start_idx)
  109. {
  110. while (nregs--) {
  111. t4_write_reg(adap, addr_reg, start_idx);
  112. *vals++ = t4_read_reg(adap, data_reg);
  113. start_idx++;
  114. }
  115. }
  116. /**
  117. * t4_write_indirect - write indirectly addressed registers
  118. * @adap: the adapter
  119. * @addr_reg: register holding the indirect addresses
  120. * @data_reg: register holding the value for the indirect registers
  121. * @vals: values to write
  122. * @nregs: how many indirect registers to write
  123. * @start_idx: address of first indirect register to write
  124. *
  125. * Writes a sequential block of registers that are accessed indirectly
  126. * through an address/data register pair.
  127. */
  128. void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  129. unsigned int data_reg, const u32 *vals,
  130. unsigned int nregs, unsigned int start_idx)
  131. {
  132. while (nregs--) {
  133. t4_write_reg(adap, addr_reg, start_idx++);
  134. t4_write_reg(adap, data_reg, *vals++);
  135. }
  136. }
  137. /*
  138. * Read a 32-bit PCI Configuration Space register via the PCI-E backdoor
  139. * mechanism. This guarantees that we get the real value even if we're
  140. * operating within a Virtual Machine and the Hypervisor is trapping our
  141. * Configuration Space accesses.
  142. */
  143. void t4_hw_pci_read_cfg4(struct adapter *adap, int reg, u32 *val)
  144. {
  145. u32 req = FUNCTION_V(adap->pf) | REGISTER_V(reg);
  146. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  147. req |= ENABLE_F;
  148. else
  149. req |= T6_ENABLE_F;
  150. if (is_t4(adap->params.chip))
  151. req |= LOCALCFG_F;
  152. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, req);
  153. *val = t4_read_reg(adap, PCIE_CFG_SPACE_DATA_A);
  154. /* Reset ENABLE to 0 so reads of PCIE_CFG_SPACE_DATA won't cause a
  155. * Configuration Space read. (None of the other fields matter when
  156. * ENABLE is 0 so a simple register write is easier than a
  157. * read-modify-write via t4_set_reg_field().)
  158. */
  159. t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, 0);
  160. }
  161. /*
  162. * t4_report_fw_error - report firmware error
  163. * @adap: the adapter
  164. *
  165. * The adapter firmware can indicate error conditions to the host.
  166. * If the firmware has indicated an error, print out the reason for
  167. * the firmware error.
  168. */
  169. static void t4_report_fw_error(struct adapter *adap)
  170. {
  171. static const char *const reason[] = {
  172. "Crash", /* PCIE_FW_EVAL_CRASH */
  173. "During Device Preparation", /* PCIE_FW_EVAL_PREP */
  174. "During Device Configuration", /* PCIE_FW_EVAL_CONF */
  175. "During Device Initialization", /* PCIE_FW_EVAL_INIT */
  176. "Unexpected Event", /* PCIE_FW_EVAL_UNEXPECTEDEVENT */
  177. "Insufficient Airflow", /* PCIE_FW_EVAL_OVERHEAT */
  178. "Device Shutdown", /* PCIE_FW_EVAL_DEVICESHUTDOWN */
  179. "Reserved", /* reserved */
  180. };
  181. u32 pcie_fw;
  182. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  183. if (pcie_fw & PCIE_FW_ERR_F)
  184. dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
  185. reason[PCIE_FW_EVAL_G(pcie_fw)]);
  186. }
  187. /*
  188. * Get the reply to a mailbox command and store it in @rpl in big-endian order.
  189. */
  190. static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
  191. u32 mbox_addr)
  192. {
  193. for ( ; nflit; nflit--, mbox_addr += 8)
  194. *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
  195. }
  196. /*
  197. * Handle a FW assertion reported in a mailbox.
  198. */
  199. static void fw_asrt(struct adapter *adap, u32 mbox_addr)
  200. {
  201. struct fw_debug_cmd asrt;
  202. get_mbox_rpl(adap, (__be64 *)&asrt, sizeof(asrt) / 8, mbox_addr);
  203. dev_alert(adap->pdev_dev,
  204. "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  205. asrt.u.assert.filename_0_7, be32_to_cpu(asrt.u.assert.line),
  206. be32_to_cpu(asrt.u.assert.x), be32_to_cpu(asrt.u.assert.y));
  207. }
  208. /**
  209. * t4_record_mbox - record a Firmware Mailbox Command/Reply in the log
  210. * @adapter: the adapter
  211. * @cmd: the Firmware Mailbox Command or Reply
  212. * @size: command length in bytes
  213. * @access: the time (ms) needed to access the Firmware Mailbox
  214. * @execute: the time (ms) the command spent being executed
  215. */
  216. static void t4_record_mbox(struct adapter *adapter,
  217. const __be64 *cmd, unsigned int size,
  218. int access, int execute)
  219. {
  220. struct mbox_cmd_log *log = adapter->mbox_log;
  221. struct mbox_cmd *entry;
  222. int i;
  223. entry = mbox_cmd_log_entry(log, log->cursor++);
  224. if (log->cursor == log->size)
  225. log->cursor = 0;
  226. for (i = 0; i < size / 8; i++)
  227. entry->cmd[i] = be64_to_cpu(cmd[i]);
  228. while (i < MBOX_LEN / 8)
  229. entry->cmd[i++] = 0;
  230. entry->timestamp = jiffies;
  231. entry->seqno = log->seqno++;
  232. entry->access = access;
  233. entry->execute = execute;
  234. }
  235. /**
  236. * t4_wr_mbox_meat_timeout - send a command to FW through the given mailbox
  237. * @adap: the adapter
  238. * @mbox: index of the mailbox to use
  239. * @cmd: the command to write
  240. * @size: command length in bytes
  241. * @rpl: where to optionally store the reply
  242. * @sleep_ok: if true we may sleep while awaiting command completion
  243. * @timeout: time to wait for command to finish before timing out
  244. *
  245. * Sends the given command to FW through the selected mailbox and waits
  246. * for the FW to execute the command. If @rpl is not %NULL it is used to
  247. * store the FW's reply to the command. The command and its optional
  248. * reply are of the same length. FW can take up to %FW_CMD_MAX_TIMEOUT ms
  249. * to respond. @sleep_ok determines whether we may sleep while awaiting
  250. * the response. If sleeping is allowed we use progressive backoff
  251. * otherwise we spin.
  252. *
  253. * The return value is 0 on success or a negative errno on failure. A
  254. * failure can happen either because we are not able to execute the
  255. * command or FW executes it but signals an error. In the latter case
  256. * the return value is the error code indicated by FW (negated).
  257. */
  258. int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,
  259. int size, void *rpl, bool sleep_ok, int timeout)
  260. {
  261. static const int delay[] = {
  262. 1, 1, 3, 5, 10, 10, 20, 50, 100, 200
  263. };
  264. struct mbox_list entry;
  265. u16 access = 0;
  266. u16 execute = 0;
  267. u32 v;
  268. u64 res;
  269. int i, ms, delay_idx, ret;
  270. const __be64 *p = cmd;
  271. u32 data_reg = PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  272. u32 ctl_reg = PF_REG(mbox, CIM_PF_MAILBOX_CTRL_A);
  273. __be64 cmd_rpl[MBOX_LEN / 8];
  274. u32 pcie_fw;
  275. if ((size & 15) || size > MBOX_LEN)
  276. return -EINVAL;
  277. /*
  278. * If the device is off-line, as in EEH, commands will time out.
  279. * Fail them early so we don't waste time waiting.
  280. */
  281. if (adap->pdev->error_state != pci_channel_io_normal)
  282. return -EIO;
  283. /* If we have a negative timeout, that implies that we can't sleep. */
  284. if (timeout < 0) {
  285. sleep_ok = false;
  286. timeout = -timeout;
  287. }
  288. /* Queue ourselves onto the mailbox access list. When our entry is at
  289. * the front of the list, we have rights to access the mailbox. So we
  290. * wait [for a while] till we're at the front [or bail out with an
  291. * EBUSY] ...
  292. */
  293. spin_lock(&adap->mbox_lock);
  294. list_add_tail(&entry.list, &adap->mlist.list);
  295. spin_unlock(&adap->mbox_lock);
  296. delay_idx = 0;
  297. ms = delay[0];
  298. for (i = 0; ; i += ms) {
  299. /* If we've waited too long, return a busy indication. This
  300. * really ought to be based on our initial position in the
  301. * mailbox access list but this is a start. We very rearely
  302. * contend on access to the mailbox ...
  303. */
  304. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  305. if (i > FW_CMD_MAX_TIMEOUT || (pcie_fw & PCIE_FW_ERR_F)) {
  306. spin_lock(&adap->mbox_lock);
  307. list_del(&entry.list);
  308. spin_unlock(&adap->mbox_lock);
  309. ret = (pcie_fw & PCIE_FW_ERR_F) ? -ENXIO : -EBUSY;
  310. t4_record_mbox(adap, cmd, size, access, ret);
  311. return ret;
  312. }
  313. /* If we're at the head, break out and start the mailbox
  314. * protocol.
  315. */
  316. if (list_first_entry(&adap->mlist.list, struct mbox_list,
  317. list) == &entry)
  318. break;
  319. /* Delay for a bit before checking again ... */
  320. if (sleep_ok) {
  321. ms = delay[delay_idx]; /* last element may repeat */
  322. if (delay_idx < ARRAY_SIZE(delay) - 1)
  323. delay_idx++;
  324. msleep(ms);
  325. } else {
  326. mdelay(ms);
  327. }
  328. }
  329. /* Loop trying to get ownership of the mailbox. Return an error
  330. * if we can't gain ownership.
  331. */
  332. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  333. for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
  334. v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
  335. if (v != MBOX_OWNER_DRV) {
  336. spin_lock(&adap->mbox_lock);
  337. list_del(&entry.list);
  338. spin_unlock(&adap->mbox_lock);
  339. ret = (v == MBOX_OWNER_FW) ? -EBUSY : -ETIMEDOUT;
  340. t4_record_mbox(adap, cmd, MBOX_LEN, access, ret);
  341. return ret;
  342. }
  343. /* Copy in the new mailbox command and send it on its way ... */
  344. t4_record_mbox(adap, cmd, MBOX_LEN, access, 0);
  345. for (i = 0; i < size; i += 8)
  346. t4_write_reg64(adap, data_reg + i, be64_to_cpu(*p++));
  347. t4_write_reg(adap, ctl_reg, MBMSGVALID_F | MBOWNER_V(MBOX_OWNER_FW));
  348. t4_read_reg(adap, ctl_reg); /* flush write */
  349. delay_idx = 0;
  350. ms = delay[0];
  351. for (i = 0;
  352. !((pcie_fw = t4_read_reg(adap, PCIE_FW_A)) & PCIE_FW_ERR_F) &&
  353. i < timeout;
  354. i += ms) {
  355. if (sleep_ok) {
  356. ms = delay[delay_idx]; /* last element may repeat */
  357. if (delay_idx < ARRAY_SIZE(delay) - 1)
  358. delay_idx++;
  359. msleep(ms);
  360. } else
  361. mdelay(ms);
  362. v = t4_read_reg(adap, ctl_reg);
  363. if (MBOWNER_G(v) == MBOX_OWNER_DRV) {
  364. if (!(v & MBMSGVALID_F)) {
  365. t4_write_reg(adap, ctl_reg, 0);
  366. continue;
  367. }
  368. get_mbox_rpl(adap, cmd_rpl, MBOX_LEN / 8, data_reg);
  369. res = be64_to_cpu(cmd_rpl[0]);
  370. if (FW_CMD_OP_G(res >> 32) == FW_DEBUG_CMD) {
  371. fw_asrt(adap, data_reg);
  372. res = FW_CMD_RETVAL_V(EIO);
  373. } else if (rpl) {
  374. memcpy(rpl, cmd_rpl, size);
  375. }
  376. t4_write_reg(adap, ctl_reg, 0);
  377. execute = i + ms;
  378. t4_record_mbox(adap, cmd_rpl,
  379. MBOX_LEN, access, execute);
  380. spin_lock(&adap->mbox_lock);
  381. list_del(&entry.list);
  382. spin_unlock(&adap->mbox_lock);
  383. return -FW_CMD_RETVAL_G((int)res);
  384. }
  385. }
  386. ret = (pcie_fw & PCIE_FW_ERR_F) ? -ENXIO : -ETIMEDOUT;
  387. t4_record_mbox(adap, cmd, MBOX_LEN, access, ret);
  388. dev_err(adap->pdev_dev, "command %#x in mailbox %d timed out\n",
  389. *(const u8 *)cmd, mbox);
  390. t4_report_fw_error(adap);
  391. spin_lock(&adap->mbox_lock);
  392. list_del(&entry.list);
  393. spin_unlock(&adap->mbox_lock);
  394. t4_fatal_err(adap);
  395. return ret;
  396. }
  397. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  398. void *rpl, bool sleep_ok)
  399. {
  400. return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl, sleep_ok,
  401. FW_CMD_MAX_TIMEOUT);
  402. }
  403. static int t4_edc_err_read(struct adapter *adap, int idx)
  404. {
  405. u32 edc_ecc_err_addr_reg;
  406. u32 rdata_reg;
  407. if (is_t4(adap->params.chip)) {
  408. CH_WARN(adap, "%s: T4 NOT supported.\n", __func__);
  409. return 0;
  410. }
  411. if (idx != 0 && idx != 1) {
  412. CH_WARN(adap, "%s: idx %d NOT supported.\n", __func__, idx);
  413. return 0;
  414. }
  415. edc_ecc_err_addr_reg = EDC_T5_REG(EDC_H_ECC_ERR_ADDR_A, idx);
  416. rdata_reg = EDC_T5_REG(EDC_H_BIST_STATUS_RDATA_A, idx);
  417. CH_WARN(adap,
  418. "edc%d err addr 0x%x: 0x%x.\n",
  419. idx, edc_ecc_err_addr_reg,
  420. t4_read_reg(adap, edc_ecc_err_addr_reg));
  421. CH_WARN(adap,
  422. "bist: 0x%x, status %llx %llx %llx %llx %llx %llx %llx %llx %llx.\n",
  423. rdata_reg,
  424. (unsigned long long)t4_read_reg64(adap, rdata_reg),
  425. (unsigned long long)t4_read_reg64(adap, rdata_reg + 8),
  426. (unsigned long long)t4_read_reg64(adap, rdata_reg + 16),
  427. (unsigned long long)t4_read_reg64(adap, rdata_reg + 24),
  428. (unsigned long long)t4_read_reg64(adap, rdata_reg + 32),
  429. (unsigned long long)t4_read_reg64(adap, rdata_reg + 40),
  430. (unsigned long long)t4_read_reg64(adap, rdata_reg + 48),
  431. (unsigned long long)t4_read_reg64(adap, rdata_reg + 56),
  432. (unsigned long long)t4_read_reg64(adap, rdata_reg + 64));
  433. return 0;
  434. }
  435. /**
  436. * t4_memory_rw - read/write EDC 0, EDC 1 or MC via PCIE memory window
  437. * @adap: the adapter
  438. * @win: PCI-E Memory Window to use
  439. * @mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
  440. * @addr: address within indicated memory type
  441. * @len: amount of memory to transfer
  442. * @hbuf: host memory buffer
  443. * @dir: direction of transfer T4_MEMORY_READ (1) or T4_MEMORY_WRITE (0)
  444. *
  445. * Reads/writes an [almost] arbitrary memory region in the firmware: the
  446. * firmware memory address and host buffer must be aligned on 32-bit
  447. * boudaries; the length may be arbitrary. The memory is transferred as
  448. * a raw byte sequence from/to the firmware's memory. If this memory
  449. * contains data structures which contain multi-byte integers, it's the
  450. * caller's responsibility to perform appropriate byte order conversions.
  451. */
  452. int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr,
  453. u32 len, void *hbuf, int dir)
  454. {
  455. u32 pos, offset, resid, memoffset;
  456. u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
  457. u32 *buf;
  458. /* Argument sanity checks ...
  459. */
  460. if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
  461. return -EINVAL;
  462. buf = (u32 *)hbuf;
  463. /* It's convenient to be able to handle lengths which aren't a
  464. * multiple of 32-bits because we often end up transferring files to
  465. * the firmware. So we'll handle that by normalizing the length here
  466. * and then handling any residual transfer at the end.
  467. */
  468. resid = len & 0x3;
  469. len -= resid;
  470. /* Offset into the region of memory which is being accessed
  471. * MEM_EDC0 = 0
  472. * MEM_EDC1 = 1
  473. * MEM_MC = 2 -- MEM_MC for chips with only 1 memory controller
  474. * MEM_MC1 = 3 -- for chips with 2 memory controllers (e.g. T5)
  475. */
  476. edc_size = EDRAM0_SIZE_G(t4_read_reg(adap, MA_EDRAM0_BAR_A));
  477. if (mtype != MEM_MC1)
  478. memoffset = (mtype * (edc_size * 1024 * 1024));
  479. else {
  480. mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap,
  481. MA_EXT_MEMORY0_BAR_A));
  482. memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
  483. }
  484. /* Determine the PCIE_MEM_ACCESS_OFFSET */
  485. addr = addr + memoffset;
  486. /* Each PCI-E Memory Window is programmed with a window size -- or
  487. * "aperture" -- which controls the granularity of its mapping onto
  488. * adapter memory. We need to grab that aperture in order to know
  489. * how to use the specified window. The window is also programmed
  490. * with the base address of the Memory Window in BAR0's address
  491. * space. For T4 this is an absolute PCI-E Bus Address. For T5
  492. * the address is relative to BAR0.
  493. */
  494. mem_reg = t4_read_reg(adap,
  495. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A,
  496. win));
  497. mem_aperture = 1 << (WINDOW_G(mem_reg) + WINDOW_SHIFT_X);
  498. mem_base = PCIEOFST_G(mem_reg) << PCIEOFST_SHIFT_X;
  499. if (is_t4(adap->params.chip))
  500. mem_base -= adap->t4_bar0;
  501. win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
  502. /* Calculate our initial PCI-E Memory Window Position and Offset into
  503. * that Window.
  504. */
  505. pos = addr & ~(mem_aperture-1);
  506. offset = addr - pos;
  507. /* Set up initial PCI-E Memory Window to cover the start of our
  508. * transfer. (Read it back to ensure that changes propagate before we
  509. * attempt to use the new value.)
  510. */
  511. t4_write_reg(adap,
  512. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win),
  513. pos | win_pf);
  514. t4_read_reg(adap,
  515. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
  516. /* Transfer data to/from the adapter as long as there's an integral
  517. * number of 32-bit transfers to complete.
  518. *
  519. * A note on Endianness issues:
  520. *
  521. * The "register" reads and writes below from/to the PCI-E Memory
  522. * Window invoke the standard adapter Big-Endian to PCI-E Link
  523. * Little-Endian "swizzel." As a result, if we have the following
  524. * data in adapter memory:
  525. *
  526. * Memory: ... | b0 | b1 | b2 | b3 | ...
  527. * Address: i+0 i+1 i+2 i+3
  528. *
  529. * Then a read of the adapter memory via the PCI-E Memory Window
  530. * will yield:
  531. *
  532. * x = readl(i)
  533. * 31 0
  534. * [ b3 | b2 | b1 | b0 ]
  535. *
  536. * If this value is stored into local memory on a Little-Endian system
  537. * it will show up correctly in local memory as:
  538. *
  539. * ( ..., b0, b1, b2, b3, ... )
  540. *
  541. * But on a Big-Endian system, the store will show up in memory
  542. * incorrectly swizzled as:
  543. *
  544. * ( ..., b3, b2, b1, b0, ... )
  545. *
  546. * So we need to account for this in the reads and writes to the
  547. * PCI-E Memory Window below by undoing the register read/write
  548. * swizzels.
  549. */
  550. while (len > 0) {
  551. if (dir == T4_MEMORY_READ)
  552. *buf++ = le32_to_cpu((__force __le32)t4_read_reg(adap,
  553. mem_base + offset));
  554. else
  555. t4_write_reg(adap, mem_base + offset,
  556. (__force u32)cpu_to_le32(*buf++));
  557. offset += sizeof(__be32);
  558. len -= sizeof(__be32);
  559. /* If we've reached the end of our current window aperture,
  560. * move the PCI-E Memory Window on to the next. Note that
  561. * doing this here after "len" may be 0 allows us to set up
  562. * the PCI-E Memory Window for a possible final residual
  563. * transfer below ...
  564. */
  565. if (offset == mem_aperture) {
  566. pos += mem_aperture;
  567. offset = 0;
  568. t4_write_reg(adap,
  569. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  570. win), pos | win_pf);
  571. t4_read_reg(adap,
  572. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
  573. win));
  574. }
  575. }
  576. /* If the original transfer had a length which wasn't a multiple of
  577. * 32-bits, now's where we need to finish off the transfer of the
  578. * residual amount. The PCI-E Memory Window has already been moved
  579. * above (if necessary) to cover this final transfer.
  580. */
  581. if (resid) {
  582. union {
  583. u32 word;
  584. char byte[4];
  585. } last;
  586. unsigned char *bp;
  587. int i;
  588. if (dir == T4_MEMORY_READ) {
  589. last.word = le32_to_cpu(
  590. (__force __le32)t4_read_reg(adap,
  591. mem_base + offset));
  592. for (bp = (unsigned char *)buf, i = resid; i < 4; i++)
  593. bp[i] = last.byte[i];
  594. } else {
  595. last.word = *buf;
  596. for (i = resid; i < 4; i++)
  597. last.byte[i] = 0;
  598. t4_write_reg(adap, mem_base + offset,
  599. (__force u32)cpu_to_le32(last.word));
  600. }
  601. }
  602. return 0;
  603. }
  604. /* Return the specified PCI-E Configuration Space register from our Physical
  605. * Function. We try first via a Firmware LDST Command since we prefer to let
  606. * the firmware own all of these registers, but if that fails we go for it
  607. * directly ourselves.
  608. */
  609. u32 t4_read_pcie_cfg4(struct adapter *adap, int reg)
  610. {
  611. u32 val, ldst_addrspace;
  612. /* If fw_attach != 0, construct and send the Firmware LDST Command to
  613. * retrieve the specified PCI-E Configuration Space register.
  614. */
  615. struct fw_ldst_cmd ldst_cmd;
  616. int ret;
  617. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  618. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FUNC_PCIE);
  619. ldst_cmd.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  620. FW_CMD_REQUEST_F |
  621. FW_CMD_READ_F |
  622. ldst_addrspace);
  623. ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
  624. ldst_cmd.u.pcie.select_naccess = FW_LDST_CMD_NACCESS_V(1);
  625. ldst_cmd.u.pcie.ctrl_to_fn =
  626. (FW_LDST_CMD_LC_F | FW_LDST_CMD_FN_V(adap->pf));
  627. ldst_cmd.u.pcie.r = reg;
  628. /* If the LDST Command succeeds, return the result, otherwise
  629. * fall through to reading it directly ourselves ...
  630. */
  631. ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, sizeof(ldst_cmd),
  632. &ldst_cmd);
  633. if (ret == 0)
  634. val = be32_to_cpu(ldst_cmd.u.pcie.data[0]);
  635. else
  636. /* Read the desired Configuration Space register via the PCI-E
  637. * Backdoor mechanism.
  638. */
  639. t4_hw_pci_read_cfg4(adap, reg, &val);
  640. return val;
  641. }
  642. /* Get the window based on base passed to it.
  643. * Window aperture is currently unhandled, but there is no use case for it
  644. * right now
  645. */
  646. static u32 t4_get_window(struct adapter *adap, u32 pci_base, u64 pci_mask,
  647. u32 memwin_base)
  648. {
  649. u32 ret;
  650. if (is_t4(adap->params.chip)) {
  651. u32 bar0;
  652. /* Truncation intentional: we only read the bottom 32-bits of
  653. * the 64-bit BAR0/BAR1 ... We use the hardware backdoor
  654. * mechanism to read BAR0 instead of using
  655. * pci_resource_start() because we could be operating from
  656. * within a Virtual Machine which is trapping our accesses to
  657. * our Configuration Space and we need to set up the PCI-E
  658. * Memory Window decoders with the actual addresses which will
  659. * be coming across the PCI-E link.
  660. */
  661. bar0 = t4_read_pcie_cfg4(adap, pci_base);
  662. bar0 &= pci_mask;
  663. adap->t4_bar0 = bar0;
  664. ret = bar0 + memwin_base;
  665. } else {
  666. /* For T5, only relative offset inside the PCIe BAR is passed */
  667. ret = memwin_base;
  668. }
  669. return ret;
  670. }
  671. /* Get the default utility window (win0) used by everyone */
  672. u32 t4_get_util_window(struct adapter *adap)
  673. {
  674. return t4_get_window(adap, PCI_BASE_ADDRESS_0,
  675. PCI_BASE_ADDRESS_MEM_MASK, MEMWIN0_BASE);
  676. }
  677. /* Set up memory window for accessing adapter memory ranges. (Read
  678. * back MA register to ensure that changes propagate before we attempt
  679. * to use the new values.)
  680. */
  681. void t4_setup_memwin(struct adapter *adap, u32 memwin_base, u32 window)
  682. {
  683. t4_write_reg(adap,
  684. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window),
  685. memwin_base | BIR_V(0) |
  686. WINDOW_V(ilog2(MEMWIN0_APERTURE) - WINDOW_SHIFT_X));
  687. t4_read_reg(adap,
  688. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window));
  689. }
  690. /**
  691. * t4_get_regs_len - return the size of the chips register set
  692. * @adapter: the adapter
  693. *
  694. * Returns the size of the chip's BAR0 register space.
  695. */
  696. unsigned int t4_get_regs_len(struct adapter *adapter)
  697. {
  698. unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
  699. switch (chip_version) {
  700. case CHELSIO_T4:
  701. return T4_REGMAP_SIZE;
  702. case CHELSIO_T5:
  703. case CHELSIO_T6:
  704. return T5_REGMAP_SIZE;
  705. }
  706. dev_err(adapter->pdev_dev,
  707. "Unsupported chip version %d\n", chip_version);
  708. return 0;
  709. }
  710. /**
  711. * t4_get_regs - read chip registers into provided buffer
  712. * @adap: the adapter
  713. * @buf: register buffer
  714. * @buf_size: size (in bytes) of register buffer
  715. *
  716. * If the provided register buffer isn't large enough for the chip's
  717. * full register range, the register dump will be truncated to the
  718. * register buffer's size.
  719. */
  720. void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)
  721. {
  722. static const unsigned int t4_reg_ranges[] = {
  723. 0x1008, 0x1108,
  724. 0x1180, 0x1184,
  725. 0x1190, 0x1194,
  726. 0x11a0, 0x11a4,
  727. 0x11b0, 0x11b4,
  728. 0x11fc, 0x123c,
  729. 0x1300, 0x173c,
  730. 0x1800, 0x18fc,
  731. 0x3000, 0x30d8,
  732. 0x30e0, 0x30e4,
  733. 0x30ec, 0x5910,
  734. 0x5920, 0x5924,
  735. 0x5960, 0x5960,
  736. 0x5968, 0x5968,
  737. 0x5970, 0x5970,
  738. 0x5978, 0x5978,
  739. 0x5980, 0x5980,
  740. 0x5988, 0x5988,
  741. 0x5990, 0x5990,
  742. 0x5998, 0x5998,
  743. 0x59a0, 0x59d4,
  744. 0x5a00, 0x5ae0,
  745. 0x5ae8, 0x5ae8,
  746. 0x5af0, 0x5af0,
  747. 0x5af8, 0x5af8,
  748. 0x6000, 0x6098,
  749. 0x6100, 0x6150,
  750. 0x6200, 0x6208,
  751. 0x6240, 0x6248,
  752. 0x6280, 0x62b0,
  753. 0x62c0, 0x6338,
  754. 0x6370, 0x638c,
  755. 0x6400, 0x643c,
  756. 0x6500, 0x6524,
  757. 0x6a00, 0x6a04,
  758. 0x6a14, 0x6a38,
  759. 0x6a60, 0x6a70,
  760. 0x6a78, 0x6a78,
  761. 0x6b00, 0x6b0c,
  762. 0x6b1c, 0x6b84,
  763. 0x6bf0, 0x6bf8,
  764. 0x6c00, 0x6c0c,
  765. 0x6c1c, 0x6c84,
  766. 0x6cf0, 0x6cf8,
  767. 0x6d00, 0x6d0c,
  768. 0x6d1c, 0x6d84,
  769. 0x6df0, 0x6df8,
  770. 0x6e00, 0x6e0c,
  771. 0x6e1c, 0x6e84,
  772. 0x6ef0, 0x6ef8,
  773. 0x6f00, 0x6f0c,
  774. 0x6f1c, 0x6f84,
  775. 0x6ff0, 0x6ff8,
  776. 0x7000, 0x700c,
  777. 0x701c, 0x7084,
  778. 0x70f0, 0x70f8,
  779. 0x7100, 0x710c,
  780. 0x711c, 0x7184,
  781. 0x71f0, 0x71f8,
  782. 0x7200, 0x720c,
  783. 0x721c, 0x7284,
  784. 0x72f0, 0x72f8,
  785. 0x7300, 0x730c,
  786. 0x731c, 0x7384,
  787. 0x73f0, 0x73f8,
  788. 0x7400, 0x7450,
  789. 0x7500, 0x7530,
  790. 0x7600, 0x760c,
  791. 0x7614, 0x761c,
  792. 0x7680, 0x76cc,
  793. 0x7700, 0x7798,
  794. 0x77c0, 0x77fc,
  795. 0x7900, 0x79fc,
  796. 0x7b00, 0x7b58,
  797. 0x7b60, 0x7b84,
  798. 0x7b8c, 0x7c38,
  799. 0x7d00, 0x7d38,
  800. 0x7d40, 0x7d80,
  801. 0x7d8c, 0x7ddc,
  802. 0x7de4, 0x7e04,
  803. 0x7e10, 0x7e1c,
  804. 0x7e24, 0x7e38,
  805. 0x7e40, 0x7e44,
  806. 0x7e4c, 0x7e78,
  807. 0x7e80, 0x7ea4,
  808. 0x7eac, 0x7edc,
  809. 0x7ee8, 0x7efc,
  810. 0x8dc0, 0x8e04,
  811. 0x8e10, 0x8e1c,
  812. 0x8e30, 0x8e78,
  813. 0x8ea0, 0x8eb8,
  814. 0x8ec0, 0x8f6c,
  815. 0x8fc0, 0x9008,
  816. 0x9010, 0x9058,
  817. 0x9060, 0x9060,
  818. 0x9068, 0x9074,
  819. 0x90fc, 0x90fc,
  820. 0x9400, 0x9408,
  821. 0x9410, 0x9458,
  822. 0x9600, 0x9600,
  823. 0x9608, 0x9638,
  824. 0x9640, 0x96bc,
  825. 0x9800, 0x9808,
  826. 0x9820, 0x983c,
  827. 0x9850, 0x9864,
  828. 0x9c00, 0x9c6c,
  829. 0x9c80, 0x9cec,
  830. 0x9d00, 0x9d6c,
  831. 0x9d80, 0x9dec,
  832. 0x9e00, 0x9e6c,
  833. 0x9e80, 0x9eec,
  834. 0x9f00, 0x9f6c,
  835. 0x9f80, 0x9fec,
  836. 0xd004, 0xd004,
  837. 0xd010, 0xd03c,
  838. 0xdfc0, 0xdfe0,
  839. 0xe000, 0xea7c,
  840. 0xf000, 0x11190,
  841. 0x19040, 0x1906c,
  842. 0x19078, 0x19080,
  843. 0x1908c, 0x190e4,
  844. 0x190f0, 0x190f8,
  845. 0x19100, 0x19110,
  846. 0x19120, 0x19124,
  847. 0x19150, 0x19194,
  848. 0x1919c, 0x191b0,
  849. 0x191d0, 0x191e8,
  850. 0x19238, 0x1924c,
  851. 0x193f8, 0x1943c,
  852. 0x1944c, 0x19474,
  853. 0x19490, 0x194e0,
  854. 0x194f0, 0x194f8,
  855. 0x19800, 0x19c08,
  856. 0x19c10, 0x19c90,
  857. 0x19ca0, 0x19ce4,
  858. 0x19cf0, 0x19d40,
  859. 0x19d50, 0x19d94,
  860. 0x19da0, 0x19de8,
  861. 0x19df0, 0x19e40,
  862. 0x19e50, 0x19e90,
  863. 0x19ea0, 0x19f4c,
  864. 0x1a000, 0x1a004,
  865. 0x1a010, 0x1a06c,
  866. 0x1a0b0, 0x1a0e4,
  867. 0x1a0ec, 0x1a0f4,
  868. 0x1a100, 0x1a108,
  869. 0x1a114, 0x1a120,
  870. 0x1a128, 0x1a130,
  871. 0x1a138, 0x1a138,
  872. 0x1a190, 0x1a1c4,
  873. 0x1a1fc, 0x1a1fc,
  874. 0x1e040, 0x1e04c,
  875. 0x1e284, 0x1e28c,
  876. 0x1e2c0, 0x1e2c0,
  877. 0x1e2e0, 0x1e2e0,
  878. 0x1e300, 0x1e384,
  879. 0x1e3c0, 0x1e3c8,
  880. 0x1e440, 0x1e44c,
  881. 0x1e684, 0x1e68c,
  882. 0x1e6c0, 0x1e6c0,
  883. 0x1e6e0, 0x1e6e0,
  884. 0x1e700, 0x1e784,
  885. 0x1e7c0, 0x1e7c8,
  886. 0x1e840, 0x1e84c,
  887. 0x1ea84, 0x1ea8c,
  888. 0x1eac0, 0x1eac0,
  889. 0x1eae0, 0x1eae0,
  890. 0x1eb00, 0x1eb84,
  891. 0x1ebc0, 0x1ebc8,
  892. 0x1ec40, 0x1ec4c,
  893. 0x1ee84, 0x1ee8c,
  894. 0x1eec0, 0x1eec0,
  895. 0x1eee0, 0x1eee0,
  896. 0x1ef00, 0x1ef84,
  897. 0x1efc0, 0x1efc8,
  898. 0x1f040, 0x1f04c,
  899. 0x1f284, 0x1f28c,
  900. 0x1f2c0, 0x1f2c0,
  901. 0x1f2e0, 0x1f2e0,
  902. 0x1f300, 0x1f384,
  903. 0x1f3c0, 0x1f3c8,
  904. 0x1f440, 0x1f44c,
  905. 0x1f684, 0x1f68c,
  906. 0x1f6c0, 0x1f6c0,
  907. 0x1f6e0, 0x1f6e0,
  908. 0x1f700, 0x1f784,
  909. 0x1f7c0, 0x1f7c8,
  910. 0x1f840, 0x1f84c,
  911. 0x1fa84, 0x1fa8c,
  912. 0x1fac0, 0x1fac0,
  913. 0x1fae0, 0x1fae0,
  914. 0x1fb00, 0x1fb84,
  915. 0x1fbc0, 0x1fbc8,
  916. 0x1fc40, 0x1fc4c,
  917. 0x1fe84, 0x1fe8c,
  918. 0x1fec0, 0x1fec0,
  919. 0x1fee0, 0x1fee0,
  920. 0x1ff00, 0x1ff84,
  921. 0x1ffc0, 0x1ffc8,
  922. 0x20000, 0x2002c,
  923. 0x20100, 0x2013c,
  924. 0x20190, 0x201a0,
  925. 0x201a8, 0x201b8,
  926. 0x201c4, 0x201c8,
  927. 0x20200, 0x20318,
  928. 0x20400, 0x204b4,
  929. 0x204c0, 0x20528,
  930. 0x20540, 0x20614,
  931. 0x21000, 0x21040,
  932. 0x2104c, 0x21060,
  933. 0x210c0, 0x210ec,
  934. 0x21200, 0x21268,
  935. 0x21270, 0x21284,
  936. 0x212fc, 0x21388,
  937. 0x21400, 0x21404,
  938. 0x21500, 0x21500,
  939. 0x21510, 0x21518,
  940. 0x2152c, 0x21530,
  941. 0x2153c, 0x2153c,
  942. 0x21550, 0x21554,
  943. 0x21600, 0x21600,
  944. 0x21608, 0x2161c,
  945. 0x21624, 0x21628,
  946. 0x21630, 0x21634,
  947. 0x2163c, 0x2163c,
  948. 0x21700, 0x2171c,
  949. 0x21780, 0x2178c,
  950. 0x21800, 0x21818,
  951. 0x21820, 0x21828,
  952. 0x21830, 0x21848,
  953. 0x21850, 0x21854,
  954. 0x21860, 0x21868,
  955. 0x21870, 0x21870,
  956. 0x21878, 0x21898,
  957. 0x218a0, 0x218a8,
  958. 0x218b0, 0x218c8,
  959. 0x218d0, 0x218d4,
  960. 0x218e0, 0x218e8,
  961. 0x218f0, 0x218f0,
  962. 0x218f8, 0x21a18,
  963. 0x21a20, 0x21a28,
  964. 0x21a30, 0x21a48,
  965. 0x21a50, 0x21a54,
  966. 0x21a60, 0x21a68,
  967. 0x21a70, 0x21a70,
  968. 0x21a78, 0x21a98,
  969. 0x21aa0, 0x21aa8,
  970. 0x21ab0, 0x21ac8,
  971. 0x21ad0, 0x21ad4,
  972. 0x21ae0, 0x21ae8,
  973. 0x21af0, 0x21af0,
  974. 0x21af8, 0x21c18,
  975. 0x21c20, 0x21c20,
  976. 0x21c28, 0x21c30,
  977. 0x21c38, 0x21c38,
  978. 0x21c80, 0x21c98,
  979. 0x21ca0, 0x21ca8,
  980. 0x21cb0, 0x21cc8,
  981. 0x21cd0, 0x21cd4,
  982. 0x21ce0, 0x21ce8,
  983. 0x21cf0, 0x21cf0,
  984. 0x21cf8, 0x21d7c,
  985. 0x21e00, 0x21e04,
  986. 0x22000, 0x2202c,
  987. 0x22100, 0x2213c,
  988. 0x22190, 0x221a0,
  989. 0x221a8, 0x221b8,
  990. 0x221c4, 0x221c8,
  991. 0x22200, 0x22318,
  992. 0x22400, 0x224b4,
  993. 0x224c0, 0x22528,
  994. 0x22540, 0x22614,
  995. 0x23000, 0x23040,
  996. 0x2304c, 0x23060,
  997. 0x230c0, 0x230ec,
  998. 0x23200, 0x23268,
  999. 0x23270, 0x23284,
  1000. 0x232fc, 0x23388,
  1001. 0x23400, 0x23404,
  1002. 0x23500, 0x23500,
  1003. 0x23510, 0x23518,
  1004. 0x2352c, 0x23530,
  1005. 0x2353c, 0x2353c,
  1006. 0x23550, 0x23554,
  1007. 0x23600, 0x23600,
  1008. 0x23608, 0x2361c,
  1009. 0x23624, 0x23628,
  1010. 0x23630, 0x23634,
  1011. 0x2363c, 0x2363c,
  1012. 0x23700, 0x2371c,
  1013. 0x23780, 0x2378c,
  1014. 0x23800, 0x23818,
  1015. 0x23820, 0x23828,
  1016. 0x23830, 0x23848,
  1017. 0x23850, 0x23854,
  1018. 0x23860, 0x23868,
  1019. 0x23870, 0x23870,
  1020. 0x23878, 0x23898,
  1021. 0x238a0, 0x238a8,
  1022. 0x238b0, 0x238c8,
  1023. 0x238d0, 0x238d4,
  1024. 0x238e0, 0x238e8,
  1025. 0x238f0, 0x238f0,
  1026. 0x238f8, 0x23a18,
  1027. 0x23a20, 0x23a28,
  1028. 0x23a30, 0x23a48,
  1029. 0x23a50, 0x23a54,
  1030. 0x23a60, 0x23a68,
  1031. 0x23a70, 0x23a70,
  1032. 0x23a78, 0x23a98,
  1033. 0x23aa0, 0x23aa8,
  1034. 0x23ab0, 0x23ac8,
  1035. 0x23ad0, 0x23ad4,
  1036. 0x23ae0, 0x23ae8,
  1037. 0x23af0, 0x23af0,
  1038. 0x23af8, 0x23c18,
  1039. 0x23c20, 0x23c20,
  1040. 0x23c28, 0x23c30,
  1041. 0x23c38, 0x23c38,
  1042. 0x23c80, 0x23c98,
  1043. 0x23ca0, 0x23ca8,
  1044. 0x23cb0, 0x23cc8,
  1045. 0x23cd0, 0x23cd4,
  1046. 0x23ce0, 0x23ce8,
  1047. 0x23cf0, 0x23cf0,
  1048. 0x23cf8, 0x23d7c,
  1049. 0x23e00, 0x23e04,
  1050. 0x24000, 0x2402c,
  1051. 0x24100, 0x2413c,
  1052. 0x24190, 0x241a0,
  1053. 0x241a8, 0x241b8,
  1054. 0x241c4, 0x241c8,
  1055. 0x24200, 0x24318,
  1056. 0x24400, 0x244b4,
  1057. 0x244c0, 0x24528,
  1058. 0x24540, 0x24614,
  1059. 0x25000, 0x25040,
  1060. 0x2504c, 0x25060,
  1061. 0x250c0, 0x250ec,
  1062. 0x25200, 0x25268,
  1063. 0x25270, 0x25284,
  1064. 0x252fc, 0x25388,
  1065. 0x25400, 0x25404,
  1066. 0x25500, 0x25500,
  1067. 0x25510, 0x25518,
  1068. 0x2552c, 0x25530,
  1069. 0x2553c, 0x2553c,
  1070. 0x25550, 0x25554,
  1071. 0x25600, 0x25600,
  1072. 0x25608, 0x2561c,
  1073. 0x25624, 0x25628,
  1074. 0x25630, 0x25634,
  1075. 0x2563c, 0x2563c,
  1076. 0x25700, 0x2571c,
  1077. 0x25780, 0x2578c,
  1078. 0x25800, 0x25818,
  1079. 0x25820, 0x25828,
  1080. 0x25830, 0x25848,
  1081. 0x25850, 0x25854,
  1082. 0x25860, 0x25868,
  1083. 0x25870, 0x25870,
  1084. 0x25878, 0x25898,
  1085. 0x258a0, 0x258a8,
  1086. 0x258b0, 0x258c8,
  1087. 0x258d0, 0x258d4,
  1088. 0x258e0, 0x258e8,
  1089. 0x258f0, 0x258f0,
  1090. 0x258f8, 0x25a18,
  1091. 0x25a20, 0x25a28,
  1092. 0x25a30, 0x25a48,
  1093. 0x25a50, 0x25a54,
  1094. 0x25a60, 0x25a68,
  1095. 0x25a70, 0x25a70,
  1096. 0x25a78, 0x25a98,
  1097. 0x25aa0, 0x25aa8,
  1098. 0x25ab0, 0x25ac8,
  1099. 0x25ad0, 0x25ad4,
  1100. 0x25ae0, 0x25ae8,
  1101. 0x25af0, 0x25af0,
  1102. 0x25af8, 0x25c18,
  1103. 0x25c20, 0x25c20,
  1104. 0x25c28, 0x25c30,
  1105. 0x25c38, 0x25c38,
  1106. 0x25c80, 0x25c98,
  1107. 0x25ca0, 0x25ca8,
  1108. 0x25cb0, 0x25cc8,
  1109. 0x25cd0, 0x25cd4,
  1110. 0x25ce0, 0x25ce8,
  1111. 0x25cf0, 0x25cf0,
  1112. 0x25cf8, 0x25d7c,
  1113. 0x25e00, 0x25e04,
  1114. 0x26000, 0x2602c,
  1115. 0x26100, 0x2613c,
  1116. 0x26190, 0x261a0,
  1117. 0x261a8, 0x261b8,
  1118. 0x261c4, 0x261c8,
  1119. 0x26200, 0x26318,
  1120. 0x26400, 0x264b4,
  1121. 0x264c0, 0x26528,
  1122. 0x26540, 0x26614,
  1123. 0x27000, 0x27040,
  1124. 0x2704c, 0x27060,
  1125. 0x270c0, 0x270ec,
  1126. 0x27200, 0x27268,
  1127. 0x27270, 0x27284,
  1128. 0x272fc, 0x27388,
  1129. 0x27400, 0x27404,
  1130. 0x27500, 0x27500,
  1131. 0x27510, 0x27518,
  1132. 0x2752c, 0x27530,
  1133. 0x2753c, 0x2753c,
  1134. 0x27550, 0x27554,
  1135. 0x27600, 0x27600,
  1136. 0x27608, 0x2761c,
  1137. 0x27624, 0x27628,
  1138. 0x27630, 0x27634,
  1139. 0x2763c, 0x2763c,
  1140. 0x27700, 0x2771c,
  1141. 0x27780, 0x2778c,
  1142. 0x27800, 0x27818,
  1143. 0x27820, 0x27828,
  1144. 0x27830, 0x27848,
  1145. 0x27850, 0x27854,
  1146. 0x27860, 0x27868,
  1147. 0x27870, 0x27870,
  1148. 0x27878, 0x27898,
  1149. 0x278a0, 0x278a8,
  1150. 0x278b0, 0x278c8,
  1151. 0x278d0, 0x278d4,
  1152. 0x278e0, 0x278e8,
  1153. 0x278f0, 0x278f0,
  1154. 0x278f8, 0x27a18,
  1155. 0x27a20, 0x27a28,
  1156. 0x27a30, 0x27a48,
  1157. 0x27a50, 0x27a54,
  1158. 0x27a60, 0x27a68,
  1159. 0x27a70, 0x27a70,
  1160. 0x27a78, 0x27a98,
  1161. 0x27aa0, 0x27aa8,
  1162. 0x27ab0, 0x27ac8,
  1163. 0x27ad0, 0x27ad4,
  1164. 0x27ae0, 0x27ae8,
  1165. 0x27af0, 0x27af0,
  1166. 0x27af8, 0x27c18,
  1167. 0x27c20, 0x27c20,
  1168. 0x27c28, 0x27c30,
  1169. 0x27c38, 0x27c38,
  1170. 0x27c80, 0x27c98,
  1171. 0x27ca0, 0x27ca8,
  1172. 0x27cb0, 0x27cc8,
  1173. 0x27cd0, 0x27cd4,
  1174. 0x27ce0, 0x27ce8,
  1175. 0x27cf0, 0x27cf0,
  1176. 0x27cf8, 0x27d7c,
  1177. 0x27e00, 0x27e04,
  1178. };
  1179. static const unsigned int t5_reg_ranges[] = {
  1180. 0x1008, 0x10c0,
  1181. 0x10cc, 0x10f8,
  1182. 0x1100, 0x1100,
  1183. 0x110c, 0x1148,
  1184. 0x1180, 0x1184,
  1185. 0x1190, 0x1194,
  1186. 0x11a0, 0x11a4,
  1187. 0x11b0, 0x11b4,
  1188. 0x11fc, 0x123c,
  1189. 0x1280, 0x173c,
  1190. 0x1800, 0x18fc,
  1191. 0x3000, 0x3028,
  1192. 0x3060, 0x30b0,
  1193. 0x30b8, 0x30d8,
  1194. 0x30e0, 0x30fc,
  1195. 0x3140, 0x357c,
  1196. 0x35a8, 0x35cc,
  1197. 0x35ec, 0x35ec,
  1198. 0x3600, 0x5624,
  1199. 0x56cc, 0x56ec,
  1200. 0x56f4, 0x5720,
  1201. 0x5728, 0x575c,
  1202. 0x580c, 0x5814,
  1203. 0x5890, 0x589c,
  1204. 0x58a4, 0x58ac,
  1205. 0x58b8, 0x58bc,
  1206. 0x5940, 0x59c8,
  1207. 0x59d0, 0x59dc,
  1208. 0x59fc, 0x5a18,
  1209. 0x5a60, 0x5a70,
  1210. 0x5a80, 0x5a9c,
  1211. 0x5b94, 0x5bfc,
  1212. 0x6000, 0x6020,
  1213. 0x6028, 0x6040,
  1214. 0x6058, 0x609c,
  1215. 0x60a8, 0x614c,
  1216. 0x7700, 0x7798,
  1217. 0x77c0, 0x78fc,
  1218. 0x7b00, 0x7b58,
  1219. 0x7b60, 0x7b84,
  1220. 0x7b8c, 0x7c54,
  1221. 0x7d00, 0x7d38,
  1222. 0x7d40, 0x7d80,
  1223. 0x7d8c, 0x7ddc,
  1224. 0x7de4, 0x7e04,
  1225. 0x7e10, 0x7e1c,
  1226. 0x7e24, 0x7e38,
  1227. 0x7e40, 0x7e44,
  1228. 0x7e4c, 0x7e78,
  1229. 0x7e80, 0x7edc,
  1230. 0x7ee8, 0x7efc,
  1231. 0x8dc0, 0x8de0,
  1232. 0x8df8, 0x8e04,
  1233. 0x8e10, 0x8e84,
  1234. 0x8ea0, 0x8f84,
  1235. 0x8fc0, 0x9058,
  1236. 0x9060, 0x9060,
  1237. 0x9068, 0x90f8,
  1238. 0x9400, 0x9408,
  1239. 0x9410, 0x9470,
  1240. 0x9600, 0x9600,
  1241. 0x9608, 0x9638,
  1242. 0x9640, 0x96f4,
  1243. 0x9800, 0x9808,
  1244. 0x9820, 0x983c,
  1245. 0x9850, 0x9864,
  1246. 0x9c00, 0x9c6c,
  1247. 0x9c80, 0x9cec,
  1248. 0x9d00, 0x9d6c,
  1249. 0x9d80, 0x9dec,
  1250. 0x9e00, 0x9e6c,
  1251. 0x9e80, 0x9eec,
  1252. 0x9f00, 0x9f6c,
  1253. 0x9f80, 0xa020,
  1254. 0xd004, 0xd004,
  1255. 0xd010, 0xd03c,
  1256. 0xdfc0, 0xdfe0,
  1257. 0xe000, 0x1106c,
  1258. 0x11074, 0x11088,
  1259. 0x1109c, 0x1117c,
  1260. 0x11190, 0x11204,
  1261. 0x19040, 0x1906c,
  1262. 0x19078, 0x19080,
  1263. 0x1908c, 0x190e8,
  1264. 0x190f0, 0x190f8,
  1265. 0x19100, 0x19110,
  1266. 0x19120, 0x19124,
  1267. 0x19150, 0x19194,
  1268. 0x1919c, 0x191b0,
  1269. 0x191d0, 0x191e8,
  1270. 0x19238, 0x19290,
  1271. 0x193f8, 0x19428,
  1272. 0x19430, 0x19444,
  1273. 0x1944c, 0x1946c,
  1274. 0x19474, 0x19474,
  1275. 0x19490, 0x194cc,
  1276. 0x194f0, 0x194f8,
  1277. 0x19c00, 0x19c08,
  1278. 0x19c10, 0x19c60,
  1279. 0x19c94, 0x19ce4,
  1280. 0x19cf0, 0x19d40,
  1281. 0x19d50, 0x19d94,
  1282. 0x19da0, 0x19de8,
  1283. 0x19df0, 0x19e10,
  1284. 0x19e50, 0x19e90,
  1285. 0x19ea0, 0x19f24,
  1286. 0x19f34, 0x19f34,
  1287. 0x19f40, 0x19f50,
  1288. 0x19f90, 0x19fb4,
  1289. 0x19fc4, 0x19fe4,
  1290. 0x1a000, 0x1a004,
  1291. 0x1a010, 0x1a06c,
  1292. 0x1a0b0, 0x1a0e4,
  1293. 0x1a0ec, 0x1a0f8,
  1294. 0x1a100, 0x1a108,
  1295. 0x1a114, 0x1a120,
  1296. 0x1a128, 0x1a130,
  1297. 0x1a138, 0x1a138,
  1298. 0x1a190, 0x1a1c4,
  1299. 0x1a1fc, 0x1a1fc,
  1300. 0x1e008, 0x1e00c,
  1301. 0x1e040, 0x1e044,
  1302. 0x1e04c, 0x1e04c,
  1303. 0x1e284, 0x1e290,
  1304. 0x1e2c0, 0x1e2c0,
  1305. 0x1e2e0, 0x1e2e0,
  1306. 0x1e300, 0x1e384,
  1307. 0x1e3c0, 0x1e3c8,
  1308. 0x1e408, 0x1e40c,
  1309. 0x1e440, 0x1e444,
  1310. 0x1e44c, 0x1e44c,
  1311. 0x1e684, 0x1e690,
  1312. 0x1e6c0, 0x1e6c0,
  1313. 0x1e6e0, 0x1e6e0,
  1314. 0x1e700, 0x1e784,
  1315. 0x1e7c0, 0x1e7c8,
  1316. 0x1e808, 0x1e80c,
  1317. 0x1e840, 0x1e844,
  1318. 0x1e84c, 0x1e84c,
  1319. 0x1ea84, 0x1ea90,
  1320. 0x1eac0, 0x1eac0,
  1321. 0x1eae0, 0x1eae0,
  1322. 0x1eb00, 0x1eb84,
  1323. 0x1ebc0, 0x1ebc8,
  1324. 0x1ec08, 0x1ec0c,
  1325. 0x1ec40, 0x1ec44,
  1326. 0x1ec4c, 0x1ec4c,
  1327. 0x1ee84, 0x1ee90,
  1328. 0x1eec0, 0x1eec0,
  1329. 0x1eee0, 0x1eee0,
  1330. 0x1ef00, 0x1ef84,
  1331. 0x1efc0, 0x1efc8,
  1332. 0x1f008, 0x1f00c,
  1333. 0x1f040, 0x1f044,
  1334. 0x1f04c, 0x1f04c,
  1335. 0x1f284, 0x1f290,
  1336. 0x1f2c0, 0x1f2c0,
  1337. 0x1f2e0, 0x1f2e0,
  1338. 0x1f300, 0x1f384,
  1339. 0x1f3c0, 0x1f3c8,
  1340. 0x1f408, 0x1f40c,
  1341. 0x1f440, 0x1f444,
  1342. 0x1f44c, 0x1f44c,
  1343. 0x1f684, 0x1f690,
  1344. 0x1f6c0, 0x1f6c0,
  1345. 0x1f6e0, 0x1f6e0,
  1346. 0x1f700, 0x1f784,
  1347. 0x1f7c0, 0x1f7c8,
  1348. 0x1f808, 0x1f80c,
  1349. 0x1f840, 0x1f844,
  1350. 0x1f84c, 0x1f84c,
  1351. 0x1fa84, 0x1fa90,
  1352. 0x1fac0, 0x1fac0,
  1353. 0x1fae0, 0x1fae0,
  1354. 0x1fb00, 0x1fb84,
  1355. 0x1fbc0, 0x1fbc8,
  1356. 0x1fc08, 0x1fc0c,
  1357. 0x1fc40, 0x1fc44,
  1358. 0x1fc4c, 0x1fc4c,
  1359. 0x1fe84, 0x1fe90,
  1360. 0x1fec0, 0x1fec0,
  1361. 0x1fee0, 0x1fee0,
  1362. 0x1ff00, 0x1ff84,
  1363. 0x1ffc0, 0x1ffc8,
  1364. 0x30000, 0x30030,
  1365. 0x30038, 0x30038,
  1366. 0x30040, 0x30040,
  1367. 0x30100, 0x30144,
  1368. 0x30190, 0x301a0,
  1369. 0x301a8, 0x301b8,
  1370. 0x301c4, 0x301c8,
  1371. 0x301d0, 0x301d0,
  1372. 0x30200, 0x30318,
  1373. 0x30400, 0x304b4,
  1374. 0x304c0, 0x3052c,
  1375. 0x30540, 0x3061c,
  1376. 0x30800, 0x30828,
  1377. 0x30834, 0x30834,
  1378. 0x308c0, 0x30908,
  1379. 0x30910, 0x309ac,
  1380. 0x30a00, 0x30a14,
  1381. 0x30a1c, 0x30a2c,
  1382. 0x30a44, 0x30a50,
  1383. 0x30a74, 0x30a74,
  1384. 0x30a7c, 0x30afc,
  1385. 0x30b08, 0x30c24,
  1386. 0x30d00, 0x30d00,
  1387. 0x30d08, 0x30d14,
  1388. 0x30d1c, 0x30d20,
  1389. 0x30d3c, 0x30d3c,
  1390. 0x30d48, 0x30d50,
  1391. 0x31200, 0x3120c,
  1392. 0x31220, 0x31220,
  1393. 0x31240, 0x31240,
  1394. 0x31600, 0x3160c,
  1395. 0x31a00, 0x31a1c,
  1396. 0x31e00, 0x31e20,
  1397. 0x31e38, 0x31e3c,
  1398. 0x31e80, 0x31e80,
  1399. 0x31e88, 0x31ea8,
  1400. 0x31eb0, 0x31eb4,
  1401. 0x31ec8, 0x31ed4,
  1402. 0x31fb8, 0x32004,
  1403. 0x32200, 0x32200,
  1404. 0x32208, 0x32240,
  1405. 0x32248, 0x32280,
  1406. 0x32288, 0x322c0,
  1407. 0x322c8, 0x322fc,
  1408. 0x32600, 0x32630,
  1409. 0x32a00, 0x32abc,
  1410. 0x32b00, 0x32b10,
  1411. 0x32b20, 0x32b30,
  1412. 0x32b40, 0x32b50,
  1413. 0x32b60, 0x32b70,
  1414. 0x33000, 0x33028,
  1415. 0x33030, 0x33048,
  1416. 0x33060, 0x33068,
  1417. 0x33070, 0x3309c,
  1418. 0x330f0, 0x33128,
  1419. 0x33130, 0x33148,
  1420. 0x33160, 0x33168,
  1421. 0x33170, 0x3319c,
  1422. 0x331f0, 0x33238,
  1423. 0x33240, 0x33240,
  1424. 0x33248, 0x33250,
  1425. 0x3325c, 0x33264,
  1426. 0x33270, 0x332b8,
  1427. 0x332c0, 0x332e4,
  1428. 0x332f8, 0x33338,
  1429. 0x33340, 0x33340,
  1430. 0x33348, 0x33350,
  1431. 0x3335c, 0x33364,
  1432. 0x33370, 0x333b8,
  1433. 0x333c0, 0x333e4,
  1434. 0x333f8, 0x33428,
  1435. 0x33430, 0x33448,
  1436. 0x33460, 0x33468,
  1437. 0x33470, 0x3349c,
  1438. 0x334f0, 0x33528,
  1439. 0x33530, 0x33548,
  1440. 0x33560, 0x33568,
  1441. 0x33570, 0x3359c,
  1442. 0x335f0, 0x33638,
  1443. 0x33640, 0x33640,
  1444. 0x33648, 0x33650,
  1445. 0x3365c, 0x33664,
  1446. 0x33670, 0x336b8,
  1447. 0x336c0, 0x336e4,
  1448. 0x336f8, 0x33738,
  1449. 0x33740, 0x33740,
  1450. 0x33748, 0x33750,
  1451. 0x3375c, 0x33764,
  1452. 0x33770, 0x337b8,
  1453. 0x337c0, 0x337e4,
  1454. 0x337f8, 0x337fc,
  1455. 0x33814, 0x33814,
  1456. 0x3382c, 0x3382c,
  1457. 0x33880, 0x3388c,
  1458. 0x338e8, 0x338ec,
  1459. 0x33900, 0x33928,
  1460. 0x33930, 0x33948,
  1461. 0x33960, 0x33968,
  1462. 0x33970, 0x3399c,
  1463. 0x339f0, 0x33a38,
  1464. 0x33a40, 0x33a40,
  1465. 0x33a48, 0x33a50,
  1466. 0x33a5c, 0x33a64,
  1467. 0x33a70, 0x33ab8,
  1468. 0x33ac0, 0x33ae4,
  1469. 0x33af8, 0x33b10,
  1470. 0x33b28, 0x33b28,
  1471. 0x33b3c, 0x33b50,
  1472. 0x33bf0, 0x33c10,
  1473. 0x33c28, 0x33c28,
  1474. 0x33c3c, 0x33c50,
  1475. 0x33cf0, 0x33cfc,
  1476. 0x34000, 0x34030,
  1477. 0x34038, 0x34038,
  1478. 0x34040, 0x34040,
  1479. 0x34100, 0x34144,
  1480. 0x34190, 0x341a0,
  1481. 0x341a8, 0x341b8,
  1482. 0x341c4, 0x341c8,
  1483. 0x341d0, 0x341d0,
  1484. 0x34200, 0x34318,
  1485. 0x34400, 0x344b4,
  1486. 0x344c0, 0x3452c,
  1487. 0x34540, 0x3461c,
  1488. 0x34800, 0x34828,
  1489. 0x34834, 0x34834,
  1490. 0x348c0, 0x34908,
  1491. 0x34910, 0x349ac,
  1492. 0x34a00, 0x34a14,
  1493. 0x34a1c, 0x34a2c,
  1494. 0x34a44, 0x34a50,
  1495. 0x34a74, 0x34a74,
  1496. 0x34a7c, 0x34afc,
  1497. 0x34b08, 0x34c24,
  1498. 0x34d00, 0x34d00,
  1499. 0x34d08, 0x34d14,
  1500. 0x34d1c, 0x34d20,
  1501. 0x34d3c, 0x34d3c,
  1502. 0x34d48, 0x34d50,
  1503. 0x35200, 0x3520c,
  1504. 0x35220, 0x35220,
  1505. 0x35240, 0x35240,
  1506. 0x35600, 0x3560c,
  1507. 0x35a00, 0x35a1c,
  1508. 0x35e00, 0x35e20,
  1509. 0x35e38, 0x35e3c,
  1510. 0x35e80, 0x35e80,
  1511. 0x35e88, 0x35ea8,
  1512. 0x35eb0, 0x35eb4,
  1513. 0x35ec8, 0x35ed4,
  1514. 0x35fb8, 0x36004,
  1515. 0x36200, 0x36200,
  1516. 0x36208, 0x36240,
  1517. 0x36248, 0x36280,
  1518. 0x36288, 0x362c0,
  1519. 0x362c8, 0x362fc,
  1520. 0x36600, 0x36630,
  1521. 0x36a00, 0x36abc,
  1522. 0x36b00, 0x36b10,
  1523. 0x36b20, 0x36b30,
  1524. 0x36b40, 0x36b50,
  1525. 0x36b60, 0x36b70,
  1526. 0x37000, 0x37028,
  1527. 0x37030, 0x37048,
  1528. 0x37060, 0x37068,
  1529. 0x37070, 0x3709c,
  1530. 0x370f0, 0x37128,
  1531. 0x37130, 0x37148,
  1532. 0x37160, 0x37168,
  1533. 0x37170, 0x3719c,
  1534. 0x371f0, 0x37238,
  1535. 0x37240, 0x37240,
  1536. 0x37248, 0x37250,
  1537. 0x3725c, 0x37264,
  1538. 0x37270, 0x372b8,
  1539. 0x372c0, 0x372e4,
  1540. 0x372f8, 0x37338,
  1541. 0x37340, 0x37340,
  1542. 0x37348, 0x37350,
  1543. 0x3735c, 0x37364,
  1544. 0x37370, 0x373b8,
  1545. 0x373c0, 0x373e4,
  1546. 0x373f8, 0x37428,
  1547. 0x37430, 0x37448,
  1548. 0x37460, 0x37468,
  1549. 0x37470, 0x3749c,
  1550. 0x374f0, 0x37528,
  1551. 0x37530, 0x37548,
  1552. 0x37560, 0x37568,
  1553. 0x37570, 0x3759c,
  1554. 0x375f0, 0x37638,
  1555. 0x37640, 0x37640,
  1556. 0x37648, 0x37650,
  1557. 0x3765c, 0x37664,
  1558. 0x37670, 0x376b8,
  1559. 0x376c0, 0x376e4,
  1560. 0x376f8, 0x37738,
  1561. 0x37740, 0x37740,
  1562. 0x37748, 0x37750,
  1563. 0x3775c, 0x37764,
  1564. 0x37770, 0x377b8,
  1565. 0x377c0, 0x377e4,
  1566. 0x377f8, 0x377fc,
  1567. 0x37814, 0x37814,
  1568. 0x3782c, 0x3782c,
  1569. 0x37880, 0x3788c,
  1570. 0x378e8, 0x378ec,
  1571. 0x37900, 0x37928,
  1572. 0x37930, 0x37948,
  1573. 0x37960, 0x37968,
  1574. 0x37970, 0x3799c,
  1575. 0x379f0, 0x37a38,
  1576. 0x37a40, 0x37a40,
  1577. 0x37a48, 0x37a50,
  1578. 0x37a5c, 0x37a64,
  1579. 0x37a70, 0x37ab8,
  1580. 0x37ac0, 0x37ae4,
  1581. 0x37af8, 0x37b10,
  1582. 0x37b28, 0x37b28,
  1583. 0x37b3c, 0x37b50,
  1584. 0x37bf0, 0x37c10,
  1585. 0x37c28, 0x37c28,
  1586. 0x37c3c, 0x37c50,
  1587. 0x37cf0, 0x37cfc,
  1588. 0x38000, 0x38030,
  1589. 0x38038, 0x38038,
  1590. 0x38040, 0x38040,
  1591. 0x38100, 0x38144,
  1592. 0x38190, 0x381a0,
  1593. 0x381a8, 0x381b8,
  1594. 0x381c4, 0x381c8,
  1595. 0x381d0, 0x381d0,
  1596. 0x38200, 0x38318,
  1597. 0x38400, 0x384b4,
  1598. 0x384c0, 0x3852c,
  1599. 0x38540, 0x3861c,
  1600. 0x38800, 0x38828,
  1601. 0x38834, 0x38834,
  1602. 0x388c0, 0x38908,
  1603. 0x38910, 0x389ac,
  1604. 0x38a00, 0x38a14,
  1605. 0x38a1c, 0x38a2c,
  1606. 0x38a44, 0x38a50,
  1607. 0x38a74, 0x38a74,
  1608. 0x38a7c, 0x38afc,
  1609. 0x38b08, 0x38c24,
  1610. 0x38d00, 0x38d00,
  1611. 0x38d08, 0x38d14,
  1612. 0x38d1c, 0x38d20,
  1613. 0x38d3c, 0x38d3c,
  1614. 0x38d48, 0x38d50,
  1615. 0x39200, 0x3920c,
  1616. 0x39220, 0x39220,
  1617. 0x39240, 0x39240,
  1618. 0x39600, 0x3960c,
  1619. 0x39a00, 0x39a1c,
  1620. 0x39e00, 0x39e20,
  1621. 0x39e38, 0x39e3c,
  1622. 0x39e80, 0x39e80,
  1623. 0x39e88, 0x39ea8,
  1624. 0x39eb0, 0x39eb4,
  1625. 0x39ec8, 0x39ed4,
  1626. 0x39fb8, 0x3a004,
  1627. 0x3a200, 0x3a200,
  1628. 0x3a208, 0x3a240,
  1629. 0x3a248, 0x3a280,
  1630. 0x3a288, 0x3a2c0,
  1631. 0x3a2c8, 0x3a2fc,
  1632. 0x3a600, 0x3a630,
  1633. 0x3aa00, 0x3aabc,
  1634. 0x3ab00, 0x3ab10,
  1635. 0x3ab20, 0x3ab30,
  1636. 0x3ab40, 0x3ab50,
  1637. 0x3ab60, 0x3ab70,
  1638. 0x3b000, 0x3b028,
  1639. 0x3b030, 0x3b048,
  1640. 0x3b060, 0x3b068,
  1641. 0x3b070, 0x3b09c,
  1642. 0x3b0f0, 0x3b128,
  1643. 0x3b130, 0x3b148,
  1644. 0x3b160, 0x3b168,
  1645. 0x3b170, 0x3b19c,
  1646. 0x3b1f0, 0x3b238,
  1647. 0x3b240, 0x3b240,
  1648. 0x3b248, 0x3b250,
  1649. 0x3b25c, 0x3b264,
  1650. 0x3b270, 0x3b2b8,
  1651. 0x3b2c0, 0x3b2e4,
  1652. 0x3b2f8, 0x3b338,
  1653. 0x3b340, 0x3b340,
  1654. 0x3b348, 0x3b350,
  1655. 0x3b35c, 0x3b364,
  1656. 0x3b370, 0x3b3b8,
  1657. 0x3b3c0, 0x3b3e4,
  1658. 0x3b3f8, 0x3b428,
  1659. 0x3b430, 0x3b448,
  1660. 0x3b460, 0x3b468,
  1661. 0x3b470, 0x3b49c,
  1662. 0x3b4f0, 0x3b528,
  1663. 0x3b530, 0x3b548,
  1664. 0x3b560, 0x3b568,
  1665. 0x3b570, 0x3b59c,
  1666. 0x3b5f0, 0x3b638,
  1667. 0x3b640, 0x3b640,
  1668. 0x3b648, 0x3b650,
  1669. 0x3b65c, 0x3b664,
  1670. 0x3b670, 0x3b6b8,
  1671. 0x3b6c0, 0x3b6e4,
  1672. 0x3b6f8, 0x3b738,
  1673. 0x3b740, 0x3b740,
  1674. 0x3b748, 0x3b750,
  1675. 0x3b75c, 0x3b764,
  1676. 0x3b770, 0x3b7b8,
  1677. 0x3b7c0, 0x3b7e4,
  1678. 0x3b7f8, 0x3b7fc,
  1679. 0x3b814, 0x3b814,
  1680. 0x3b82c, 0x3b82c,
  1681. 0x3b880, 0x3b88c,
  1682. 0x3b8e8, 0x3b8ec,
  1683. 0x3b900, 0x3b928,
  1684. 0x3b930, 0x3b948,
  1685. 0x3b960, 0x3b968,
  1686. 0x3b970, 0x3b99c,
  1687. 0x3b9f0, 0x3ba38,
  1688. 0x3ba40, 0x3ba40,
  1689. 0x3ba48, 0x3ba50,
  1690. 0x3ba5c, 0x3ba64,
  1691. 0x3ba70, 0x3bab8,
  1692. 0x3bac0, 0x3bae4,
  1693. 0x3baf8, 0x3bb10,
  1694. 0x3bb28, 0x3bb28,
  1695. 0x3bb3c, 0x3bb50,
  1696. 0x3bbf0, 0x3bc10,
  1697. 0x3bc28, 0x3bc28,
  1698. 0x3bc3c, 0x3bc50,
  1699. 0x3bcf0, 0x3bcfc,
  1700. 0x3c000, 0x3c030,
  1701. 0x3c038, 0x3c038,
  1702. 0x3c040, 0x3c040,
  1703. 0x3c100, 0x3c144,
  1704. 0x3c190, 0x3c1a0,
  1705. 0x3c1a8, 0x3c1b8,
  1706. 0x3c1c4, 0x3c1c8,
  1707. 0x3c1d0, 0x3c1d0,
  1708. 0x3c200, 0x3c318,
  1709. 0x3c400, 0x3c4b4,
  1710. 0x3c4c0, 0x3c52c,
  1711. 0x3c540, 0x3c61c,
  1712. 0x3c800, 0x3c828,
  1713. 0x3c834, 0x3c834,
  1714. 0x3c8c0, 0x3c908,
  1715. 0x3c910, 0x3c9ac,
  1716. 0x3ca00, 0x3ca14,
  1717. 0x3ca1c, 0x3ca2c,
  1718. 0x3ca44, 0x3ca50,
  1719. 0x3ca74, 0x3ca74,
  1720. 0x3ca7c, 0x3cafc,
  1721. 0x3cb08, 0x3cc24,
  1722. 0x3cd00, 0x3cd00,
  1723. 0x3cd08, 0x3cd14,
  1724. 0x3cd1c, 0x3cd20,
  1725. 0x3cd3c, 0x3cd3c,
  1726. 0x3cd48, 0x3cd50,
  1727. 0x3d200, 0x3d20c,
  1728. 0x3d220, 0x3d220,
  1729. 0x3d240, 0x3d240,
  1730. 0x3d600, 0x3d60c,
  1731. 0x3da00, 0x3da1c,
  1732. 0x3de00, 0x3de20,
  1733. 0x3de38, 0x3de3c,
  1734. 0x3de80, 0x3de80,
  1735. 0x3de88, 0x3dea8,
  1736. 0x3deb0, 0x3deb4,
  1737. 0x3dec8, 0x3ded4,
  1738. 0x3dfb8, 0x3e004,
  1739. 0x3e200, 0x3e200,
  1740. 0x3e208, 0x3e240,
  1741. 0x3e248, 0x3e280,
  1742. 0x3e288, 0x3e2c0,
  1743. 0x3e2c8, 0x3e2fc,
  1744. 0x3e600, 0x3e630,
  1745. 0x3ea00, 0x3eabc,
  1746. 0x3eb00, 0x3eb10,
  1747. 0x3eb20, 0x3eb30,
  1748. 0x3eb40, 0x3eb50,
  1749. 0x3eb60, 0x3eb70,
  1750. 0x3f000, 0x3f028,
  1751. 0x3f030, 0x3f048,
  1752. 0x3f060, 0x3f068,
  1753. 0x3f070, 0x3f09c,
  1754. 0x3f0f0, 0x3f128,
  1755. 0x3f130, 0x3f148,
  1756. 0x3f160, 0x3f168,
  1757. 0x3f170, 0x3f19c,
  1758. 0x3f1f0, 0x3f238,
  1759. 0x3f240, 0x3f240,
  1760. 0x3f248, 0x3f250,
  1761. 0x3f25c, 0x3f264,
  1762. 0x3f270, 0x3f2b8,
  1763. 0x3f2c0, 0x3f2e4,
  1764. 0x3f2f8, 0x3f338,
  1765. 0x3f340, 0x3f340,
  1766. 0x3f348, 0x3f350,
  1767. 0x3f35c, 0x3f364,
  1768. 0x3f370, 0x3f3b8,
  1769. 0x3f3c0, 0x3f3e4,
  1770. 0x3f3f8, 0x3f428,
  1771. 0x3f430, 0x3f448,
  1772. 0x3f460, 0x3f468,
  1773. 0x3f470, 0x3f49c,
  1774. 0x3f4f0, 0x3f528,
  1775. 0x3f530, 0x3f548,
  1776. 0x3f560, 0x3f568,
  1777. 0x3f570, 0x3f59c,
  1778. 0x3f5f0, 0x3f638,
  1779. 0x3f640, 0x3f640,
  1780. 0x3f648, 0x3f650,
  1781. 0x3f65c, 0x3f664,
  1782. 0x3f670, 0x3f6b8,
  1783. 0x3f6c0, 0x3f6e4,
  1784. 0x3f6f8, 0x3f738,
  1785. 0x3f740, 0x3f740,
  1786. 0x3f748, 0x3f750,
  1787. 0x3f75c, 0x3f764,
  1788. 0x3f770, 0x3f7b8,
  1789. 0x3f7c0, 0x3f7e4,
  1790. 0x3f7f8, 0x3f7fc,
  1791. 0x3f814, 0x3f814,
  1792. 0x3f82c, 0x3f82c,
  1793. 0x3f880, 0x3f88c,
  1794. 0x3f8e8, 0x3f8ec,
  1795. 0x3f900, 0x3f928,
  1796. 0x3f930, 0x3f948,
  1797. 0x3f960, 0x3f968,
  1798. 0x3f970, 0x3f99c,
  1799. 0x3f9f0, 0x3fa38,
  1800. 0x3fa40, 0x3fa40,
  1801. 0x3fa48, 0x3fa50,
  1802. 0x3fa5c, 0x3fa64,
  1803. 0x3fa70, 0x3fab8,
  1804. 0x3fac0, 0x3fae4,
  1805. 0x3faf8, 0x3fb10,
  1806. 0x3fb28, 0x3fb28,
  1807. 0x3fb3c, 0x3fb50,
  1808. 0x3fbf0, 0x3fc10,
  1809. 0x3fc28, 0x3fc28,
  1810. 0x3fc3c, 0x3fc50,
  1811. 0x3fcf0, 0x3fcfc,
  1812. 0x40000, 0x4000c,
  1813. 0x40040, 0x40050,
  1814. 0x40060, 0x40068,
  1815. 0x4007c, 0x4008c,
  1816. 0x40094, 0x400b0,
  1817. 0x400c0, 0x40144,
  1818. 0x40180, 0x4018c,
  1819. 0x40200, 0x40254,
  1820. 0x40260, 0x40264,
  1821. 0x40270, 0x40288,
  1822. 0x40290, 0x40298,
  1823. 0x402ac, 0x402c8,
  1824. 0x402d0, 0x402e0,
  1825. 0x402f0, 0x402f0,
  1826. 0x40300, 0x4033c,
  1827. 0x403f8, 0x403fc,
  1828. 0x41304, 0x413c4,
  1829. 0x41400, 0x4140c,
  1830. 0x41414, 0x4141c,
  1831. 0x41480, 0x414d0,
  1832. 0x44000, 0x44054,
  1833. 0x4405c, 0x44078,
  1834. 0x440c0, 0x44174,
  1835. 0x44180, 0x441ac,
  1836. 0x441b4, 0x441b8,
  1837. 0x441c0, 0x44254,
  1838. 0x4425c, 0x44278,
  1839. 0x442c0, 0x44374,
  1840. 0x44380, 0x443ac,
  1841. 0x443b4, 0x443b8,
  1842. 0x443c0, 0x44454,
  1843. 0x4445c, 0x44478,
  1844. 0x444c0, 0x44574,
  1845. 0x44580, 0x445ac,
  1846. 0x445b4, 0x445b8,
  1847. 0x445c0, 0x44654,
  1848. 0x4465c, 0x44678,
  1849. 0x446c0, 0x44774,
  1850. 0x44780, 0x447ac,
  1851. 0x447b4, 0x447b8,
  1852. 0x447c0, 0x44854,
  1853. 0x4485c, 0x44878,
  1854. 0x448c0, 0x44974,
  1855. 0x44980, 0x449ac,
  1856. 0x449b4, 0x449b8,
  1857. 0x449c0, 0x449fc,
  1858. 0x45000, 0x45004,
  1859. 0x45010, 0x45030,
  1860. 0x45040, 0x45060,
  1861. 0x45068, 0x45068,
  1862. 0x45080, 0x45084,
  1863. 0x450a0, 0x450b0,
  1864. 0x45200, 0x45204,
  1865. 0x45210, 0x45230,
  1866. 0x45240, 0x45260,
  1867. 0x45268, 0x45268,
  1868. 0x45280, 0x45284,
  1869. 0x452a0, 0x452b0,
  1870. 0x460c0, 0x460e4,
  1871. 0x47000, 0x4703c,
  1872. 0x47044, 0x4708c,
  1873. 0x47200, 0x47250,
  1874. 0x47400, 0x47408,
  1875. 0x47414, 0x47420,
  1876. 0x47600, 0x47618,
  1877. 0x47800, 0x47814,
  1878. 0x48000, 0x4800c,
  1879. 0x48040, 0x48050,
  1880. 0x48060, 0x48068,
  1881. 0x4807c, 0x4808c,
  1882. 0x48094, 0x480b0,
  1883. 0x480c0, 0x48144,
  1884. 0x48180, 0x4818c,
  1885. 0x48200, 0x48254,
  1886. 0x48260, 0x48264,
  1887. 0x48270, 0x48288,
  1888. 0x48290, 0x48298,
  1889. 0x482ac, 0x482c8,
  1890. 0x482d0, 0x482e0,
  1891. 0x482f0, 0x482f0,
  1892. 0x48300, 0x4833c,
  1893. 0x483f8, 0x483fc,
  1894. 0x49304, 0x493c4,
  1895. 0x49400, 0x4940c,
  1896. 0x49414, 0x4941c,
  1897. 0x49480, 0x494d0,
  1898. 0x4c000, 0x4c054,
  1899. 0x4c05c, 0x4c078,
  1900. 0x4c0c0, 0x4c174,
  1901. 0x4c180, 0x4c1ac,
  1902. 0x4c1b4, 0x4c1b8,
  1903. 0x4c1c0, 0x4c254,
  1904. 0x4c25c, 0x4c278,
  1905. 0x4c2c0, 0x4c374,
  1906. 0x4c380, 0x4c3ac,
  1907. 0x4c3b4, 0x4c3b8,
  1908. 0x4c3c0, 0x4c454,
  1909. 0x4c45c, 0x4c478,
  1910. 0x4c4c0, 0x4c574,
  1911. 0x4c580, 0x4c5ac,
  1912. 0x4c5b4, 0x4c5b8,
  1913. 0x4c5c0, 0x4c654,
  1914. 0x4c65c, 0x4c678,
  1915. 0x4c6c0, 0x4c774,
  1916. 0x4c780, 0x4c7ac,
  1917. 0x4c7b4, 0x4c7b8,
  1918. 0x4c7c0, 0x4c854,
  1919. 0x4c85c, 0x4c878,
  1920. 0x4c8c0, 0x4c974,
  1921. 0x4c980, 0x4c9ac,
  1922. 0x4c9b4, 0x4c9b8,
  1923. 0x4c9c0, 0x4c9fc,
  1924. 0x4d000, 0x4d004,
  1925. 0x4d010, 0x4d030,
  1926. 0x4d040, 0x4d060,
  1927. 0x4d068, 0x4d068,
  1928. 0x4d080, 0x4d084,
  1929. 0x4d0a0, 0x4d0b0,
  1930. 0x4d200, 0x4d204,
  1931. 0x4d210, 0x4d230,
  1932. 0x4d240, 0x4d260,
  1933. 0x4d268, 0x4d268,
  1934. 0x4d280, 0x4d284,
  1935. 0x4d2a0, 0x4d2b0,
  1936. 0x4e0c0, 0x4e0e4,
  1937. 0x4f000, 0x4f03c,
  1938. 0x4f044, 0x4f08c,
  1939. 0x4f200, 0x4f250,
  1940. 0x4f400, 0x4f408,
  1941. 0x4f414, 0x4f420,
  1942. 0x4f600, 0x4f618,
  1943. 0x4f800, 0x4f814,
  1944. 0x50000, 0x50084,
  1945. 0x50090, 0x500cc,
  1946. 0x50400, 0x50400,
  1947. 0x50800, 0x50884,
  1948. 0x50890, 0x508cc,
  1949. 0x50c00, 0x50c00,
  1950. 0x51000, 0x5101c,
  1951. 0x51300, 0x51308,
  1952. };
  1953. static const unsigned int t6_reg_ranges[] = {
  1954. 0x1008, 0x101c,
  1955. 0x1024, 0x10a8,
  1956. 0x10b4, 0x10f8,
  1957. 0x1100, 0x1114,
  1958. 0x111c, 0x112c,
  1959. 0x1138, 0x113c,
  1960. 0x1144, 0x114c,
  1961. 0x1180, 0x1184,
  1962. 0x1190, 0x1194,
  1963. 0x11a0, 0x11a4,
  1964. 0x11b0, 0x11b4,
  1965. 0x11fc, 0x1258,
  1966. 0x1280, 0x12d4,
  1967. 0x12d9, 0x12d9,
  1968. 0x12de, 0x12de,
  1969. 0x12e3, 0x12e3,
  1970. 0x12e8, 0x133c,
  1971. 0x1800, 0x18fc,
  1972. 0x3000, 0x302c,
  1973. 0x3060, 0x30b0,
  1974. 0x30b8, 0x30d8,
  1975. 0x30e0, 0x30fc,
  1976. 0x3140, 0x357c,
  1977. 0x35a8, 0x35cc,
  1978. 0x35ec, 0x35ec,
  1979. 0x3600, 0x5624,
  1980. 0x56cc, 0x56ec,
  1981. 0x56f4, 0x5720,
  1982. 0x5728, 0x575c,
  1983. 0x580c, 0x5814,
  1984. 0x5890, 0x589c,
  1985. 0x58a4, 0x58ac,
  1986. 0x58b8, 0x58bc,
  1987. 0x5940, 0x595c,
  1988. 0x5980, 0x598c,
  1989. 0x59b0, 0x59c8,
  1990. 0x59d0, 0x59dc,
  1991. 0x59fc, 0x5a18,
  1992. 0x5a60, 0x5a6c,
  1993. 0x5a80, 0x5a8c,
  1994. 0x5a94, 0x5a9c,
  1995. 0x5b94, 0x5bfc,
  1996. 0x5c10, 0x5e48,
  1997. 0x5e50, 0x5e94,
  1998. 0x5ea0, 0x5eb0,
  1999. 0x5ec0, 0x5ec0,
  2000. 0x5ec8, 0x5ed0,
  2001. 0x6000, 0x6020,
  2002. 0x6028, 0x6040,
  2003. 0x6058, 0x609c,
  2004. 0x60a8, 0x619c,
  2005. 0x7700, 0x7798,
  2006. 0x77c0, 0x7880,
  2007. 0x78cc, 0x78fc,
  2008. 0x7b00, 0x7b58,
  2009. 0x7b60, 0x7b84,
  2010. 0x7b8c, 0x7c54,
  2011. 0x7d00, 0x7d38,
  2012. 0x7d40, 0x7d84,
  2013. 0x7d8c, 0x7ddc,
  2014. 0x7de4, 0x7e04,
  2015. 0x7e10, 0x7e1c,
  2016. 0x7e24, 0x7e38,
  2017. 0x7e40, 0x7e44,
  2018. 0x7e4c, 0x7e78,
  2019. 0x7e80, 0x7edc,
  2020. 0x7ee8, 0x7efc,
  2021. 0x8dc0, 0x8de4,
  2022. 0x8df8, 0x8e04,
  2023. 0x8e10, 0x8e84,
  2024. 0x8ea0, 0x8f88,
  2025. 0x8fb8, 0x9058,
  2026. 0x9060, 0x9060,
  2027. 0x9068, 0x90f8,
  2028. 0x9100, 0x9124,
  2029. 0x9400, 0x9470,
  2030. 0x9600, 0x9600,
  2031. 0x9608, 0x9638,
  2032. 0x9640, 0x9704,
  2033. 0x9710, 0x971c,
  2034. 0x9800, 0x9808,
  2035. 0x9820, 0x983c,
  2036. 0x9850, 0x9864,
  2037. 0x9c00, 0x9c6c,
  2038. 0x9c80, 0x9cec,
  2039. 0x9d00, 0x9d6c,
  2040. 0x9d80, 0x9dec,
  2041. 0x9e00, 0x9e6c,
  2042. 0x9e80, 0x9eec,
  2043. 0x9f00, 0x9f6c,
  2044. 0x9f80, 0xa020,
  2045. 0xd004, 0xd03c,
  2046. 0xd100, 0xd118,
  2047. 0xd200, 0xd214,
  2048. 0xd220, 0xd234,
  2049. 0xd240, 0xd254,
  2050. 0xd260, 0xd274,
  2051. 0xd280, 0xd294,
  2052. 0xd2a0, 0xd2b4,
  2053. 0xd2c0, 0xd2d4,
  2054. 0xd2e0, 0xd2f4,
  2055. 0xd300, 0xd31c,
  2056. 0xdfc0, 0xdfe0,
  2057. 0xe000, 0xf008,
  2058. 0x11000, 0x11014,
  2059. 0x11048, 0x1106c,
  2060. 0x11074, 0x11088,
  2061. 0x11098, 0x11120,
  2062. 0x1112c, 0x1117c,
  2063. 0x11190, 0x112e0,
  2064. 0x11300, 0x1130c,
  2065. 0x12000, 0x1206c,
  2066. 0x19040, 0x1906c,
  2067. 0x19078, 0x19080,
  2068. 0x1908c, 0x190e8,
  2069. 0x190f0, 0x190f8,
  2070. 0x19100, 0x19110,
  2071. 0x19120, 0x19124,
  2072. 0x19150, 0x19194,
  2073. 0x1919c, 0x191b0,
  2074. 0x191d0, 0x191e8,
  2075. 0x19238, 0x19290,
  2076. 0x192a4, 0x192b0,
  2077. 0x192bc, 0x192bc,
  2078. 0x19348, 0x1934c,
  2079. 0x193f8, 0x19418,
  2080. 0x19420, 0x19428,
  2081. 0x19430, 0x19444,
  2082. 0x1944c, 0x1946c,
  2083. 0x19474, 0x19474,
  2084. 0x19490, 0x194cc,
  2085. 0x194f0, 0x194f8,
  2086. 0x19c00, 0x19c48,
  2087. 0x19c50, 0x19c80,
  2088. 0x19c94, 0x19c98,
  2089. 0x19ca0, 0x19cbc,
  2090. 0x19ce4, 0x19ce4,
  2091. 0x19cf0, 0x19cf8,
  2092. 0x19d00, 0x19d28,
  2093. 0x19d50, 0x19d78,
  2094. 0x19d94, 0x19d98,
  2095. 0x19da0, 0x19dc8,
  2096. 0x19df0, 0x19e10,
  2097. 0x19e50, 0x19e6c,
  2098. 0x19ea0, 0x19ebc,
  2099. 0x19ec4, 0x19ef4,
  2100. 0x19f04, 0x19f2c,
  2101. 0x19f34, 0x19f34,
  2102. 0x19f40, 0x19f50,
  2103. 0x19f90, 0x19fac,
  2104. 0x19fc4, 0x19fc8,
  2105. 0x19fd0, 0x19fe4,
  2106. 0x1a000, 0x1a004,
  2107. 0x1a010, 0x1a06c,
  2108. 0x1a0b0, 0x1a0e4,
  2109. 0x1a0ec, 0x1a0f8,
  2110. 0x1a100, 0x1a108,
  2111. 0x1a114, 0x1a120,
  2112. 0x1a128, 0x1a130,
  2113. 0x1a138, 0x1a138,
  2114. 0x1a190, 0x1a1c4,
  2115. 0x1a1fc, 0x1a1fc,
  2116. 0x1e008, 0x1e00c,
  2117. 0x1e040, 0x1e044,
  2118. 0x1e04c, 0x1e04c,
  2119. 0x1e284, 0x1e290,
  2120. 0x1e2c0, 0x1e2c0,
  2121. 0x1e2e0, 0x1e2e0,
  2122. 0x1e300, 0x1e384,
  2123. 0x1e3c0, 0x1e3c8,
  2124. 0x1e408, 0x1e40c,
  2125. 0x1e440, 0x1e444,
  2126. 0x1e44c, 0x1e44c,
  2127. 0x1e684, 0x1e690,
  2128. 0x1e6c0, 0x1e6c0,
  2129. 0x1e6e0, 0x1e6e0,
  2130. 0x1e700, 0x1e784,
  2131. 0x1e7c0, 0x1e7c8,
  2132. 0x1e808, 0x1e80c,
  2133. 0x1e840, 0x1e844,
  2134. 0x1e84c, 0x1e84c,
  2135. 0x1ea84, 0x1ea90,
  2136. 0x1eac0, 0x1eac0,
  2137. 0x1eae0, 0x1eae0,
  2138. 0x1eb00, 0x1eb84,
  2139. 0x1ebc0, 0x1ebc8,
  2140. 0x1ec08, 0x1ec0c,
  2141. 0x1ec40, 0x1ec44,
  2142. 0x1ec4c, 0x1ec4c,
  2143. 0x1ee84, 0x1ee90,
  2144. 0x1eec0, 0x1eec0,
  2145. 0x1eee0, 0x1eee0,
  2146. 0x1ef00, 0x1ef84,
  2147. 0x1efc0, 0x1efc8,
  2148. 0x1f008, 0x1f00c,
  2149. 0x1f040, 0x1f044,
  2150. 0x1f04c, 0x1f04c,
  2151. 0x1f284, 0x1f290,
  2152. 0x1f2c0, 0x1f2c0,
  2153. 0x1f2e0, 0x1f2e0,
  2154. 0x1f300, 0x1f384,
  2155. 0x1f3c0, 0x1f3c8,
  2156. 0x1f408, 0x1f40c,
  2157. 0x1f440, 0x1f444,
  2158. 0x1f44c, 0x1f44c,
  2159. 0x1f684, 0x1f690,
  2160. 0x1f6c0, 0x1f6c0,
  2161. 0x1f6e0, 0x1f6e0,
  2162. 0x1f700, 0x1f784,
  2163. 0x1f7c0, 0x1f7c8,
  2164. 0x1f808, 0x1f80c,
  2165. 0x1f840, 0x1f844,
  2166. 0x1f84c, 0x1f84c,
  2167. 0x1fa84, 0x1fa90,
  2168. 0x1fac0, 0x1fac0,
  2169. 0x1fae0, 0x1fae0,
  2170. 0x1fb00, 0x1fb84,
  2171. 0x1fbc0, 0x1fbc8,
  2172. 0x1fc08, 0x1fc0c,
  2173. 0x1fc40, 0x1fc44,
  2174. 0x1fc4c, 0x1fc4c,
  2175. 0x1fe84, 0x1fe90,
  2176. 0x1fec0, 0x1fec0,
  2177. 0x1fee0, 0x1fee0,
  2178. 0x1ff00, 0x1ff84,
  2179. 0x1ffc0, 0x1ffc8,
  2180. 0x30000, 0x30030,
  2181. 0x30038, 0x30038,
  2182. 0x30040, 0x30040,
  2183. 0x30048, 0x30048,
  2184. 0x30050, 0x30050,
  2185. 0x3005c, 0x30060,
  2186. 0x30068, 0x30068,
  2187. 0x30070, 0x30070,
  2188. 0x30100, 0x30168,
  2189. 0x30190, 0x301a0,
  2190. 0x301a8, 0x301b8,
  2191. 0x301c4, 0x301c8,
  2192. 0x301d0, 0x301d0,
  2193. 0x30200, 0x30320,
  2194. 0x30400, 0x304b4,
  2195. 0x304c0, 0x3052c,
  2196. 0x30540, 0x3061c,
  2197. 0x30800, 0x308a0,
  2198. 0x308c0, 0x30908,
  2199. 0x30910, 0x309b8,
  2200. 0x30a00, 0x30a04,
  2201. 0x30a0c, 0x30a14,
  2202. 0x30a1c, 0x30a2c,
  2203. 0x30a44, 0x30a50,
  2204. 0x30a74, 0x30a74,
  2205. 0x30a7c, 0x30afc,
  2206. 0x30b08, 0x30c24,
  2207. 0x30d00, 0x30d14,
  2208. 0x30d1c, 0x30d3c,
  2209. 0x30d44, 0x30d4c,
  2210. 0x30d54, 0x30d74,
  2211. 0x30d7c, 0x30d7c,
  2212. 0x30de0, 0x30de0,
  2213. 0x30e00, 0x30ed4,
  2214. 0x30f00, 0x30fa4,
  2215. 0x30fc0, 0x30fc4,
  2216. 0x31000, 0x31004,
  2217. 0x31080, 0x310fc,
  2218. 0x31208, 0x31220,
  2219. 0x3123c, 0x31254,
  2220. 0x31300, 0x31300,
  2221. 0x31308, 0x3131c,
  2222. 0x31338, 0x3133c,
  2223. 0x31380, 0x31380,
  2224. 0x31388, 0x313a8,
  2225. 0x313b4, 0x313b4,
  2226. 0x31400, 0x31420,
  2227. 0x31438, 0x3143c,
  2228. 0x31480, 0x31480,
  2229. 0x314a8, 0x314a8,
  2230. 0x314b0, 0x314b4,
  2231. 0x314c8, 0x314d4,
  2232. 0x31a40, 0x31a4c,
  2233. 0x31af0, 0x31b20,
  2234. 0x31b38, 0x31b3c,
  2235. 0x31b80, 0x31b80,
  2236. 0x31ba8, 0x31ba8,
  2237. 0x31bb0, 0x31bb4,
  2238. 0x31bc8, 0x31bd4,
  2239. 0x32140, 0x3218c,
  2240. 0x321f0, 0x321f4,
  2241. 0x32200, 0x32200,
  2242. 0x32218, 0x32218,
  2243. 0x32400, 0x32400,
  2244. 0x32408, 0x3241c,
  2245. 0x32618, 0x32620,
  2246. 0x32664, 0x32664,
  2247. 0x326a8, 0x326a8,
  2248. 0x326ec, 0x326ec,
  2249. 0x32a00, 0x32abc,
  2250. 0x32b00, 0x32b38,
  2251. 0x32b40, 0x32b58,
  2252. 0x32b60, 0x32b78,
  2253. 0x32c00, 0x32c00,
  2254. 0x32c08, 0x32c3c,
  2255. 0x32e00, 0x32e2c,
  2256. 0x32f00, 0x32f2c,
  2257. 0x33000, 0x3302c,
  2258. 0x33034, 0x33050,
  2259. 0x33058, 0x33058,
  2260. 0x33060, 0x3308c,
  2261. 0x3309c, 0x330ac,
  2262. 0x330c0, 0x330c0,
  2263. 0x330c8, 0x330d0,
  2264. 0x330d8, 0x330e0,
  2265. 0x330ec, 0x3312c,
  2266. 0x33134, 0x33150,
  2267. 0x33158, 0x33158,
  2268. 0x33160, 0x3318c,
  2269. 0x3319c, 0x331ac,
  2270. 0x331c0, 0x331c0,
  2271. 0x331c8, 0x331d0,
  2272. 0x331d8, 0x331e0,
  2273. 0x331ec, 0x33290,
  2274. 0x33298, 0x332c4,
  2275. 0x332e4, 0x33390,
  2276. 0x33398, 0x333c4,
  2277. 0x333e4, 0x3342c,
  2278. 0x33434, 0x33450,
  2279. 0x33458, 0x33458,
  2280. 0x33460, 0x3348c,
  2281. 0x3349c, 0x334ac,
  2282. 0x334c0, 0x334c0,
  2283. 0x334c8, 0x334d0,
  2284. 0x334d8, 0x334e0,
  2285. 0x334ec, 0x3352c,
  2286. 0x33534, 0x33550,
  2287. 0x33558, 0x33558,
  2288. 0x33560, 0x3358c,
  2289. 0x3359c, 0x335ac,
  2290. 0x335c0, 0x335c0,
  2291. 0x335c8, 0x335d0,
  2292. 0x335d8, 0x335e0,
  2293. 0x335ec, 0x33690,
  2294. 0x33698, 0x336c4,
  2295. 0x336e4, 0x33790,
  2296. 0x33798, 0x337c4,
  2297. 0x337e4, 0x337fc,
  2298. 0x33814, 0x33814,
  2299. 0x33854, 0x33868,
  2300. 0x33880, 0x3388c,
  2301. 0x338c0, 0x338d0,
  2302. 0x338e8, 0x338ec,
  2303. 0x33900, 0x3392c,
  2304. 0x33934, 0x33950,
  2305. 0x33958, 0x33958,
  2306. 0x33960, 0x3398c,
  2307. 0x3399c, 0x339ac,
  2308. 0x339c0, 0x339c0,
  2309. 0x339c8, 0x339d0,
  2310. 0x339d8, 0x339e0,
  2311. 0x339ec, 0x33a90,
  2312. 0x33a98, 0x33ac4,
  2313. 0x33ae4, 0x33b10,
  2314. 0x33b24, 0x33b28,
  2315. 0x33b38, 0x33b50,
  2316. 0x33bf0, 0x33c10,
  2317. 0x33c24, 0x33c28,
  2318. 0x33c38, 0x33c50,
  2319. 0x33cf0, 0x33cfc,
  2320. 0x34000, 0x34030,
  2321. 0x34038, 0x34038,
  2322. 0x34040, 0x34040,
  2323. 0x34048, 0x34048,
  2324. 0x34050, 0x34050,
  2325. 0x3405c, 0x34060,
  2326. 0x34068, 0x34068,
  2327. 0x34070, 0x34070,
  2328. 0x34100, 0x34168,
  2329. 0x34190, 0x341a0,
  2330. 0x341a8, 0x341b8,
  2331. 0x341c4, 0x341c8,
  2332. 0x341d0, 0x341d0,
  2333. 0x34200, 0x34320,
  2334. 0x34400, 0x344b4,
  2335. 0x344c0, 0x3452c,
  2336. 0x34540, 0x3461c,
  2337. 0x34800, 0x348a0,
  2338. 0x348c0, 0x34908,
  2339. 0x34910, 0x349b8,
  2340. 0x34a00, 0x34a04,
  2341. 0x34a0c, 0x34a14,
  2342. 0x34a1c, 0x34a2c,
  2343. 0x34a44, 0x34a50,
  2344. 0x34a74, 0x34a74,
  2345. 0x34a7c, 0x34afc,
  2346. 0x34b08, 0x34c24,
  2347. 0x34d00, 0x34d14,
  2348. 0x34d1c, 0x34d3c,
  2349. 0x34d44, 0x34d4c,
  2350. 0x34d54, 0x34d74,
  2351. 0x34d7c, 0x34d7c,
  2352. 0x34de0, 0x34de0,
  2353. 0x34e00, 0x34ed4,
  2354. 0x34f00, 0x34fa4,
  2355. 0x34fc0, 0x34fc4,
  2356. 0x35000, 0x35004,
  2357. 0x35080, 0x350fc,
  2358. 0x35208, 0x35220,
  2359. 0x3523c, 0x35254,
  2360. 0x35300, 0x35300,
  2361. 0x35308, 0x3531c,
  2362. 0x35338, 0x3533c,
  2363. 0x35380, 0x35380,
  2364. 0x35388, 0x353a8,
  2365. 0x353b4, 0x353b4,
  2366. 0x35400, 0x35420,
  2367. 0x35438, 0x3543c,
  2368. 0x35480, 0x35480,
  2369. 0x354a8, 0x354a8,
  2370. 0x354b0, 0x354b4,
  2371. 0x354c8, 0x354d4,
  2372. 0x35a40, 0x35a4c,
  2373. 0x35af0, 0x35b20,
  2374. 0x35b38, 0x35b3c,
  2375. 0x35b80, 0x35b80,
  2376. 0x35ba8, 0x35ba8,
  2377. 0x35bb0, 0x35bb4,
  2378. 0x35bc8, 0x35bd4,
  2379. 0x36140, 0x3618c,
  2380. 0x361f0, 0x361f4,
  2381. 0x36200, 0x36200,
  2382. 0x36218, 0x36218,
  2383. 0x36400, 0x36400,
  2384. 0x36408, 0x3641c,
  2385. 0x36618, 0x36620,
  2386. 0x36664, 0x36664,
  2387. 0x366a8, 0x366a8,
  2388. 0x366ec, 0x366ec,
  2389. 0x36a00, 0x36abc,
  2390. 0x36b00, 0x36b38,
  2391. 0x36b40, 0x36b58,
  2392. 0x36b60, 0x36b78,
  2393. 0x36c00, 0x36c00,
  2394. 0x36c08, 0x36c3c,
  2395. 0x36e00, 0x36e2c,
  2396. 0x36f00, 0x36f2c,
  2397. 0x37000, 0x3702c,
  2398. 0x37034, 0x37050,
  2399. 0x37058, 0x37058,
  2400. 0x37060, 0x3708c,
  2401. 0x3709c, 0x370ac,
  2402. 0x370c0, 0x370c0,
  2403. 0x370c8, 0x370d0,
  2404. 0x370d8, 0x370e0,
  2405. 0x370ec, 0x3712c,
  2406. 0x37134, 0x37150,
  2407. 0x37158, 0x37158,
  2408. 0x37160, 0x3718c,
  2409. 0x3719c, 0x371ac,
  2410. 0x371c0, 0x371c0,
  2411. 0x371c8, 0x371d0,
  2412. 0x371d8, 0x371e0,
  2413. 0x371ec, 0x37290,
  2414. 0x37298, 0x372c4,
  2415. 0x372e4, 0x37390,
  2416. 0x37398, 0x373c4,
  2417. 0x373e4, 0x3742c,
  2418. 0x37434, 0x37450,
  2419. 0x37458, 0x37458,
  2420. 0x37460, 0x3748c,
  2421. 0x3749c, 0x374ac,
  2422. 0x374c0, 0x374c0,
  2423. 0x374c8, 0x374d0,
  2424. 0x374d8, 0x374e0,
  2425. 0x374ec, 0x3752c,
  2426. 0x37534, 0x37550,
  2427. 0x37558, 0x37558,
  2428. 0x37560, 0x3758c,
  2429. 0x3759c, 0x375ac,
  2430. 0x375c0, 0x375c0,
  2431. 0x375c8, 0x375d0,
  2432. 0x375d8, 0x375e0,
  2433. 0x375ec, 0x37690,
  2434. 0x37698, 0x376c4,
  2435. 0x376e4, 0x37790,
  2436. 0x37798, 0x377c4,
  2437. 0x377e4, 0x377fc,
  2438. 0x37814, 0x37814,
  2439. 0x37854, 0x37868,
  2440. 0x37880, 0x3788c,
  2441. 0x378c0, 0x378d0,
  2442. 0x378e8, 0x378ec,
  2443. 0x37900, 0x3792c,
  2444. 0x37934, 0x37950,
  2445. 0x37958, 0x37958,
  2446. 0x37960, 0x3798c,
  2447. 0x3799c, 0x379ac,
  2448. 0x379c0, 0x379c0,
  2449. 0x379c8, 0x379d0,
  2450. 0x379d8, 0x379e0,
  2451. 0x379ec, 0x37a90,
  2452. 0x37a98, 0x37ac4,
  2453. 0x37ae4, 0x37b10,
  2454. 0x37b24, 0x37b28,
  2455. 0x37b38, 0x37b50,
  2456. 0x37bf0, 0x37c10,
  2457. 0x37c24, 0x37c28,
  2458. 0x37c38, 0x37c50,
  2459. 0x37cf0, 0x37cfc,
  2460. 0x40040, 0x40040,
  2461. 0x40080, 0x40084,
  2462. 0x40100, 0x40100,
  2463. 0x40140, 0x401bc,
  2464. 0x40200, 0x40214,
  2465. 0x40228, 0x40228,
  2466. 0x40240, 0x40258,
  2467. 0x40280, 0x40280,
  2468. 0x40304, 0x40304,
  2469. 0x40330, 0x4033c,
  2470. 0x41304, 0x413b8,
  2471. 0x413c0, 0x413c8,
  2472. 0x413d0, 0x413dc,
  2473. 0x413f0, 0x413f0,
  2474. 0x41400, 0x4140c,
  2475. 0x41414, 0x4141c,
  2476. 0x41480, 0x414d0,
  2477. 0x44000, 0x4407c,
  2478. 0x440c0, 0x441ac,
  2479. 0x441b4, 0x4427c,
  2480. 0x442c0, 0x443ac,
  2481. 0x443b4, 0x4447c,
  2482. 0x444c0, 0x445ac,
  2483. 0x445b4, 0x4467c,
  2484. 0x446c0, 0x447ac,
  2485. 0x447b4, 0x4487c,
  2486. 0x448c0, 0x449ac,
  2487. 0x449b4, 0x44a7c,
  2488. 0x44ac0, 0x44bac,
  2489. 0x44bb4, 0x44c7c,
  2490. 0x44cc0, 0x44dac,
  2491. 0x44db4, 0x44e7c,
  2492. 0x44ec0, 0x44fac,
  2493. 0x44fb4, 0x4507c,
  2494. 0x450c0, 0x451ac,
  2495. 0x451b4, 0x451fc,
  2496. 0x45800, 0x45804,
  2497. 0x45810, 0x45830,
  2498. 0x45840, 0x45860,
  2499. 0x45868, 0x45868,
  2500. 0x45880, 0x45884,
  2501. 0x458a0, 0x458b0,
  2502. 0x45a00, 0x45a04,
  2503. 0x45a10, 0x45a30,
  2504. 0x45a40, 0x45a60,
  2505. 0x45a68, 0x45a68,
  2506. 0x45a80, 0x45a84,
  2507. 0x45aa0, 0x45ab0,
  2508. 0x460c0, 0x460e4,
  2509. 0x47000, 0x4703c,
  2510. 0x47044, 0x4708c,
  2511. 0x47200, 0x47250,
  2512. 0x47400, 0x47408,
  2513. 0x47414, 0x47420,
  2514. 0x47600, 0x47618,
  2515. 0x47800, 0x47814,
  2516. 0x47820, 0x4782c,
  2517. 0x50000, 0x50084,
  2518. 0x50090, 0x500cc,
  2519. 0x50300, 0x50384,
  2520. 0x50400, 0x50400,
  2521. 0x50800, 0x50884,
  2522. 0x50890, 0x508cc,
  2523. 0x50b00, 0x50b84,
  2524. 0x50c00, 0x50c00,
  2525. 0x51000, 0x51020,
  2526. 0x51028, 0x510b0,
  2527. 0x51300, 0x51324,
  2528. };
  2529. u32 *buf_end = (u32 *)((char *)buf + buf_size);
  2530. const unsigned int *reg_ranges;
  2531. int reg_ranges_size, range;
  2532. unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
  2533. /* Select the right set of register ranges to dump depending on the
  2534. * adapter chip type.
  2535. */
  2536. switch (chip_version) {
  2537. case CHELSIO_T4:
  2538. reg_ranges = t4_reg_ranges;
  2539. reg_ranges_size = ARRAY_SIZE(t4_reg_ranges);
  2540. break;
  2541. case CHELSIO_T5:
  2542. reg_ranges = t5_reg_ranges;
  2543. reg_ranges_size = ARRAY_SIZE(t5_reg_ranges);
  2544. break;
  2545. case CHELSIO_T6:
  2546. reg_ranges = t6_reg_ranges;
  2547. reg_ranges_size = ARRAY_SIZE(t6_reg_ranges);
  2548. break;
  2549. default:
  2550. dev_err(adap->pdev_dev,
  2551. "Unsupported chip version %d\n", chip_version);
  2552. return;
  2553. }
  2554. /* Clear the register buffer and insert the appropriate register
  2555. * values selected by the above register ranges.
  2556. */
  2557. memset(buf, 0, buf_size);
  2558. for (range = 0; range < reg_ranges_size; range += 2) {
  2559. unsigned int reg = reg_ranges[range];
  2560. unsigned int last_reg = reg_ranges[range + 1];
  2561. u32 *bufp = (u32 *)((char *)buf + reg);
  2562. /* Iterate across the register range filling in the register
  2563. * buffer but don't write past the end of the register buffer.
  2564. */
  2565. while (reg <= last_reg && bufp < buf_end) {
  2566. *bufp++ = t4_read_reg(adap, reg);
  2567. reg += sizeof(u32);
  2568. }
  2569. }
  2570. }
  2571. #define EEPROM_STAT_ADDR 0x7bfc
  2572. #define VPD_SIZE 0x800
  2573. #define VPD_BASE 0x400
  2574. #define VPD_BASE_OLD 0
  2575. #define VPD_LEN 1024
  2576. #define CHELSIO_VPD_UNIQUE_ID 0x82
  2577. /**
  2578. * t4_seeprom_wp - enable/disable EEPROM write protection
  2579. * @adapter: the adapter
  2580. * @enable: whether to enable or disable write protection
  2581. *
  2582. * Enables or disables write protection on the serial EEPROM.
  2583. */
  2584. int t4_seeprom_wp(struct adapter *adapter, bool enable)
  2585. {
  2586. unsigned int v = enable ? 0xc : 0;
  2587. int ret = pci_write_vpd(adapter->pdev, EEPROM_STAT_ADDR, 4, &v);
  2588. return ret < 0 ? ret : 0;
  2589. }
  2590. /**
  2591. * t4_get_raw_vpd_params - read VPD parameters from VPD EEPROM
  2592. * @adapter: adapter to read
  2593. * @p: where to store the parameters
  2594. *
  2595. * Reads card parameters stored in VPD EEPROM.
  2596. */
  2597. int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
  2598. {
  2599. int i, ret = 0, addr;
  2600. int ec, sn, pn, na;
  2601. u8 *vpd, csum;
  2602. unsigned int vpdr_len, kw_offset, id_len;
  2603. vpd = vmalloc(VPD_LEN);
  2604. if (!vpd)
  2605. return -ENOMEM;
  2606. /* We have two VPD data structures stored in the adapter VPD area.
  2607. * By default, Linux calculates the size of the VPD area by traversing
  2608. * the first VPD area at offset 0x0, so we need to tell the OS what
  2609. * our real VPD size is.
  2610. */
  2611. ret = pci_set_vpd_size(adapter->pdev, VPD_SIZE);
  2612. if (ret < 0)
  2613. goto out;
  2614. /* Card information normally starts at VPD_BASE but early cards had
  2615. * it at 0.
  2616. */
  2617. ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(u32), vpd);
  2618. if (ret < 0)
  2619. goto out;
  2620. /* The VPD shall have a unique identifier specified by the PCI SIG.
  2621. * For chelsio adapters, the identifier is 0x82. The first byte of a VPD
  2622. * shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software
  2623. * is expected to automatically put this entry at the
  2624. * beginning of the VPD.
  2625. */
  2626. addr = *vpd == CHELSIO_VPD_UNIQUE_ID ? VPD_BASE : VPD_BASE_OLD;
  2627. ret = pci_read_vpd(adapter->pdev, addr, VPD_LEN, vpd);
  2628. if (ret < 0)
  2629. goto out;
  2630. if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
  2631. dev_err(adapter->pdev_dev, "missing VPD ID string\n");
  2632. ret = -EINVAL;
  2633. goto out;
  2634. }
  2635. id_len = pci_vpd_lrdt_size(vpd);
  2636. if (id_len > ID_LEN)
  2637. id_len = ID_LEN;
  2638. i = pci_vpd_find_tag(vpd, 0, VPD_LEN, PCI_VPD_LRDT_RO_DATA);
  2639. if (i < 0) {
  2640. dev_err(adapter->pdev_dev, "missing VPD-R section\n");
  2641. ret = -EINVAL;
  2642. goto out;
  2643. }
  2644. vpdr_len = pci_vpd_lrdt_size(&vpd[i]);
  2645. kw_offset = i + PCI_VPD_LRDT_TAG_SIZE;
  2646. if (vpdr_len + kw_offset > VPD_LEN) {
  2647. dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
  2648. ret = -EINVAL;
  2649. goto out;
  2650. }
  2651. #define FIND_VPD_KW(var, name) do { \
  2652. var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \
  2653. if (var < 0) { \
  2654. dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
  2655. ret = -EINVAL; \
  2656. goto out; \
  2657. } \
  2658. var += PCI_VPD_INFO_FLD_HDR_SIZE; \
  2659. } while (0)
  2660. FIND_VPD_KW(i, "RV");
  2661. for (csum = 0; i >= 0; i--)
  2662. csum += vpd[i];
  2663. if (csum) {
  2664. dev_err(adapter->pdev_dev,
  2665. "corrupted VPD EEPROM, actual csum %u\n", csum);
  2666. ret = -EINVAL;
  2667. goto out;
  2668. }
  2669. FIND_VPD_KW(ec, "EC");
  2670. FIND_VPD_KW(sn, "SN");
  2671. FIND_VPD_KW(pn, "PN");
  2672. FIND_VPD_KW(na, "NA");
  2673. #undef FIND_VPD_KW
  2674. memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len);
  2675. strim(p->id);
  2676. memcpy(p->ec, vpd + ec, EC_LEN);
  2677. strim(p->ec);
  2678. i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE);
  2679. memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
  2680. strim(p->sn);
  2681. i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE);
  2682. memcpy(p->pn, vpd + pn, min(i, PN_LEN));
  2683. strim(p->pn);
  2684. memcpy(p->na, vpd + na, min(i, MACADDR_LEN));
  2685. strim((char *)p->na);
  2686. out:
  2687. vfree(vpd);
  2688. return ret < 0 ? ret : 0;
  2689. }
  2690. /**
  2691. * t4_get_vpd_params - read VPD parameters & retrieve Core Clock
  2692. * @adapter: adapter to read
  2693. * @p: where to store the parameters
  2694. *
  2695. * Reads card parameters stored in VPD EEPROM and retrieves the Core
  2696. * Clock. This can only be called after a connection to the firmware
  2697. * is established.
  2698. */
  2699. int t4_get_vpd_params(struct adapter *adapter, struct vpd_params *p)
  2700. {
  2701. u32 cclk_param, cclk_val;
  2702. int ret;
  2703. /* Grab the raw VPD parameters.
  2704. */
  2705. ret = t4_get_raw_vpd_params(adapter, p);
  2706. if (ret)
  2707. return ret;
  2708. /* Ask firmware for the Core Clock since it knows how to translate the
  2709. * Reference Clock ('V2') VPD field into a Core Clock value ...
  2710. */
  2711. cclk_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2712. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CCLK));
  2713. ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
  2714. 1, &cclk_param, &cclk_val);
  2715. if (ret)
  2716. return ret;
  2717. p->cclk = cclk_val;
  2718. return 0;
  2719. }
  2720. /* serial flash and firmware constants */
  2721. enum {
  2722. SF_ATTEMPTS = 10, /* max retries for SF operations */
  2723. /* flash command opcodes */
  2724. SF_PROG_PAGE = 2, /* program page */
  2725. SF_WR_DISABLE = 4, /* disable writes */
  2726. SF_RD_STATUS = 5, /* read status register */
  2727. SF_WR_ENABLE = 6, /* enable writes */
  2728. SF_RD_DATA_FAST = 0xb, /* read flash */
  2729. SF_RD_ID = 0x9f, /* read ID */
  2730. SF_ERASE_SECTOR = 0xd8, /* erase sector */
  2731. FW_MAX_SIZE = 16 * SF_SEC_SIZE,
  2732. };
  2733. /**
  2734. * sf1_read - read data from the serial flash
  2735. * @adapter: the adapter
  2736. * @byte_cnt: number of bytes to read
  2737. * @cont: whether another operation will be chained
  2738. * @lock: whether to lock SF for PL access only
  2739. * @valp: where to store the read data
  2740. *
  2741. * Reads up to 4 bytes of data from the serial flash. The location of
  2742. * the read needs to be specified prior to calling this by issuing the
  2743. * appropriate commands to the serial flash.
  2744. */
  2745. static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
  2746. int lock, u32 *valp)
  2747. {
  2748. int ret;
  2749. if (!byte_cnt || byte_cnt > 4)
  2750. return -EINVAL;
  2751. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  2752. return -EBUSY;
  2753. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  2754. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1));
  2755. ret = t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  2756. if (!ret)
  2757. *valp = t4_read_reg(adapter, SF_DATA_A);
  2758. return ret;
  2759. }
  2760. /**
  2761. * sf1_write - write data to the serial flash
  2762. * @adapter: the adapter
  2763. * @byte_cnt: number of bytes to write
  2764. * @cont: whether another operation will be chained
  2765. * @lock: whether to lock SF for PL access only
  2766. * @val: value to write
  2767. *
  2768. * Writes up to 4 bytes of data to the serial flash. The location of
  2769. * the write needs to be specified prior to calling this by issuing the
  2770. * appropriate commands to the serial flash.
  2771. */
  2772. static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
  2773. int lock, u32 val)
  2774. {
  2775. if (!byte_cnt || byte_cnt > 4)
  2776. return -EINVAL;
  2777. if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
  2778. return -EBUSY;
  2779. t4_write_reg(adapter, SF_DATA_A, val);
  2780. t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
  2781. SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1) | OP_V(1));
  2782. return t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
  2783. }
  2784. /**
  2785. * flash_wait_op - wait for a flash operation to complete
  2786. * @adapter: the adapter
  2787. * @attempts: max number of polls of the status register
  2788. * @delay: delay between polls in ms
  2789. *
  2790. * Wait for a flash operation to complete by polling the status register.
  2791. */
  2792. static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
  2793. {
  2794. int ret;
  2795. u32 status;
  2796. while (1) {
  2797. if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
  2798. (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
  2799. return ret;
  2800. if (!(status & 1))
  2801. return 0;
  2802. if (--attempts == 0)
  2803. return -EAGAIN;
  2804. if (delay)
  2805. msleep(delay);
  2806. }
  2807. }
  2808. /**
  2809. * t4_read_flash - read words from serial flash
  2810. * @adapter: the adapter
  2811. * @addr: the start address for the read
  2812. * @nwords: how many 32-bit words to read
  2813. * @data: where to store the read data
  2814. * @byte_oriented: whether to store data as bytes or as words
  2815. *
  2816. * Read the specified number of 32-bit words from the serial flash.
  2817. * If @byte_oriented is set the read data is stored as a byte array
  2818. * (i.e., big-endian), otherwise as 32-bit words in the platform's
  2819. * natural endianness.
  2820. */
  2821. int t4_read_flash(struct adapter *adapter, unsigned int addr,
  2822. unsigned int nwords, u32 *data, int byte_oriented)
  2823. {
  2824. int ret;
  2825. if (addr + nwords * sizeof(u32) > adapter->params.sf_size || (addr & 3))
  2826. return -EINVAL;
  2827. addr = swab32(addr) | SF_RD_DATA_FAST;
  2828. if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
  2829. (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
  2830. return ret;
  2831. for ( ; nwords; nwords--, data++) {
  2832. ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
  2833. if (nwords == 1)
  2834. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2835. if (ret)
  2836. return ret;
  2837. if (byte_oriented)
  2838. *data = (__force __u32)(cpu_to_be32(*data));
  2839. }
  2840. return 0;
  2841. }
  2842. /**
  2843. * t4_write_flash - write up to a page of data to the serial flash
  2844. * @adapter: the adapter
  2845. * @addr: the start address to write
  2846. * @n: length of data to write in bytes
  2847. * @data: the data to write
  2848. *
  2849. * Writes up to a page of data (256 bytes) to the serial flash starting
  2850. * at the given address. All the data must be written to the same page.
  2851. */
  2852. static int t4_write_flash(struct adapter *adapter, unsigned int addr,
  2853. unsigned int n, const u8 *data)
  2854. {
  2855. int ret;
  2856. u32 buf[64];
  2857. unsigned int i, c, left, val, offset = addr & 0xff;
  2858. if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
  2859. return -EINVAL;
  2860. val = swab32(addr) | SF_PROG_PAGE;
  2861. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  2862. (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
  2863. goto unlock;
  2864. for (left = n; left; left -= c) {
  2865. c = min(left, 4U);
  2866. for (val = 0, i = 0; i < c; ++i)
  2867. val = (val << 8) + *data++;
  2868. ret = sf1_write(adapter, c, c != left, 1, val);
  2869. if (ret)
  2870. goto unlock;
  2871. }
  2872. ret = flash_wait_op(adapter, 8, 1);
  2873. if (ret)
  2874. goto unlock;
  2875. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2876. /* Read the page to verify the write succeeded */
  2877. ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
  2878. if (ret)
  2879. return ret;
  2880. if (memcmp(data - n, (u8 *)buf + offset, n)) {
  2881. dev_err(adapter->pdev_dev,
  2882. "failed to correctly write the flash page at %#x\n",
  2883. addr);
  2884. return -EIO;
  2885. }
  2886. return 0;
  2887. unlock:
  2888. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  2889. return ret;
  2890. }
  2891. /**
  2892. * t4_get_fw_version - read the firmware version
  2893. * @adapter: the adapter
  2894. * @vers: where to place the version
  2895. *
  2896. * Reads the FW version from flash.
  2897. */
  2898. int t4_get_fw_version(struct adapter *adapter, u32 *vers)
  2899. {
  2900. return t4_read_flash(adapter, FLASH_FW_START +
  2901. offsetof(struct fw_hdr, fw_ver), 1,
  2902. vers, 0);
  2903. }
  2904. /**
  2905. * t4_get_bs_version - read the firmware bootstrap version
  2906. * @adapter: the adapter
  2907. * @vers: where to place the version
  2908. *
  2909. * Reads the FW Bootstrap version from flash.
  2910. */
  2911. int t4_get_bs_version(struct adapter *adapter, u32 *vers)
  2912. {
  2913. return t4_read_flash(adapter, FLASH_FWBOOTSTRAP_START +
  2914. offsetof(struct fw_hdr, fw_ver), 1,
  2915. vers, 0);
  2916. }
  2917. /**
  2918. * t4_get_tp_version - read the TP microcode version
  2919. * @adapter: the adapter
  2920. * @vers: where to place the version
  2921. *
  2922. * Reads the TP microcode version from flash.
  2923. */
  2924. int t4_get_tp_version(struct adapter *adapter, u32 *vers)
  2925. {
  2926. return t4_read_flash(adapter, FLASH_FW_START +
  2927. offsetof(struct fw_hdr, tp_microcode_ver),
  2928. 1, vers, 0);
  2929. }
  2930. /**
  2931. * t4_get_exprom_version - return the Expansion ROM version (if any)
  2932. * @adapter: the adapter
  2933. * @vers: where to place the version
  2934. *
  2935. * Reads the Expansion ROM header from FLASH and returns the version
  2936. * number (if present) through the @vers return value pointer. We return
  2937. * this in the Firmware Version Format since it's convenient. Return
  2938. * 0 on success, -ENOENT if no Expansion ROM is present.
  2939. */
  2940. int t4_get_exprom_version(struct adapter *adap, u32 *vers)
  2941. {
  2942. struct exprom_header {
  2943. unsigned char hdr_arr[16]; /* must start with 0x55aa */
  2944. unsigned char hdr_ver[4]; /* Expansion ROM version */
  2945. } *hdr;
  2946. u32 exprom_header_buf[DIV_ROUND_UP(sizeof(struct exprom_header),
  2947. sizeof(u32))];
  2948. int ret;
  2949. ret = t4_read_flash(adap, FLASH_EXP_ROM_START,
  2950. ARRAY_SIZE(exprom_header_buf), exprom_header_buf,
  2951. 0);
  2952. if (ret)
  2953. return ret;
  2954. hdr = (struct exprom_header *)exprom_header_buf;
  2955. if (hdr->hdr_arr[0] != 0x55 || hdr->hdr_arr[1] != 0xaa)
  2956. return -ENOENT;
  2957. *vers = (FW_HDR_FW_VER_MAJOR_V(hdr->hdr_ver[0]) |
  2958. FW_HDR_FW_VER_MINOR_V(hdr->hdr_ver[1]) |
  2959. FW_HDR_FW_VER_MICRO_V(hdr->hdr_ver[2]) |
  2960. FW_HDR_FW_VER_BUILD_V(hdr->hdr_ver[3]));
  2961. return 0;
  2962. }
  2963. /**
  2964. * t4_check_fw_version - check if the FW is supported with this driver
  2965. * @adap: the adapter
  2966. *
  2967. * Checks if an adapter's FW is compatible with the driver. Returns 0
  2968. * if there's exact match, a negative error if the version could not be
  2969. * read or there's a major version mismatch
  2970. */
  2971. int t4_check_fw_version(struct adapter *adap)
  2972. {
  2973. int i, ret, major, minor, micro;
  2974. int exp_major, exp_minor, exp_micro;
  2975. unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
  2976. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  2977. /* Try multiple times before returning error */
  2978. for (i = 0; (ret == -EBUSY || ret == -EAGAIN) && i < 3; i++)
  2979. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  2980. if (ret)
  2981. return ret;
  2982. major = FW_HDR_FW_VER_MAJOR_G(adap->params.fw_vers);
  2983. minor = FW_HDR_FW_VER_MINOR_G(adap->params.fw_vers);
  2984. micro = FW_HDR_FW_VER_MICRO_G(adap->params.fw_vers);
  2985. switch (chip_version) {
  2986. case CHELSIO_T4:
  2987. exp_major = T4FW_MIN_VERSION_MAJOR;
  2988. exp_minor = T4FW_MIN_VERSION_MINOR;
  2989. exp_micro = T4FW_MIN_VERSION_MICRO;
  2990. break;
  2991. case CHELSIO_T5:
  2992. exp_major = T5FW_MIN_VERSION_MAJOR;
  2993. exp_minor = T5FW_MIN_VERSION_MINOR;
  2994. exp_micro = T5FW_MIN_VERSION_MICRO;
  2995. break;
  2996. case CHELSIO_T6:
  2997. exp_major = T6FW_MIN_VERSION_MAJOR;
  2998. exp_minor = T6FW_MIN_VERSION_MINOR;
  2999. exp_micro = T6FW_MIN_VERSION_MICRO;
  3000. break;
  3001. default:
  3002. dev_err(adap->pdev_dev, "Unsupported chip type, %x\n",
  3003. adap->chip);
  3004. return -EINVAL;
  3005. }
  3006. if (major < exp_major || (major == exp_major && minor < exp_minor) ||
  3007. (major == exp_major && minor == exp_minor && micro < exp_micro)) {
  3008. dev_err(adap->pdev_dev,
  3009. "Card has firmware version %u.%u.%u, minimum "
  3010. "supported firmware is %u.%u.%u.\n", major, minor,
  3011. micro, exp_major, exp_minor, exp_micro);
  3012. return -EFAULT;
  3013. }
  3014. return 0;
  3015. }
  3016. /* Is the given firmware API compatible with the one the driver was compiled
  3017. * with?
  3018. */
  3019. static int fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
  3020. {
  3021. /* short circuit if it's the exact same firmware version */
  3022. if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
  3023. return 1;
  3024. #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
  3025. if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
  3026. SAME_INTF(ri) && SAME_INTF(iscsi) && SAME_INTF(fcoe))
  3027. return 1;
  3028. #undef SAME_INTF
  3029. return 0;
  3030. }
  3031. /* The firmware in the filesystem is usable, but should it be installed?
  3032. * This routine explains itself in detail if it indicates the filesystem
  3033. * firmware should be installed.
  3034. */
  3035. static int should_install_fs_fw(struct adapter *adap, int card_fw_usable,
  3036. int k, int c)
  3037. {
  3038. const char *reason;
  3039. if (!card_fw_usable) {
  3040. reason = "incompatible or unusable";
  3041. goto install;
  3042. }
  3043. if (k > c) {
  3044. reason = "older than the version supported with this driver";
  3045. goto install;
  3046. }
  3047. return 0;
  3048. install:
  3049. dev_err(adap->pdev_dev, "firmware on card (%u.%u.%u.%u) is %s, "
  3050. "installing firmware %u.%u.%u.%u on card.\n",
  3051. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  3052. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
  3053. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  3054. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  3055. return 1;
  3056. }
  3057. int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
  3058. const u8 *fw_data, unsigned int fw_size,
  3059. struct fw_hdr *card_fw, enum dev_state state,
  3060. int *reset)
  3061. {
  3062. int ret, card_fw_usable, fs_fw_usable;
  3063. const struct fw_hdr *fs_fw;
  3064. const struct fw_hdr *drv_fw;
  3065. drv_fw = &fw_info->fw_hdr;
  3066. /* Read the header of the firmware on the card */
  3067. ret = -t4_read_flash(adap, FLASH_FW_START,
  3068. sizeof(*card_fw) / sizeof(uint32_t),
  3069. (uint32_t *)card_fw, 1);
  3070. if (ret == 0) {
  3071. card_fw_usable = fw_compatible(drv_fw, (const void *)card_fw);
  3072. } else {
  3073. dev_err(adap->pdev_dev,
  3074. "Unable to read card's firmware header: %d\n", ret);
  3075. card_fw_usable = 0;
  3076. }
  3077. if (fw_data != NULL) {
  3078. fs_fw = (const void *)fw_data;
  3079. fs_fw_usable = fw_compatible(drv_fw, fs_fw);
  3080. } else {
  3081. fs_fw = NULL;
  3082. fs_fw_usable = 0;
  3083. }
  3084. if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
  3085. (!fs_fw_usable || fs_fw->fw_ver == drv_fw->fw_ver)) {
  3086. /* Common case: the firmware on the card is an exact match and
  3087. * the filesystem one is an exact match too, or the filesystem
  3088. * one is absent/incompatible.
  3089. */
  3090. } else if (fs_fw_usable && state == DEV_STATE_UNINIT &&
  3091. should_install_fs_fw(adap, card_fw_usable,
  3092. be32_to_cpu(fs_fw->fw_ver),
  3093. be32_to_cpu(card_fw->fw_ver))) {
  3094. ret = -t4_fw_upgrade(adap, adap->mbox, fw_data,
  3095. fw_size, 0);
  3096. if (ret != 0) {
  3097. dev_err(adap->pdev_dev,
  3098. "failed to install firmware: %d\n", ret);
  3099. goto bye;
  3100. }
  3101. /* Installed successfully, update the cached header too. */
  3102. *card_fw = *fs_fw;
  3103. card_fw_usable = 1;
  3104. *reset = 0; /* already reset as part of load_fw */
  3105. }
  3106. if (!card_fw_usable) {
  3107. uint32_t d, c, k;
  3108. d = be32_to_cpu(drv_fw->fw_ver);
  3109. c = be32_to_cpu(card_fw->fw_ver);
  3110. k = fs_fw ? be32_to_cpu(fs_fw->fw_ver) : 0;
  3111. dev_err(adap->pdev_dev, "Cannot find a usable firmware: "
  3112. "chip state %d, "
  3113. "driver compiled with %d.%d.%d.%d, "
  3114. "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
  3115. state,
  3116. FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
  3117. FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
  3118. FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
  3119. FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
  3120. FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
  3121. FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
  3122. ret = EINVAL;
  3123. goto bye;
  3124. }
  3125. /* We're using whatever's on the card and it's known to be good. */
  3126. adap->params.fw_vers = be32_to_cpu(card_fw->fw_ver);
  3127. adap->params.tp_vers = be32_to_cpu(card_fw->tp_microcode_ver);
  3128. bye:
  3129. return ret;
  3130. }
  3131. /**
  3132. * t4_flash_erase_sectors - erase a range of flash sectors
  3133. * @adapter: the adapter
  3134. * @start: the first sector to erase
  3135. * @end: the last sector to erase
  3136. *
  3137. * Erases the sectors in the given inclusive range.
  3138. */
  3139. static int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
  3140. {
  3141. int ret = 0;
  3142. if (end >= adapter->params.sf_nsec)
  3143. return -EINVAL;
  3144. while (start <= end) {
  3145. if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
  3146. (ret = sf1_write(adapter, 4, 0, 1,
  3147. SF_ERASE_SECTOR | (start << 8))) != 0 ||
  3148. (ret = flash_wait_op(adapter, 14, 500)) != 0) {
  3149. dev_err(adapter->pdev_dev,
  3150. "erase of flash sector %d failed, error %d\n",
  3151. start, ret);
  3152. break;
  3153. }
  3154. start++;
  3155. }
  3156. t4_write_reg(adapter, SF_OP_A, 0); /* unlock SF */
  3157. return ret;
  3158. }
  3159. /**
  3160. * t4_flash_cfg_addr - return the address of the flash configuration file
  3161. * @adapter: the adapter
  3162. *
  3163. * Return the address within the flash where the Firmware Configuration
  3164. * File is stored.
  3165. */
  3166. unsigned int t4_flash_cfg_addr(struct adapter *adapter)
  3167. {
  3168. if (adapter->params.sf_size == 0x100000)
  3169. return FLASH_FPGA_CFG_START;
  3170. else
  3171. return FLASH_CFG_START;
  3172. }
  3173. /* Return TRUE if the specified firmware matches the adapter. I.e. T4
  3174. * firmware for T4 adapters, T5 firmware for T5 adapters, etc. We go ahead
  3175. * and emit an error message for mismatched firmware to save our caller the
  3176. * effort ...
  3177. */
  3178. static bool t4_fw_matches_chip(const struct adapter *adap,
  3179. const struct fw_hdr *hdr)
  3180. {
  3181. /* The expression below will return FALSE for any unsupported adapter
  3182. * which will keep us "honest" in the future ...
  3183. */
  3184. if ((is_t4(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T4) ||
  3185. (is_t5(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T5) ||
  3186. (is_t6(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T6))
  3187. return true;
  3188. dev_err(adap->pdev_dev,
  3189. "FW image (%d) is not suitable for this adapter (%d)\n",
  3190. hdr->chip, CHELSIO_CHIP_VERSION(adap->params.chip));
  3191. return false;
  3192. }
  3193. /**
  3194. * t4_load_fw - download firmware
  3195. * @adap: the adapter
  3196. * @fw_data: the firmware image to write
  3197. * @size: image size
  3198. *
  3199. * Write the supplied firmware image to the card's serial flash.
  3200. */
  3201. int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
  3202. {
  3203. u32 csum;
  3204. int ret, addr;
  3205. unsigned int i;
  3206. u8 first_page[SF_PAGE_SIZE];
  3207. const __be32 *p = (const __be32 *)fw_data;
  3208. const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
  3209. unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
  3210. unsigned int fw_img_start = adap->params.sf_fw_start;
  3211. unsigned int fw_start_sec = fw_img_start / sf_sec_size;
  3212. if (!size) {
  3213. dev_err(adap->pdev_dev, "FW image has no data\n");
  3214. return -EINVAL;
  3215. }
  3216. if (size & 511) {
  3217. dev_err(adap->pdev_dev,
  3218. "FW image size not multiple of 512 bytes\n");
  3219. return -EINVAL;
  3220. }
  3221. if ((unsigned int)be16_to_cpu(hdr->len512) * 512 != size) {
  3222. dev_err(adap->pdev_dev,
  3223. "FW image size differs from size in FW header\n");
  3224. return -EINVAL;
  3225. }
  3226. if (size > FW_MAX_SIZE) {
  3227. dev_err(adap->pdev_dev, "FW image too large, max is %u bytes\n",
  3228. FW_MAX_SIZE);
  3229. return -EFBIG;
  3230. }
  3231. if (!t4_fw_matches_chip(adap, hdr))
  3232. return -EINVAL;
  3233. for (csum = 0, i = 0; i < size / sizeof(csum); i++)
  3234. csum += be32_to_cpu(p[i]);
  3235. if (csum != 0xffffffff) {
  3236. dev_err(adap->pdev_dev,
  3237. "corrupted firmware image, checksum %#x\n", csum);
  3238. return -EINVAL;
  3239. }
  3240. i = DIV_ROUND_UP(size, sf_sec_size); /* # of sectors spanned */
  3241. ret = t4_flash_erase_sectors(adap, fw_start_sec, fw_start_sec + i - 1);
  3242. if (ret)
  3243. goto out;
  3244. /*
  3245. * We write the correct version at the end so the driver can see a bad
  3246. * version if the FW write fails. Start by writing a copy of the
  3247. * first page with a bad version.
  3248. */
  3249. memcpy(first_page, fw_data, SF_PAGE_SIZE);
  3250. ((struct fw_hdr *)first_page)->fw_ver = cpu_to_be32(0xffffffff);
  3251. ret = t4_write_flash(adap, fw_img_start, SF_PAGE_SIZE, first_page);
  3252. if (ret)
  3253. goto out;
  3254. addr = fw_img_start;
  3255. for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
  3256. addr += SF_PAGE_SIZE;
  3257. fw_data += SF_PAGE_SIZE;
  3258. ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
  3259. if (ret)
  3260. goto out;
  3261. }
  3262. ret = t4_write_flash(adap,
  3263. fw_img_start + offsetof(struct fw_hdr, fw_ver),
  3264. sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
  3265. out:
  3266. if (ret)
  3267. dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
  3268. ret);
  3269. else
  3270. ret = t4_get_fw_version(adap, &adap->params.fw_vers);
  3271. return ret;
  3272. }
  3273. /**
  3274. * t4_phy_fw_ver - return current PHY firmware version
  3275. * @adap: the adapter
  3276. * @phy_fw_ver: return value buffer for PHY firmware version
  3277. *
  3278. * Returns the current version of external PHY firmware on the
  3279. * adapter.
  3280. */
  3281. int t4_phy_fw_ver(struct adapter *adap, int *phy_fw_ver)
  3282. {
  3283. u32 param, val;
  3284. int ret;
  3285. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3286. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3287. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3288. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_VERSION));
  3289. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3290. &param, &val);
  3291. if (ret < 0)
  3292. return ret;
  3293. *phy_fw_ver = val;
  3294. return 0;
  3295. }
  3296. /**
  3297. * t4_load_phy_fw - download port PHY firmware
  3298. * @adap: the adapter
  3299. * @win: the PCI-E Memory Window index to use for t4_memory_rw()
  3300. * @win_lock: the lock to use to guard the memory copy
  3301. * @phy_fw_version: function to check PHY firmware versions
  3302. * @phy_fw_data: the PHY firmware image to write
  3303. * @phy_fw_size: image size
  3304. *
  3305. * Transfer the specified PHY firmware to the adapter. If a non-NULL
  3306. * @phy_fw_version is supplied, then it will be used to determine if
  3307. * it's necessary to perform the transfer by comparing the version
  3308. * of any existing adapter PHY firmware with that of the passed in
  3309. * PHY firmware image. If @win_lock is non-NULL then it will be used
  3310. * around the call to t4_memory_rw() which transfers the PHY firmware
  3311. * to the adapter.
  3312. *
  3313. * A negative error number will be returned if an error occurs. If
  3314. * version number support is available and there's no need to upgrade
  3315. * the firmware, 0 will be returned. If firmware is successfully
  3316. * transferred to the adapter, 1 will be retured.
  3317. *
  3318. * NOTE: some adapters only have local RAM to store the PHY firmware. As
  3319. * a result, a RESET of the adapter would cause that RAM to lose its
  3320. * contents. Thus, loading PHY firmware on such adapters must happen
  3321. * after any FW_RESET_CMDs ...
  3322. */
  3323. int t4_load_phy_fw(struct adapter *adap,
  3324. int win, spinlock_t *win_lock,
  3325. int (*phy_fw_version)(const u8 *, size_t),
  3326. const u8 *phy_fw_data, size_t phy_fw_size)
  3327. {
  3328. unsigned long mtype = 0, maddr = 0;
  3329. u32 param, val;
  3330. int cur_phy_fw_ver = 0, new_phy_fw_vers = 0;
  3331. int ret;
  3332. /* If we have version number support, then check to see if the adapter
  3333. * already has up-to-date PHY firmware loaded.
  3334. */
  3335. if (phy_fw_version) {
  3336. new_phy_fw_vers = phy_fw_version(phy_fw_data, phy_fw_size);
  3337. ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3338. if (ret < 0)
  3339. return ret;
  3340. if (cur_phy_fw_ver >= new_phy_fw_vers) {
  3341. CH_WARN(adap, "PHY Firmware already up-to-date, "
  3342. "version %#x\n", cur_phy_fw_ver);
  3343. return 0;
  3344. }
  3345. }
  3346. /* Ask the firmware where it wants us to copy the PHY firmware image.
  3347. * The size of the file requires a special version of the READ coommand
  3348. * which will pass the file size via the values field in PARAMS_CMD and
  3349. * retrieve the return value from firmware and place it in the same
  3350. * buffer values
  3351. */
  3352. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3353. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3354. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3355. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
  3356. val = phy_fw_size;
  3357. ret = t4_query_params_rw(adap, adap->mbox, adap->pf, 0, 1,
  3358. &param, &val, 1);
  3359. if (ret < 0)
  3360. return ret;
  3361. mtype = val >> 8;
  3362. maddr = (val & 0xff) << 16;
  3363. /* Copy the supplied PHY Firmware image to the adapter memory location
  3364. * allocated by the adapter firmware.
  3365. */
  3366. if (win_lock)
  3367. spin_lock_bh(win_lock);
  3368. ret = t4_memory_rw(adap, win, mtype, maddr,
  3369. phy_fw_size, (__be32 *)phy_fw_data,
  3370. T4_MEMORY_WRITE);
  3371. if (win_lock)
  3372. spin_unlock_bh(win_lock);
  3373. if (ret)
  3374. return ret;
  3375. /* Tell the firmware that the PHY firmware image has been written to
  3376. * RAM and it can now start copying it over to the PHYs. The chip
  3377. * firmware will RESET the affected PHYs as part of this operation
  3378. * leaving them running the new PHY firmware image.
  3379. */
  3380. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3381. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
  3382. FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
  3383. FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
  3384. ret = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  3385. &param, &val, 30000);
  3386. /* If we have version number support, then check to see that the new
  3387. * firmware got loaded properly.
  3388. */
  3389. if (phy_fw_version) {
  3390. ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3391. if (ret < 0)
  3392. return ret;
  3393. if (cur_phy_fw_ver != new_phy_fw_vers) {
  3394. CH_WARN(adap, "PHY Firmware did not update: "
  3395. "version on adapter %#x, "
  3396. "version flashed %#x\n",
  3397. cur_phy_fw_ver, new_phy_fw_vers);
  3398. return -ENXIO;
  3399. }
  3400. }
  3401. return 1;
  3402. }
  3403. /**
  3404. * t4_fwcache - firmware cache operation
  3405. * @adap: the adapter
  3406. * @op : the operation (flush or flush and invalidate)
  3407. */
  3408. int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op)
  3409. {
  3410. struct fw_params_cmd c;
  3411. memset(&c, 0, sizeof(c));
  3412. c.op_to_vfn =
  3413. cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  3414. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  3415. FW_PARAMS_CMD_PFN_V(adap->pf) |
  3416. FW_PARAMS_CMD_VFN_V(0));
  3417. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  3418. c.param[0].mnem =
  3419. cpu_to_be32(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3420. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FWCACHE));
  3421. c.param[0].val = (__force __be32)op;
  3422. return t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), NULL);
  3423. }
  3424. void t4_cim_read_pif_la(struct adapter *adap, u32 *pif_req, u32 *pif_rsp,
  3425. unsigned int *pif_req_wrptr,
  3426. unsigned int *pif_rsp_wrptr)
  3427. {
  3428. int i, j;
  3429. u32 cfg, val, req, rsp;
  3430. cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
  3431. if (cfg & LADBGEN_F)
  3432. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
  3433. val = t4_read_reg(adap, CIM_DEBUGSTS_A);
  3434. req = POLADBGWRPTR_G(val);
  3435. rsp = PILADBGWRPTR_G(val);
  3436. if (pif_req_wrptr)
  3437. *pif_req_wrptr = req;
  3438. if (pif_rsp_wrptr)
  3439. *pif_rsp_wrptr = rsp;
  3440. for (i = 0; i < CIM_PIFLA_SIZE; i++) {
  3441. for (j = 0; j < 6; j++) {
  3442. t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(req) |
  3443. PILADBGRDPTR_V(rsp));
  3444. *pif_req++ = t4_read_reg(adap, CIM_PO_LA_DEBUGDATA_A);
  3445. *pif_rsp++ = t4_read_reg(adap, CIM_PI_LA_DEBUGDATA_A);
  3446. req++;
  3447. rsp++;
  3448. }
  3449. req = (req + 2) & POLADBGRDPTR_M;
  3450. rsp = (rsp + 2) & PILADBGRDPTR_M;
  3451. }
  3452. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
  3453. }
  3454. void t4_cim_read_ma_la(struct adapter *adap, u32 *ma_req, u32 *ma_rsp)
  3455. {
  3456. u32 cfg;
  3457. int i, j, idx;
  3458. cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
  3459. if (cfg & LADBGEN_F)
  3460. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
  3461. for (i = 0; i < CIM_MALA_SIZE; i++) {
  3462. for (j = 0; j < 5; j++) {
  3463. idx = 8 * i + j;
  3464. t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(idx) |
  3465. PILADBGRDPTR_V(idx));
  3466. *ma_req++ = t4_read_reg(adap, CIM_PO_LA_MADEBUGDATA_A);
  3467. *ma_rsp++ = t4_read_reg(adap, CIM_PI_LA_MADEBUGDATA_A);
  3468. }
  3469. }
  3470. t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
  3471. }
  3472. void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf)
  3473. {
  3474. unsigned int i, j;
  3475. for (i = 0; i < 8; i++) {
  3476. u32 *p = la_buf + i;
  3477. t4_write_reg(adap, ULP_RX_LA_CTL_A, i);
  3478. j = t4_read_reg(adap, ULP_RX_LA_WRPTR_A);
  3479. t4_write_reg(adap, ULP_RX_LA_RDPTR_A, j);
  3480. for (j = 0; j < ULPRX_LA_SIZE; j++, p += 8)
  3481. *p = t4_read_reg(adap, ULP_RX_LA_RDDATA_A);
  3482. }
  3483. }
  3484. #define ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
  3485. FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_SPEED_25G | \
  3486. FW_PORT_CAP_SPEED_40G | FW_PORT_CAP_SPEED_100G | \
  3487. FW_PORT_CAP_ANEG)
  3488. /**
  3489. * t4_link_l1cfg - apply link configuration to MAC/PHY
  3490. * @phy: the PHY to setup
  3491. * @mac: the MAC to setup
  3492. * @lc: the requested link configuration
  3493. *
  3494. * Set up a port's MAC and PHY according to a desired link configuration.
  3495. * - If the PHY can auto-negotiate first decide what to advertise, then
  3496. * enable/disable auto-negotiation as desired, and reset.
  3497. * - If the PHY does not auto-negotiate just reset it.
  3498. * - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  3499. * otherwise do it later based on the outcome of auto-negotiation.
  3500. */
  3501. int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
  3502. struct link_config *lc)
  3503. {
  3504. struct fw_port_cmd c;
  3505. unsigned int mdi = FW_PORT_CAP_MDI_V(FW_PORT_CAP_MDI_AUTO);
  3506. unsigned int fc = 0, fec = 0, fw_fec = 0;
  3507. lc->link_ok = 0;
  3508. if (lc->requested_fc & PAUSE_RX)
  3509. fc |= FW_PORT_CAP_FC_RX;
  3510. if (lc->requested_fc & PAUSE_TX)
  3511. fc |= FW_PORT_CAP_FC_TX;
  3512. fec = lc->requested_fec & FEC_AUTO ? lc->auto_fec : lc->requested_fec;
  3513. if (fec & FEC_RS)
  3514. fw_fec |= FW_PORT_CAP_FEC_RS;
  3515. if (fec & FEC_BASER_RS)
  3516. fw_fec |= FW_PORT_CAP_FEC_BASER_RS;
  3517. memset(&c, 0, sizeof(c));
  3518. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  3519. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  3520. FW_PORT_CMD_PORTID_V(port));
  3521. c.action_to_len16 =
  3522. cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  3523. FW_LEN16(c));
  3524. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  3525. c.u.l1cfg.rcap = cpu_to_be32((lc->supported & ADVERT_MASK) |
  3526. fc | fw_fec);
  3527. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  3528. } else if (lc->autoneg == AUTONEG_DISABLE) {
  3529. c.u.l1cfg.rcap = cpu_to_be32(lc->requested_speed | fc |
  3530. fw_fec | mdi);
  3531. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  3532. } else
  3533. c.u.l1cfg.rcap = cpu_to_be32(lc->advertising | fc |
  3534. fw_fec | mdi);
  3535. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3536. }
  3537. /**
  3538. * t4_restart_aneg - restart autonegotiation
  3539. * @adap: the adapter
  3540. * @mbox: mbox to use for the FW command
  3541. * @port: the port id
  3542. *
  3543. * Restarts autonegotiation for the selected port.
  3544. */
  3545. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
  3546. {
  3547. struct fw_port_cmd c;
  3548. memset(&c, 0, sizeof(c));
  3549. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  3550. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  3551. FW_PORT_CMD_PORTID_V(port));
  3552. c.action_to_len16 =
  3553. cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
  3554. FW_LEN16(c));
  3555. c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP_ANEG);
  3556. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  3557. }
  3558. typedef void (*int_handler_t)(struct adapter *adap);
  3559. struct intr_info {
  3560. unsigned int mask; /* bits to check in interrupt status */
  3561. const char *msg; /* message to print or NULL */
  3562. short stat_idx; /* stat counter to increment or -1 */
  3563. unsigned short fatal; /* whether the condition reported is fatal */
  3564. int_handler_t int_handler; /* platform-specific int handler */
  3565. };
  3566. /**
  3567. * t4_handle_intr_status - table driven interrupt handler
  3568. * @adapter: the adapter that generated the interrupt
  3569. * @reg: the interrupt status register to process
  3570. * @acts: table of interrupt actions
  3571. *
  3572. * A table driven interrupt handler that applies a set of masks to an
  3573. * interrupt status word and performs the corresponding actions if the
  3574. * interrupts described by the mask have occurred. The actions include
  3575. * optionally emitting a warning or alert message. The table is terminated
  3576. * by an entry specifying mask 0. Returns the number of fatal interrupt
  3577. * conditions.
  3578. */
  3579. static int t4_handle_intr_status(struct adapter *adapter, unsigned int reg,
  3580. const struct intr_info *acts)
  3581. {
  3582. int fatal = 0;
  3583. unsigned int mask = 0;
  3584. unsigned int status = t4_read_reg(adapter, reg);
  3585. for ( ; acts->mask; ++acts) {
  3586. if (!(status & acts->mask))
  3587. continue;
  3588. if (acts->fatal) {
  3589. fatal++;
  3590. dev_alert(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  3591. status & acts->mask);
  3592. } else if (acts->msg && printk_ratelimit())
  3593. dev_warn(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
  3594. status & acts->mask);
  3595. if (acts->int_handler)
  3596. acts->int_handler(adapter);
  3597. mask |= acts->mask;
  3598. }
  3599. status &= mask;
  3600. if (status) /* clear processed interrupts */
  3601. t4_write_reg(adapter, reg, status);
  3602. return fatal;
  3603. }
  3604. /*
  3605. * Interrupt handler for the PCIE module.
  3606. */
  3607. static void pcie_intr_handler(struct adapter *adapter)
  3608. {
  3609. static const struct intr_info sysbus_intr_info[] = {
  3610. { RNPP_F, "RXNP array parity error", -1, 1 },
  3611. { RPCP_F, "RXPC array parity error", -1, 1 },
  3612. { RCIP_F, "RXCIF array parity error", -1, 1 },
  3613. { RCCP_F, "Rx completions control array parity error", -1, 1 },
  3614. { RFTP_F, "RXFT array parity error", -1, 1 },
  3615. { 0 }
  3616. };
  3617. static const struct intr_info pcie_port_intr_info[] = {
  3618. { TPCP_F, "TXPC array parity error", -1, 1 },
  3619. { TNPP_F, "TXNP array parity error", -1, 1 },
  3620. { TFTP_F, "TXFT array parity error", -1, 1 },
  3621. { TCAP_F, "TXCA array parity error", -1, 1 },
  3622. { TCIP_F, "TXCIF array parity error", -1, 1 },
  3623. { RCAP_F, "RXCA array parity error", -1, 1 },
  3624. { OTDD_F, "outbound request TLP discarded", -1, 1 },
  3625. { RDPE_F, "Rx data parity error", -1, 1 },
  3626. { TDUE_F, "Tx uncorrectable data error", -1, 1 },
  3627. { 0 }
  3628. };
  3629. static const struct intr_info pcie_intr_info[] = {
  3630. { MSIADDRLPERR_F, "MSI AddrL parity error", -1, 1 },
  3631. { MSIADDRHPERR_F, "MSI AddrH parity error", -1, 1 },
  3632. { MSIDATAPERR_F, "MSI data parity error", -1, 1 },
  3633. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  3634. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  3635. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  3636. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  3637. { PIOCPLPERR_F, "PCI PIO completion FIFO parity error", -1, 1 },
  3638. { PIOREQPERR_F, "PCI PIO request FIFO parity error", -1, 1 },
  3639. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  3640. { CCNTPERR_F, "PCI CMD channel count parity error", -1, 1 },
  3641. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  3642. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  3643. { DCNTPERR_F, "PCI DMA channel count parity error", -1, 1 },
  3644. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  3645. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  3646. { HCNTPERR_F, "PCI HMA channel count parity error", -1, 1 },
  3647. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  3648. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  3649. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  3650. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  3651. { INTXCLRPERR_F, "PCI INTx clear parity error", -1, 1 },
  3652. { MATAGPERR_F, "PCI MA tag parity error", -1, 1 },
  3653. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  3654. { RXCPLPERR_F, "PCI Rx completion parity error", -1, 1 },
  3655. { RXWRPERR_F, "PCI Rx write parity error", -1, 1 },
  3656. { RPLPERR_F, "PCI replay buffer parity error", -1, 1 },
  3657. { PCIESINT_F, "PCI core secondary fault", -1, 1 },
  3658. { PCIEPINT_F, "PCI core primary fault", -1, 1 },
  3659. { UNXSPLCPLERR_F, "PCI unexpected split completion error",
  3660. -1, 0 },
  3661. { 0 }
  3662. };
  3663. static struct intr_info t5_pcie_intr_info[] = {
  3664. { MSTGRPPERR_F, "Master Response Read Queue parity error",
  3665. -1, 1 },
  3666. { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
  3667. { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
  3668. { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
  3669. { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
  3670. { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
  3671. { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
  3672. { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
  3673. -1, 1 },
  3674. { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
  3675. -1, 1 },
  3676. { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
  3677. { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
  3678. { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
  3679. { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
  3680. { DREQWRPERR_F, "PCI DMA channel write request parity error",
  3681. -1, 1 },
  3682. { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
  3683. { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
  3684. { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
  3685. { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
  3686. { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
  3687. { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
  3688. { FIDPERR_F, "PCI FID parity error", -1, 1 },
  3689. { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
  3690. { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
  3691. { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
  3692. { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
  3693. -1, 1 },
  3694. { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
  3695. -1, 1 },
  3696. { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
  3697. { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
  3698. { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
  3699. { READRSPERR_F, "Outbound read error", -1, 0 },
  3700. { 0 }
  3701. };
  3702. int fat;
  3703. if (is_t4(adapter->params.chip))
  3704. fat = t4_handle_intr_status(adapter,
  3705. PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS_A,
  3706. sysbus_intr_info) +
  3707. t4_handle_intr_status(adapter,
  3708. PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS_A,
  3709. pcie_port_intr_info) +
  3710. t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  3711. pcie_intr_info);
  3712. else
  3713. fat = t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
  3714. t5_pcie_intr_info);
  3715. if (fat)
  3716. t4_fatal_err(adapter);
  3717. }
  3718. /*
  3719. * TP interrupt handler.
  3720. */
  3721. static void tp_intr_handler(struct adapter *adapter)
  3722. {
  3723. static const struct intr_info tp_intr_info[] = {
  3724. { 0x3fffffff, "TP parity error", -1, 1 },
  3725. { FLMTXFLSTEMPTY_F, "TP out of Tx pages", -1, 1 },
  3726. { 0 }
  3727. };
  3728. if (t4_handle_intr_status(adapter, TP_INT_CAUSE_A, tp_intr_info))
  3729. t4_fatal_err(adapter);
  3730. }
  3731. /*
  3732. * SGE interrupt handler.
  3733. */
  3734. static void sge_intr_handler(struct adapter *adapter)
  3735. {
  3736. u64 v;
  3737. u32 err;
  3738. static const struct intr_info sge_intr_info[] = {
  3739. { ERR_CPL_EXCEED_IQE_SIZE_F,
  3740. "SGE received CPL exceeding IQE size", -1, 1 },
  3741. { ERR_INVALID_CIDX_INC_F,
  3742. "SGE GTS CIDX increment too large", -1, 0 },
  3743. { ERR_CPL_OPCODE_0_F, "SGE received 0-length CPL", -1, 0 },
  3744. { DBFIFO_LP_INT_F, NULL, -1, 0, t4_db_full },
  3745. { ERR_DATA_CPL_ON_HIGH_QID1_F | ERR_DATA_CPL_ON_HIGH_QID0_F,
  3746. "SGE IQID > 1023 received CPL for FL", -1, 0 },
  3747. { ERR_BAD_DB_PIDX3_F, "SGE DBP 3 pidx increment too large", -1,
  3748. 0 },
  3749. { ERR_BAD_DB_PIDX2_F, "SGE DBP 2 pidx increment too large", -1,
  3750. 0 },
  3751. { ERR_BAD_DB_PIDX1_F, "SGE DBP 1 pidx increment too large", -1,
  3752. 0 },
  3753. { ERR_BAD_DB_PIDX0_F, "SGE DBP 0 pidx increment too large", -1,
  3754. 0 },
  3755. { ERR_ING_CTXT_PRIO_F,
  3756. "SGE too many priority ingress contexts", -1, 0 },
  3757. { INGRESS_SIZE_ERR_F, "SGE illegal ingress QID", -1, 0 },
  3758. { EGRESS_SIZE_ERR_F, "SGE illegal egress QID", -1, 0 },
  3759. { 0 }
  3760. };
  3761. static struct intr_info t4t5_sge_intr_info[] = {
  3762. { ERR_DROPPED_DB_F, NULL, -1, 0, t4_db_dropped },
  3763. { DBFIFO_HP_INT_F, NULL, -1, 0, t4_db_full },
  3764. { ERR_EGR_CTXT_PRIO_F,
  3765. "SGE too many priority egress contexts", -1, 0 },
  3766. { 0 }
  3767. };
  3768. v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1_A) |
  3769. ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2_A) << 32);
  3770. if (v) {
  3771. dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
  3772. (unsigned long long)v);
  3773. t4_write_reg(adapter, SGE_INT_CAUSE1_A, v);
  3774. t4_write_reg(adapter, SGE_INT_CAUSE2_A, v >> 32);
  3775. }
  3776. v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A, sge_intr_info);
  3777. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  3778. v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A,
  3779. t4t5_sge_intr_info);
  3780. err = t4_read_reg(adapter, SGE_ERROR_STATS_A);
  3781. if (err & ERROR_QID_VALID_F) {
  3782. dev_err(adapter->pdev_dev, "SGE error for queue %u\n",
  3783. ERROR_QID_G(err));
  3784. if (err & UNCAPTURED_ERROR_F)
  3785. dev_err(adapter->pdev_dev,
  3786. "SGE UNCAPTURED_ERROR set (clearing)\n");
  3787. t4_write_reg(adapter, SGE_ERROR_STATS_A, ERROR_QID_VALID_F |
  3788. UNCAPTURED_ERROR_F);
  3789. }
  3790. if (v != 0)
  3791. t4_fatal_err(adapter);
  3792. }
  3793. #define CIM_OBQ_INTR (OBQULP0PARERR_F | OBQULP1PARERR_F | OBQULP2PARERR_F |\
  3794. OBQULP3PARERR_F | OBQSGEPARERR_F | OBQNCSIPARERR_F)
  3795. #define CIM_IBQ_INTR (IBQTP0PARERR_F | IBQTP1PARERR_F | IBQULPPARERR_F |\
  3796. IBQSGEHIPARERR_F | IBQSGELOPARERR_F | IBQNCSIPARERR_F)
  3797. /*
  3798. * CIM interrupt handler.
  3799. */
  3800. static void cim_intr_handler(struct adapter *adapter)
  3801. {
  3802. static const struct intr_info cim_intr_info[] = {
  3803. { PREFDROPINT_F, "CIM control register prefetch drop", -1, 1 },
  3804. { CIM_OBQ_INTR, "CIM OBQ parity error", -1, 1 },
  3805. { CIM_IBQ_INTR, "CIM IBQ parity error", -1, 1 },
  3806. { MBUPPARERR_F, "CIM mailbox uP parity error", -1, 1 },
  3807. { MBHOSTPARERR_F, "CIM mailbox host parity error", -1, 1 },
  3808. { TIEQINPARERRINT_F, "CIM TIEQ outgoing parity error", -1, 1 },
  3809. { TIEQOUTPARERRINT_F, "CIM TIEQ incoming parity error", -1, 1 },
  3810. { 0 }
  3811. };
  3812. static const struct intr_info cim_upintr_info[] = {
  3813. { RSVDSPACEINT_F, "CIM reserved space access", -1, 1 },
  3814. { ILLTRANSINT_F, "CIM illegal transaction", -1, 1 },
  3815. { ILLWRINT_F, "CIM illegal write", -1, 1 },
  3816. { ILLRDINT_F, "CIM illegal read", -1, 1 },
  3817. { ILLRDBEINT_F, "CIM illegal read BE", -1, 1 },
  3818. { ILLWRBEINT_F, "CIM illegal write BE", -1, 1 },
  3819. { SGLRDBOOTINT_F, "CIM single read from boot space", -1, 1 },
  3820. { SGLWRBOOTINT_F, "CIM single write to boot space", -1, 1 },
  3821. { BLKWRBOOTINT_F, "CIM block write to boot space", -1, 1 },
  3822. { SGLRDFLASHINT_F, "CIM single read from flash space", -1, 1 },
  3823. { SGLWRFLASHINT_F, "CIM single write to flash space", -1, 1 },
  3824. { BLKWRFLASHINT_F, "CIM block write to flash space", -1, 1 },
  3825. { SGLRDEEPROMINT_F, "CIM single EEPROM read", -1, 1 },
  3826. { SGLWREEPROMINT_F, "CIM single EEPROM write", -1, 1 },
  3827. { BLKRDEEPROMINT_F, "CIM block EEPROM read", -1, 1 },
  3828. { BLKWREEPROMINT_F, "CIM block EEPROM write", -1, 1 },
  3829. { SGLRDCTLINT_F, "CIM single read from CTL space", -1, 1 },
  3830. { SGLWRCTLINT_F, "CIM single write to CTL space", -1, 1 },
  3831. { BLKRDCTLINT_F, "CIM block read from CTL space", -1, 1 },
  3832. { BLKWRCTLINT_F, "CIM block write to CTL space", -1, 1 },
  3833. { SGLRDPLINT_F, "CIM single read from PL space", -1, 1 },
  3834. { SGLWRPLINT_F, "CIM single write to PL space", -1, 1 },
  3835. { BLKRDPLINT_F, "CIM block read from PL space", -1, 1 },
  3836. { BLKWRPLINT_F, "CIM block write to PL space", -1, 1 },
  3837. { REQOVRLOOKUPINT_F, "CIM request FIFO overwrite", -1, 1 },
  3838. { RSPOVRLOOKUPINT_F, "CIM response FIFO overwrite", -1, 1 },
  3839. { TIMEOUTINT_F, "CIM PIF timeout", -1, 1 },
  3840. { TIMEOUTMAINT_F, "CIM PIF MA timeout", -1, 1 },
  3841. { 0 }
  3842. };
  3843. int fat;
  3844. if (t4_read_reg(adapter, PCIE_FW_A) & PCIE_FW_ERR_F)
  3845. t4_report_fw_error(adapter);
  3846. fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE_A,
  3847. cim_intr_info) +
  3848. t4_handle_intr_status(adapter, CIM_HOST_UPACC_INT_CAUSE_A,
  3849. cim_upintr_info);
  3850. if (fat)
  3851. t4_fatal_err(adapter);
  3852. }
  3853. /*
  3854. * ULP RX interrupt handler.
  3855. */
  3856. static void ulprx_intr_handler(struct adapter *adapter)
  3857. {
  3858. static const struct intr_info ulprx_intr_info[] = {
  3859. { 0x1800000, "ULPRX context error", -1, 1 },
  3860. { 0x7fffff, "ULPRX parity error", -1, 1 },
  3861. { 0 }
  3862. };
  3863. if (t4_handle_intr_status(adapter, ULP_RX_INT_CAUSE_A, ulprx_intr_info))
  3864. t4_fatal_err(adapter);
  3865. }
  3866. /*
  3867. * ULP TX interrupt handler.
  3868. */
  3869. static void ulptx_intr_handler(struct adapter *adapter)
  3870. {
  3871. static const struct intr_info ulptx_intr_info[] = {
  3872. { PBL_BOUND_ERR_CH3_F, "ULPTX channel 3 PBL out of bounds", -1,
  3873. 0 },
  3874. { PBL_BOUND_ERR_CH2_F, "ULPTX channel 2 PBL out of bounds", -1,
  3875. 0 },
  3876. { PBL_BOUND_ERR_CH1_F, "ULPTX channel 1 PBL out of bounds", -1,
  3877. 0 },
  3878. { PBL_BOUND_ERR_CH0_F, "ULPTX channel 0 PBL out of bounds", -1,
  3879. 0 },
  3880. { 0xfffffff, "ULPTX parity error", -1, 1 },
  3881. { 0 }
  3882. };
  3883. if (t4_handle_intr_status(adapter, ULP_TX_INT_CAUSE_A, ulptx_intr_info))
  3884. t4_fatal_err(adapter);
  3885. }
  3886. /*
  3887. * PM TX interrupt handler.
  3888. */
  3889. static void pmtx_intr_handler(struct adapter *adapter)
  3890. {
  3891. static const struct intr_info pmtx_intr_info[] = {
  3892. { PCMD_LEN_OVFL0_F, "PMTX channel 0 pcmd too large", -1, 1 },
  3893. { PCMD_LEN_OVFL1_F, "PMTX channel 1 pcmd too large", -1, 1 },
  3894. { PCMD_LEN_OVFL2_F, "PMTX channel 2 pcmd too large", -1, 1 },
  3895. { ZERO_C_CMD_ERROR_F, "PMTX 0-length pcmd", -1, 1 },
  3896. { PMTX_FRAMING_ERROR_F, "PMTX framing error", -1, 1 },
  3897. { OESPI_PAR_ERROR_F, "PMTX oespi parity error", -1, 1 },
  3898. { DB_OPTIONS_PAR_ERROR_F, "PMTX db_options parity error",
  3899. -1, 1 },
  3900. { ICSPI_PAR_ERROR_F, "PMTX icspi parity error", -1, 1 },
  3901. { PMTX_C_PCMD_PAR_ERROR_F, "PMTX c_pcmd parity error", -1, 1},
  3902. { 0 }
  3903. };
  3904. if (t4_handle_intr_status(adapter, PM_TX_INT_CAUSE_A, pmtx_intr_info))
  3905. t4_fatal_err(adapter);
  3906. }
  3907. /*
  3908. * PM RX interrupt handler.
  3909. */
  3910. static void pmrx_intr_handler(struct adapter *adapter)
  3911. {
  3912. static const struct intr_info pmrx_intr_info[] = {
  3913. { ZERO_E_CMD_ERROR_F, "PMRX 0-length pcmd", -1, 1 },
  3914. { PMRX_FRAMING_ERROR_F, "PMRX framing error", -1, 1 },
  3915. { OCSPI_PAR_ERROR_F, "PMRX ocspi parity error", -1, 1 },
  3916. { DB_OPTIONS_PAR_ERROR_F, "PMRX db_options parity error",
  3917. -1, 1 },
  3918. { IESPI_PAR_ERROR_F, "PMRX iespi parity error", -1, 1 },
  3919. { PMRX_E_PCMD_PAR_ERROR_F, "PMRX e_pcmd parity error", -1, 1},
  3920. { 0 }
  3921. };
  3922. if (t4_handle_intr_status(adapter, PM_RX_INT_CAUSE_A, pmrx_intr_info))
  3923. t4_fatal_err(adapter);
  3924. }
  3925. /*
  3926. * CPL switch interrupt handler.
  3927. */
  3928. static void cplsw_intr_handler(struct adapter *adapter)
  3929. {
  3930. static const struct intr_info cplsw_intr_info[] = {
  3931. { CIM_OP_MAP_PERR_F, "CPLSW CIM op_map parity error", -1, 1 },
  3932. { CIM_OVFL_ERROR_F, "CPLSW CIM overflow", -1, 1 },
  3933. { TP_FRAMING_ERROR_F, "CPLSW TP framing error", -1, 1 },
  3934. { SGE_FRAMING_ERROR_F, "CPLSW SGE framing error", -1, 1 },
  3935. { CIM_FRAMING_ERROR_F, "CPLSW CIM framing error", -1, 1 },
  3936. { ZERO_SWITCH_ERROR_F, "CPLSW no-switch error", -1, 1 },
  3937. { 0 }
  3938. };
  3939. if (t4_handle_intr_status(adapter, CPL_INTR_CAUSE_A, cplsw_intr_info))
  3940. t4_fatal_err(adapter);
  3941. }
  3942. /*
  3943. * LE interrupt handler.
  3944. */
  3945. static void le_intr_handler(struct adapter *adap)
  3946. {
  3947. enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
  3948. static const struct intr_info le_intr_info[] = {
  3949. { LIPMISS_F, "LE LIP miss", -1, 0 },
  3950. { LIP0_F, "LE 0 LIP error", -1, 0 },
  3951. { PARITYERR_F, "LE parity error", -1, 1 },
  3952. { UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  3953. { REQQPARERR_F, "LE request queue parity error", -1, 1 },
  3954. { 0 }
  3955. };
  3956. static struct intr_info t6_le_intr_info[] = {
  3957. { T6_LIPMISS_F, "LE LIP miss", -1, 0 },
  3958. { T6_LIP0_F, "LE 0 LIP error", -1, 0 },
  3959. { TCAMINTPERR_F, "LE parity error", -1, 1 },
  3960. { T6_UNKNOWNCMD_F, "LE unknown command", -1, 1 },
  3961. { SSRAMINTPERR_F, "LE request queue parity error", -1, 1 },
  3962. { 0 }
  3963. };
  3964. if (t4_handle_intr_status(adap, LE_DB_INT_CAUSE_A,
  3965. (chip <= CHELSIO_T5) ?
  3966. le_intr_info : t6_le_intr_info))
  3967. t4_fatal_err(adap);
  3968. }
  3969. /*
  3970. * MPS interrupt handler.
  3971. */
  3972. static void mps_intr_handler(struct adapter *adapter)
  3973. {
  3974. static const struct intr_info mps_rx_intr_info[] = {
  3975. { 0xffffff, "MPS Rx parity error", -1, 1 },
  3976. { 0 }
  3977. };
  3978. static const struct intr_info mps_tx_intr_info[] = {
  3979. { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
  3980. { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
  3981. { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
  3982. -1, 1 },
  3983. { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
  3984. -1, 1 },
  3985. { BUBBLE_F, "MPS Tx underflow", -1, 1 },
  3986. { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
  3987. { FRMERR_F, "MPS Tx framing error", -1, 1 },
  3988. { 0 }
  3989. };
  3990. static const struct intr_info mps_trc_intr_info[] = {
  3991. { FILTMEM_V(FILTMEM_M), "MPS TRC filter parity error", -1, 1 },
  3992. { PKTFIFO_V(PKTFIFO_M), "MPS TRC packet FIFO parity error",
  3993. -1, 1 },
  3994. { MISCPERR_F, "MPS TRC misc parity error", -1, 1 },
  3995. { 0 }
  3996. };
  3997. static const struct intr_info mps_stat_sram_intr_info[] = {
  3998. { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
  3999. { 0 }
  4000. };
  4001. static const struct intr_info mps_stat_tx_intr_info[] = {
  4002. { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
  4003. { 0 }
  4004. };
  4005. static const struct intr_info mps_stat_rx_intr_info[] = {
  4006. { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
  4007. { 0 }
  4008. };
  4009. static const struct intr_info mps_cls_intr_info[] = {
  4010. { MATCHSRAM_F, "MPS match SRAM parity error", -1, 1 },
  4011. { MATCHTCAM_F, "MPS match TCAM parity error", -1, 1 },
  4012. { HASHSRAM_F, "MPS hash SRAM parity error", -1, 1 },
  4013. { 0 }
  4014. };
  4015. int fat;
  4016. fat = t4_handle_intr_status(adapter, MPS_RX_PERR_INT_CAUSE_A,
  4017. mps_rx_intr_info) +
  4018. t4_handle_intr_status(adapter, MPS_TX_INT_CAUSE_A,
  4019. mps_tx_intr_info) +
  4020. t4_handle_intr_status(adapter, MPS_TRC_INT_CAUSE_A,
  4021. mps_trc_intr_info) +
  4022. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_SRAM_A,
  4023. mps_stat_sram_intr_info) +
  4024. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_TX_FIFO_A,
  4025. mps_stat_tx_intr_info) +
  4026. t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_RX_FIFO_A,
  4027. mps_stat_rx_intr_info) +
  4028. t4_handle_intr_status(adapter, MPS_CLS_INT_CAUSE_A,
  4029. mps_cls_intr_info);
  4030. t4_write_reg(adapter, MPS_INT_CAUSE_A, 0);
  4031. t4_read_reg(adapter, MPS_INT_CAUSE_A); /* flush */
  4032. if (fat)
  4033. t4_fatal_err(adapter);
  4034. }
  4035. #define MEM_INT_MASK (PERR_INT_CAUSE_F | ECC_CE_INT_CAUSE_F | \
  4036. ECC_UE_INT_CAUSE_F)
  4037. /*
  4038. * EDC/MC interrupt handler.
  4039. */
  4040. static void mem_intr_handler(struct adapter *adapter, int idx)
  4041. {
  4042. static const char name[4][7] = { "EDC0", "EDC1", "MC/MC0", "MC1" };
  4043. unsigned int addr, cnt_addr, v;
  4044. if (idx <= MEM_EDC1) {
  4045. addr = EDC_REG(EDC_INT_CAUSE_A, idx);
  4046. cnt_addr = EDC_REG(EDC_ECC_STATUS_A, idx);
  4047. } else if (idx == MEM_MC) {
  4048. if (is_t4(adapter->params.chip)) {
  4049. addr = MC_INT_CAUSE_A;
  4050. cnt_addr = MC_ECC_STATUS_A;
  4051. } else {
  4052. addr = MC_P_INT_CAUSE_A;
  4053. cnt_addr = MC_P_ECC_STATUS_A;
  4054. }
  4055. } else {
  4056. addr = MC_REG(MC_P_INT_CAUSE_A, 1);
  4057. cnt_addr = MC_REG(MC_P_ECC_STATUS_A, 1);
  4058. }
  4059. v = t4_read_reg(adapter, addr) & MEM_INT_MASK;
  4060. if (v & PERR_INT_CAUSE_F)
  4061. dev_alert(adapter->pdev_dev, "%s FIFO parity error\n",
  4062. name[idx]);
  4063. if (v & ECC_CE_INT_CAUSE_F) {
  4064. u32 cnt = ECC_CECNT_G(t4_read_reg(adapter, cnt_addr));
  4065. t4_edc_err_read(adapter, idx);
  4066. t4_write_reg(adapter, cnt_addr, ECC_CECNT_V(ECC_CECNT_M));
  4067. if (printk_ratelimit())
  4068. dev_warn(adapter->pdev_dev,
  4069. "%u %s correctable ECC data error%s\n",
  4070. cnt, name[idx], cnt > 1 ? "s" : "");
  4071. }
  4072. if (v & ECC_UE_INT_CAUSE_F)
  4073. dev_alert(adapter->pdev_dev,
  4074. "%s uncorrectable ECC data error\n", name[idx]);
  4075. t4_write_reg(adapter, addr, v);
  4076. if (v & (PERR_INT_CAUSE_F | ECC_UE_INT_CAUSE_F))
  4077. t4_fatal_err(adapter);
  4078. }
  4079. /*
  4080. * MA interrupt handler.
  4081. */
  4082. static void ma_intr_handler(struct adapter *adap)
  4083. {
  4084. u32 v, status = t4_read_reg(adap, MA_INT_CAUSE_A);
  4085. if (status & MEM_PERR_INT_CAUSE_F) {
  4086. dev_alert(adap->pdev_dev,
  4087. "MA parity error, parity status %#x\n",
  4088. t4_read_reg(adap, MA_PARITY_ERROR_STATUS1_A));
  4089. if (is_t5(adap->params.chip))
  4090. dev_alert(adap->pdev_dev,
  4091. "MA parity error, parity status %#x\n",
  4092. t4_read_reg(adap,
  4093. MA_PARITY_ERROR_STATUS2_A));
  4094. }
  4095. if (status & MEM_WRAP_INT_CAUSE_F) {
  4096. v = t4_read_reg(adap, MA_INT_WRAP_STATUS_A);
  4097. dev_alert(adap->pdev_dev, "MA address wrap-around error by "
  4098. "client %u to address %#x\n",
  4099. MEM_WRAP_CLIENT_NUM_G(v),
  4100. MEM_WRAP_ADDRESS_G(v) << 4);
  4101. }
  4102. t4_write_reg(adap, MA_INT_CAUSE_A, status);
  4103. t4_fatal_err(adap);
  4104. }
  4105. /*
  4106. * SMB interrupt handler.
  4107. */
  4108. static void smb_intr_handler(struct adapter *adap)
  4109. {
  4110. static const struct intr_info smb_intr_info[] = {
  4111. { MSTTXFIFOPARINT_F, "SMB master Tx FIFO parity error", -1, 1 },
  4112. { MSTRXFIFOPARINT_F, "SMB master Rx FIFO parity error", -1, 1 },
  4113. { SLVFIFOPARINT_F, "SMB slave FIFO parity error", -1, 1 },
  4114. { 0 }
  4115. };
  4116. if (t4_handle_intr_status(adap, SMB_INT_CAUSE_A, smb_intr_info))
  4117. t4_fatal_err(adap);
  4118. }
  4119. /*
  4120. * NC-SI interrupt handler.
  4121. */
  4122. static void ncsi_intr_handler(struct adapter *adap)
  4123. {
  4124. static const struct intr_info ncsi_intr_info[] = {
  4125. { CIM_DM_PRTY_ERR_F, "NC-SI CIM parity error", -1, 1 },
  4126. { MPS_DM_PRTY_ERR_F, "NC-SI MPS parity error", -1, 1 },
  4127. { TXFIFO_PRTY_ERR_F, "NC-SI Tx FIFO parity error", -1, 1 },
  4128. { RXFIFO_PRTY_ERR_F, "NC-SI Rx FIFO parity error", -1, 1 },
  4129. { 0 }
  4130. };
  4131. if (t4_handle_intr_status(adap, NCSI_INT_CAUSE_A, ncsi_intr_info))
  4132. t4_fatal_err(adap);
  4133. }
  4134. /*
  4135. * XGMAC interrupt handler.
  4136. */
  4137. static void xgmac_intr_handler(struct adapter *adap, int port)
  4138. {
  4139. u32 v, int_cause_reg;
  4140. if (is_t4(adap->params.chip))
  4141. int_cause_reg = PORT_REG(port, XGMAC_PORT_INT_CAUSE_A);
  4142. else
  4143. int_cause_reg = T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A);
  4144. v = t4_read_reg(adap, int_cause_reg);
  4145. v &= TXFIFO_PRTY_ERR_F | RXFIFO_PRTY_ERR_F;
  4146. if (!v)
  4147. return;
  4148. if (v & TXFIFO_PRTY_ERR_F)
  4149. dev_alert(adap->pdev_dev, "XGMAC %d Tx FIFO parity error\n",
  4150. port);
  4151. if (v & RXFIFO_PRTY_ERR_F)
  4152. dev_alert(adap->pdev_dev, "XGMAC %d Rx FIFO parity error\n",
  4153. port);
  4154. t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE_A), v);
  4155. t4_fatal_err(adap);
  4156. }
  4157. /*
  4158. * PL interrupt handler.
  4159. */
  4160. static void pl_intr_handler(struct adapter *adap)
  4161. {
  4162. static const struct intr_info pl_intr_info[] = {
  4163. { FATALPERR_F, "T4 fatal parity error", -1, 1 },
  4164. { PERRVFID_F, "PL VFID_MAP parity error", -1, 1 },
  4165. { 0 }
  4166. };
  4167. if (t4_handle_intr_status(adap, PL_PL_INT_CAUSE_A, pl_intr_info))
  4168. t4_fatal_err(adap);
  4169. }
  4170. #define PF_INTR_MASK (PFSW_F)
  4171. #define GLBL_INTR_MASK (CIM_F | MPS_F | PL_F | PCIE_F | MC_F | EDC0_F | \
  4172. EDC1_F | LE_F | TP_F | MA_F | PM_TX_F | PM_RX_F | ULP_RX_F | \
  4173. CPL_SWITCH_F | SGE_F | ULP_TX_F)
  4174. /**
  4175. * t4_slow_intr_handler - control path interrupt handler
  4176. * @adapter: the adapter
  4177. *
  4178. * T4 interrupt handler for non-data global interrupt events, e.g., errors.
  4179. * The designation 'slow' is because it involves register reads, while
  4180. * data interrupts typically don't involve any MMIOs.
  4181. */
  4182. int t4_slow_intr_handler(struct adapter *adapter)
  4183. {
  4184. u32 cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
  4185. if (!(cause & GLBL_INTR_MASK))
  4186. return 0;
  4187. if (cause & CIM_F)
  4188. cim_intr_handler(adapter);
  4189. if (cause & MPS_F)
  4190. mps_intr_handler(adapter);
  4191. if (cause & NCSI_F)
  4192. ncsi_intr_handler(adapter);
  4193. if (cause & PL_F)
  4194. pl_intr_handler(adapter);
  4195. if (cause & SMB_F)
  4196. smb_intr_handler(adapter);
  4197. if (cause & XGMAC0_F)
  4198. xgmac_intr_handler(adapter, 0);
  4199. if (cause & XGMAC1_F)
  4200. xgmac_intr_handler(adapter, 1);
  4201. if (cause & XGMAC_KR0_F)
  4202. xgmac_intr_handler(adapter, 2);
  4203. if (cause & XGMAC_KR1_F)
  4204. xgmac_intr_handler(adapter, 3);
  4205. if (cause & PCIE_F)
  4206. pcie_intr_handler(adapter);
  4207. if (cause & MC_F)
  4208. mem_intr_handler(adapter, MEM_MC);
  4209. if (is_t5(adapter->params.chip) && (cause & MC1_F))
  4210. mem_intr_handler(adapter, MEM_MC1);
  4211. if (cause & EDC0_F)
  4212. mem_intr_handler(adapter, MEM_EDC0);
  4213. if (cause & EDC1_F)
  4214. mem_intr_handler(adapter, MEM_EDC1);
  4215. if (cause & LE_F)
  4216. le_intr_handler(adapter);
  4217. if (cause & TP_F)
  4218. tp_intr_handler(adapter);
  4219. if (cause & MA_F)
  4220. ma_intr_handler(adapter);
  4221. if (cause & PM_TX_F)
  4222. pmtx_intr_handler(adapter);
  4223. if (cause & PM_RX_F)
  4224. pmrx_intr_handler(adapter);
  4225. if (cause & ULP_RX_F)
  4226. ulprx_intr_handler(adapter);
  4227. if (cause & CPL_SWITCH_F)
  4228. cplsw_intr_handler(adapter);
  4229. if (cause & SGE_F)
  4230. sge_intr_handler(adapter);
  4231. if (cause & ULP_TX_F)
  4232. ulptx_intr_handler(adapter);
  4233. /* Clear the interrupts just processed for which we are the master. */
  4234. t4_write_reg(adapter, PL_INT_CAUSE_A, cause & GLBL_INTR_MASK);
  4235. (void)t4_read_reg(adapter, PL_INT_CAUSE_A); /* flush */
  4236. return 1;
  4237. }
  4238. /**
  4239. * t4_intr_enable - enable interrupts
  4240. * @adapter: the adapter whose interrupts should be enabled
  4241. *
  4242. * Enable PF-specific interrupts for the calling function and the top-level
  4243. * interrupt concentrator for global interrupts. Interrupts are already
  4244. * enabled at each module, here we just enable the roots of the interrupt
  4245. * hierarchies.
  4246. *
  4247. * Note: this function should be called only when the driver manages
  4248. * non PF-specific interrupts from the various HW modules. Only one PCI
  4249. * function at a time should be doing this.
  4250. */
  4251. void t4_intr_enable(struct adapter *adapter)
  4252. {
  4253. u32 val = 0;
  4254. u32 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4255. u32 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
  4256. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4257. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  4258. val = ERR_DROPPED_DB_F | ERR_EGR_CTXT_PRIO_F | DBFIFO_HP_INT_F;
  4259. t4_write_reg(adapter, SGE_INT_ENABLE3_A, ERR_CPL_EXCEED_IQE_SIZE_F |
  4260. ERR_INVALID_CIDX_INC_F | ERR_CPL_OPCODE_0_F |
  4261. ERR_DATA_CPL_ON_HIGH_QID1_F | INGRESS_SIZE_ERR_F |
  4262. ERR_DATA_CPL_ON_HIGH_QID0_F | ERR_BAD_DB_PIDX3_F |
  4263. ERR_BAD_DB_PIDX2_F | ERR_BAD_DB_PIDX1_F |
  4264. ERR_BAD_DB_PIDX0_F | ERR_ING_CTXT_PRIO_F |
  4265. DBFIFO_LP_INT_F | EGRESS_SIZE_ERR_F | val);
  4266. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), PF_INTR_MASK);
  4267. t4_set_reg_field(adapter, PL_INT_MAP0_A, 0, 1 << pf);
  4268. }
  4269. /**
  4270. * t4_intr_disable - disable interrupts
  4271. * @adapter: the adapter whose interrupts should be disabled
  4272. *
  4273. * Disable interrupts. We only disable the top-level interrupt
  4274. * concentrators. The caller must be a PCI function managing global
  4275. * interrupts.
  4276. */
  4277. void t4_intr_disable(struct adapter *adapter)
  4278. {
  4279. u32 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4280. u32 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
  4281. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4282. t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), 0);
  4283. t4_set_reg_field(adapter, PL_INT_MAP0_A, 1 << pf, 0);
  4284. }
  4285. /**
  4286. * t4_config_rss_range - configure a portion of the RSS mapping table
  4287. * @adapter: the adapter
  4288. * @mbox: mbox to use for the FW command
  4289. * @viid: virtual interface whose RSS subtable is to be written
  4290. * @start: start entry in the table to write
  4291. * @n: how many table entries to write
  4292. * @rspq: values for the response queue lookup table
  4293. * @nrspq: number of values in @rspq
  4294. *
  4295. * Programs the selected part of the VI's RSS mapping table with the
  4296. * provided values. If @nrspq < @n the supplied values are used repeatedly
  4297. * until the full table range is populated.
  4298. *
  4299. * The caller must ensure the values in @rspq are in the range allowed for
  4300. * @viid.
  4301. */
  4302. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  4303. int start, int n, const u16 *rspq, unsigned int nrspq)
  4304. {
  4305. int ret;
  4306. const u16 *rsp = rspq;
  4307. const u16 *rsp_end = rspq + nrspq;
  4308. struct fw_rss_ind_tbl_cmd cmd;
  4309. memset(&cmd, 0, sizeof(cmd));
  4310. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
  4311. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  4312. FW_RSS_IND_TBL_CMD_VIID_V(viid));
  4313. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  4314. /* each fw_rss_ind_tbl_cmd takes up to 32 entries */
  4315. while (n > 0) {
  4316. int nq = min(n, 32);
  4317. __be32 *qp = &cmd.iq0_to_iq2;
  4318. cmd.niqid = cpu_to_be16(nq);
  4319. cmd.startidx = cpu_to_be16(start);
  4320. start += nq;
  4321. n -= nq;
  4322. while (nq > 0) {
  4323. unsigned int v;
  4324. v = FW_RSS_IND_TBL_CMD_IQ0_V(*rsp);
  4325. if (++rsp >= rsp_end)
  4326. rsp = rspq;
  4327. v |= FW_RSS_IND_TBL_CMD_IQ1_V(*rsp);
  4328. if (++rsp >= rsp_end)
  4329. rsp = rspq;
  4330. v |= FW_RSS_IND_TBL_CMD_IQ2_V(*rsp);
  4331. if (++rsp >= rsp_end)
  4332. rsp = rspq;
  4333. *qp++ = cpu_to_be32(v);
  4334. nq -= 3;
  4335. }
  4336. ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
  4337. if (ret)
  4338. return ret;
  4339. }
  4340. return 0;
  4341. }
  4342. /**
  4343. * t4_config_glbl_rss - configure the global RSS mode
  4344. * @adapter: the adapter
  4345. * @mbox: mbox to use for the FW command
  4346. * @mode: global RSS mode
  4347. * @flags: mode-specific flags
  4348. *
  4349. * Sets the global RSS mode.
  4350. */
  4351. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  4352. unsigned int flags)
  4353. {
  4354. struct fw_rss_glb_config_cmd c;
  4355. memset(&c, 0, sizeof(c));
  4356. c.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_RSS_GLB_CONFIG_CMD) |
  4357. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  4358. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  4359. if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
  4360. c.u.manual.mode_pkd =
  4361. cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  4362. } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  4363. c.u.basicvirtual.mode_pkd =
  4364. cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
  4365. c.u.basicvirtual.synmapen_to_hashtoeplitz = cpu_to_be32(flags);
  4366. } else
  4367. return -EINVAL;
  4368. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  4369. }
  4370. /**
  4371. * t4_config_vi_rss - configure per VI RSS settings
  4372. * @adapter: the adapter
  4373. * @mbox: mbox to use for the FW command
  4374. * @viid: the VI id
  4375. * @flags: RSS flags
  4376. * @defq: id of the default RSS queue for the VI.
  4377. *
  4378. * Configures VI-specific RSS properties.
  4379. */
  4380. int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
  4381. unsigned int flags, unsigned int defq)
  4382. {
  4383. struct fw_rss_vi_config_cmd c;
  4384. memset(&c, 0, sizeof(c));
  4385. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  4386. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  4387. FW_RSS_VI_CONFIG_CMD_VIID_V(viid));
  4388. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  4389. c.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(flags |
  4390. FW_RSS_VI_CONFIG_CMD_DEFAULTQ_V(defq));
  4391. return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
  4392. }
  4393. /* Read an RSS table row */
  4394. static int rd_rss_row(struct adapter *adap, int row, u32 *val)
  4395. {
  4396. t4_write_reg(adap, TP_RSS_LKP_TABLE_A, 0xfff00000 | row);
  4397. return t4_wait_op_done_val(adap, TP_RSS_LKP_TABLE_A, LKPTBLROWVLD_F, 1,
  4398. 5, 0, val);
  4399. }
  4400. /**
  4401. * t4_read_rss - read the contents of the RSS mapping table
  4402. * @adapter: the adapter
  4403. * @map: holds the contents of the RSS mapping table
  4404. *
  4405. * Reads the contents of the RSS hash->queue mapping table.
  4406. */
  4407. int t4_read_rss(struct adapter *adapter, u16 *map)
  4408. {
  4409. u32 val;
  4410. int i, ret;
  4411. for (i = 0; i < RSS_NENTRIES / 2; ++i) {
  4412. ret = rd_rss_row(adapter, i, &val);
  4413. if (ret)
  4414. return ret;
  4415. *map++ = LKPTBLQUEUE0_G(val);
  4416. *map++ = LKPTBLQUEUE1_G(val);
  4417. }
  4418. return 0;
  4419. }
  4420. static unsigned int t4_use_ldst(struct adapter *adap)
  4421. {
  4422. return (adap->flags & FW_OK) || !adap->use_bd;
  4423. }
  4424. /**
  4425. * t4_fw_tp_pio_rw - Access TP PIO through LDST
  4426. * @adap: the adapter
  4427. * @vals: where the indirect register values are stored/written
  4428. * @nregs: how many indirect registers to read/write
  4429. * @start_idx: index of first indirect register to read/write
  4430. * @rw: Read (1) or Write (0)
  4431. *
  4432. * Access TP PIO registers through LDST
  4433. */
  4434. static void t4_fw_tp_pio_rw(struct adapter *adap, u32 *vals, unsigned int nregs,
  4435. unsigned int start_index, unsigned int rw)
  4436. {
  4437. int ret, i;
  4438. int cmd = FW_LDST_ADDRSPC_TP_PIO;
  4439. struct fw_ldst_cmd c;
  4440. for (i = 0 ; i < nregs; i++) {
  4441. memset(&c, 0, sizeof(c));
  4442. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  4443. FW_CMD_REQUEST_F |
  4444. (rw ? FW_CMD_READ_F :
  4445. FW_CMD_WRITE_F) |
  4446. FW_LDST_CMD_ADDRSPACE_V(cmd));
  4447. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  4448. c.u.addrval.addr = cpu_to_be32(start_index + i);
  4449. c.u.addrval.val = rw ? 0 : cpu_to_be32(vals[i]);
  4450. ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c);
  4451. if (!ret && rw)
  4452. vals[i] = be32_to_cpu(c.u.addrval.val);
  4453. }
  4454. }
  4455. /**
  4456. * t4_read_rss_key - read the global RSS key
  4457. * @adap: the adapter
  4458. * @key: 10-entry array holding the 320-bit RSS key
  4459. *
  4460. * Reads the global 320-bit RSS key.
  4461. */
  4462. void t4_read_rss_key(struct adapter *adap, u32 *key)
  4463. {
  4464. if (t4_use_ldst(adap))
  4465. t4_fw_tp_pio_rw(adap, key, 10, TP_RSS_SECRET_KEY0_A, 1);
  4466. else
  4467. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  4468. TP_RSS_SECRET_KEY0_A);
  4469. }
  4470. /**
  4471. * t4_write_rss_key - program one of the RSS keys
  4472. * @adap: the adapter
  4473. * @key: 10-entry array holding the 320-bit RSS key
  4474. * @idx: which RSS key to write
  4475. *
  4476. * Writes one of the RSS keys with the given 320-bit value. If @idx is
  4477. * 0..15 the corresponding entry in the RSS key table is written,
  4478. * otherwise the global RSS key is written.
  4479. */
  4480. void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx)
  4481. {
  4482. u8 rss_key_addr_cnt = 16;
  4483. u32 vrt = t4_read_reg(adap, TP_RSS_CONFIG_VRT_A);
  4484. /* T6 and later: for KeyMode 3 (per-vf and per-vf scramble),
  4485. * allows access to key addresses 16-63 by using KeyWrAddrX
  4486. * as index[5:4](upper 2) into key table
  4487. */
  4488. if ((CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) &&
  4489. (vrt & KEYEXTEND_F) && (KEYMODE_G(vrt) == 3))
  4490. rss_key_addr_cnt = 32;
  4491. if (t4_use_ldst(adap))
  4492. t4_fw_tp_pio_rw(adap, (void *)key, 10, TP_RSS_SECRET_KEY0_A, 0);
  4493. else
  4494. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
  4495. TP_RSS_SECRET_KEY0_A);
  4496. if (idx >= 0 && idx < rss_key_addr_cnt) {
  4497. if (rss_key_addr_cnt > 16)
  4498. t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
  4499. KEYWRADDRX_V(idx >> 4) |
  4500. T6_VFWRADDR_V(idx) | KEYWREN_F);
  4501. else
  4502. t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
  4503. KEYWRADDR_V(idx) | KEYWREN_F);
  4504. }
  4505. }
  4506. /**
  4507. * t4_read_rss_pf_config - read PF RSS Configuration Table
  4508. * @adapter: the adapter
  4509. * @index: the entry in the PF RSS table to read
  4510. * @valp: where to store the returned value
  4511. *
  4512. * Reads the PF RSS Configuration Table at the specified index and returns
  4513. * the value found there.
  4514. */
  4515. void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
  4516. u32 *valp)
  4517. {
  4518. if (t4_use_ldst(adapter))
  4519. t4_fw_tp_pio_rw(adapter, valp, 1,
  4520. TP_RSS_PF0_CONFIG_A + index, 1);
  4521. else
  4522. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4523. valp, 1, TP_RSS_PF0_CONFIG_A + index);
  4524. }
  4525. /**
  4526. * t4_read_rss_vf_config - read VF RSS Configuration Table
  4527. * @adapter: the adapter
  4528. * @index: the entry in the VF RSS table to read
  4529. * @vfl: where to store the returned VFL
  4530. * @vfh: where to store the returned VFH
  4531. *
  4532. * Reads the VF RSS Configuration Table at the specified index and returns
  4533. * the (VFL, VFH) values found there.
  4534. */
  4535. void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
  4536. u32 *vfl, u32 *vfh)
  4537. {
  4538. u32 vrt, mask, data;
  4539. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) {
  4540. mask = VFWRADDR_V(VFWRADDR_M);
  4541. data = VFWRADDR_V(index);
  4542. } else {
  4543. mask = T6_VFWRADDR_V(T6_VFWRADDR_M);
  4544. data = T6_VFWRADDR_V(index);
  4545. }
  4546. /* Request that the index'th VF Table values be read into VFL/VFH.
  4547. */
  4548. vrt = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
  4549. vrt &= ~(VFRDRG_F | VFWREN_F | KEYWREN_F | mask);
  4550. vrt |= data | VFRDEN_F;
  4551. t4_write_reg(adapter, TP_RSS_CONFIG_VRT_A, vrt);
  4552. /* Grab the VFL/VFH values ...
  4553. */
  4554. if (t4_use_ldst(adapter)) {
  4555. t4_fw_tp_pio_rw(adapter, vfl, 1, TP_RSS_VFL_CONFIG_A, 1);
  4556. t4_fw_tp_pio_rw(adapter, vfh, 1, TP_RSS_VFH_CONFIG_A, 1);
  4557. } else {
  4558. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4559. vfl, 1, TP_RSS_VFL_CONFIG_A);
  4560. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4561. vfh, 1, TP_RSS_VFH_CONFIG_A);
  4562. }
  4563. }
  4564. /**
  4565. * t4_read_rss_pf_map - read PF RSS Map
  4566. * @adapter: the adapter
  4567. *
  4568. * Reads the PF RSS Map register and returns its value.
  4569. */
  4570. u32 t4_read_rss_pf_map(struct adapter *adapter)
  4571. {
  4572. u32 pfmap;
  4573. if (t4_use_ldst(adapter))
  4574. t4_fw_tp_pio_rw(adapter, &pfmap, 1, TP_RSS_PF_MAP_A, 1);
  4575. else
  4576. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4577. &pfmap, 1, TP_RSS_PF_MAP_A);
  4578. return pfmap;
  4579. }
  4580. /**
  4581. * t4_read_rss_pf_mask - read PF RSS Mask
  4582. * @adapter: the adapter
  4583. *
  4584. * Reads the PF RSS Mask register and returns its value.
  4585. */
  4586. u32 t4_read_rss_pf_mask(struct adapter *adapter)
  4587. {
  4588. u32 pfmask;
  4589. if (t4_use_ldst(adapter))
  4590. t4_fw_tp_pio_rw(adapter, &pfmask, 1, TP_RSS_PF_MSK_A, 1);
  4591. else
  4592. t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4593. &pfmask, 1, TP_RSS_PF_MSK_A);
  4594. return pfmask;
  4595. }
  4596. /**
  4597. * t4_tp_get_tcp_stats - read TP's TCP MIB counters
  4598. * @adap: the adapter
  4599. * @v4: holds the TCP/IP counter values
  4600. * @v6: holds the TCP/IPv6 counter values
  4601. *
  4602. * Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
  4603. * Either @v4 or @v6 may be %NULL to skip the corresponding stats.
  4604. */
  4605. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  4606. struct tp_tcp_stats *v6)
  4607. {
  4608. u32 val[TP_MIB_TCP_RXT_SEG_LO_A - TP_MIB_TCP_OUT_RST_A + 1];
  4609. #define STAT_IDX(x) ((TP_MIB_TCP_##x##_A) - TP_MIB_TCP_OUT_RST_A)
  4610. #define STAT(x) val[STAT_IDX(x)]
  4611. #define STAT64(x) (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
  4612. if (v4) {
  4613. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4614. ARRAY_SIZE(val), TP_MIB_TCP_OUT_RST_A);
  4615. v4->tcp_out_rsts = STAT(OUT_RST);
  4616. v4->tcp_in_segs = STAT64(IN_SEG);
  4617. v4->tcp_out_segs = STAT64(OUT_SEG);
  4618. v4->tcp_retrans_segs = STAT64(RXT_SEG);
  4619. }
  4620. if (v6) {
  4621. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4622. ARRAY_SIZE(val), TP_MIB_TCP_V6OUT_RST_A);
  4623. v6->tcp_out_rsts = STAT(OUT_RST);
  4624. v6->tcp_in_segs = STAT64(IN_SEG);
  4625. v6->tcp_out_segs = STAT64(OUT_SEG);
  4626. v6->tcp_retrans_segs = STAT64(RXT_SEG);
  4627. }
  4628. #undef STAT64
  4629. #undef STAT
  4630. #undef STAT_IDX
  4631. }
  4632. /**
  4633. * t4_tp_get_err_stats - read TP's error MIB counters
  4634. * @adap: the adapter
  4635. * @st: holds the counter values
  4636. *
  4637. * Returns the values of TP's error counters.
  4638. */
  4639. void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st)
  4640. {
  4641. int nchan = adap->params.arch.nchan;
  4642. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4643. st->mac_in_errs, nchan, TP_MIB_MAC_IN_ERR_0_A);
  4644. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4645. st->hdr_in_errs, nchan, TP_MIB_HDR_IN_ERR_0_A);
  4646. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4647. st->tcp_in_errs, nchan, TP_MIB_TCP_IN_ERR_0_A);
  4648. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4649. st->tnl_cong_drops, nchan, TP_MIB_TNL_CNG_DROP_0_A);
  4650. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4651. st->ofld_chan_drops, nchan, TP_MIB_OFD_CHN_DROP_0_A);
  4652. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4653. st->tnl_tx_drops, nchan, TP_MIB_TNL_DROP_0_A);
  4654. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4655. st->ofld_vlan_drops, nchan, TP_MIB_OFD_VLN_DROP_0_A);
  4656. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4657. st->tcp6_in_errs, nchan, TP_MIB_TCP_V6IN_ERR_0_A);
  4658. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
  4659. &st->ofld_no_neigh, 2, TP_MIB_OFD_ARP_DROP_A);
  4660. }
  4661. /**
  4662. * t4_tp_get_cpl_stats - read TP's CPL MIB counters
  4663. * @adap: the adapter
  4664. * @st: holds the counter values
  4665. *
  4666. * Returns the values of TP's CPL counters.
  4667. */
  4668. void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st)
  4669. {
  4670. int nchan = adap->params.arch.nchan;
  4671. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->req,
  4672. nchan, TP_MIB_CPL_IN_REQ_0_A);
  4673. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->rsp,
  4674. nchan, TP_MIB_CPL_OUT_RSP_0_A);
  4675. }
  4676. /**
  4677. * t4_tp_get_rdma_stats - read TP's RDMA MIB counters
  4678. * @adap: the adapter
  4679. * @st: holds the counter values
  4680. *
  4681. * Returns the values of TP's RDMA counters.
  4682. */
  4683. void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st)
  4684. {
  4685. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->rqe_dfr_pkt,
  4686. 2, TP_MIB_RQE_DFR_PKT_A);
  4687. }
  4688. /**
  4689. * t4_get_fcoe_stats - read TP's FCoE MIB counters for a port
  4690. * @adap: the adapter
  4691. * @idx: the port index
  4692. * @st: holds the counter values
  4693. *
  4694. * Returns the values of TP's FCoE counters for the selected port.
  4695. */
  4696. void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
  4697. struct tp_fcoe_stats *st)
  4698. {
  4699. u32 val[2];
  4700. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_ddp,
  4701. 1, TP_MIB_FCOE_DDP_0_A + idx);
  4702. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_drop,
  4703. 1, TP_MIB_FCOE_DROP_0_A + idx);
  4704. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
  4705. 2, TP_MIB_FCOE_BYTE_0_HI_A + 2 * idx);
  4706. st->octets_ddp = ((u64)val[0] << 32) | val[1];
  4707. }
  4708. /**
  4709. * t4_get_usm_stats - read TP's non-TCP DDP MIB counters
  4710. * @adap: the adapter
  4711. * @st: holds the counter values
  4712. *
  4713. * Returns the values of TP's counters for non-TCP directly-placed packets.
  4714. */
  4715. void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st)
  4716. {
  4717. u32 val[4];
  4718. t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val, 4,
  4719. TP_MIB_USM_PKTS_A);
  4720. st->frames = val[0];
  4721. st->drops = val[1];
  4722. st->octets = ((u64)val[2] << 32) | val[3];
  4723. }
  4724. /**
  4725. * t4_read_mtu_tbl - returns the values in the HW path MTU table
  4726. * @adap: the adapter
  4727. * @mtus: where to store the MTU values
  4728. * @mtu_log: where to store the MTU base-2 log (may be %NULL)
  4729. *
  4730. * Reads the HW path MTU table.
  4731. */
  4732. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
  4733. {
  4734. u32 v;
  4735. int i;
  4736. for (i = 0; i < NMTUS; ++i) {
  4737. t4_write_reg(adap, TP_MTU_TABLE_A,
  4738. MTUINDEX_V(0xff) | MTUVALUE_V(i));
  4739. v = t4_read_reg(adap, TP_MTU_TABLE_A);
  4740. mtus[i] = MTUVALUE_G(v);
  4741. if (mtu_log)
  4742. mtu_log[i] = MTUWIDTH_G(v);
  4743. }
  4744. }
  4745. /**
  4746. * t4_read_cong_tbl - reads the congestion control table
  4747. * @adap: the adapter
  4748. * @incr: where to store the alpha values
  4749. *
  4750. * Reads the additive increments programmed into the HW congestion
  4751. * control table.
  4752. */
  4753. void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
  4754. {
  4755. unsigned int mtu, w;
  4756. for (mtu = 0; mtu < NMTUS; ++mtu)
  4757. for (w = 0; w < NCCTRL_WIN; ++w) {
  4758. t4_write_reg(adap, TP_CCTRL_TABLE_A,
  4759. ROWINDEX_V(0xffff) | (mtu << 5) | w);
  4760. incr[mtu][w] = (u16)t4_read_reg(adap,
  4761. TP_CCTRL_TABLE_A) & 0x1fff;
  4762. }
  4763. }
  4764. /**
  4765. * t4_tp_wr_bits_indirect - set/clear bits in an indirect TP register
  4766. * @adap: the adapter
  4767. * @addr: the indirect TP register address
  4768. * @mask: specifies the field within the register to modify
  4769. * @val: new value for the field
  4770. *
  4771. * Sets a field of an indirect TP register to the given value.
  4772. */
  4773. void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
  4774. unsigned int mask, unsigned int val)
  4775. {
  4776. t4_write_reg(adap, TP_PIO_ADDR_A, addr);
  4777. val |= t4_read_reg(adap, TP_PIO_DATA_A) & ~mask;
  4778. t4_write_reg(adap, TP_PIO_DATA_A, val);
  4779. }
  4780. /**
  4781. * init_cong_ctrl - initialize congestion control parameters
  4782. * @a: the alpha values for congestion control
  4783. * @b: the beta values for congestion control
  4784. *
  4785. * Initialize the congestion control parameters.
  4786. */
  4787. static void init_cong_ctrl(unsigned short *a, unsigned short *b)
  4788. {
  4789. a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
  4790. a[9] = 2;
  4791. a[10] = 3;
  4792. a[11] = 4;
  4793. a[12] = 5;
  4794. a[13] = 6;
  4795. a[14] = 7;
  4796. a[15] = 8;
  4797. a[16] = 9;
  4798. a[17] = 10;
  4799. a[18] = 14;
  4800. a[19] = 17;
  4801. a[20] = 21;
  4802. a[21] = 25;
  4803. a[22] = 30;
  4804. a[23] = 35;
  4805. a[24] = 45;
  4806. a[25] = 60;
  4807. a[26] = 80;
  4808. a[27] = 100;
  4809. a[28] = 200;
  4810. a[29] = 300;
  4811. a[30] = 400;
  4812. a[31] = 500;
  4813. b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
  4814. b[9] = b[10] = 1;
  4815. b[11] = b[12] = 2;
  4816. b[13] = b[14] = b[15] = b[16] = 3;
  4817. b[17] = b[18] = b[19] = b[20] = b[21] = 4;
  4818. b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
  4819. b[28] = b[29] = 6;
  4820. b[30] = b[31] = 7;
  4821. }
  4822. /* The minimum additive increment value for the congestion control table */
  4823. #define CC_MIN_INCR 2U
  4824. /**
  4825. * t4_load_mtus - write the MTU and congestion control HW tables
  4826. * @adap: the adapter
  4827. * @mtus: the values for the MTU table
  4828. * @alpha: the values for the congestion control alpha parameter
  4829. * @beta: the values for the congestion control beta parameter
  4830. *
  4831. * Write the HW MTU table with the supplied MTUs and the high-speed
  4832. * congestion control table with the supplied alpha, beta, and MTUs.
  4833. * We write the two tables together because the additive increments
  4834. * depend on the MTUs.
  4835. */
  4836. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  4837. const unsigned short *alpha, const unsigned short *beta)
  4838. {
  4839. static const unsigned int avg_pkts[NCCTRL_WIN] = {
  4840. 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
  4841. 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
  4842. 28672, 40960, 57344, 81920, 114688, 163840, 229376
  4843. };
  4844. unsigned int i, w;
  4845. for (i = 0; i < NMTUS; ++i) {
  4846. unsigned int mtu = mtus[i];
  4847. unsigned int log2 = fls(mtu);
  4848. if (!(mtu & ((1 << log2) >> 2))) /* round */
  4849. log2--;
  4850. t4_write_reg(adap, TP_MTU_TABLE_A, MTUINDEX_V(i) |
  4851. MTUWIDTH_V(log2) | MTUVALUE_V(mtu));
  4852. for (w = 0; w < NCCTRL_WIN; ++w) {
  4853. unsigned int inc;
  4854. inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
  4855. CC_MIN_INCR);
  4856. t4_write_reg(adap, TP_CCTRL_TABLE_A, (i << 21) |
  4857. (w << 16) | (beta[w] << 13) | inc);
  4858. }
  4859. }
  4860. }
  4861. /* Calculates a rate in bytes/s given the number of 256-byte units per 4K core
  4862. * clocks. The formula is
  4863. *
  4864. * bytes/s = bytes256 * 256 * ClkFreq / 4096
  4865. *
  4866. * which is equivalent to
  4867. *
  4868. * bytes/s = 62.5 * bytes256 * ClkFreq_ms
  4869. */
  4870. static u64 chan_rate(struct adapter *adap, unsigned int bytes256)
  4871. {
  4872. u64 v = bytes256 * adap->params.vpd.cclk;
  4873. return v * 62 + v / 2;
  4874. }
  4875. /**
  4876. * t4_get_chan_txrate - get the current per channel Tx rates
  4877. * @adap: the adapter
  4878. * @nic_rate: rates for NIC traffic
  4879. * @ofld_rate: rates for offloaded traffic
  4880. *
  4881. * Return the current Tx rates in bytes/s for NIC and offloaded traffic
  4882. * for each channel.
  4883. */
  4884. void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate)
  4885. {
  4886. u32 v;
  4887. v = t4_read_reg(adap, TP_TX_TRATE_A);
  4888. nic_rate[0] = chan_rate(adap, TNLRATE0_G(v));
  4889. nic_rate[1] = chan_rate(adap, TNLRATE1_G(v));
  4890. if (adap->params.arch.nchan == NCHAN) {
  4891. nic_rate[2] = chan_rate(adap, TNLRATE2_G(v));
  4892. nic_rate[3] = chan_rate(adap, TNLRATE3_G(v));
  4893. }
  4894. v = t4_read_reg(adap, TP_TX_ORATE_A);
  4895. ofld_rate[0] = chan_rate(adap, OFDRATE0_G(v));
  4896. ofld_rate[1] = chan_rate(adap, OFDRATE1_G(v));
  4897. if (adap->params.arch.nchan == NCHAN) {
  4898. ofld_rate[2] = chan_rate(adap, OFDRATE2_G(v));
  4899. ofld_rate[3] = chan_rate(adap, OFDRATE3_G(v));
  4900. }
  4901. }
  4902. /**
  4903. * t4_set_trace_filter - configure one of the tracing filters
  4904. * @adap: the adapter
  4905. * @tp: the desired trace filter parameters
  4906. * @idx: which filter to configure
  4907. * @enable: whether to enable or disable the filter
  4908. *
  4909. * Configures one of the tracing filters available in HW. If @enable is
  4910. * %0 @tp is not examined and may be %NULL. The user is responsible to
  4911. * set the single/multiple trace mode by writing to MPS_TRC_CFG_A register
  4912. */
  4913. int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
  4914. int idx, int enable)
  4915. {
  4916. int i, ofst = idx * 4;
  4917. u32 data_reg, mask_reg, cfg;
  4918. u32 multitrc = TRCMULTIFILTER_F;
  4919. if (!enable) {
  4920. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
  4921. return 0;
  4922. }
  4923. cfg = t4_read_reg(adap, MPS_TRC_CFG_A);
  4924. if (cfg & TRCMULTIFILTER_F) {
  4925. /* If multiple tracers are enabled, then maximum
  4926. * capture size is 2.5KB (FIFO size of a single channel)
  4927. * minus 2 flits for CPL_TRACE_PKT header.
  4928. */
  4929. if (tp->snap_len > ((10 * 1024 / 4) - (2 * 8)))
  4930. return -EINVAL;
  4931. } else {
  4932. /* If multiple tracers are disabled, to avoid deadlocks
  4933. * maximum packet capture size of 9600 bytes is recommended.
  4934. * Also in this mode, only trace0 can be enabled and running.
  4935. */
  4936. multitrc = 0;
  4937. if (tp->snap_len > 9600 || idx)
  4938. return -EINVAL;
  4939. }
  4940. if (tp->port > (is_t4(adap->params.chip) ? 11 : 19) || tp->invert > 1 ||
  4941. tp->skip_len > TFLENGTH_M || tp->skip_ofst > TFOFFSET_M ||
  4942. tp->min_len > TFMINPKTSIZE_M)
  4943. return -EINVAL;
  4944. /* stop the tracer we'll be changing */
  4945. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
  4946. idx *= (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A);
  4947. data_reg = MPS_TRC_FILTER0_MATCH_A + idx;
  4948. mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + idx;
  4949. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  4950. t4_write_reg(adap, data_reg, tp->data[i]);
  4951. t4_write_reg(adap, mask_reg, ~tp->mask[i]);
  4952. }
  4953. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst,
  4954. TFCAPTUREMAX_V(tp->snap_len) |
  4955. TFMINPKTSIZE_V(tp->min_len));
  4956. t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst,
  4957. TFOFFSET_V(tp->skip_ofst) | TFLENGTH_V(tp->skip_len) |
  4958. (is_t4(adap->params.chip) ?
  4959. TFPORT_V(tp->port) | TFEN_F | TFINVERTMATCH_V(tp->invert) :
  4960. T5_TFPORT_V(tp->port) | T5_TFEN_F |
  4961. T5_TFINVERTMATCH_V(tp->invert)));
  4962. return 0;
  4963. }
  4964. /**
  4965. * t4_get_trace_filter - query one of the tracing filters
  4966. * @adap: the adapter
  4967. * @tp: the current trace filter parameters
  4968. * @idx: which trace filter to query
  4969. * @enabled: non-zero if the filter is enabled
  4970. *
  4971. * Returns the current settings of one of the HW tracing filters.
  4972. */
  4973. void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
  4974. int *enabled)
  4975. {
  4976. u32 ctla, ctlb;
  4977. int i, ofst = idx * 4;
  4978. u32 data_reg, mask_reg;
  4979. ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst);
  4980. ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst);
  4981. if (is_t4(adap->params.chip)) {
  4982. *enabled = !!(ctla & TFEN_F);
  4983. tp->port = TFPORT_G(ctla);
  4984. tp->invert = !!(ctla & TFINVERTMATCH_F);
  4985. } else {
  4986. *enabled = !!(ctla & T5_TFEN_F);
  4987. tp->port = T5_TFPORT_G(ctla);
  4988. tp->invert = !!(ctla & T5_TFINVERTMATCH_F);
  4989. }
  4990. tp->snap_len = TFCAPTUREMAX_G(ctlb);
  4991. tp->min_len = TFMINPKTSIZE_G(ctlb);
  4992. tp->skip_ofst = TFOFFSET_G(ctla);
  4993. tp->skip_len = TFLENGTH_G(ctla);
  4994. ofst = (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A) * idx;
  4995. data_reg = MPS_TRC_FILTER0_MATCH_A + ofst;
  4996. mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + ofst;
  4997. for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
  4998. tp->mask[i] = ~t4_read_reg(adap, mask_reg);
  4999. tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
  5000. }
  5001. }
  5002. /**
  5003. * t4_pmtx_get_stats - returns the HW stats from PMTX
  5004. * @adap: the adapter
  5005. * @cnt: where to store the count statistics
  5006. * @cycles: where to store the cycle statistics
  5007. *
  5008. * Returns performance statistics from PMTX.
  5009. */
  5010. void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  5011. {
  5012. int i;
  5013. u32 data[2];
  5014. for (i = 0; i < adap->params.arch.pm_stats_cnt; i++) {
  5015. t4_write_reg(adap, PM_TX_STAT_CONFIG_A, i + 1);
  5016. cnt[i] = t4_read_reg(adap, PM_TX_STAT_COUNT_A);
  5017. if (is_t4(adap->params.chip)) {
  5018. cycles[i] = t4_read_reg64(adap, PM_TX_STAT_LSB_A);
  5019. } else {
  5020. t4_read_indirect(adap, PM_TX_DBG_CTRL_A,
  5021. PM_TX_DBG_DATA_A, data, 2,
  5022. PM_TX_DBG_STAT_MSB_A);
  5023. cycles[i] = (((u64)data[0] << 32) | data[1]);
  5024. }
  5025. }
  5026. }
  5027. /**
  5028. * t4_pmrx_get_stats - returns the HW stats from PMRX
  5029. * @adap: the adapter
  5030. * @cnt: where to store the count statistics
  5031. * @cycles: where to store the cycle statistics
  5032. *
  5033. * Returns performance statistics from PMRX.
  5034. */
  5035. void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
  5036. {
  5037. int i;
  5038. u32 data[2];
  5039. for (i = 0; i < adap->params.arch.pm_stats_cnt; i++) {
  5040. t4_write_reg(adap, PM_RX_STAT_CONFIG_A, i + 1);
  5041. cnt[i] = t4_read_reg(adap, PM_RX_STAT_COUNT_A);
  5042. if (is_t4(adap->params.chip)) {
  5043. cycles[i] = t4_read_reg64(adap, PM_RX_STAT_LSB_A);
  5044. } else {
  5045. t4_read_indirect(adap, PM_RX_DBG_CTRL_A,
  5046. PM_RX_DBG_DATA_A, data, 2,
  5047. PM_RX_DBG_STAT_MSB_A);
  5048. cycles[i] = (((u64)data[0] << 32) | data[1]);
  5049. }
  5050. }
  5051. }
  5052. /**
  5053. * t4_get_mps_bg_map - return the buffer groups associated with a port
  5054. * @adap: the adapter
  5055. * @idx: the port index
  5056. *
  5057. * Returns a bitmap indicating which MPS buffer groups are associated
  5058. * with the given port. Bit i is set if buffer group i is used by the
  5059. * port.
  5060. */
  5061. unsigned int t4_get_mps_bg_map(struct adapter *adap, int idx)
  5062. {
  5063. u32 n = NUMPORTS_G(t4_read_reg(adap, MPS_CMN_CTL_A));
  5064. if (n == 0)
  5065. return idx == 0 ? 0xf : 0;
  5066. /* In T6 (which is a 2 port card),
  5067. * port 0 is mapped to channel 0 and port 1 is mapped to channel 1.
  5068. * For 2 port T4/T5 adapter,
  5069. * port 0 is mapped to channel 0 and 1,
  5070. * port 1 is mapped to channel 2 and 3.
  5071. */
  5072. if ((n == 1) &&
  5073. (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5))
  5074. return idx < 2 ? (3 << (2 * idx)) : 0;
  5075. return 1 << idx;
  5076. }
  5077. /**
  5078. * t4_get_port_type_description - return Port Type string description
  5079. * @port_type: firmware Port Type enumeration
  5080. */
  5081. const char *t4_get_port_type_description(enum fw_port_type port_type)
  5082. {
  5083. static const char *const port_type_description[] = {
  5084. "Fiber_XFI",
  5085. "Fiber_XAUI",
  5086. "BT_SGMII",
  5087. "BT_XFI",
  5088. "BT_XAUI",
  5089. "KX4",
  5090. "CX4",
  5091. "KX",
  5092. "KR",
  5093. "SFP",
  5094. "BP_AP",
  5095. "BP4_AP",
  5096. "QSFP_10G",
  5097. "QSA",
  5098. "QSFP",
  5099. "BP40_BA",
  5100. "KR4_100G",
  5101. "CR4_QSFP",
  5102. "CR_QSFP",
  5103. "CR2_QSFP",
  5104. "SFP28",
  5105. "KR_SFP28",
  5106. };
  5107. if (port_type < ARRAY_SIZE(port_type_description))
  5108. return port_type_description[port_type];
  5109. return "UNKNOWN";
  5110. }
  5111. /**
  5112. * t4_get_port_stats_offset - collect port stats relative to a previous
  5113. * snapshot
  5114. * @adap: The adapter
  5115. * @idx: The port
  5116. * @stats: Current stats to fill
  5117. * @offset: Previous stats snapshot
  5118. */
  5119. void t4_get_port_stats_offset(struct adapter *adap, int idx,
  5120. struct port_stats *stats,
  5121. struct port_stats *offset)
  5122. {
  5123. u64 *s, *o;
  5124. int i;
  5125. t4_get_port_stats(adap, idx, stats);
  5126. for (i = 0, s = (u64 *)stats, o = (u64 *)offset;
  5127. i < (sizeof(struct port_stats) / sizeof(u64));
  5128. i++, s++, o++)
  5129. *s -= *o;
  5130. }
  5131. /**
  5132. * t4_get_port_stats - collect port statistics
  5133. * @adap: the adapter
  5134. * @idx: the port index
  5135. * @p: the stats structure to fill
  5136. *
  5137. * Collect statistics related to the given port from HW.
  5138. */
  5139. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
  5140. {
  5141. u32 bgmap = t4_get_mps_bg_map(adap, idx);
  5142. u32 stat_ctl = t4_read_reg(adap, MPS_STAT_CTL_A);
  5143. #define GET_STAT(name) \
  5144. t4_read_reg64(adap, \
  5145. (is_t4(adap->params.chip) ? PORT_REG(idx, MPS_PORT_STAT_##name##_L) : \
  5146. T5_PORT_REG(idx, MPS_PORT_STAT_##name##_L)))
  5147. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  5148. p->tx_octets = GET_STAT(TX_PORT_BYTES);
  5149. p->tx_frames = GET_STAT(TX_PORT_FRAMES);
  5150. p->tx_bcast_frames = GET_STAT(TX_PORT_BCAST);
  5151. p->tx_mcast_frames = GET_STAT(TX_PORT_MCAST);
  5152. p->tx_ucast_frames = GET_STAT(TX_PORT_UCAST);
  5153. p->tx_error_frames = GET_STAT(TX_PORT_ERROR);
  5154. p->tx_frames_64 = GET_STAT(TX_PORT_64B);
  5155. p->tx_frames_65_127 = GET_STAT(TX_PORT_65B_127B);
  5156. p->tx_frames_128_255 = GET_STAT(TX_PORT_128B_255B);
  5157. p->tx_frames_256_511 = GET_STAT(TX_PORT_256B_511B);
  5158. p->tx_frames_512_1023 = GET_STAT(TX_PORT_512B_1023B);
  5159. p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
  5160. p->tx_frames_1519_max = GET_STAT(TX_PORT_1519B_MAX);
  5161. p->tx_drop = GET_STAT(TX_PORT_DROP);
  5162. p->tx_pause = GET_STAT(TX_PORT_PAUSE);
  5163. p->tx_ppp0 = GET_STAT(TX_PORT_PPP0);
  5164. p->tx_ppp1 = GET_STAT(TX_PORT_PPP1);
  5165. p->tx_ppp2 = GET_STAT(TX_PORT_PPP2);
  5166. p->tx_ppp3 = GET_STAT(TX_PORT_PPP3);
  5167. p->tx_ppp4 = GET_STAT(TX_PORT_PPP4);
  5168. p->tx_ppp5 = GET_STAT(TX_PORT_PPP5);
  5169. p->tx_ppp6 = GET_STAT(TX_PORT_PPP6);
  5170. p->tx_ppp7 = GET_STAT(TX_PORT_PPP7);
  5171. if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
  5172. if (stat_ctl & COUNTPAUSESTATTX_F) {
  5173. p->tx_frames -= p->tx_pause;
  5174. p->tx_octets -= p->tx_pause * 64;
  5175. }
  5176. if (stat_ctl & COUNTPAUSEMCTX_F)
  5177. p->tx_mcast_frames -= p->tx_pause;
  5178. }
  5179. p->rx_octets = GET_STAT(RX_PORT_BYTES);
  5180. p->rx_frames = GET_STAT(RX_PORT_FRAMES);
  5181. p->rx_bcast_frames = GET_STAT(RX_PORT_BCAST);
  5182. p->rx_mcast_frames = GET_STAT(RX_PORT_MCAST);
  5183. p->rx_ucast_frames = GET_STAT(RX_PORT_UCAST);
  5184. p->rx_too_long = GET_STAT(RX_PORT_MTU_ERROR);
  5185. p->rx_jabber = GET_STAT(RX_PORT_MTU_CRC_ERROR);
  5186. p->rx_fcs_err = GET_STAT(RX_PORT_CRC_ERROR);
  5187. p->rx_len_err = GET_STAT(RX_PORT_LEN_ERROR);
  5188. p->rx_symbol_err = GET_STAT(RX_PORT_SYM_ERROR);
  5189. p->rx_runt = GET_STAT(RX_PORT_LESS_64B);
  5190. p->rx_frames_64 = GET_STAT(RX_PORT_64B);
  5191. p->rx_frames_65_127 = GET_STAT(RX_PORT_65B_127B);
  5192. p->rx_frames_128_255 = GET_STAT(RX_PORT_128B_255B);
  5193. p->rx_frames_256_511 = GET_STAT(RX_PORT_256B_511B);
  5194. p->rx_frames_512_1023 = GET_STAT(RX_PORT_512B_1023B);
  5195. p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
  5196. p->rx_frames_1519_max = GET_STAT(RX_PORT_1519B_MAX);
  5197. p->rx_pause = GET_STAT(RX_PORT_PAUSE);
  5198. p->rx_ppp0 = GET_STAT(RX_PORT_PPP0);
  5199. p->rx_ppp1 = GET_STAT(RX_PORT_PPP1);
  5200. p->rx_ppp2 = GET_STAT(RX_PORT_PPP2);
  5201. p->rx_ppp3 = GET_STAT(RX_PORT_PPP3);
  5202. p->rx_ppp4 = GET_STAT(RX_PORT_PPP4);
  5203. p->rx_ppp5 = GET_STAT(RX_PORT_PPP5);
  5204. p->rx_ppp6 = GET_STAT(RX_PORT_PPP6);
  5205. p->rx_ppp7 = GET_STAT(RX_PORT_PPP7);
  5206. if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
  5207. if (stat_ctl & COUNTPAUSESTATRX_F) {
  5208. p->rx_frames -= p->rx_pause;
  5209. p->rx_octets -= p->rx_pause * 64;
  5210. }
  5211. if (stat_ctl & COUNTPAUSEMCRX_F)
  5212. p->rx_mcast_frames -= p->rx_pause;
  5213. }
  5214. p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
  5215. p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
  5216. p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
  5217. p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
  5218. p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
  5219. p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
  5220. p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
  5221. p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
  5222. #undef GET_STAT
  5223. #undef GET_STAT_COM
  5224. }
  5225. /**
  5226. * t4_get_lb_stats - collect loopback port statistics
  5227. * @adap: the adapter
  5228. * @idx: the loopback port index
  5229. * @p: the stats structure to fill
  5230. *
  5231. * Return HW statistics for the given loopback port.
  5232. */
  5233. void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
  5234. {
  5235. u32 bgmap = t4_get_mps_bg_map(adap, idx);
  5236. #define GET_STAT(name) \
  5237. t4_read_reg64(adap, \
  5238. (is_t4(adap->params.chip) ? \
  5239. PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L) : \
  5240. T5_PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L)))
  5241. #define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
  5242. p->octets = GET_STAT(BYTES);
  5243. p->frames = GET_STAT(FRAMES);
  5244. p->bcast_frames = GET_STAT(BCAST);
  5245. p->mcast_frames = GET_STAT(MCAST);
  5246. p->ucast_frames = GET_STAT(UCAST);
  5247. p->error_frames = GET_STAT(ERROR);
  5248. p->frames_64 = GET_STAT(64B);
  5249. p->frames_65_127 = GET_STAT(65B_127B);
  5250. p->frames_128_255 = GET_STAT(128B_255B);
  5251. p->frames_256_511 = GET_STAT(256B_511B);
  5252. p->frames_512_1023 = GET_STAT(512B_1023B);
  5253. p->frames_1024_1518 = GET_STAT(1024B_1518B);
  5254. p->frames_1519_max = GET_STAT(1519B_MAX);
  5255. p->drop = GET_STAT(DROP_FRAMES);
  5256. p->ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
  5257. p->ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
  5258. p->ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
  5259. p->ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
  5260. p->trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
  5261. p->trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
  5262. p->trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
  5263. p->trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
  5264. #undef GET_STAT
  5265. #undef GET_STAT_COM
  5266. }
  5267. /* t4_mk_filtdelwr - create a delete filter WR
  5268. * @ftid: the filter ID
  5269. * @wr: the filter work request to populate
  5270. * @qid: ingress queue to receive the delete notification
  5271. *
  5272. * Creates a filter work request to delete the supplied filter. If @qid is
  5273. * negative the delete notification is suppressed.
  5274. */
  5275. void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
  5276. {
  5277. memset(wr, 0, sizeof(*wr));
  5278. wr->op_pkd = cpu_to_be32(FW_WR_OP_V(FW_FILTER_WR));
  5279. wr->len16_pkd = cpu_to_be32(FW_WR_LEN16_V(sizeof(*wr) / 16));
  5280. wr->tid_to_iq = cpu_to_be32(FW_FILTER_WR_TID_V(ftid) |
  5281. FW_FILTER_WR_NOREPLY_V(qid < 0));
  5282. wr->del_filter_to_l2tix = cpu_to_be32(FW_FILTER_WR_DEL_FILTER_F);
  5283. if (qid >= 0)
  5284. wr->rx_chan_rx_rpl_iq =
  5285. cpu_to_be16(FW_FILTER_WR_RX_RPL_IQ_V(qid));
  5286. }
  5287. #define INIT_CMD(var, cmd, rd_wr) do { \
  5288. (var).op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_##cmd##_CMD) | \
  5289. FW_CMD_REQUEST_F | \
  5290. FW_CMD_##rd_wr##_F); \
  5291. (var).retval_len16 = cpu_to_be32(FW_LEN16(var)); \
  5292. } while (0)
  5293. int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
  5294. u32 addr, u32 val)
  5295. {
  5296. u32 ldst_addrspace;
  5297. struct fw_ldst_cmd c;
  5298. memset(&c, 0, sizeof(c));
  5299. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FIRMWARE);
  5300. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5301. FW_CMD_REQUEST_F |
  5302. FW_CMD_WRITE_F |
  5303. ldst_addrspace);
  5304. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5305. c.u.addrval.addr = cpu_to_be32(addr);
  5306. c.u.addrval.val = cpu_to_be32(val);
  5307. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5308. }
  5309. /**
  5310. * t4_mdio_rd - read a PHY register through MDIO
  5311. * @adap: the adapter
  5312. * @mbox: mailbox to use for the FW command
  5313. * @phy_addr: the PHY address
  5314. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  5315. * @reg: the register to read
  5316. * @valp: where to store the value
  5317. *
  5318. * Issues a FW command through the given mailbox to read a PHY register.
  5319. */
  5320. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  5321. unsigned int mmd, unsigned int reg, u16 *valp)
  5322. {
  5323. int ret;
  5324. u32 ldst_addrspace;
  5325. struct fw_ldst_cmd c;
  5326. memset(&c, 0, sizeof(c));
  5327. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
  5328. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5329. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  5330. ldst_addrspace);
  5331. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5332. c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
  5333. FW_LDST_CMD_MMD_V(mmd));
  5334. c.u.mdio.raddr = cpu_to_be16(reg);
  5335. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5336. if (ret == 0)
  5337. *valp = be16_to_cpu(c.u.mdio.rval);
  5338. return ret;
  5339. }
  5340. /**
  5341. * t4_mdio_wr - write a PHY register through MDIO
  5342. * @adap: the adapter
  5343. * @mbox: mailbox to use for the FW command
  5344. * @phy_addr: the PHY address
  5345. * @mmd: the PHY MMD to access (0 for clause 22 PHYs)
  5346. * @reg: the register to write
  5347. * @valp: value to write
  5348. *
  5349. * Issues a FW command through the given mailbox to write a PHY register.
  5350. */
  5351. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  5352. unsigned int mmd, unsigned int reg, u16 val)
  5353. {
  5354. u32 ldst_addrspace;
  5355. struct fw_ldst_cmd c;
  5356. memset(&c, 0, sizeof(c));
  5357. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
  5358. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5359. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  5360. ldst_addrspace);
  5361. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5362. c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
  5363. FW_LDST_CMD_MMD_V(mmd));
  5364. c.u.mdio.raddr = cpu_to_be16(reg);
  5365. c.u.mdio.rval = cpu_to_be16(val);
  5366. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5367. }
  5368. /**
  5369. * t4_sge_decode_idma_state - decode the idma state
  5370. * @adap: the adapter
  5371. * @state: the state idma is stuck in
  5372. */
  5373. void t4_sge_decode_idma_state(struct adapter *adapter, int state)
  5374. {
  5375. static const char * const t4_decode[] = {
  5376. "IDMA_IDLE",
  5377. "IDMA_PUSH_MORE_CPL_FIFO",
  5378. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  5379. "Not used",
  5380. "IDMA_PHYSADDR_SEND_PCIEHDR",
  5381. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  5382. "IDMA_PHYSADDR_SEND_PAYLOAD",
  5383. "IDMA_SEND_FIFO_TO_IMSG",
  5384. "IDMA_FL_REQ_DATA_FL_PREP",
  5385. "IDMA_FL_REQ_DATA_FL",
  5386. "IDMA_FL_DROP",
  5387. "IDMA_FL_H_REQ_HEADER_FL",
  5388. "IDMA_FL_H_SEND_PCIEHDR",
  5389. "IDMA_FL_H_PUSH_CPL_FIFO",
  5390. "IDMA_FL_H_SEND_CPL",
  5391. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  5392. "IDMA_FL_H_SEND_IP_HDR",
  5393. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  5394. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  5395. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  5396. "IDMA_FL_D_SEND_PCIEHDR",
  5397. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  5398. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  5399. "IDMA_FL_SEND_PCIEHDR",
  5400. "IDMA_FL_PUSH_CPL_FIFO",
  5401. "IDMA_FL_SEND_CPL",
  5402. "IDMA_FL_SEND_PAYLOAD_FIRST",
  5403. "IDMA_FL_SEND_PAYLOAD",
  5404. "IDMA_FL_REQ_NEXT_DATA_FL",
  5405. "IDMA_FL_SEND_NEXT_PCIEHDR",
  5406. "IDMA_FL_SEND_PADDING",
  5407. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  5408. "IDMA_FL_SEND_FIFO_TO_IMSG",
  5409. "IDMA_FL_REQ_DATAFL_DONE",
  5410. "IDMA_FL_REQ_HEADERFL_DONE",
  5411. };
  5412. static const char * const t5_decode[] = {
  5413. "IDMA_IDLE",
  5414. "IDMA_ALMOST_IDLE",
  5415. "IDMA_PUSH_MORE_CPL_FIFO",
  5416. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  5417. "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
  5418. "IDMA_PHYSADDR_SEND_PCIEHDR",
  5419. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  5420. "IDMA_PHYSADDR_SEND_PAYLOAD",
  5421. "IDMA_SEND_FIFO_TO_IMSG",
  5422. "IDMA_FL_REQ_DATA_FL",
  5423. "IDMA_FL_DROP",
  5424. "IDMA_FL_DROP_SEND_INC",
  5425. "IDMA_FL_H_REQ_HEADER_FL",
  5426. "IDMA_FL_H_SEND_PCIEHDR",
  5427. "IDMA_FL_H_PUSH_CPL_FIFO",
  5428. "IDMA_FL_H_SEND_CPL",
  5429. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  5430. "IDMA_FL_H_SEND_IP_HDR",
  5431. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  5432. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  5433. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  5434. "IDMA_FL_D_SEND_PCIEHDR",
  5435. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  5436. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  5437. "IDMA_FL_SEND_PCIEHDR",
  5438. "IDMA_FL_PUSH_CPL_FIFO",
  5439. "IDMA_FL_SEND_CPL",
  5440. "IDMA_FL_SEND_PAYLOAD_FIRST",
  5441. "IDMA_FL_SEND_PAYLOAD",
  5442. "IDMA_FL_REQ_NEXT_DATA_FL",
  5443. "IDMA_FL_SEND_NEXT_PCIEHDR",
  5444. "IDMA_FL_SEND_PADDING",
  5445. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  5446. };
  5447. static const char * const t6_decode[] = {
  5448. "IDMA_IDLE",
  5449. "IDMA_PUSH_MORE_CPL_FIFO",
  5450. "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
  5451. "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
  5452. "IDMA_PHYSADDR_SEND_PCIEHDR",
  5453. "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
  5454. "IDMA_PHYSADDR_SEND_PAYLOAD",
  5455. "IDMA_FL_REQ_DATA_FL",
  5456. "IDMA_FL_DROP",
  5457. "IDMA_FL_DROP_SEND_INC",
  5458. "IDMA_FL_H_REQ_HEADER_FL",
  5459. "IDMA_FL_H_SEND_PCIEHDR",
  5460. "IDMA_FL_H_PUSH_CPL_FIFO",
  5461. "IDMA_FL_H_SEND_CPL",
  5462. "IDMA_FL_H_SEND_IP_HDR_FIRST",
  5463. "IDMA_FL_H_SEND_IP_HDR",
  5464. "IDMA_FL_H_REQ_NEXT_HEADER_FL",
  5465. "IDMA_FL_H_SEND_NEXT_PCIEHDR",
  5466. "IDMA_FL_H_SEND_IP_HDR_PADDING",
  5467. "IDMA_FL_D_SEND_PCIEHDR",
  5468. "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
  5469. "IDMA_FL_D_REQ_NEXT_DATA_FL",
  5470. "IDMA_FL_SEND_PCIEHDR",
  5471. "IDMA_FL_PUSH_CPL_FIFO",
  5472. "IDMA_FL_SEND_CPL",
  5473. "IDMA_FL_SEND_PAYLOAD_FIRST",
  5474. "IDMA_FL_SEND_PAYLOAD",
  5475. "IDMA_FL_REQ_NEXT_DATA_FL",
  5476. "IDMA_FL_SEND_NEXT_PCIEHDR",
  5477. "IDMA_FL_SEND_PADDING",
  5478. "IDMA_FL_SEND_COMPLETION_TO_IMSG",
  5479. };
  5480. static const u32 sge_regs[] = {
  5481. SGE_DEBUG_DATA_LOW_INDEX_2_A,
  5482. SGE_DEBUG_DATA_LOW_INDEX_3_A,
  5483. SGE_DEBUG_DATA_HIGH_INDEX_10_A,
  5484. };
  5485. const char **sge_idma_decode;
  5486. int sge_idma_decode_nstates;
  5487. int i;
  5488. unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
  5489. /* Select the right set of decode strings to dump depending on the
  5490. * adapter chip type.
  5491. */
  5492. switch (chip_version) {
  5493. case CHELSIO_T4:
  5494. sge_idma_decode = (const char **)t4_decode;
  5495. sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
  5496. break;
  5497. case CHELSIO_T5:
  5498. sge_idma_decode = (const char **)t5_decode;
  5499. sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
  5500. break;
  5501. case CHELSIO_T6:
  5502. sge_idma_decode = (const char **)t6_decode;
  5503. sge_idma_decode_nstates = ARRAY_SIZE(t6_decode);
  5504. break;
  5505. default:
  5506. dev_err(adapter->pdev_dev,
  5507. "Unsupported chip version %d\n", chip_version);
  5508. return;
  5509. }
  5510. if (is_t4(adapter->params.chip)) {
  5511. sge_idma_decode = (const char **)t4_decode;
  5512. sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
  5513. } else {
  5514. sge_idma_decode = (const char **)t5_decode;
  5515. sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
  5516. }
  5517. if (state < sge_idma_decode_nstates)
  5518. CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
  5519. else
  5520. CH_WARN(adapter, "idma state %d unknown\n", state);
  5521. for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
  5522. CH_WARN(adapter, "SGE register %#x value %#x\n",
  5523. sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
  5524. }
  5525. /**
  5526. * t4_sge_ctxt_flush - flush the SGE context cache
  5527. * @adap: the adapter
  5528. * @mbox: mailbox to use for the FW command
  5529. *
  5530. * Issues a FW command through the given mailbox to flush the
  5531. * SGE context cache.
  5532. */
  5533. int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox)
  5534. {
  5535. int ret;
  5536. u32 ldst_addrspace;
  5537. struct fw_ldst_cmd c;
  5538. memset(&c, 0, sizeof(c));
  5539. ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_SGE_EGRC);
  5540. c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
  5541. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  5542. ldst_addrspace);
  5543. c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
  5544. c.u.idctxt.msg_ctxtflush = cpu_to_be32(FW_LDST_CMD_CTXTFLUSH_F);
  5545. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5546. return ret;
  5547. }
  5548. /**
  5549. * t4_fw_hello - establish communication with FW
  5550. * @adap: the adapter
  5551. * @mbox: mailbox to use for the FW command
  5552. * @evt_mbox: mailbox to receive async FW events
  5553. * @master: specifies the caller's willingness to be the device master
  5554. * @state: returns the current device state (if non-NULL)
  5555. *
  5556. * Issues a command to establish communication with FW. Returns either
  5557. * an error (negative integer) or the mailbox of the Master PF.
  5558. */
  5559. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  5560. enum dev_master master, enum dev_state *state)
  5561. {
  5562. int ret;
  5563. struct fw_hello_cmd c;
  5564. u32 v;
  5565. unsigned int master_mbox;
  5566. int retries = FW_CMD_HELLO_RETRIES;
  5567. retry:
  5568. memset(&c, 0, sizeof(c));
  5569. INIT_CMD(c, HELLO, WRITE);
  5570. c.err_to_clearinit = cpu_to_be32(
  5571. FW_HELLO_CMD_MASTERDIS_V(master == MASTER_CANT) |
  5572. FW_HELLO_CMD_MASTERFORCE_V(master == MASTER_MUST) |
  5573. FW_HELLO_CMD_MBMASTER_V(master == MASTER_MUST ?
  5574. mbox : FW_HELLO_CMD_MBMASTER_M) |
  5575. FW_HELLO_CMD_MBASYNCNOT_V(evt_mbox) |
  5576. FW_HELLO_CMD_STAGE_V(fw_hello_cmd_stage_os) |
  5577. FW_HELLO_CMD_CLEARINIT_F);
  5578. /*
  5579. * Issue the HELLO command to the firmware. If it's not successful
  5580. * but indicates that we got a "busy" or "timeout" condition, retry
  5581. * the HELLO until we exhaust our retry limit. If we do exceed our
  5582. * retry limit, check to see if the firmware left us any error
  5583. * information and report that if so.
  5584. */
  5585. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  5586. if (ret < 0) {
  5587. if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
  5588. goto retry;
  5589. if (t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_ERR_F)
  5590. t4_report_fw_error(adap);
  5591. return ret;
  5592. }
  5593. v = be32_to_cpu(c.err_to_clearinit);
  5594. master_mbox = FW_HELLO_CMD_MBMASTER_G(v);
  5595. if (state) {
  5596. if (v & FW_HELLO_CMD_ERR_F)
  5597. *state = DEV_STATE_ERR;
  5598. else if (v & FW_HELLO_CMD_INIT_F)
  5599. *state = DEV_STATE_INIT;
  5600. else
  5601. *state = DEV_STATE_UNINIT;
  5602. }
  5603. /*
  5604. * If we're not the Master PF then we need to wait around for the
  5605. * Master PF Driver to finish setting up the adapter.
  5606. *
  5607. * Note that we also do this wait if we're a non-Master-capable PF and
  5608. * there is no current Master PF; a Master PF may show up momentarily
  5609. * and we wouldn't want to fail pointlessly. (This can happen when an
  5610. * OS loads lots of different drivers rapidly at the same time). In
  5611. * this case, the Master PF returned by the firmware will be
  5612. * PCIE_FW_MASTER_M so the test below will work ...
  5613. */
  5614. if ((v & (FW_HELLO_CMD_ERR_F|FW_HELLO_CMD_INIT_F)) == 0 &&
  5615. master_mbox != mbox) {
  5616. int waiting = FW_CMD_HELLO_TIMEOUT;
  5617. /*
  5618. * Wait for the firmware to either indicate an error or
  5619. * initialized state. If we see either of these we bail out
  5620. * and report the issue to the caller. If we exhaust the
  5621. * "hello timeout" and we haven't exhausted our retries, try
  5622. * again. Otherwise bail with a timeout error.
  5623. */
  5624. for (;;) {
  5625. u32 pcie_fw;
  5626. msleep(50);
  5627. waiting -= 50;
  5628. /*
  5629. * If neither Error nor Initialialized are indicated
  5630. * by the firmware keep waiting till we exaust our
  5631. * timeout ... and then retry if we haven't exhausted
  5632. * our retries ...
  5633. */
  5634. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  5635. if (!(pcie_fw & (PCIE_FW_ERR_F|PCIE_FW_INIT_F))) {
  5636. if (waiting <= 0) {
  5637. if (retries-- > 0)
  5638. goto retry;
  5639. return -ETIMEDOUT;
  5640. }
  5641. continue;
  5642. }
  5643. /*
  5644. * We either have an Error or Initialized condition
  5645. * report errors preferentially.
  5646. */
  5647. if (state) {
  5648. if (pcie_fw & PCIE_FW_ERR_F)
  5649. *state = DEV_STATE_ERR;
  5650. else if (pcie_fw & PCIE_FW_INIT_F)
  5651. *state = DEV_STATE_INIT;
  5652. }
  5653. /*
  5654. * If we arrived before a Master PF was selected and
  5655. * there's not a valid Master PF, grab its identity
  5656. * for our caller.
  5657. */
  5658. if (master_mbox == PCIE_FW_MASTER_M &&
  5659. (pcie_fw & PCIE_FW_MASTER_VLD_F))
  5660. master_mbox = PCIE_FW_MASTER_G(pcie_fw);
  5661. break;
  5662. }
  5663. }
  5664. return master_mbox;
  5665. }
  5666. /**
  5667. * t4_fw_bye - end communication with FW
  5668. * @adap: the adapter
  5669. * @mbox: mailbox to use for the FW command
  5670. *
  5671. * Issues a command to terminate communication with FW.
  5672. */
  5673. int t4_fw_bye(struct adapter *adap, unsigned int mbox)
  5674. {
  5675. struct fw_bye_cmd c;
  5676. memset(&c, 0, sizeof(c));
  5677. INIT_CMD(c, BYE, WRITE);
  5678. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5679. }
  5680. /**
  5681. * t4_init_cmd - ask FW to initialize the device
  5682. * @adap: the adapter
  5683. * @mbox: mailbox to use for the FW command
  5684. *
  5685. * Issues a command to FW to partially initialize the device. This
  5686. * performs initialization that generally doesn't depend on user input.
  5687. */
  5688. int t4_early_init(struct adapter *adap, unsigned int mbox)
  5689. {
  5690. struct fw_initialize_cmd c;
  5691. memset(&c, 0, sizeof(c));
  5692. INIT_CMD(c, INITIALIZE, WRITE);
  5693. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5694. }
  5695. /**
  5696. * t4_fw_reset - issue a reset to FW
  5697. * @adap: the adapter
  5698. * @mbox: mailbox to use for the FW command
  5699. * @reset: specifies the type of reset to perform
  5700. *
  5701. * Issues a reset command of the specified type to FW.
  5702. */
  5703. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
  5704. {
  5705. struct fw_reset_cmd c;
  5706. memset(&c, 0, sizeof(c));
  5707. INIT_CMD(c, RESET, WRITE);
  5708. c.val = cpu_to_be32(reset);
  5709. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5710. }
  5711. /**
  5712. * t4_fw_halt - issue a reset/halt to FW and put uP into RESET
  5713. * @adap: the adapter
  5714. * @mbox: mailbox to use for the FW RESET command (if desired)
  5715. * @force: force uP into RESET even if FW RESET command fails
  5716. *
  5717. * Issues a RESET command to firmware (if desired) with a HALT indication
  5718. * and then puts the microprocessor into RESET state. The RESET command
  5719. * will only be issued if a legitimate mailbox is provided (mbox <=
  5720. * PCIE_FW_MASTER_M).
  5721. *
  5722. * This is generally used in order for the host to safely manipulate the
  5723. * adapter without fear of conflicting with whatever the firmware might
  5724. * be doing. The only way out of this state is to RESTART the firmware
  5725. * ...
  5726. */
  5727. static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
  5728. {
  5729. int ret = 0;
  5730. /*
  5731. * If a legitimate mailbox is provided, issue a RESET command
  5732. * with a HALT indication.
  5733. */
  5734. if (mbox <= PCIE_FW_MASTER_M) {
  5735. struct fw_reset_cmd c;
  5736. memset(&c, 0, sizeof(c));
  5737. INIT_CMD(c, RESET, WRITE);
  5738. c.val = cpu_to_be32(PIORST_F | PIORSTMODE_F);
  5739. c.halt_pkd = cpu_to_be32(FW_RESET_CMD_HALT_F);
  5740. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  5741. }
  5742. /*
  5743. * Normally we won't complete the operation if the firmware RESET
  5744. * command fails but if our caller insists we'll go ahead and put the
  5745. * uP into RESET. This can be useful if the firmware is hung or even
  5746. * missing ... We'll have to take the risk of putting the uP into
  5747. * RESET without the cooperation of firmware in that case.
  5748. *
  5749. * We also force the firmware's HALT flag to be on in case we bypassed
  5750. * the firmware RESET command above or we're dealing with old firmware
  5751. * which doesn't have the HALT capability. This will serve as a flag
  5752. * for the incoming firmware to know that it's coming out of a HALT
  5753. * rather than a RESET ... if it's new enough to understand that ...
  5754. */
  5755. if (ret == 0 || force) {
  5756. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, UPCRST_F);
  5757. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F,
  5758. PCIE_FW_HALT_F);
  5759. }
  5760. /*
  5761. * And we always return the result of the firmware RESET command
  5762. * even when we force the uP into RESET ...
  5763. */
  5764. return ret;
  5765. }
  5766. /**
  5767. * t4_fw_restart - restart the firmware by taking the uP out of RESET
  5768. * @adap: the adapter
  5769. * @reset: if we want to do a RESET to restart things
  5770. *
  5771. * Restart firmware previously halted by t4_fw_halt(). On successful
  5772. * return the previous PF Master remains as the new PF Master and there
  5773. * is no need to issue a new HELLO command, etc.
  5774. *
  5775. * We do this in two ways:
  5776. *
  5777. * 1. If we're dealing with newer firmware we'll simply want to take
  5778. * the chip's microprocessor out of RESET. This will cause the
  5779. * firmware to start up from its start vector. And then we'll loop
  5780. * until the firmware indicates it's started again (PCIE_FW.HALT
  5781. * reset to 0) or we timeout.
  5782. *
  5783. * 2. If we're dealing with older firmware then we'll need to RESET
  5784. * the chip since older firmware won't recognize the PCIE_FW.HALT
  5785. * flag and automatically RESET itself on startup.
  5786. */
  5787. static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
  5788. {
  5789. if (reset) {
  5790. /*
  5791. * Since we're directing the RESET instead of the firmware
  5792. * doing it automatically, we need to clear the PCIE_FW.HALT
  5793. * bit.
  5794. */
  5795. t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F, 0);
  5796. /*
  5797. * If we've been given a valid mailbox, first try to get the
  5798. * firmware to do the RESET. If that works, great and we can
  5799. * return success. Otherwise, if we haven't been given a
  5800. * valid mailbox or the RESET command failed, fall back to
  5801. * hitting the chip with a hammer.
  5802. */
  5803. if (mbox <= PCIE_FW_MASTER_M) {
  5804. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  5805. msleep(100);
  5806. if (t4_fw_reset(adap, mbox,
  5807. PIORST_F | PIORSTMODE_F) == 0)
  5808. return 0;
  5809. }
  5810. t4_write_reg(adap, PL_RST_A, PIORST_F | PIORSTMODE_F);
  5811. msleep(2000);
  5812. } else {
  5813. int ms;
  5814. t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
  5815. for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
  5816. if (!(t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_HALT_F))
  5817. return 0;
  5818. msleep(100);
  5819. ms += 100;
  5820. }
  5821. return -ETIMEDOUT;
  5822. }
  5823. return 0;
  5824. }
  5825. /**
  5826. * t4_fw_upgrade - perform all of the steps necessary to upgrade FW
  5827. * @adap: the adapter
  5828. * @mbox: mailbox to use for the FW RESET command (if desired)
  5829. * @fw_data: the firmware image to write
  5830. * @size: image size
  5831. * @force: force upgrade even if firmware doesn't cooperate
  5832. *
  5833. * Perform all of the steps necessary for upgrading an adapter's
  5834. * firmware image. Normally this requires the cooperation of the
  5835. * existing firmware in order to halt all existing activities
  5836. * but if an invalid mailbox token is passed in we skip that step
  5837. * (though we'll still put the adapter microprocessor into RESET in
  5838. * that case).
  5839. *
  5840. * On successful return the new firmware will have been loaded and
  5841. * the adapter will have been fully RESET losing all previous setup
  5842. * state. On unsuccessful return the adapter may be completely hosed ...
  5843. * positive errno indicates that the adapter is ~probably~ intact, a
  5844. * negative errno indicates that things are looking bad ...
  5845. */
  5846. int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
  5847. const u8 *fw_data, unsigned int size, int force)
  5848. {
  5849. const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
  5850. int reset, ret;
  5851. if (!t4_fw_matches_chip(adap, fw_hdr))
  5852. return -EINVAL;
  5853. ret = t4_fw_halt(adap, mbox, force);
  5854. if (ret < 0 && !force)
  5855. return ret;
  5856. ret = t4_load_fw(adap, fw_data, size);
  5857. if (ret < 0)
  5858. return ret;
  5859. /*
  5860. * Older versions of the firmware don't understand the new
  5861. * PCIE_FW.HALT flag and so won't know to perform a RESET when they
  5862. * restart. So for newly loaded older firmware we'll have to do the
  5863. * RESET for it so it starts up on a clean slate. We can tell if
  5864. * the newly loaded firmware will handle this right by checking
  5865. * its header flags to see if it advertises the capability.
  5866. */
  5867. reset = ((be32_to_cpu(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
  5868. return t4_fw_restart(adap, mbox, reset);
  5869. }
  5870. /**
  5871. * t4_fl_pkt_align - return the fl packet alignment
  5872. * @adap: the adapter
  5873. *
  5874. * T4 has a single field to specify the packing and padding boundary.
  5875. * T5 onwards has separate fields for this and hence the alignment for
  5876. * next packet offset is maximum of these two.
  5877. *
  5878. */
  5879. int t4_fl_pkt_align(struct adapter *adap)
  5880. {
  5881. u32 sge_control, sge_control2;
  5882. unsigned int ingpadboundary, ingpackboundary, fl_align, ingpad_shift;
  5883. sge_control = t4_read_reg(adap, SGE_CONTROL_A);
  5884. /* T4 uses a single control field to specify both the PCIe Padding and
  5885. * Packing Boundary. T5 introduced the ability to specify these
  5886. * separately. The actual Ingress Packet Data alignment boundary
  5887. * within Packed Buffer Mode is the maximum of these two
  5888. * specifications. (Note that it makes no real practical sense to
  5889. * have the Pading Boudary be larger than the Packing Boundary but you
  5890. * could set the chip up that way and, in fact, legacy T4 code would
  5891. * end doing this because it would initialize the Padding Boundary and
  5892. * leave the Packing Boundary initialized to 0 (16 bytes).)
  5893. * Padding Boundary values in T6 starts from 8B,
  5894. * where as it is 32B for T4 and T5.
  5895. */
  5896. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  5897. ingpad_shift = INGPADBOUNDARY_SHIFT_X;
  5898. else
  5899. ingpad_shift = T6_INGPADBOUNDARY_SHIFT_X;
  5900. ingpadboundary = 1 << (INGPADBOUNDARY_G(sge_control) + ingpad_shift);
  5901. fl_align = ingpadboundary;
  5902. if (!is_t4(adap->params.chip)) {
  5903. /* T5 has a weird interpretation of one of the PCIe Packing
  5904. * Boundary values. No idea why ...
  5905. */
  5906. sge_control2 = t4_read_reg(adap, SGE_CONTROL2_A);
  5907. ingpackboundary = INGPACKBOUNDARY_G(sge_control2);
  5908. if (ingpackboundary == INGPACKBOUNDARY_16B_X)
  5909. ingpackboundary = 16;
  5910. else
  5911. ingpackboundary = 1 << (ingpackboundary +
  5912. INGPACKBOUNDARY_SHIFT_X);
  5913. fl_align = max(ingpadboundary, ingpackboundary);
  5914. }
  5915. return fl_align;
  5916. }
  5917. /**
  5918. * t4_fixup_host_params - fix up host-dependent parameters
  5919. * @adap: the adapter
  5920. * @page_size: the host's Base Page Size
  5921. * @cache_line_size: the host's Cache Line Size
  5922. *
  5923. * Various registers in T4 contain values which are dependent on the
  5924. * host's Base Page and Cache Line Sizes. This function will fix all of
  5925. * those registers with the appropriate values as passed in ...
  5926. */
  5927. int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
  5928. unsigned int cache_line_size)
  5929. {
  5930. unsigned int page_shift = fls(page_size) - 1;
  5931. unsigned int sge_hps = page_shift - 10;
  5932. unsigned int stat_len = cache_line_size > 64 ? 128 : 64;
  5933. unsigned int fl_align = cache_line_size < 32 ? 32 : cache_line_size;
  5934. unsigned int fl_align_log = fls(fl_align) - 1;
  5935. t4_write_reg(adap, SGE_HOST_PAGE_SIZE_A,
  5936. HOSTPAGESIZEPF0_V(sge_hps) |
  5937. HOSTPAGESIZEPF1_V(sge_hps) |
  5938. HOSTPAGESIZEPF2_V(sge_hps) |
  5939. HOSTPAGESIZEPF3_V(sge_hps) |
  5940. HOSTPAGESIZEPF4_V(sge_hps) |
  5941. HOSTPAGESIZEPF5_V(sge_hps) |
  5942. HOSTPAGESIZEPF6_V(sge_hps) |
  5943. HOSTPAGESIZEPF7_V(sge_hps));
  5944. if (is_t4(adap->params.chip)) {
  5945. t4_set_reg_field(adap, SGE_CONTROL_A,
  5946. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  5947. EGRSTATUSPAGESIZE_F,
  5948. INGPADBOUNDARY_V(fl_align_log -
  5949. INGPADBOUNDARY_SHIFT_X) |
  5950. EGRSTATUSPAGESIZE_V(stat_len != 64));
  5951. } else {
  5952. unsigned int pack_align;
  5953. unsigned int ingpad, ingpack;
  5954. unsigned int pcie_cap;
  5955. /* T5 introduced the separation of the Free List Padding and
  5956. * Packing Boundaries. Thus, we can select a smaller Padding
  5957. * Boundary to avoid uselessly chewing up PCIe Link and Memory
  5958. * Bandwidth, and use a Packing Boundary which is large enough
  5959. * to avoid false sharing between CPUs, etc.
  5960. *
  5961. * For the PCI Link, the smaller the Padding Boundary the
  5962. * better. For the Memory Controller, a smaller Padding
  5963. * Boundary is better until we cross under the Memory Line
  5964. * Size (the minimum unit of transfer to/from Memory). If we
  5965. * have a Padding Boundary which is smaller than the Memory
  5966. * Line Size, that'll involve a Read-Modify-Write cycle on the
  5967. * Memory Controller which is never good.
  5968. */
  5969. /* We want the Packing Boundary to be based on the Cache Line
  5970. * Size in order to help avoid False Sharing performance
  5971. * issues between CPUs, etc. We also want the Packing
  5972. * Boundary to incorporate the PCI-E Maximum Payload Size. We
  5973. * get best performance when the Packing Boundary is a
  5974. * multiple of the Maximum Payload Size.
  5975. */
  5976. pack_align = fl_align;
  5977. pcie_cap = pci_find_capability(adap->pdev, PCI_CAP_ID_EXP);
  5978. if (pcie_cap) {
  5979. unsigned int mps, mps_log;
  5980. u16 devctl;
  5981. /* The PCIe Device Control Maximum Payload Size field
  5982. * [bits 7:5] encodes sizes as powers of 2 starting at
  5983. * 128 bytes.
  5984. */
  5985. pci_read_config_word(adap->pdev,
  5986. pcie_cap + PCI_EXP_DEVCTL,
  5987. &devctl);
  5988. mps_log = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5) + 7;
  5989. mps = 1 << mps_log;
  5990. if (mps > pack_align)
  5991. pack_align = mps;
  5992. }
  5993. /* N.B. T5/T6 have a crazy special interpretation of the "0"
  5994. * value for the Packing Boundary. This corresponds to 16
  5995. * bytes instead of the expected 32 bytes. So if we want 32
  5996. * bytes, the best we can really do is 64 bytes ...
  5997. */
  5998. if (pack_align <= 16) {
  5999. ingpack = INGPACKBOUNDARY_16B_X;
  6000. fl_align = 16;
  6001. } else if (pack_align == 32) {
  6002. ingpack = INGPACKBOUNDARY_64B_X;
  6003. fl_align = 64;
  6004. } else {
  6005. unsigned int pack_align_log = fls(pack_align) - 1;
  6006. ingpack = pack_align_log - INGPACKBOUNDARY_SHIFT_X;
  6007. fl_align = pack_align;
  6008. }
  6009. /* Use the smallest Ingress Padding which isn't smaller than
  6010. * the Memory Controller Read/Write Size. We'll take that as
  6011. * being 8 bytes since we don't know of any system with a
  6012. * wider Memory Controller Bus Width.
  6013. */
  6014. if (is_t5(adap->params.chip))
  6015. ingpad = INGPADBOUNDARY_32B_X;
  6016. else
  6017. ingpad = T6_INGPADBOUNDARY_8B_X;
  6018. t4_set_reg_field(adap, SGE_CONTROL_A,
  6019. INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
  6020. EGRSTATUSPAGESIZE_F,
  6021. INGPADBOUNDARY_V(ingpad) |
  6022. EGRSTATUSPAGESIZE_V(stat_len != 64));
  6023. t4_set_reg_field(adap, SGE_CONTROL2_A,
  6024. INGPACKBOUNDARY_V(INGPACKBOUNDARY_M),
  6025. INGPACKBOUNDARY_V(ingpack));
  6026. }
  6027. /*
  6028. * Adjust various SGE Free List Host Buffer Sizes.
  6029. *
  6030. * This is something of a crock since we're using fixed indices into
  6031. * the array which are also known by the sge.c code and the T4
  6032. * Firmware Configuration File. We need to come up with a much better
  6033. * approach to managing this array. For now, the first four entries
  6034. * are:
  6035. *
  6036. * 0: Host Page Size
  6037. * 1: 64KB
  6038. * 2: Buffer size corresponding to 1500 byte MTU (unpacked mode)
  6039. * 3: Buffer size corresponding to 9000 byte MTU (unpacked mode)
  6040. *
  6041. * For the single-MTU buffers in unpacked mode we need to include
  6042. * space for the SGE Control Packet Shift, 14 byte Ethernet header,
  6043. * possible 4 byte VLAN tag, all rounded up to the next Ingress Packet
  6044. * Padding boundary. All of these are accommodated in the Factory
  6045. * Default Firmware Configuration File but we need to adjust it for
  6046. * this host's cache line size.
  6047. */
  6048. t4_write_reg(adap, SGE_FL_BUFFER_SIZE0_A, page_size);
  6049. t4_write_reg(adap, SGE_FL_BUFFER_SIZE2_A,
  6050. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE2_A) + fl_align-1)
  6051. & ~(fl_align-1));
  6052. t4_write_reg(adap, SGE_FL_BUFFER_SIZE3_A,
  6053. (t4_read_reg(adap, SGE_FL_BUFFER_SIZE3_A) + fl_align-1)
  6054. & ~(fl_align-1));
  6055. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(page_shift - 12));
  6056. return 0;
  6057. }
  6058. /**
  6059. * t4_fw_initialize - ask FW to initialize the device
  6060. * @adap: the adapter
  6061. * @mbox: mailbox to use for the FW command
  6062. *
  6063. * Issues a command to FW to partially initialize the device. This
  6064. * performs initialization that generally doesn't depend on user input.
  6065. */
  6066. int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
  6067. {
  6068. struct fw_initialize_cmd c;
  6069. memset(&c, 0, sizeof(c));
  6070. INIT_CMD(c, INITIALIZE, WRITE);
  6071. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6072. }
  6073. /**
  6074. * t4_query_params_rw - query FW or device parameters
  6075. * @adap: the adapter
  6076. * @mbox: mailbox to use for the FW command
  6077. * @pf: the PF
  6078. * @vf: the VF
  6079. * @nparams: the number of parameters
  6080. * @params: the parameter names
  6081. * @val: the parameter values
  6082. * @rw: Write and read flag
  6083. *
  6084. * Reads the value of FW or device parameters. Up to 7 parameters can be
  6085. * queried at once.
  6086. */
  6087. int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6088. unsigned int vf, unsigned int nparams, const u32 *params,
  6089. u32 *val, int rw)
  6090. {
  6091. int i, ret;
  6092. struct fw_params_cmd c;
  6093. __be32 *p = &c.param[0].mnem;
  6094. if (nparams > 7)
  6095. return -EINVAL;
  6096. memset(&c, 0, sizeof(c));
  6097. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  6098. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  6099. FW_PARAMS_CMD_PFN_V(pf) |
  6100. FW_PARAMS_CMD_VFN_V(vf));
  6101. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  6102. for (i = 0; i < nparams; i++) {
  6103. *p++ = cpu_to_be32(*params++);
  6104. if (rw)
  6105. *p = cpu_to_be32(*(val + i));
  6106. p++;
  6107. }
  6108. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6109. if (ret == 0)
  6110. for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
  6111. *val++ = be32_to_cpu(*p);
  6112. return ret;
  6113. }
  6114. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6115. unsigned int vf, unsigned int nparams, const u32 *params,
  6116. u32 *val)
  6117. {
  6118. return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0);
  6119. }
  6120. /**
  6121. * t4_set_params_timeout - sets FW or device parameters
  6122. * @adap: the adapter
  6123. * @mbox: mailbox to use for the FW command
  6124. * @pf: the PF
  6125. * @vf: the VF
  6126. * @nparams: the number of parameters
  6127. * @params: the parameter names
  6128. * @val: the parameter values
  6129. * @timeout: the timeout time
  6130. *
  6131. * Sets the value of FW or device parameters. Up to 7 parameters can be
  6132. * specified at once.
  6133. */
  6134. int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
  6135. unsigned int pf, unsigned int vf,
  6136. unsigned int nparams, const u32 *params,
  6137. const u32 *val, int timeout)
  6138. {
  6139. struct fw_params_cmd c;
  6140. __be32 *p = &c.param[0].mnem;
  6141. if (nparams > 7)
  6142. return -EINVAL;
  6143. memset(&c, 0, sizeof(c));
  6144. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  6145. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6146. FW_PARAMS_CMD_PFN_V(pf) |
  6147. FW_PARAMS_CMD_VFN_V(vf));
  6148. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  6149. while (nparams--) {
  6150. *p++ = cpu_to_be32(*params++);
  6151. *p++ = cpu_to_be32(*val++);
  6152. }
  6153. return t4_wr_mbox_timeout(adap, mbox, &c, sizeof(c), NULL, timeout);
  6154. }
  6155. /**
  6156. * t4_set_params - sets FW or device parameters
  6157. * @adap: the adapter
  6158. * @mbox: mailbox to use for the FW command
  6159. * @pf: the PF
  6160. * @vf: the VF
  6161. * @nparams: the number of parameters
  6162. * @params: the parameter names
  6163. * @val: the parameter values
  6164. *
  6165. * Sets the value of FW or device parameters. Up to 7 parameters can be
  6166. * specified at once.
  6167. */
  6168. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6169. unsigned int vf, unsigned int nparams, const u32 *params,
  6170. const u32 *val)
  6171. {
  6172. return t4_set_params_timeout(adap, mbox, pf, vf, nparams, params, val,
  6173. FW_CMD_MAX_TIMEOUT);
  6174. }
  6175. /**
  6176. * t4_cfg_pfvf - configure PF/VF resource limits
  6177. * @adap: the adapter
  6178. * @mbox: mailbox to use for the FW command
  6179. * @pf: the PF being configured
  6180. * @vf: the VF being configured
  6181. * @txq: the max number of egress queues
  6182. * @txq_eth_ctrl: the max number of egress Ethernet or control queues
  6183. * @rxqi: the max number of interrupt-capable ingress queues
  6184. * @rxq: the max number of interruptless ingress queues
  6185. * @tc: the PCI traffic class
  6186. * @vi: the max number of virtual interfaces
  6187. * @cmask: the channel access rights mask for the PF/VF
  6188. * @pmask: the port access rights mask for the PF/VF
  6189. * @nexact: the maximum number of exact MPS filters
  6190. * @rcaps: read capabilities
  6191. * @wxcaps: write/execute capabilities
  6192. *
  6193. * Configures resource limits and capabilities for a physical or virtual
  6194. * function.
  6195. */
  6196. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6197. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  6198. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  6199. unsigned int vi, unsigned int cmask, unsigned int pmask,
  6200. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
  6201. {
  6202. struct fw_pfvf_cmd c;
  6203. memset(&c, 0, sizeof(c));
  6204. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) | FW_CMD_REQUEST_F |
  6205. FW_CMD_WRITE_F | FW_PFVF_CMD_PFN_V(pf) |
  6206. FW_PFVF_CMD_VFN_V(vf));
  6207. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  6208. c.niqflint_niq = cpu_to_be32(FW_PFVF_CMD_NIQFLINT_V(rxqi) |
  6209. FW_PFVF_CMD_NIQ_V(rxq));
  6210. c.type_to_neq = cpu_to_be32(FW_PFVF_CMD_CMASK_V(cmask) |
  6211. FW_PFVF_CMD_PMASK_V(pmask) |
  6212. FW_PFVF_CMD_NEQ_V(txq));
  6213. c.tc_to_nexactf = cpu_to_be32(FW_PFVF_CMD_TC_V(tc) |
  6214. FW_PFVF_CMD_NVI_V(vi) |
  6215. FW_PFVF_CMD_NEXACTF_V(nexact));
  6216. c.r_caps_to_nethctrl = cpu_to_be32(FW_PFVF_CMD_R_CAPS_V(rcaps) |
  6217. FW_PFVF_CMD_WX_CAPS_V(wxcaps) |
  6218. FW_PFVF_CMD_NETHCTRL_V(txq_eth_ctrl));
  6219. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6220. }
  6221. /**
  6222. * t4_alloc_vi - allocate a virtual interface
  6223. * @adap: the adapter
  6224. * @mbox: mailbox to use for the FW command
  6225. * @port: physical port associated with the VI
  6226. * @pf: the PF owning the VI
  6227. * @vf: the VF owning the VI
  6228. * @nmac: number of MAC addresses needed (1 to 5)
  6229. * @mac: the MAC addresses of the VI
  6230. * @rss_size: size of RSS table slice associated with this VI
  6231. *
  6232. * Allocates a virtual interface for the given physical port. If @mac is
  6233. * not %NULL it contains the MAC addresses of the VI as assigned by FW.
  6234. * @mac should be large enough to hold @nmac Ethernet addresses, they are
  6235. * stored consecutively so the space needed is @nmac * 6 bytes.
  6236. * Returns a negative error number or the non-negative VI id.
  6237. */
  6238. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  6239. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  6240. unsigned int *rss_size)
  6241. {
  6242. int ret;
  6243. struct fw_vi_cmd c;
  6244. memset(&c, 0, sizeof(c));
  6245. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) | FW_CMD_REQUEST_F |
  6246. FW_CMD_WRITE_F | FW_CMD_EXEC_F |
  6247. FW_VI_CMD_PFN_V(pf) | FW_VI_CMD_VFN_V(vf));
  6248. c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_ALLOC_F | FW_LEN16(c));
  6249. c.portid_pkd = FW_VI_CMD_PORTID_V(port);
  6250. c.nmac = nmac - 1;
  6251. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6252. if (ret)
  6253. return ret;
  6254. if (mac) {
  6255. memcpy(mac, c.mac, sizeof(c.mac));
  6256. switch (nmac) {
  6257. case 5:
  6258. memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
  6259. case 4:
  6260. memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
  6261. case 3:
  6262. memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
  6263. case 2:
  6264. memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
  6265. }
  6266. }
  6267. if (rss_size)
  6268. *rss_size = FW_VI_CMD_RSSSIZE_G(be16_to_cpu(c.rsssize_pkd));
  6269. return FW_VI_CMD_VIID_G(be16_to_cpu(c.type_viid));
  6270. }
  6271. /**
  6272. * t4_free_vi - free a virtual interface
  6273. * @adap: the adapter
  6274. * @mbox: mailbox to use for the FW command
  6275. * @pf: the PF owning the VI
  6276. * @vf: the VF owning the VI
  6277. * @viid: virtual interface identifiler
  6278. *
  6279. * Free a previously allocated virtual interface.
  6280. */
  6281. int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6282. unsigned int vf, unsigned int viid)
  6283. {
  6284. struct fw_vi_cmd c;
  6285. memset(&c, 0, sizeof(c));
  6286. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
  6287. FW_CMD_REQUEST_F |
  6288. FW_CMD_EXEC_F |
  6289. FW_VI_CMD_PFN_V(pf) |
  6290. FW_VI_CMD_VFN_V(vf));
  6291. c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_FREE_F | FW_LEN16(c));
  6292. c.type_viid = cpu_to_be16(FW_VI_CMD_VIID_V(viid));
  6293. return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6294. }
  6295. /**
  6296. * t4_set_rxmode - set Rx properties of a virtual interface
  6297. * @adap: the adapter
  6298. * @mbox: mailbox to use for the FW command
  6299. * @viid: the VI id
  6300. * @mtu: the new MTU or -1
  6301. * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  6302. * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
  6303. * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
  6304. * @vlanex: 1 to enable HW VLAN extraction, 0 to disable it, -1 no change
  6305. * @sleep_ok: if true we may sleep while awaiting command completion
  6306. *
  6307. * Sets Rx properties of a virtual interface.
  6308. */
  6309. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6310. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  6311. bool sleep_ok)
  6312. {
  6313. struct fw_vi_rxmode_cmd c;
  6314. /* convert to FW values */
  6315. if (mtu < 0)
  6316. mtu = FW_RXMODE_MTU_NO_CHG;
  6317. if (promisc < 0)
  6318. promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
  6319. if (all_multi < 0)
  6320. all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
  6321. if (bcast < 0)
  6322. bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
  6323. if (vlanex < 0)
  6324. vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
  6325. memset(&c, 0, sizeof(c));
  6326. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
  6327. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6328. FW_VI_RXMODE_CMD_VIID_V(viid));
  6329. c.retval_len16 = cpu_to_be32(FW_LEN16(c));
  6330. c.mtu_to_vlanexen =
  6331. cpu_to_be32(FW_VI_RXMODE_CMD_MTU_V(mtu) |
  6332. FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
  6333. FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
  6334. FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
  6335. FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
  6336. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  6337. }
  6338. /**
  6339. * t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
  6340. * @adap: the adapter
  6341. * @mbox: mailbox to use for the FW command
  6342. * @viid: the VI id
  6343. * @free: if true any existing filters for this VI id are first removed
  6344. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  6345. * @addr: the MAC address(es)
  6346. * @idx: where to store the index of each allocated filter
  6347. * @hash: pointer to hash address filter bitmap
  6348. * @sleep_ok: call is allowed to sleep
  6349. *
  6350. * Allocates an exact-match filter for each of the supplied addresses and
  6351. * sets it to the corresponding address. If @idx is not %NULL it should
  6352. * have at least @naddr entries, each of which will be set to the index of
  6353. * the filter allocated for the corresponding MAC address. If a filter
  6354. * could not be allocated for an address its index is set to 0xffff.
  6355. * If @hash is not %NULL addresses that fail to allocate an exact filter
  6356. * are hashed and update the hash filter bitmap pointed at by @hash.
  6357. *
  6358. * Returns a negative error number or the number of filters allocated.
  6359. */
  6360. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  6361. unsigned int viid, bool free, unsigned int naddr,
  6362. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
  6363. {
  6364. int offset, ret = 0;
  6365. struct fw_vi_mac_cmd c;
  6366. unsigned int nfilters = 0;
  6367. unsigned int max_naddr = adap->params.arch.mps_tcam_size;
  6368. unsigned int rem = naddr;
  6369. if (naddr > max_naddr)
  6370. return -EINVAL;
  6371. for (offset = 0; offset < naddr ; /**/) {
  6372. unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact) ?
  6373. rem : ARRAY_SIZE(c.u.exact));
  6374. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  6375. u.exact[fw_naddr]), 16);
  6376. struct fw_vi_mac_exact *p;
  6377. int i;
  6378. memset(&c, 0, sizeof(c));
  6379. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6380. FW_CMD_REQUEST_F |
  6381. FW_CMD_WRITE_F |
  6382. FW_CMD_EXEC_V(free) |
  6383. FW_VI_MAC_CMD_VIID_V(viid));
  6384. c.freemacs_to_len16 =
  6385. cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(free) |
  6386. FW_CMD_LEN16_V(len16));
  6387. for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
  6388. p->valid_to_idx =
  6389. cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
  6390. FW_VI_MAC_CMD_IDX_V(
  6391. FW_VI_MAC_ADD_MAC));
  6392. memcpy(p->macaddr, addr[offset + i],
  6393. sizeof(p->macaddr));
  6394. }
  6395. /* It's okay if we run out of space in our MAC address arena.
  6396. * Some of the addresses we submit may get stored so we need
  6397. * to run through the reply to see what the results were ...
  6398. */
  6399. ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
  6400. if (ret && ret != -FW_ENOMEM)
  6401. break;
  6402. for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
  6403. u16 index = FW_VI_MAC_CMD_IDX_G(
  6404. be16_to_cpu(p->valid_to_idx));
  6405. if (idx)
  6406. idx[offset + i] = (index >= max_naddr ?
  6407. 0xffff : index);
  6408. if (index < max_naddr)
  6409. nfilters++;
  6410. else if (hash)
  6411. *hash |= (1ULL <<
  6412. hash_mac_addr(addr[offset + i]));
  6413. }
  6414. free = false;
  6415. offset += fw_naddr;
  6416. rem -= fw_naddr;
  6417. }
  6418. if (ret == 0 || ret == -FW_ENOMEM)
  6419. ret = nfilters;
  6420. return ret;
  6421. }
  6422. /**
  6423. * t4_free_mac_filt - frees exact-match filters of given MAC addresses
  6424. * @adap: the adapter
  6425. * @mbox: mailbox to use for the FW command
  6426. * @viid: the VI id
  6427. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  6428. * @addr: the MAC address(es)
  6429. * @sleep_ok: call is allowed to sleep
  6430. *
  6431. * Frees the exact-match filter for each of the supplied addresses
  6432. *
  6433. * Returns a negative error number or the number of filters freed.
  6434. */
  6435. int t4_free_mac_filt(struct adapter *adap, unsigned int mbox,
  6436. unsigned int viid, unsigned int naddr,
  6437. const u8 **addr, bool sleep_ok)
  6438. {
  6439. int offset, ret = 0;
  6440. struct fw_vi_mac_cmd c;
  6441. unsigned int nfilters = 0;
  6442. unsigned int max_naddr = is_t4(adap->params.chip) ?
  6443. NUM_MPS_CLS_SRAM_L_INSTANCES :
  6444. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  6445. unsigned int rem = naddr;
  6446. if (naddr > max_naddr)
  6447. return -EINVAL;
  6448. for (offset = 0; offset < (int)naddr ; /**/) {
  6449. unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
  6450. ? rem
  6451. : ARRAY_SIZE(c.u.exact));
  6452. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  6453. u.exact[fw_naddr]), 16);
  6454. struct fw_vi_mac_exact *p;
  6455. int i;
  6456. memset(&c, 0, sizeof(c));
  6457. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6458. FW_CMD_REQUEST_F |
  6459. FW_CMD_WRITE_F |
  6460. FW_CMD_EXEC_V(0) |
  6461. FW_VI_MAC_CMD_VIID_V(viid));
  6462. c.freemacs_to_len16 =
  6463. cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(0) |
  6464. FW_CMD_LEN16_V(len16));
  6465. for (i = 0, p = c.u.exact; i < (int)fw_naddr; i++, p++) {
  6466. p->valid_to_idx = cpu_to_be16(
  6467. FW_VI_MAC_CMD_VALID_F |
  6468. FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_MAC_BASED_FREE));
  6469. memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
  6470. }
  6471. ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
  6472. if (ret)
  6473. break;
  6474. for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
  6475. u16 index = FW_VI_MAC_CMD_IDX_G(
  6476. be16_to_cpu(p->valid_to_idx));
  6477. if (index < max_naddr)
  6478. nfilters++;
  6479. }
  6480. offset += fw_naddr;
  6481. rem -= fw_naddr;
  6482. }
  6483. if (ret == 0)
  6484. ret = nfilters;
  6485. return ret;
  6486. }
  6487. /**
  6488. * t4_change_mac - modifies the exact-match filter for a MAC address
  6489. * @adap: the adapter
  6490. * @mbox: mailbox to use for the FW command
  6491. * @viid: the VI id
  6492. * @idx: index of existing filter for old value of MAC address, or -1
  6493. * @addr: the new MAC address value
  6494. * @persist: whether a new MAC allocation should be persistent
  6495. * @add_smt: if true also add the address to the HW SMT
  6496. *
  6497. * Modifies an exact-match filter and sets it to the new MAC address.
  6498. * Note that in general it is not possible to modify the value of a given
  6499. * filter so the generic way to modify an address filter is to free the one
  6500. * being used by the old address value and allocate a new filter for the
  6501. * new address value. @idx can be -1 if the address is a new addition.
  6502. *
  6503. * Returns a negative error number or the index of the filter with the new
  6504. * MAC value.
  6505. */
  6506. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6507. int idx, const u8 *addr, bool persist, bool add_smt)
  6508. {
  6509. int ret, mode;
  6510. struct fw_vi_mac_cmd c;
  6511. struct fw_vi_mac_exact *p = c.u.exact;
  6512. unsigned int max_mac_addr = adap->params.arch.mps_tcam_size;
  6513. if (idx < 0) /* new allocation */
  6514. idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
  6515. mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
  6516. memset(&c, 0, sizeof(c));
  6517. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6518. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6519. FW_VI_MAC_CMD_VIID_V(viid));
  6520. c.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16_V(1));
  6521. p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
  6522. FW_VI_MAC_CMD_SMAC_RESULT_V(mode) |
  6523. FW_VI_MAC_CMD_IDX_V(idx));
  6524. memcpy(p->macaddr, addr, sizeof(p->macaddr));
  6525. ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
  6526. if (ret == 0) {
  6527. ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
  6528. if (ret >= max_mac_addr)
  6529. ret = -ENOMEM;
  6530. }
  6531. return ret;
  6532. }
  6533. /**
  6534. * t4_set_addr_hash - program the MAC inexact-match hash filter
  6535. * @adap: the adapter
  6536. * @mbox: mailbox to use for the FW command
  6537. * @viid: the VI id
  6538. * @ucast: whether the hash filter should also match unicast addresses
  6539. * @vec: the value to be written to the hash filter
  6540. * @sleep_ok: call is allowed to sleep
  6541. *
  6542. * Sets the 64-bit inexact-match hash filter for a virtual interface.
  6543. */
  6544. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6545. bool ucast, u64 vec, bool sleep_ok)
  6546. {
  6547. struct fw_vi_mac_cmd c;
  6548. memset(&c, 0, sizeof(c));
  6549. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  6550. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  6551. FW_VI_ENABLE_CMD_VIID_V(viid));
  6552. c.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN_F |
  6553. FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
  6554. FW_CMD_LEN16_V(1));
  6555. c.u.hash.hashvec = cpu_to_be64(vec);
  6556. return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
  6557. }
  6558. /**
  6559. * t4_enable_vi_params - enable/disable a virtual interface
  6560. * @adap: the adapter
  6561. * @mbox: mailbox to use for the FW command
  6562. * @viid: the VI id
  6563. * @rx_en: 1=enable Rx, 0=disable Rx
  6564. * @tx_en: 1=enable Tx, 0=disable Tx
  6565. * @dcb_en: 1=enable delivery of Data Center Bridging messages.
  6566. *
  6567. * Enables/disables a virtual interface. Note that setting DCB Enable
  6568. * only makes sense when enabling a Virtual Interface ...
  6569. */
  6570. int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
  6571. unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
  6572. {
  6573. struct fw_vi_enable_cmd c;
  6574. memset(&c, 0, sizeof(c));
  6575. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  6576. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6577. FW_VI_ENABLE_CMD_VIID_V(viid));
  6578. c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
  6579. FW_VI_ENABLE_CMD_EEN_V(tx_en) |
  6580. FW_VI_ENABLE_CMD_DCB_INFO_V(dcb_en) |
  6581. FW_LEN16(c));
  6582. return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
  6583. }
  6584. /**
  6585. * t4_enable_vi - enable/disable a virtual interface
  6586. * @adap: the adapter
  6587. * @mbox: mailbox to use for the FW command
  6588. * @viid: the VI id
  6589. * @rx_en: 1=enable Rx, 0=disable Rx
  6590. * @tx_en: 1=enable Tx, 0=disable Tx
  6591. *
  6592. * Enables/disables a virtual interface.
  6593. */
  6594. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6595. bool rx_en, bool tx_en)
  6596. {
  6597. return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
  6598. }
  6599. /**
  6600. * t4_identify_port - identify a VI's port by blinking its LED
  6601. * @adap: the adapter
  6602. * @mbox: mailbox to use for the FW command
  6603. * @viid: the VI id
  6604. * @nblinks: how many times to blink LED at 2.5 Hz
  6605. *
  6606. * Identifies a VI's port by blinking its LED.
  6607. */
  6608. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  6609. unsigned int nblinks)
  6610. {
  6611. struct fw_vi_enable_cmd c;
  6612. memset(&c, 0, sizeof(c));
  6613. c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  6614. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6615. FW_VI_ENABLE_CMD_VIID_V(viid));
  6616. c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED_F | FW_LEN16(c));
  6617. c.blinkdur = cpu_to_be16(nblinks);
  6618. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6619. }
  6620. /**
  6621. * t4_iq_stop - stop an ingress queue and its FLs
  6622. * @adap: the adapter
  6623. * @mbox: mailbox to use for the FW command
  6624. * @pf: the PF owning the queues
  6625. * @vf: the VF owning the queues
  6626. * @iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
  6627. * @iqid: ingress queue id
  6628. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  6629. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  6630. *
  6631. * Stops an ingress queue and its associated FLs, if any. This causes
  6632. * any current or future data/messages destined for these queues to be
  6633. * tossed.
  6634. */
  6635. int t4_iq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6636. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  6637. unsigned int fl0id, unsigned int fl1id)
  6638. {
  6639. struct fw_iq_cmd c;
  6640. memset(&c, 0, sizeof(c));
  6641. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
  6642. FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
  6643. FW_IQ_CMD_VFN_V(vf));
  6644. c.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_IQSTOP_F | FW_LEN16(c));
  6645. c.type_to_iqandstindex = cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
  6646. c.iqid = cpu_to_be16(iqid);
  6647. c.fl0id = cpu_to_be16(fl0id);
  6648. c.fl1id = cpu_to_be16(fl1id);
  6649. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6650. }
  6651. /**
  6652. * t4_iq_free - free an ingress queue and its FLs
  6653. * @adap: the adapter
  6654. * @mbox: mailbox to use for the FW command
  6655. * @pf: the PF owning the queues
  6656. * @vf: the VF owning the queues
  6657. * @iqtype: the ingress queue type
  6658. * @iqid: ingress queue id
  6659. * @fl0id: FL0 queue id or 0xffff if no attached FL0
  6660. * @fl1id: FL1 queue id or 0xffff if no attached FL1
  6661. *
  6662. * Frees an ingress queue and its associated FLs, if any.
  6663. */
  6664. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6665. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  6666. unsigned int fl0id, unsigned int fl1id)
  6667. {
  6668. struct fw_iq_cmd c;
  6669. memset(&c, 0, sizeof(c));
  6670. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
  6671. FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
  6672. FW_IQ_CMD_VFN_V(vf));
  6673. c.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE_F | FW_LEN16(c));
  6674. c.type_to_iqandstindex = cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
  6675. c.iqid = cpu_to_be16(iqid);
  6676. c.fl0id = cpu_to_be16(fl0id);
  6677. c.fl1id = cpu_to_be16(fl1id);
  6678. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6679. }
  6680. /**
  6681. * t4_eth_eq_free - free an Ethernet egress queue
  6682. * @adap: the adapter
  6683. * @mbox: mailbox to use for the FW command
  6684. * @pf: the PF owning the queue
  6685. * @vf: the VF owning the queue
  6686. * @eqid: egress queue id
  6687. *
  6688. * Frees an Ethernet egress queue.
  6689. */
  6690. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6691. unsigned int vf, unsigned int eqid)
  6692. {
  6693. struct fw_eq_eth_cmd c;
  6694. memset(&c, 0, sizeof(c));
  6695. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_ETH_CMD) |
  6696. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6697. FW_EQ_ETH_CMD_PFN_V(pf) |
  6698. FW_EQ_ETH_CMD_VFN_V(vf));
  6699. c.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE_F | FW_LEN16(c));
  6700. c.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID_V(eqid));
  6701. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6702. }
  6703. /**
  6704. * t4_ctrl_eq_free - free a control egress queue
  6705. * @adap: the adapter
  6706. * @mbox: mailbox to use for the FW command
  6707. * @pf: the PF owning the queue
  6708. * @vf: the VF owning the queue
  6709. * @eqid: egress queue id
  6710. *
  6711. * Frees a control egress queue.
  6712. */
  6713. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6714. unsigned int vf, unsigned int eqid)
  6715. {
  6716. struct fw_eq_ctrl_cmd c;
  6717. memset(&c, 0, sizeof(c));
  6718. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_CTRL_CMD) |
  6719. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6720. FW_EQ_CTRL_CMD_PFN_V(pf) |
  6721. FW_EQ_CTRL_CMD_VFN_V(vf));
  6722. c.alloc_to_len16 = cpu_to_be32(FW_EQ_CTRL_CMD_FREE_F | FW_LEN16(c));
  6723. c.cmpliqid_eqid = cpu_to_be32(FW_EQ_CTRL_CMD_EQID_V(eqid));
  6724. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6725. }
  6726. /**
  6727. * t4_ofld_eq_free - free an offload egress queue
  6728. * @adap: the adapter
  6729. * @mbox: mailbox to use for the FW command
  6730. * @pf: the PF owning the queue
  6731. * @vf: the VF owning the queue
  6732. * @eqid: egress queue id
  6733. *
  6734. * Frees a control egress queue.
  6735. */
  6736. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  6737. unsigned int vf, unsigned int eqid)
  6738. {
  6739. struct fw_eq_ofld_cmd c;
  6740. memset(&c, 0, sizeof(c));
  6741. c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
  6742. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  6743. FW_EQ_OFLD_CMD_PFN_V(pf) |
  6744. FW_EQ_OFLD_CMD_VFN_V(vf));
  6745. c.alloc_to_len16 = cpu_to_be32(FW_EQ_OFLD_CMD_FREE_F | FW_LEN16(c));
  6746. c.eqid_pkd = cpu_to_be32(FW_EQ_OFLD_CMD_EQID_V(eqid));
  6747. return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
  6748. }
  6749. /**
  6750. * t4_link_down_rc_str - return a string for a Link Down Reason Code
  6751. * @adap: the adapter
  6752. * @link_down_rc: Link Down Reason Code
  6753. *
  6754. * Returns a string representation of the Link Down Reason Code.
  6755. */
  6756. static const char *t4_link_down_rc_str(unsigned char link_down_rc)
  6757. {
  6758. static const char * const reason[] = {
  6759. "Link Down",
  6760. "Remote Fault",
  6761. "Auto-negotiation Failure",
  6762. "Reserved",
  6763. "Insufficient Airflow",
  6764. "Unable To Determine Reason",
  6765. "No RX Signal Detected",
  6766. "Reserved",
  6767. };
  6768. if (link_down_rc >= ARRAY_SIZE(reason))
  6769. return "Bad Reason Code";
  6770. return reason[link_down_rc];
  6771. }
  6772. /**
  6773. * t4_handle_get_port_info - process a FW reply message
  6774. * @pi: the port info
  6775. * @rpl: start of the FW message
  6776. *
  6777. * Processes a GET_PORT_INFO FW reply message.
  6778. */
  6779. void t4_handle_get_port_info(struct port_info *pi, const __be64 *rpl)
  6780. {
  6781. const struct fw_port_cmd *p = (const void *)rpl;
  6782. struct adapter *adap = pi->adapter;
  6783. /* link/module state change message */
  6784. int speed = 0, fc = 0;
  6785. struct link_config *lc;
  6786. u32 stat = be32_to_cpu(p->u.info.lstatus_to_modtype);
  6787. int link_ok = (stat & FW_PORT_CMD_LSTATUS_F) != 0;
  6788. u32 mod = FW_PORT_CMD_MODTYPE_G(stat);
  6789. if (stat & FW_PORT_CMD_RXPAUSE_F)
  6790. fc |= PAUSE_RX;
  6791. if (stat & FW_PORT_CMD_TXPAUSE_F)
  6792. fc |= PAUSE_TX;
  6793. if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
  6794. speed = 100;
  6795. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
  6796. speed = 1000;
  6797. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
  6798. speed = 10000;
  6799. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_25G))
  6800. speed = 25000;
  6801. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
  6802. speed = 40000;
  6803. else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100G))
  6804. speed = 100000;
  6805. lc = &pi->link_cfg;
  6806. if (mod != pi->mod_type) {
  6807. pi->mod_type = mod;
  6808. t4_os_portmod_changed(adap, pi->port_id);
  6809. }
  6810. if (link_ok != lc->link_ok || speed != lc->speed ||
  6811. fc != lc->fc) { /* something changed */
  6812. if (!link_ok && lc->link_ok) {
  6813. unsigned char rc = FW_PORT_CMD_LINKDNRC_G(stat);
  6814. lc->link_down_rc = rc;
  6815. dev_warn(adap->pdev_dev,
  6816. "Port %d link down, reason: %s\n",
  6817. pi->port_id, t4_link_down_rc_str(rc));
  6818. }
  6819. lc->link_ok = link_ok;
  6820. lc->speed = speed;
  6821. lc->fc = fc;
  6822. lc->supported = be16_to_cpu(p->u.info.pcap);
  6823. lc->lp_advertising = be16_to_cpu(p->u.info.lpacap);
  6824. t4_os_link_changed(adap, pi->port_id, link_ok);
  6825. }
  6826. }
  6827. /**
  6828. * t4_handle_fw_rpl - process a FW reply message
  6829. * @adap: the adapter
  6830. * @rpl: start of the FW message
  6831. *
  6832. * Processes a FW message, such as link state change messages.
  6833. */
  6834. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
  6835. {
  6836. u8 opcode = *(const u8 *)rpl;
  6837. /* This might be a port command ... this simplifies the following
  6838. * conditionals ... We can get away with pre-dereferencing
  6839. * action_to_len16 because it's in the first 16 bytes and all messages
  6840. * will be at least that long.
  6841. */
  6842. const struct fw_port_cmd *p = (const void *)rpl;
  6843. unsigned int action =
  6844. FW_PORT_CMD_ACTION_G(be32_to_cpu(p->action_to_len16));
  6845. if (opcode == FW_PORT_CMD && action == FW_PORT_ACTION_GET_PORT_INFO) {
  6846. int i;
  6847. int chan = FW_PORT_CMD_PORTID_G(be32_to_cpu(p->op_to_portid));
  6848. struct port_info *pi = NULL;
  6849. for_each_port(adap, i) {
  6850. pi = adap2pinfo(adap, i);
  6851. if (pi->tx_chan == chan)
  6852. break;
  6853. }
  6854. t4_handle_get_port_info(pi, rpl);
  6855. } else {
  6856. dev_warn(adap->pdev_dev, "Unknown firmware reply %d\n", opcode);
  6857. return -EINVAL;
  6858. }
  6859. return 0;
  6860. }
  6861. static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
  6862. {
  6863. u16 val;
  6864. if (pci_is_pcie(adapter->pdev)) {
  6865. pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
  6866. p->speed = val & PCI_EXP_LNKSTA_CLS;
  6867. p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
  6868. }
  6869. }
  6870. /**
  6871. * init_link_config - initialize a link's SW state
  6872. * @lc: structure holding the link state
  6873. * @caps: link capabilities
  6874. *
  6875. * Initializes the SW state maintained for each link, including the link's
  6876. * capabilities and default speed/flow-control/autonegotiation settings.
  6877. */
  6878. static void init_link_config(struct link_config *lc, unsigned int pcaps,
  6879. unsigned int acaps)
  6880. {
  6881. lc->supported = pcaps;
  6882. lc->lp_advertising = 0;
  6883. lc->requested_speed = 0;
  6884. lc->speed = 0;
  6885. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  6886. lc->auto_fec = 0;
  6887. /* For Forward Error Control, we default to whatever the Firmware
  6888. * tells us the Link is currently advertising.
  6889. */
  6890. if (acaps & FW_PORT_CAP_FEC_RS)
  6891. lc->auto_fec |= FEC_RS;
  6892. if (acaps & FW_PORT_CAP_FEC_BASER_RS)
  6893. lc->auto_fec |= FEC_BASER_RS;
  6894. lc->requested_fec = FEC_AUTO;
  6895. lc->fec = lc->auto_fec;
  6896. if (lc->supported & FW_PORT_CAP_ANEG) {
  6897. lc->advertising = lc->supported & ADVERT_MASK;
  6898. lc->autoneg = AUTONEG_ENABLE;
  6899. lc->requested_fc |= PAUSE_AUTONEG;
  6900. } else {
  6901. lc->advertising = 0;
  6902. lc->autoneg = AUTONEG_DISABLE;
  6903. }
  6904. }
  6905. #define CIM_PF_NOACCESS 0xeeeeeeee
  6906. int t4_wait_dev_ready(void __iomem *regs)
  6907. {
  6908. u32 whoami;
  6909. whoami = readl(regs + PL_WHOAMI_A);
  6910. if (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS)
  6911. return 0;
  6912. msleep(500);
  6913. whoami = readl(regs + PL_WHOAMI_A);
  6914. return (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS ? 0 : -EIO);
  6915. }
  6916. struct flash_desc {
  6917. u32 vendor_and_model_id;
  6918. u32 size_mb;
  6919. };
  6920. static int get_flash_params(struct adapter *adap)
  6921. {
  6922. /* Table for non-Numonix supported flash parts. Numonix parts are left
  6923. * to the preexisting code. All flash parts have 64KB sectors.
  6924. */
  6925. static struct flash_desc supported_flash[] = {
  6926. { 0x150201, 4 << 20 }, /* Spansion 4MB S25FL032P */
  6927. };
  6928. int ret;
  6929. u32 info;
  6930. ret = sf1_write(adap, 1, 1, 0, SF_RD_ID);
  6931. if (!ret)
  6932. ret = sf1_read(adap, 3, 0, 1, &info);
  6933. t4_write_reg(adap, SF_OP_A, 0); /* unlock SF */
  6934. if (ret)
  6935. return ret;
  6936. for (ret = 0; ret < ARRAY_SIZE(supported_flash); ++ret)
  6937. if (supported_flash[ret].vendor_and_model_id == info) {
  6938. adap->params.sf_size = supported_flash[ret].size_mb;
  6939. adap->params.sf_nsec =
  6940. adap->params.sf_size / SF_SEC_SIZE;
  6941. return 0;
  6942. }
  6943. if ((info & 0xff) != 0x20) /* not a Numonix flash */
  6944. return -EINVAL;
  6945. info >>= 16; /* log2 of size */
  6946. if (info >= 0x14 && info < 0x18)
  6947. adap->params.sf_nsec = 1 << (info - 16);
  6948. else if (info == 0x18)
  6949. adap->params.sf_nsec = 64;
  6950. else
  6951. return -EINVAL;
  6952. adap->params.sf_size = 1 << info;
  6953. adap->params.sf_fw_start =
  6954. t4_read_reg(adap, CIM_BOOT_CFG_A) & BOOTADDR_M;
  6955. if (adap->params.sf_size < FLASH_MIN_SIZE)
  6956. dev_warn(adap->pdev_dev, "WARNING!!! FLASH size %#x < %#x!!!\n",
  6957. adap->params.sf_size, FLASH_MIN_SIZE);
  6958. return 0;
  6959. }
  6960. static void set_pcie_completion_timeout(struct adapter *adapter, u8 range)
  6961. {
  6962. u16 val;
  6963. u32 pcie_cap;
  6964. pcie_cap = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  6965. if (pcie_cap) {
  6966. pci_read_config_word(adapter->pdev,
  6967. pcie_cap + PCI_EXP_DEVCTL2, &val);
  6968. val &= ~PCI_EXP_DEVCTL2_COMP_TIMEOUT;
  6969. val |= range;
  6970. pci_write_config_word(adapter->pdev,
  6971. pcie_cap + PCI_EXP_DEVCTL2, val);
  6972. }
  6973. }
  6974. /**
  6975. * t4_prep_adapter - prepare SW and HW for operation
  6976. * @adapter: the adapter
  6977. * @reset: if true perform a HW reset
  6978. *
  6979. * Initialize adapter SW state for the various HW modules, set initial
  6980. * values for some adapter tunables, take PHYs out of reset, and
  6981. * initialize the MDIO interface.
  6982. */
  6983. int t4_prep_adapter(struct adapter *adapter)
  6984. {
  6985. int ret, ver;
  6986. uint16_t device_id;
  6987. u32 pl_rev;
  6988. get_pci_mode(adapter, &adapter->params.pci);
  6989. pl_rev = REV_G(t4_read_reg(adapter, PL_REV_A));
  6990. ret = get_flash_params(adapter);
  6991. if (ret < 0) {
  6992. dev_err(adapter->pdev_dev, "error %d identifying flash\n", ret);
  6993. return ret;
  6994. }
  6995. /* Retrieve adapter's device ID
  6996. */
  6997. pci_read_config_word(adapter->pdev, PCI_DEVICE_ID, &device_id);
  6998. ver = device_id >> 12;
  6999. adapter->params.chip = 0;
  7000. switch (ver) {
  7001. case CHELSIO_T4:
  7002. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  7003. adapter->params.arch.sge_fl_db = DBPRIO_F;
  7004. adapter->params.arch.mps_tcam_size =
  7005. NUM_MPS_CLS_SRAM_L_INSTANCES;
  7006. adapter->params.arch.mps_rplc_size = 128;
  7007. adapter->params.arch.nchan = NCHAN;
  7008. adapter->params.arch.pm_stats_cnt = PM_NSTATS;
  7009. adapter->params.arch.vfcount = 128;
  7010. /* Congestion map is for 4 channels so that
  7011. * MPS can have 4 priority per port.
  7012. */
  7013. adapter->params.arch.cng_ch_bits_log = 2;
  7014. break;
  7015. case CHELSIO_T5:
  7016. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  7017. adapter->params.arch.sge_fl_db = DBPRIO_F | DBTYPE_F;
  7018. adapter->params.arch.mps_tcam_size =
  7019. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  7020. adapter->params.arch.mps_rplc_size = 128;
  7021. adapter->params.arch.nchan = NCHAN;
  7022. adapter->params.arch.pm_stats_cnt = PM_NSTATS;
  7023. adapter->params.arch.vfcount = 128;
  7024. adapter->params.arch.cng_ch_bits_log = 2;
  7025. break;
  7026. case CHELSIO_T6:
  7027. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  7028. adapter->params.arch.sge_fl_db = 0;
  7029. adapter->params.arch.mps_tcam_size =
  7030. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  7031. adapter->params.arch.mps_rplc_size = 256;
  7032. adapter->params.arch.nchan = 2;
  7033. adapter->params.arch.pm_stats_cnt = T6_PM_NSTATS;
  7034. adapter->params.arch.vfcount = 256;
  7035. /* Congestion map will be for 2 channels so that
  7036. * MPS can have 8 priority per port.
  7037. */
  7038. adapter->params.arch.cng_ch_bits_log = 3;
  7039. break;
  7040. default:
  7041. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  7042. device_id);
  7043. return -EINVAL;
  7044. }
  7045. adapter->params.cim_la_size = CIMLA_SIZE;
  7046. init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
  7047. /*
  7048. * Default port for debugging in case we can't reach FW.
  7049. */
  7050. adapter->params.nports = 1;
  7051. adapter->params.portvec = 1;
  7052. adapter->params.vpd.cclk = 50000;
  7053. /* Set pci completion timeout value to 4 seconds. */
  7054. set_pcie_completion_timeout(adapter, 0xd);
  7055. return 0;
  7056. }
  7057. /**
  7058. * t4_shutdown_adapter - shut down adapter, host & wire
  7059. * @adapter: the adapter
  7060. *
  7061. * Perform an emergency shutdown of the adapter and stop it from
  7062. * continuing any further communication on the ports or DMA to the
  7063. * host. This is typically used when the adapter and/or firmware
  7064. * have crashed and we want to prevent any further accidental
  7065. * communication with the rest of the world. This will also force
  7066. * the port Link Status to go down -- if register writes work --
  7067. * which should help our peers figure out that we're down.
  7068. */
  7069. int t4_shutdown_adapter(struct adapter *adapter)
  7070. {
  7071. int port;
  7072. t4_intr_disable(adapter);
  7073. t4_write_reg(adapter, DBG_GPIO_EN_A, 0);
  7074. for_each_port(adapter, port) {
  7075. u32 a_port_cfg = PORT_REG(port,
  7076. is_t4(adapter->params.chip)
  7077. ? XGMAC_PORT_CFG_A
  7078. : MAC_PORT_CFG_A);
  7079. t4_write_reg(adapter, a_port_cfg,
  7080. t4_read_reg(adapter, a_port_cfg)
  7081. & ~SIGNAL_DET_V(1));
  7082. }
  7083. t4_set_reg_field(adapter, SGE_CONTROL_A, GLOBALENABLE_F, 0);
  7084. return 0;
  7085. }
  7086. /**
  7087. * t4_bar2_sge_qregs - return BAR2 SGE Queue register information
  7088. * @adapter: the adapter
  7089. * @qid: the Queue ID
  7090. * @qtype: the Ingress or Egress type for @qid
  7091. * @user: true if this request is for a user mode queue
  7092. * @pbar2_qoffset: BAR2 Queue Offset
  7093. * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
  7094. *
  7095. * Returns the BAR2 SGE Queue Registers information associated with the
  7096. * indicated Absolute Queue ID. These are passed back in return value
  7097. * pointers. @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
  7098. * and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
  7099. *
  7100. * This may return an error which indicates that BAR2 SGE Queue
  7101. * registers aren't available. If an error is not returned, then the
  7102. * following values are returned:
  7103. *
  7104. * *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
  7105. * *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
  7106. *
  7107. * If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
  7108. * require the "Inferred Queue ID" ability may be used. E.g. the
  7109. * Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
  7110. * then these "Inferred Queue ID" register may not be used.
  7111. */
  7112. int t4_bar2_sge_qregs(struct adapter *adapter,
  7113. unsigned int qid,
  7114. enum t4_bar2_qtype qtype,
  7115. int user,
  7116. u64 *pbar2_qoffset,
  7117. unsigned int *pbar2_qid)
  7118. {
  7119. unsigned int page_shift, page_size, qpp_shift, qpp_mask;
  7120. u64 bar2_page_offset, bar2_qoffset;
  7121. unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
  7122. /* T4 doesn't support BAR2 SGE Queue registers for kernel mode queues */
  7123. if (!user && is_t4(adapter->params.chip))
  7124. return -EINVAL;
  7125. /* Get our SGE Page Size parameters.
  7126. */
  7127. page_shift = adapter->params.sge.hps + 10;
  7128. page_size = 1 << page_shift;
  7129. /* Get the right Queues per Page parameters for our Queue.
  7130. */
  7131. qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
  7132. ? adapter->params.sge.eq_qpp
  7133. : adapter->params.sge.iq_qpp);
  7134. qpp_mask = (1 << qpp_shift) - 1;
  7135. /* Calculate the basics of the BAR2 SGE Queue register area:
  7136. * o The BAR2 page the Queue registers will be in.
  7137. * o The BAR2 Queue ID.
  7138. * o The BAR2 Queue ID Offset into the BAR2 page.
  7139. */
  7140. bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
  7141. bar2_qid = qid & qpp_mask;
  7142. bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
  7143. /* If the BAR2 Queue ID Offset is less than the Page Size, then the
  7144. * hardware will infer the Absolute Queue ID simply from the writes to
  7145. * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
  7146. * BAR2 Queue ID of 0 for those writes). Otherwise, we'll simply
  7147. * write to the first BAR2 SGE Queue Area within the BAR2 Page with
  7148. * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
  7149. * from the BAR2 Page and BAR2 Queue ID.
  7150. *
  7151. * One important censequence of this is that some BAR2 SGE registers
  7152. * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
  7153. * there. But other registers synthesize the SGE Queue ID purely
  7154. * from the writes to the registers -- the Write Combined Doorbell
  7155. * Buffer is a good example. These BAR2 SGE Registers are only
  7156. * available for those BAR2 SGE Register areas where the SGE Absolute
  7157. * Queue ID can be inferred from simple writes.
  7158. */
  7159. bar2_qoffset = bar2_page_offset;
  7160. bar2_qinferred = (bar2_qid_offset < page_size);
  7161. if (bar2_qinferred) {
  7162. bar2_qoffset += bar2_qid_offset;
  7163. bar2_qid = 0;
  7164. }
  7165. *pbar2_qoffset = bar2_qoffset;
  7166. *pbar2_qid = bar2_qid;
  7167. return 0;
  7168. }
  7169. /**
  7170. * t4_init_devlog_params - initialize adapter->params.devlog
  7171. * @adap: the adapter
  7172. *
  7173. * Initialize various fields of the adapter's Firmware Device Log
  7174. * Parameters structure.
  7175. */
  7176. int t4_init_devlog_params(struct adapter *adap)
  7177. {
  7178. struct devlog_params *dparams = &adap->params.devlog;
  7179. u32 pf_dparams;
  7180. unsigned int devlog_meminfo;
  7181. struct fw_devlog_cmd devlog_cmd;
  7182. int ret;
  7183. /* If we're dealing with newer firmware, the Device Log Paramerters
  7184. * are stored in a designated register which allows us to access the
  7185. * Device Log even if we can't talk to the firmware.
  7186. */
  7187. pf_dparams =
  7188. t4_read_reg(adap, PCIE_FW_REG(PCIE_FW_PF_A, PCIE_FW_PF_DEVLOG));
  7189. if (pf_dparams) {
  7190. unsigned int nentries, nentries128;
  7191. dparams->memtype = PCIE_FW_PF_DEVLOG_MEMTYPE_G(pf_dparams);
  7192. dparams->start = PCIE_FW_PF_DEVLOG_ADDR16_G(pf_dparams) << 4;
  7193. nentries128 = PCIE_FW_PF_DEVLOG_NENTRIES128_G(pf_dparams);
  7194. nentries = (nentries128 + 1) * 128;
  7195. dparams->size = nentries * sizeof(struct fw_devlog_e);
  7196. return 0;
  7197. }
  7198. /* Otherwise, ask the firmware for it's Device Log Parameters.
  7199. */
  7200. memset(&devlog_cmd, 0, sizeof(devlog_cmd));
  7201. devlog_cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_DEVLOG_CMD) |
  7202. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  7203. devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
  7204. ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
  7205. &devlog_cmd);
  7206. if (ret)
  7207. return ret;
  7208. devlog_meminfo =
  7209. be32_to_cpu(devlog_cmd.memtype_devlog_memaddr16_devlog);
  7210. dparams->memtype = FW_DEVLOG_CMD_MEMTYPE_DEVLOG_G(devlog_meminfo);
  7211. dparams->start = FW_DEVLOG_CMD_MEMADDR16_DEVLOG_G(devlog_meminfo) << 4;
  7212. dparams->size = be32_to_cpu(devlog_cmd.memsize_devlog);
  7213. return 0;
  7214. }
  7215. /**
  7216. * t4_init_sge_params - initialize adap->params.sge
  7217. * @adapter: the adapter
  7218. *
  7219. * Initialize various fields of the adapter's SGE Parameters structure.
  7220. */
  7221. int t4_init_sge_params(struct adapter *adapter)
  7222. {
  7223. struct sge_params *sge_params = &adapter->params.sge;
  7224. u32 hps, qpp;
  7225. unsigned int s_hps, s_qpp;
  7226. /* Extract the SGE Page Size for our PF.
  7227. */
  7228. hps = t4_read_reg(adapter, SGE_HOST_PAGE_SIZE_A);
  7229. s_hps = (HOSTPAGESIZEPF0_S +
  7230. (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * adapter->pf);
  7231. sge_params->hps = ((hps >> s_hps) & HOSTPAGESIZEPF0_M);
  7232. /* Extract the SGE Egress and Ingess Queues Per Page for our PF.
  7233. */
  7234. s_qpp = (QUEUESPERPAGEPF0_S +
  7235. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * adapter->pf);
  7236. qpp = t4_read_reg(adapter, SGE_EGRESS_QUEUES_PER_PAGE_PF_A);
  7237. sge_params->eq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  7238. qpp = t4_read_reg(adapter, SGE_INGRESS_QUEUES_PER_PAGE_PF_A);
  7239. sge_params->iq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
  7240. return 0;
  7241. }
  7242. /**
  7243. * t4_init_tp_params - initialize adap->params.tp
  7244. * @adap: the adapter
  7245. *
  7246. * Initialize various fields of the adapter's TP Parameters structure.
  7247. */
  7248. int t4_init_tp_params(struct adapter *adap)
  7249. {
  7250. int chan;
  7251. u32 v;
  7252. v = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
  7253. adap->params.tp.tre = TIMERRESOLUTION_G(v);
  7254. adap->params.tp.dack_re = DELAYEDACKRESOLUTION_G(v);
  7255. /* MODQ_REQ_MAP defaults to setting queues 0-3 to chan 0-3 */
  7256. for (chan = 0; chan < NCHAN; chan++)
  7257. adap->params.tp.tx_modq[chan] = chan;
  7258. /* Cache the adapter's Compressed Filter Mode and global Incress
  7259. * Configuration.
  7260. */
  7261. if (t4_use_ldst(adap)) {
  7262. t4_fw_tp_pio_rw(adap, &adap->params.tp.vlan_pri_map, 1,
  7263. TP_VLAN_PRI_MAP_A, 1);
  7264. t4_fw_tp_pio_rw(adap, &adap->params.tp.ingress_config, 1,
  7265. TP_INGRESS_CONFIG_A, 1);
  7266. } else {
  7267. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  7268. &adap->params.tp.vlan_pri_map, 1,
  7269. TP_VLAN_PRI_MAP_A);
  7270. t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  7271. &adap->params.tp.ingress_config, 1,
  7272. TP_INGRESS_CONFIG_A);
  7273. }
  7274. /* For T6, cache the adapter's compressed error vector
  7275. * and passing outer header info for encapsulated packets.
  7276. */
  7277. if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
  7278. v = t4_read_reg(adap, TP_OUT_CONFIG_A);
  7279. adap->params.tp.rx_pkt_encap = (v & CRXPKTENC_F) ? 1 : 0;
  7280. }
  7281. /* Now that we have TP_VLAN_PRI_MAP cached, we can calculate the field
  7282. * shift positions of several elements of the Compressed Filter Tuple
  7283. * for this adapter which we need frequently ...
  7284. */
  7285. adap->params.tp.vlan_shift = t4_filter_field_shift(adap, VLAN_F);
  7286. adap->params.tp.vnic_shift = t4_filter_field_shift(adap, VNIC_ID_F);
  7287. adap->params.tp.port_shift = t4_filter_field_shift(adap, PORT_F);
  7288. adap->params.tp.protocol_shift = t4_filter_field_shift(adap,
  7289. PROTOCOL_F);
  7290. /* If TP_INGRESS_CONFIG.VNID == 0, then TP_VLAN_PRI_MAP.VNIC_ID
  7291. * represents the presence of an Outer VLAN instead of a VNIC ID.
  7292. */
  7293. if ((adap->params.tp.ingress_config & VNIC_F) == 0)
  7294. adap->params.tp.vnic_shift = -1;
  7295. return 0;
  7296. }
  7297. /**
  7298. * t4_filter_field_shift - calculate filter field shift
  7299. * @adap: the adapter
  7300. * @filter_sel: the desired field (from TP_VLAN_PRI_MAP bits)
  7301. *
  7302. * Return the shift position of a filter field within the Compressed
  7303. * Filter Tuple. The filter field is specified via its selection bit
  7304. * within TP_VLAN_PRI_MAL (filter mode). E.g. F_VLAN.
  7305. */
  7306. int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
  7307. {
  7308. unsigned int filter_mode = adap->params.tp.vlan_pri_map;
  7309. unsigned int sel;
  7310. int field_shift;
  7311. if ((filter_mode & filter_sel) == 0)
  7312. return -1;
  7313. for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
  7314. switch (filter_mode & sel) {
  7315. case FCOE_F:
  7316. field_shift += FT_FCOE_W;
  7317. break;
  7318. case PORT_F:
  7319. field_shift += FT_PORT_W;
  7320. break;
  7321. case VNIC_ID_F:
  7322. field_shift += FT_VNIC_ID_W;
  7323. break;
  7324. case VLAN_F:
  7325. field_shift += FT_VLAN_W;
  7326. break;
  7327. case TOS_F:
  7328. field_shift += FT_TOS_W;
  7329. break;
  7330. case PROTOCOL_F:
  7331. field_shift += FT_PROTOCOL_W;
  7332. break;
  7333. case ETHERTYPE_F:
  7334. field_shift += FT_ETHERTYPE_W;
  7335. break;
  7336. case MACMATCH_F:
  7337. field_shift += FT_MACMATCH_W;
  7338. break;
  7339. case MPSHITTYPE_F:
  7340. field_shift += FT_MPSHITTYPE_W;
  7341. break;
  7342. case FRAGMENTATION_F:
  7343. field_shift += FT_FRAGMENTATION_W;
  7344. break;
  7345. }
  7346. }
  7347. return field_shift;
  7348. }
  7349. int t4_init_rss_mode(struct adapter *adap, int mbox)
  7350. {
  7351. int i, ret;
  7352. struct fw_rss_vi_config_cmd rvc;
  7353. memset(&rvc, 0, sizeof(rvc));
  7354. for_each_port(adap, i) {
  7355. struct port_info *p = adap2pinfo(adap, i);
  7356. rvc.op_to_viid =
  7357. cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  7358. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  7359. FW_RSS_VI_CONFIG_CMD_VIID_V(p->viid));
  7360. rvc.retval_len16 = cpu_to_be32(FW_LEN16(rvc));
  7361. ret = t4_wr_mbox(adap, mbox, &rvc, sizeof(rvc), &rvc);
  7362. if (ret)
  7363. return ret;
  7364. p->rss_mode = be32_to_cpu(rvc.u.basicvirtual.defaultq_to_udpen);
  7365. }
  7366. return 0;
  7367. }
  7368. /**
  7369. * t4_init_portinfo - allocate a virtual interface amd initialize port_info
  7370. * @pi: the port_info
  7371. * @mbox: mailbox to use for the FW command
  7372. * @port: physical port associated with the VI
  7373. * @pf: the PF owning the VI
  7374. * @vf: the VF owning the VI
  7375. * @mac: the MAC address of the VI
  7376. *
  7377. * Allocates a virtual interface for the given physical port. If @mac is
  7378. * not %NULL it contains the MAC address of the VI as assigned by FW.
  7379. * @mac should be large enough to hold an Ethernet address.
  7380. * Returns < 0 on error.
  7381. */
  7382. int t4_init_portinfo(struct port_info *pi, int mbox,
  7383. int port, int pf, int vf, u8 mac[])
  7384. {
  7385. int ret;
  7386. struct fw_port_cmd c;
  7387. unsigned int rss_size;
  7388. memset(&c, 0, sizeof(c));
  7389. c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  7390. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  7391. FW_PORT_CMD_PORTID_V(port));
  7392. c.action_to_len16 = cpu_to_be32(
  7393. FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
  7394. FW_LEN16(c));
  7395. ret = t4_wr_mbox(pi->adapter, mbox, &c, sizeof(c), &c);
  7396. if (ret)
  7397. return ret;
  7398. ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, mac, &rss_size);
  7399. if (ret < 0)
  7400. return ret;
  7401. pi->viid = ret;
  7402. pi->tx_chan = port;
  7403. pi->lport = port;
  7404. pi->rss_size = rss_size;
  7405. ret = be32_to_cpu(c.u.info.lstatus_to_modtype);
  7406. pi->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP_F) ?
  7407. FW_PORT_CMD_MDIOADDR_G(ret) : -1;
  7408. pi->port_type = FW_PORT_CMD_PTYPE_G(ret);
  7409. pi->mod_type = FW_PORT_MOD_TYPE_NA;
  7410. init_link_config(&pi->link_cfg, be16_to_cpu(c.u.info.pcap),
  7411. be16_to_cpu(c.u.info.acap));
  7412. return 0;
  7413. }
  7414. int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
  7415. {
  7416. u8 addr[6];
  7417. int ret, i, j = 0;
  7418. for_each_port(adap, i) {
  7419. struct port_info *pi = adap2pinfo(adap, i);
  7420. while ((adap->params.portvec & (1 << j)) == 0)
  7421. j++;
  7422. ret = t4_init_portinfo(pi, mbox, j, pf, vf, addr);
  7423. if (ret)
  7424. return ret;
  7425. memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
  7426. j++;
  7427. }
  7428. return 0;
  7429. }
  7430. /**
  7431. * t4_read_cimq_cfg - read CIM queue configuration
  7432. * @adap: the adapter
  7433. * @base: holds the queue base addresses in bytes
  7434. * @size: holds the queue sizes in bytes
  7435. * @thres: holds the queue full thresholds in bytes
  7436. *
  7437. * Returns the current configuration of the CIM queues, starting with
  7438. * the IBQs, then the OBQs.
  7439. */
  7440. void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres)
  7441. {
  7442. unsigned int i, v;
  7443. int cim_num_obq = is_t4(adap->params.chip) ?
  7444. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  7445. for (i = 0; i < CIM_NUM_IBQ; i++) {
  7446. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, IBQSELECT_F |
  7447. QUENUMSELECT_V(i));
  7448. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  7449. /* value is in 256-byte units */
  7450. *base++ = CIMQBASE_G(v) * 256;
  7451. *size++ = CIMQSIZE_G(v) * 256;
  7452. *thres++ = QUEFULLTHRSH_G(v) * 8; /* 8-byte unit */
  7453. }
  7454. for (i = 0; i < cim_num_obq; i++) {
  7455. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  7456. QUENUMSELECT_V(i));
  7457. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  7458. /* value is in 256-byte units */
  7459. *base++ = CIMQBASE_G(v) * 256;
  7460. *size++ = CIMQSIZE_G(v) * 256;
  7461. }
  7462. }
  7463. /**
  7464. * t4_read_cim_ibq - read the contents of a CIM inbound queue
  7465. * @adap: the adapter
  7466. * @qid: the queue index
  7467. * @data: where to store the queue contents
  7468. * @n: capacity of @data in 32-bit words
  7469. *
  7470. * Reads the contents of the selected CIM queue starting at address 0 up
  7471. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  7472. * error and the number of 32-bit words actually read on success.
  7473. */
  7474. int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  7475. {
  7476. int i, err, attempts;
  7477. unsigned int addr;
  7478. const unsigned int nwords = CIM_IBQ_SIZE * 4;
  7479. if (qid > 5 || (n & 3))
  7480. return -EINVAL;
  7481. addr = qid * nwords;
  7482. if (n > nwords)
  7483. n = nwords;
  7484. /* It might take 3-10ms before the IBQ debug read access is allowed.
  7485. * Wait for 1 Sec with a delay of 1 usec.
  7486. */
  7487. attempts = 1000000;
  7488. for (i = 0; i < n; i++, addr++) {
  7489. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, IBQDBGADDR_V(addr) |
  7490. IBQDBGEN_F);
  7491. err = t4_wait_op_done(adap, CIM_IBQ_DBG_CFG_A, IBQDBGBUSY_F, 0,
  7492. attempts, 1);
  7493. if (err)
  7494. return err;
  7495. *data++ = t4_read_reg(adap, CIM_IBQ_DBG_DATA_A);
  7496. }
  7497. t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, 0);
  7498. return i;
  7499. }
  7500. /**
  7501. * t4_read_cim_obq - read the contents of a CIM outbound queue
  7502. * @adap: the adapter
  7503. * @qid: the queue index
  7504. * @data: where to store the queue contents
  7505. * @n: capacity of @data in 32-bit words
  7506. *
  7507. * Reads the contents of the selected CIM queue starting at address 0 up
  7508. * to the capacity of @data. @n must be a multiple of 4. Returns < 0 on
  7509. * error and the number of 32-bit words actually read on success.
  7510. */
  7511. int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
  7512. {
  7513. int i, err;
  7514. unsigned int addr, v, nwords;
  7515. int cim_num_obq = is_t4(adap->params.chip) ?
  7516. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  7517. if ((qid > (cim_num_obq - 1)) || (n & 3))
  7518. return -EINVAL;
  7519. t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  7520. QUENUMSELECT_V(qid));
  7521. v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
  7522. addr = CIMQBASE_G(v) * 64; /* muliple of 256 -> muliple of 4 */
  7523. nwords = CIMQSIZE_G(v) * 64; /* same */
  7524. if (n > nwords)
  7525. n = nwords;
  7526. for (i = 0; i < n; i++, addr++) {
  7527. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, OBQDBGADDR_V(addr) |
  7528. OBQDBGEN_F);
  7529. err = t4_wait_op_done(adap, CIM_OBQ_DBG_CFG_A, OBQDBGBUSY_F, 0,
  7530. 2, 1);
  7531. if (err)
  7532. return err;
  7533. *data++ = t4_read_reg(adap, CIM_OBQ_DBG_DATA_A);
  7534. }
  7535. t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, 0);
  7536. return i;
  7537. }
  7538. /**
  7539. * t4_cim_read - read a block from CIM internal address space
  7540. * @adap: the adapter
  7541. * @addr: the start address within the CIM address space
  7542. * @n: number of words to read
  7543. * @valp: where to store the result
  7544. *
  7545. * Reads a block of 4-byte words from the CIM intenal address space.
  7546. */
  7547. int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
  7548. unsigned int *valp)
  7549. {
  7550. int ret = 0;
  7551. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  7552. return -EBUSY;
  7553. for ( ; !ret && n--; addr += 4) {
  7554. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr);
  7555. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  7556. 0, 5, 2);
  7557. if (!ret)
  7558. *valp++ = t4_read_reg(adap, CIM_HOST_ACC_DATA_A);
  7559. }
  7560. return ret;
  7561. }
  7562. /**
  7563. * t4_cim_write - write a block into CIM internal address space
  7564. * @adap: the adapter
  7565. * @addr: the start address within the CIM address space
  7566. * @n: number of words to write
  7567. * @valp: set of values to write
  7568. *
  7569. * Writes a block of 4-byte words into the CIM intenal address space.
  7570. */
  7571. int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
  7572. const unsigned int *valp)
  7573. {
  7574. int ret = 0;
  7575. if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
  7576. return -EBUSY;
  7577. for ( ; !ret && n--; addr += 4) {
  7578. t4_write_reg(adap, CIM_HOST_ACC_DATA_A, *valp++);
  7579. t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr | HOSTWRITE_F);
  7580. ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
  7581. 0, 5, 2);
  7582. }
  7583. return ret;
  7584. }
  7585. static int t4_cim_write1(struct adapter *adap, unsigned int addr,
  7586. unsigned int val)
  7587. {
  7588. return t4_cim_write(adap, addr, 1, &val);
  7589. }
  7590. /**
  7591. * t4_cim_read_la - read CIM LA capture buffer
  7592. * @adap: the adapter
  7593. * @la_buf: where to store the LA data
  7594. * @wrptr: the HW write pointer within the capture buffer
  7595. *
  7596. * Reads the contents of the CIM LA buffer with the most recent entry at
  7597. * the end of the returned data and with the entry at @wrptr first.
  7598. * We try to leave the LA in the running state we find it in.
  7599. */
  7600. int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr)
  7601. {
  7602. int i, ret;
  7603. unsigned int cfg, val, idx;
  7604. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  7605. if (ret)
  7606. return ret;
  7607. if (cfg & UPDBGLAEN_F) { /* LA is running, freeze it */
  7608. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A, 0);
  7609. if (ret)
  7610. return ret;
  7611. }
  7612. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  7613. if (ret)
  7614. goto restart;
  7615. idx = UPDBGLAWRPTR_G(val);
  7616. if (wrptr)
  7617. *wrptr = idx;
  7618. for (i = 0; i < adap->params.cim_la_size; i++) {
  7619. ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  7620. UPDBGLARDPTR_V(idx) | UPDBGLARDEN_F);
  7621. if (ret)
  7622. break;
  7623. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
  7624. if (ret)
  7625. break;
  7626. if (val & UPDBGLARDEN_F) {
  7627. ret = -ETIMEDOUT;
  7628. break;
  7629. }
  7630. ret = t4_cim_read(adap, UP_UP_DBG_LA_DATA_A, 1, &la_buf[i]);
  7631. if (ret)
  7632. break;
  7633. idx = (idx + 1) & UPDBGLARDPTR_M;
  7634. }
  7635. restart:
  7636. if (cfg & UPDBGLAEN_F) {
  7637. int r = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
  7638. cfg & ~UPDBGLARDEN_F);
  7639. if (!ret)
  7640. ret = r;
  7641. }
  7642. return ret;
  7643. }
  7644. /**
  7645. * t4_tp_read_la - read TP LA capture buffer
  7646. * @adap: the adapter
  7647. * @la_buf: where to store the LA data
  7648. * @wrptr: the HW write pointer within the capture buffer
  7649. *
  7650. * Reads the contents of the TP LA buffer with the most recent entry at
  7651. * the end of the returned data and with the entry at @wrptr first.
  7652. * We leave the LA in the running state we find it in.
  7653. */
  7654. void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
  7655. {
  7656. bool last_incomplete;
  7657. unsigned int i, cfg, val, idx;
  7658. cfg = t4_read_reg(adap, TP_DBG_LA_CONFIG_A) & 0xffff;
  7659. if (cfg & DBGLAENABLE_F) /* freeze LA */
  7660. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  7661. adap->params.tp.la_mask | (cfg ^ DBGLAENABLE_F));
  7662. val = t4_read_reg(adap, TP_DBG_LA_CONFIG_A);
  7663. idx = DBGLAWPTR_G(val);
  7664. last_incomplete = DBGLAMODE_G(val) >= 2 && (val & DBGLAWHLF_F) == 0;
  7665. if (last_incomplete)
  7666. idx = (idx + 1) & DBGLARPTR_M;
  7667. if (wrptr)
  7668. *wrptr = idx;
  7669. val &= 0xffff;
  7670. val &= ~DBGLARPTR_V(DBGLARPTR_M);
  7671. val |= adap->params.tp.la_mask;
  7672. for (i = 0; i < TPLA_SIZE; i++) {
  7673. t4_write_reg(adap, TP_DBG_LA_CONFIG_A, DBGLARPTR_V(idx) | val);
  7674. la_buf[i] = t4_read_reg64(adap, TP_DBG_LA_DATAL_A);
  7675. idx = (idx + 1) & DBGLARPTR_M;
  7676. }
  7677. /* Wipe out last entry if it isn't valid */
  7678. if (last_incomplete)
  7679. la_buf[TPLA_SIZE - 1] = ~0ULL;
  7680. if (cfg & DBGLAENABLE_F) /* restore running state */
  7681. t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
  7682. cfg | adap->params.tp.la_mask);
  7683. }
  7684. /* SGE Hung Ingress DMA Warning Threshold time and Warning Repeat Rate (in
  7685. * seconds). If we find one of the SGE Ingress DMA State Machines in the same
  7686. * state for more than the Warning Threshold then we'll issue a warning about
  7687. * a potential hang. We'll repeat the warning as the SGE Ingress DMA Channel
  7688. * appears to be hung every Warning Repeat second till the situation clears.
  7689. * If the situation clears, we'll note that as well.
  7690. */
  7691. #define SGE_IDMA_WARN_THRESH 1
  7692. #define SGE_IDMA_WARN_REPEAT 300
  7693. /**
  7694. * t4_idma_monitor_init - initialize SGE Ingress DMA Monitor
  7695. * @adapter: the adapter
  7696. * @idma: the adapter IDMA Monitor state
  7697. *
  7698. * Initialize the state of an SGE Ingress DMA Monitor.
  7699. */
  7700. void t4_idma_monitor_init(struct adapter *adapter,
  7701. struct sge_idma_monitor_state *idma)
  7702. {
  7703. /* Initialize the state variables for detecting an SGE Ingress DMA
  7704. * hang. The SGE has internal counters which count up on each clock
  7705. * tick whenever the SGE finds its Ingress DMA State Engines in the
  7706. * same state they were on the previous clock tick. The clock used is
  7707. * the Core Clock so we have a limit on the maximum "time" they can
  7708. * record; typically a very small number of seconds. For instance,
  7709. * with a 600MHz Core Clock, we can only count up to a bit more than
  7710. * 7s. So we'll synthesize a larger counter in order to not run the
  7711. * risk of having the "timers" overflow and give us the flexibility to
  7712. * maintain a Hung SGE State Machine of our own which operates across
  7713. * a longer time frame.
  7714. */
  7715. idma->idma_1s_thresh = core_ticks_per_usec(adapter) * 1000000; /* 1s */
  7716. idma->idma_stalled[0] = 0;
  7717. idma->idma_stalled[1] = 0;
  7718. }
  7719. /**
  7720. * t4_idma_monitor - monitor SGE Ingress DMA state
  7721. * @adapter: the adapter
  7722. * @idma: the adapter IDMA Monitor state
  7723. * @hz: number of ticks/second
  7724. * @ticks: number of ticks since the last IDMA Monitor call
  7725. */
  7726. void t4_idma_monitor(struct adapter *adapter,
  7727. struct sge_idma_monitor_state *idma,
  7728. int hz, int ticks)
  7729. {
  7730. int i, idma_same_state_cnt[2];
  7731. /* Read the SGE Debug Ingress DMA Same State Count registers. These
  7732. * are counters inside the SGE which count up on each clock when the
  7733. * SGE finds its Ingress DMA State Engines in the same states they
  7734. * were in the previous clock. The counters will peg out at
  7735. * 0xffffffff without wrapping around so once they pass the 1s
  7736. * threshold they'll stay above that till the IDMA state changes.
  7737. */
  7738. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 13);
  7739. idma_same_state_cnt[0] = t4_read_reg(adapter, SGE_DEBUG_DATA_HIGH_A);
  7740. idma_same_state_cnt[1] = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7741. for (i = 0; i < 2; i++) {
  7742. u32 debug0, debug11;
  7743. /* If the Ingress DMA Same State Counter ("timer") is less
  7744. * than 1s, then we can reset our synthesized Stall Timer and
  7745. * continue. If we have previously emitted warnings about a
  7746. * potential stalled Ingress Queue, issue a note indicating
  7747. * that the Ingress Queue has resumed forward progress.
  7748. */
  7749. if (idma_same_state_cnt[i] < idma->idma_1s_thresh) {
  7750. if (idma->idma_stalled[i] >= SGE_IDMA_WARN_THRESH * hz)
  7751. dev_warn(adapter->pdev_dev, "SGE idma%d, queue %u, "
  7752. "resumed after %d seconds\n",
  7753. i, idma->idma_qid[i],
  7754. idma->idma_stalled[i] / hz);
  7755. idma->idma_stalled[i] = 0;
  7756. continue;
  7757. }
  7758. /* Synthesize an SGE Ingress DMA Same State Timer in the Hz
  7759. * domain. The first time we get here it'll be because we
  7760. * passed the 1s Threshold; each additional time it'll be
  7761. * because the RX Timer Callback is being fired on its regular
  7762. * schedule.
  7763. *
  7764. * If the stall is below our Potential Hung Ingress Queue
  7765. * Warning Threshold, continue.
  7766. */
  7767. if (idma->idma_stalled[i] == 0) {
  7768. idma->idma_stalled[i] = hz;
  7769. idma->idma_warn[i] = 0;
  7770. } else {
  7771. idma->idma_stalled[i] += ticks;
  7772. idma->idma_warn[i] -= ticks;
  7773. }
  7774. if (idma->idma_stalled[i] < SGE_IDMA_WARN_THRESH * hz)
  7775. continue;
  7776. /* We'll issue a warning every SGE_IDMA_WARN_REPEAT seconds.
  7777. */
  7778. if (idma->idma_warn[i] > 0)
  7779. continue;
  7780. idma->idma_warn[i] = SGE_IDMA_WARN_REPEAT * hz;
  7781. /* Read and save the SGE IDMA State and Queue ID information.
  7782. * We do this every time in case it changes across time ...
  7783. * can't be too careful ...
  7784. */
  7785. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 0);
  7786. debug0 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7787. idma->idma_state[i] = (debug0 >> (i * 9)) & 0x3f;
  7788. t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 11);
  7789. debug11 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
  7790. idma->idma_qid[i] = (debug11 >> (i * 16)) & 0xffff;
  7791. dev_warn(adapter->pdev_dev, "SGE idma%u, queue %u, potentially stuck in "
  7792. "state %u for %d seconds (debug0=%#x, debug11=%#x)\n",
  7793. i, idma->idma_qid[i], idma->idma_state[i],
  7794. idma->idma_stalled[i] / hz,
  7795. debug0, debug11);
  7796. t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
  7797. }
  7798. }
  7799. /**
  7800. * t4_set_vf_mac - Set MAC address for the specified VF
  7801. * @adapter: The adapter
  7802. * @vf: one of the VFs instantiated by the specified PF
  7803. * @naddr: the number of MAC addresses
  7804. * @addr: the MAC address(es) to be set to the specified VF
  7805. */
  7806. int t4_set_vf_mac_acl(struct adapter *adapter, unsigned int vf,
  7807. unsigned int naddr, u8 *addr)
  7808. {
  7809. struct fw_acl_mac_cmd cmd;
  7810. memset(&cmd, 0, sizeof(cmd));
  7811. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_ACL_MAC_CMD) |
  7812. FW_CMD_REQUEST_F |
  7813. FW_CMD_WRITE_F |
  7814. FW_ACL_MAC_CMD_PFN_V(adapter->pf) |
  7815. FW_ACL_MAC_CMD_VFN_V(vf));
  7816. /* Note: Do not enable the ACL */
  7817. cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
  7818. cmd.nmac = naddr;
  7819. switch (adapter->pf) {
  7820. case 3:
  7821. memcpy(cmd.macaddr3, addr, sizeof(cmd.macaddr3));
  7822. break;
  7823. case 2:
  7824. memcpy(cmd.macaddr2, addr, sizeof(cmd.macaddr2));
  7825. break;
  7826. case 1:
  7827. memcpy(cmd.macaddr1, addr, sizeof(cmd.macaddr1));
  7828. break;
  7829. case 0:
  7830. memcpy(cmd.macaddr0, addr, sizeof(cmd.macaddr0));
  7831. break;
  7832. }
  7833. return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
  7834. }
  7835. int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
  7836. int rateunit, int ratemode, int channel, int class,
  7837. int minrate, int maxrate, int weight, int pktsize)
  7838. {
  7839. struct fw_sched_cmd cmd;
  7840. memset(&cmd, 0, sizeof(cmd));
  7841. cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_SCHED_CMD) |
  7842. FW_CMD_REQUEST_F |
  7843. FW_CMD_WRITE_F);
  7844. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  7845. cmd.u.params.sc = FW_SCHED_SC_PARAMS;
  7846. cmd.u.params.type = type;
  7847. cmd.u.params.level = level;
  7848. cmd.u.params.mode = mode;
  7849. cmd.u.params.ch = channel;
  7850. cmd.u.params.cl = class;
  7851. cmd.u.params.unit = rateunit;
  7852. cmd.u.params.rate = ratemode;
  7853. cmd.u.params.min = cpu_to_be32(minrate);
  7854. cmd.u.params.max = cpu_to_be32(maxrate);
  7855. cmd.u.params.weight = cpu_to_be16(weight);
  7856. cmd.u.params.pktsize = cpu_to_be16(pktsize);
  7857. return t4_wr_mbox_meat(adapter, adapter->mbox, &cmd, sizeof(cmd),
  7858. NULL, 1);
  7859. }