t4_hw.c 234 KB

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