706-fsl_ppfe-support-layercape.patch 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653
  1. From 8b7935a883d42187716fe486c83352f24d01ddcd Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Thu, 19 Oct 2017 12:48:19 +0800
  4. Subject: [PATCH] fsl_ppfe: support layercape
  5. This is a integrated patch for layerscape pfe support.
  6. Calvin Johnson <[email protected]>
  7. Signed-off-by: Yangbo Lu <[email protected]>
  8. ---
  9. drivers/staging/fsl_ppfe/Kconfig | 20 +
  10. drivers/staging/fsl_ppfe/Makefile | 19 +
  11. drivers/staging/fsl_ppfe/TODO | 2 +
  12. drivers/staging/fsl_ppfe/include/pfe/cbus.h | 78 +
  13. drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h | 55 +
  14. .../staging/fsl_ppfe/include/pfe/cbus/class_csr.h | 289 +++
  15. .../staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h | 242 ++
  16. drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h | 86 +
  17. drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h | 100 +
  18. .../staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h | 50 +
  19. .../staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h | 168 ++
  20. .../staging/fsl_ppfe/include/pfe/cbus/util_csr.h | 61 +
  21. drivers/staging/fsl_ppfe/include/pfe/pfe.h | 372 +++
  22. drivers/staging/fsl_ppfe/pfe_ctrl.c | 238 ++
  23. drivers/staging/fsl_ppfe/pfe_ctrl.h | 112 +
  24. drivers/staging/fsl_ppfe/pfe_debugfs.c | 111 +
  25. drivers/staging/fsl_ppfe/pfe_debugfs.h | 25 +
  26. drivers/staging/fsl_ppfe/pfe_eth.c | 2434 ++++++++++++++++++++
  27. drivers/staging/fsl_ppfe/pfe_eth.h | 184 ++
  28. drivers/staging/fsl_ppfe/pfe_firmware.c | 314 +++
  29. drivers/staging/fsl_ppfe/pfe_firmware.h | 32 +
  30. drivers/staging/fsl_ppfe/pfe_hal.c | 1516 ++++++++++++
  31. drivers/staging/fsl_ppfe/pfe_hif.c | 1072 +++++++++
  32. drivers/staging/fsl_ppfe/pfe_hif.h | 211 ++
  33. drivers/staging/fsl_ppfe/pfe_hif_lib.c | 601 +++++
  34. drivers/staging/fsl_ppfe/pfe_hif_lib.h | 239 ++
  35. drivers/staging/fsl_ppfe/pfe_hw.c | 176 ++
  36. drivers/staging/fsl_ppfe/pfe_hw.h | 27 +
  37. drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c | 394 ++++
  38. drivers/staging/fsl_ppfe/pfe_mod.c | 141 ++
  39. drivers/staging/fsl_ppfe/pfe_mod.h | 112 +
  40. drivers/staging/fsl_ppfe/pfe_perfmon.h | 38 +
  41. drivers/staging/fsl_ppfe/pfe_sysfs.c | 818 +++++++
  42. drivers/staging/fsl_ppfe/pfe_sysfs.h | 29 +
  43. 34 files changed, 10366 insertions(+)
  44. create mode 100644 drivers/staging/fsl_ppfe/Kconfig
  45. create mode 100644 drivers/staging/fsl_ppfe/Makefile
  46. create mode 100644 drivers/staging/fsl_ppfe/TODO
  47. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus.h
  48. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
  49. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
  50. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
  51. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
  52. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
  53. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
  54. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
  55. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
  56. create mode 100644 drivers/staging/fsl_ppfe/include/pfe/pfe.h
  57. create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.c
  58. create mode 100644 drivers/staging/fsl_ppfe/pfe_ctrl.h
  59. create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.c
  60. create mode 100644 drivers/staging/fsl_ppfe/pfe_debugfs.h
  61. create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.c
  62. create mode 100644 drivers/staging/fsl_ppfe/pfe_eth.h
  63. create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.c
  64. create mode 100644 drivers/staging/fsl_ppfe/pfe_firmware.h
  65. create mode 100644 drivers/staging/fsl_ppfe/pfe_hal.c
  66. create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.c
  67. create mode 100644 drivers/staging/fsl_ppfe/pfe_hif.h
  68. create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.c
  69. create mode 100644 drivers/staging/fsl_ppfe/pfe_hif_lib.h
  70. create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.c
  71. create mode 100644 drivers/staging/fsl_ppfe/pfe_hw.h
  72. create mode 100644 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
  73. create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.c
  74. create mode 100644 drivers/staging/fsl_ppfe/pfe_mod.h
  75. create mode 100644 drivers/staging/fsl_ppfe/pfe_perfmon.h
  76. create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.c
  77. create mode 100644 drivers/staging/fsl_ppfe/pfe_sysfs.h
  78. diff --git a/drivers/staging/fsl_ppfe/Kconfig b/drivers/staging/fsl_ppfe/Kconfig
  79. new file mode 100644
  80. index 00000000..e4096435
  81. --- /dev/null
  82. +++ b/drivers/staging/fsl_ppfe/Kconfig
  83. @@ -0,0 +1,20 @@
  84. +#
  85. +# Freescale Programmable Packet Forwarding Engine driver
  86. +#
  87. +config FSL_PPFE
  88. + bool "Freescale PPFE Driver"
  89. + default n
  90. + ---help---
  91. + Freescale LS1012A SoC has a Programmable Packet Forwarding Engine.
  92. + It provides two high performance ethernet interfaces.
  93. + This driver initializes, programs and controls the PPFE.
  94. + Use this driver to enable network connectivity on LS1012A platforms.
  95. +
  96. +if FSL_PPFE
  97. +
  98. +config FSL_PPFE_UTIL_DISABLED
  99. + bool "Disable PPFE UTIL Processor Engine"
  100. + ---help---
  101. + UTIL PE has to be enabled only if required.
  102. +
  103. +endif # FSL_PPFE
  104. diff --git a/drivers/staging/fsl_ppfe/Makefile b/drivers/staging/fsl_ppfe/Makefile
  105. new file mode 100644
  106. index 00000000..07cd351b
  107. --- /dev/null
  108. +++ b/drivers/staging/fsl_ppfe/Makefile
  109. @@ -0,0 +1,19 @@
  110. +#
  111. +# Makefile for Freesecale PPFE driver
  112. +#
  113. +
  114. +ccflags-y += -I$(src)/include -I$(src)
  115. +
  116. +obj-m += pfe.o
  117. +
  118. +pfe-y += pfe_mod.o \
  119. + pfe_hw.o \
  120. + pfe_firmware.o \
  121. + pfe_ctrl.o \
  122. + pfe_hif.o \
  123. + pfe_hif_lib.o\
  124. + pfe_eth.o \
  125. + pfe_sysfs.o \
  126. + pfe_debugfs.o \
  127. + pfe_ls1012a_platform.o \
  128. + pfe_hal.o
  129. diff --git a/drivers/staging/fsl_ppfe/TODO b/drivers/staging/fsl_ppfe/TODO
  130. new file mode 100644
  131. index 00000000..43c48ccd
  132. --- /dev/null
  133. +++ b/drivers/staging/fsl_ppfe/TODO
  134. @@ -0,0 +1,2 @@
  135. +TODO:
  136. + - provide pfe pe monitoring support
  137. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus.h b/drivers/staging/fsl_ppfe/include/pfe/cbus.h
  138. new file mode 100644
  139. index 00000000..04503d28
  140. --- /dev/null
  141. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus.h
  142. @@ -0,0 +1,78 @@
  143. +/*
  144. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  145. + * Copyright 2017 NXP
  146. + *
  147. + * This program is free software; you can redistribute it and/or modify
  148. + * it under the terms of the GNU General Public License as published by
  149. + * the Free Software Foundation; either version 2 of the License, or
  150. + * (at your option) any later version.
  151. + *
  152. + * This program is distributed in the hope that it will be useful,
  153. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  154. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  155. + * GNU General Public License for more details.
  156. + *
  157. + * You should have received a copy of the GNU General Public License
  158. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  159. + */
  160. +
  161. +#ifndef _CBUS_H_
  162. +#define _CBUS_H_
  163. +
  164. +#define EMAC1_BASE_ADDR (CBUS_BASE_ADDR + 0x200000)
  165. +#define EGPI1_BASE_ADDR (CBUS_BASE_ADDR + 0x210000)
  166. +#define EMAC2_BASE_ADDR (CBUS_BASE_ADDR + 0x220000)
  167. +#define EGPI2_BASE_ADDR (CBUS_BASE_ADDR + 0x230000)
  168. +#define BMU1_BASE_ADDR (CBUS_BASE_ADDR + 0x240000)
  169. +#define BMU2_BASE_ADDR (CBUS_BASE_ADDR + 0x250000)
  170. +#define ARB_BASE_ADDR (CBUS_BASE_ADDR + 0x260000)
  171. +#define DDR_CONFIG_BASE_ADDR (CBUS_BASE_ADDR + 0x270000)
  172. +#define HIF_BASE_ADDR (CBUS_BASE_ADDR + 0x280000)
  173. +#define HGPI_BASE_ADDR (CBUS_BASE_ADDR + 0x290000)
  174. +#define LMEM_BASE_ADDR (CBUS_BASE_ADDR + 0x300000)
  175. +#define LMEM_SIZE 0x10000
  176. +#define LMEM_END (LMEM_BASE_ADDR + LMEM_SIZE)
  177. +#define TMU_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x310000)
  178. +#define CLASS_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x320000)
  179. +#define HIF_NOCPY_BASE_ADDR (CBUS_BASE_ADDR + 0x350000)
  180. +#define UTIL_CSR_BASE_ADDR (CBUS_BASE_ADDR + 0x360000)
  181. +#define CBUS_GPT_BASE_ADDR (CBUS_BASE_ADDR + 0x370000)
  182. +
  183. +/*
  184. + * defgroup XXX_MEM_ACCESS_ADDR PE memory access through CSR
  185. + * XXX_MEM_ACCESS_ADDR register bit definitions.
  186. + */
  187. +#define PE_MEM_ACCESS_WRITE BIT(31) /* Internal Memory Write. */
  188. +#define PE_MEM_ACCESS_IMEM BIT(15)
  189. +#define PE_MEM_ACCESS_DMEM BIT(16)
  190. +
  191. +/* Byte Enables of the Internal memory access. These are interpred in BE */
  192. +#define PE_MEM_ACCESS_BYTE_ENABLE(offset, size) \
  193. + ({ typeof(size) size_ = (size); \
  194. + (((BIT(size_) - 1) << (4 - (offset) - (size_))) & 0xf) << 24; })
  195. +
  196. +#include "cbus/emac_mtip.h"
  197. +#include "cbus/gpi.h"
  198. +#include "cbus/bmu.h"
  199. +#include "cbus/hif.h"
  200. +#include "cbus/tmu_csr.h"
  201. +#include "cbus/class_csr.h"
  202. +#include "cbus/hif_nocpy.h"
  203. +#include "cbus/util_csr.h"
  204. +
  205. +/* PFE cores states */
  206. +#define CORE_DISABLE 0x00000000
  207. +#define CORE_ENABLE 0x00000001
  208. +#define CORE_SW_RESET 0x00000002
  209. +
  210. +/* LMEM defines */
  211. +#define LMEM_HDR_SIZE 0x0010
  212. +#define LMEM_BUF_SIZE_LN2 0x7
  213. +#define LMEM_BUF_SIZE BIT(LMEM_BUF_SIZE_LN2)
  214. +
  215. +/* DDR defines */
  216. +#define DDR_HDR_SIZE 0x0100
  217. +#define DDR_BUF_SIZE_LN2 0xb
  218. +#define DDR_BUF_SIZE BIT(DDR_BUF_SIZE_LN2)
  219. +
  220. +#endif /* _CBUS_H_ */
  221. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
  222. new file mode 100644
  223. index 00000000..87738ca3
  224. --- /dev/null
  225. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/bmu.h
  226. @@ -0,0 +1,55 @@
  227. +/*
  228. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  229. + * Copyright 2017 NXP
  230. + *
  231. + * This program is free software; you can redistribute it and/or modify
  232. + * it under the terms of the GNU General Public License as published by
  233. + * the Free Software Foundation; either version 2 of the License, or
  234. + * (at your option) any later version.
  235. + *
  236. + * This program is distributed in the hope that it will be useful,
  237. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  238. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  239. + * GNU General Public License for more details.
  240. + *
  241. + * You should have received a copy of the GNU General Public License
  242. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  243. + */
  244. +
  245. +#ifndef _BMU_H_
  246. +#define _BMU_H_
  247. +
  248. +#define BMU_VERSION 0x000
  249. +#define BMU_CTRL 0x004
  250. +#define BMU_UCAST_CONFIG 0x008
  251. +#define BMU_UCAST_BASE_ADDR 0x00c
  252. +#define BMU_BUF_SIZE 0x010
  253. +#define BMU_BUF_CNT 0x014
  254. +#define BMU_THRES 0x018
  255. +#define BMU_INT_SRC 0x020
  256. +#define BMU_INT_ENABLE 0x024
  257. +#define BMU_ALLOC_CTRL 0x030
  258. +#define BMU_FREE_CTRL 0x034
  259. +#define BMU_FREE_ERR_ADDR 0x038
  260. +#define BMU_CURR_BUF_CNT 0x03c
  261. +#define BMU_MCAST_CNT 0x040
  262. +#define BMU_MCAST_ALLOC_CTRL 0x044
  263. +#define BMU_REM_BUF_CNT 0x048
  264. +#define BMU_LOW_WATERMARK 0x050
  265. +#define BMU_HIGH_WATERMARK 0x054
  266. +#define BMU_INT_MEM_ACCESS 0x100
  267. +
  268. +struct BMU_CFG {
  269. + unsigned long baseaddr;
  270. + u32 count;
  271. + u32 size;
  272. + u32 low_watermark;
  273. + u32 high_watermark;
  274. +};
  275. +
  276. +#define BMU1_BUF_SIZE LMEM_BUF_SIZE_LN2
  277. +#define BMU2_BUF_SIZE DDR_BUF_SIZE_LN2
  278. +
  279. +#define BMU2_MCAST_ALLOC_CTRL (BMU2_BASE_ADDR + BMU_MCAST_ALLOC_CTRL)
  280. +
  281. +#endif /* _BMU_H_ */
  282. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
  283. new file mode 100644
  284. index 00000000..e4dadff5
  285. --- /dev/null
  286. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/class_csr.h
  287. @@ -0,0 +1,289 @@
  288. +/*
  289. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  290. + * Copyright 2017 NXP
  291. + *
  292. + * This program is free software; you can redistribute it and/or modify
  293. + * it under the terms of the GNU General Public License as published by
  294. + * the Free Software Foundation; either version 2 of the License, or
  295. + * (at your option) any later version.
  296. + *
  297. + * This program is distributed in the hope that it will be useful,
  298. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  299. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  300. + * GNU General Public License for more details.
  301. + *
  302. + * You should have received a copy of the GNU General Public License
  303. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  304. + */
  305. +
  306. +#ifndef _CLASS_CSR_H_
  307. +#define _CLASS_CSR_H_
  308. +
  309. +/* @file class_csr.h.
  310. + * class_csr - block containing all the classifier control and status register.
  311. + * Mapped on CBUS and accessible from all PE's and ARM.
  312. + */
  313. +#define CLASS_VERSION (CLASS_CSR_BASE_ADDR + 0x000)
  314. +#define CLASS_TX_CTRL (CLASS_CSR_BASE_ADDR + 0x004)
  315. +#define CLASS_INQ_PKTPTR (CLASS_CSR_BASE_ADDR + 0x010)
  316. +
  317. +/* (ddr_hdr_size[24:16], lmem_hdr_size[5:0]) */
  318. +#define CLASS_HDR_SIZE (CLASS_CSR_BASE_ADDR + 0x014)
  319. +
  320. +/* LMEM header size for the Classifier block.\ Data in the LMEM
  321. + * is written from this offset.
  322. + */
  323. +#define CLASS_HDR_SIZE_LMEM(off) ((off) & 0x3f)
  324. +
  325. +/* DDR header size for the Classifier block.\ Data in the DDR
  326. + * is written from this offset.
  327. + */
  328. +#define CLASS_HDR_SIZE_DDR(off) (((off) & 0x1ff) << 16)
  329. +
  330. +#define CLASS_PE0_QB_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x020)
  331. +
  332. +/* DMEM address of first [15:0] and second [31:16] buffers on QB side. */
  333. +#define CLASS_PE0_QB_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x024)
  334. +
  335. +/* DMEM address of third [15:0] and fourth [31:16] buffers on QB side. */
  336. +#define CLASS_PE0_RO_DM_ADDR0 (CLASS_CSR_BASE_ADDR + 0x060)
  337. +
  338. +/* DMEM address of first [15:0] and second [31:16] buffers on RO side. */
  339. +#define CLASS_PE0_RO_DM_ADDR1 (CLASS_CSR_BASE_ADDR + 0x064)
  340. +
  341. +/* DMEM address of third [15:0] and fourth [31:16] buffers on RO side. */
  342. +
  343. +/* @name Class PE memory access. Allows external PE's and HOST to
  344. + * read/write PMEM/DMEM memory ranges for each classifier PE.
  345. + */
  346. +/* {sr_pe_mem_cmd[31], csr_pe_mem_wren[27:24], csr_pe_mem_addr[23:0]},
  347. + * See \ref XXX_MEM_ACCESS_ADDR for details.
  348. + */
  349. +#define CLASS_MEM_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x100)
  350. +
  351. +/* Internal Memory Access Write Data [31:0] */
  352. +#define CLASS_MEM_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x104)
  353. +
  354. +/* Internal Memory Access Read Data [31:0] */
  355. +#define CLASS_MEM_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x108)
  356. +#define CLASS_TM_INQ_ADDR (CLASS_CSR_BASE_ADDR + 0x114)
  357. +#define CLASS_PE_STATUS (CLASS_CSR_BASE_ADDR + 0x118)
  358. +
  359. +#define CLASS_PHY1_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x11c)
  360. +#define CLASS_PHY1_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x120)
  361. +#define CLASS_PHY1_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x124)
  362. +#define CLASS_PHY1_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x128)
  363. +#define CLASS_PHY1_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x12c)
  364. +#define CLASS_PHY1_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x130)
  365. +#define CLASS_PHY1_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x134)
  366. +#define CLASS_PHY1_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x138)
  367. +#define CLASS_PHY1_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x13c)
  368. +#define CLASS_PHY1_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x140)
  369. +#define CLASS_PHY2_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x144)
  370. +#define CLASS_PHY2_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x148)
  371. +#define CLASS_PHY2_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x14c)
  372. +#define CLASS_PHY2_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x150)
  373. +#define CLASS_PHY2_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x154)
  374. +#define CLASS_PHY2_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x158)
  375. +#define CLASS_PHY2_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x15c)
  376. +#define CLASS_PHY2_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x160)
  377. +#define CLASS_PHY2_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x164)
  378. +#define CLASS_PHY2_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x168)
  379. +#define CLASS_PHY3_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x16c)
  380. +#define CLASS_PHY3_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x170)
  381. +#define CLASS_PHY3_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x174)
  382. +#define CLASS_PHY3_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x178)
  383. +#define CLASS_PHY3_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x17c)
  384. +#define CLASS_PHY3_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x180)
  385. +#define CLASS_PHY3_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x184)
  386. +#define CLASS_PHY3_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x188)
  387. +#define CLASS_PHY3_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x18c)
  388. +#define CLASS_PHY3_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x190)
  389. +#define CLASS_PHY1_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x194)
  390. +#define CLASS_PHY1_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x198)
  391. +#define CLASS_PHY1_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x19c)
  392. +#define CLASS_PHY1_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a0)
  393. +#define CLASS_PHY2_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a4)
  394. +#define CLASS_PHY2_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1a8)
  395. +#define CLASS_PHY2_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1ac)
  396. +#define CLASS_PHY2_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b0)
  397. +#define CLASS_PHY3_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b4)
  398. +#define CLASS_PHY3_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1b8)
  399. +#define CLASS_PHY3_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1bc)
  400. +#define CLASS_PHY3_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c0)
  401. +#define CLASS_PHY4_ICMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c4)
  402. +#define CLASS_PHY4_IGMP_PKTS (CLASS_CSR_BASE_ADDR + 0x1c8)
  403. +#define CLASS_PHY4_TCP_PKTS (CLASS_CSR_BASE_ADDR + 0x1cc)
  404. +#define CLASS_PHY4_UDP_PKTS (CLASS_CSR_BASE_ADDR + 0x1d0)
  405. +#define CLASS_PHY4_RX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d4)
  406. +#define CLASS_PHY4_TX_PKTS (CLASS_CSR_BASE_ADDR + 0x1d8)
  407. +#define CLASS_PHY4_LP_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1dc)
  408. +#define CLASS_PHY4_INTF_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e0)
  409. +#define CLASS_PHY4_INTF_MATCH_PKTS (CLASS_CSR_BASE_ADDR + 0x1e4)
  410. +#define CLASS_PHY4_L3_FAIL_PKTS (CLASS_CSR_BASE_ADDR + 0x1e8)
  411. +#define CLASS_PHY4_V4_PKTS (CLASS_CSR_BASE_ADDR + 0x1ec)
  412. +#define CLASS_PHY4_V6_PKTS (CLASS_CSR_BASE_ADDR + 0x1f0)
  413. +#define CLASS_PHY4_CHKSUM_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f4)
  414. +#define CLASS_PHY4_TTL_ERR_PKTS (CLASS_CSR_BASE_ADDR + 0x1f8)
  415. +
  416. +#define CLASS_PE_SYS_CLK_RATIO (CLASS_CSR_BASE_ADDR + 0x200)
  417. +#define CLASS_AFULL_THRES (CLASS_CSR_BASE_ADDR + 0x204)
  418. +#define CLASS_GAP_BETWEEN_READS (CLASS_CSR_BASE_ADDR + 0x208)
  419. +#define CLASS_MAX_BUF_CNT (CLASS_CSR_BASE_ADDR + 0x20c)
  420. +#define CLASS_TSQ_FIFO_THRES (CLASS_CSR_BASE_ADDR + 0x210)
  421. +#define CLASS_TSQ_MAX_CNT (CLASS_CSR_BASE_ADDR + 0x214)
  422. +#define CLASS_IRAM_DATA_0 (CLASS_CSR_BASE_ADDR + 0x218)
  423. +#define CLASS_IRAM_DATA_1 (CLASS_CSR_BASE_ADDR + 0x21c)
  424. +#define CLASS_IRAM_DATA_2 (CLASS_CSR_BASE_ADDR + 0x220)
  425. +#define CLASS_IRAM_DATA_3 (CLASS_CSR_BASE_ADDR + 0x224)
  426. +
  427. +#define CLASS_BUS_ACCESS_ADDR (CLASS_CSR_BASE_ADDR + 0x228)
  428. +
  429. +#define CLASS_BUS_ACCESS_WDATA (CLASS_CSR_BASE_ADDR + 0x22c)
  430. +#define CLASS_BUS_ACCESS_RDATA (CLASS_CSR_BASE_ADDR + 0x230)
  431. +
  432. +/* (route_entry_size[9:0], route_hash_size[23:16]
  433. + * (this is actually ln2(size)))
  434. + */
  435. +#define CLASS_ROUTE_HASH_ENTRY_SIZE (CLASS_CSR_BASE_ADDR + 0x234)
  436. +
  437. +#define CLASS_ROUTE_ENTRY_SIZE(size) ((size) & 0x1ff)
  438. +#define CLASS_ROUTE_HASH_SIZE(hash_bits) (((hash_bits) & 0xff) << 16)
  439. +
  440. +#define CLASS_ROUTE_TABLE_BASE (CLASS_CSR_BASE_ADDR + 0x238)
  441. +
  442. +#define CLASS_ROUTE_MULTI (CLASS_CSR_BASE_ADDR + 0x23c)
  443. +#define CLASS_SMEM_OFFSET (CLASS_CSR_BASE_ADDR + 0x240)
  444. +#define CLASS_LMEM_BUF_SIZE (CLASS_CSR_BASE_ADDR + 0x244)
  445. +#define CLASS_VLAN_ID (CLASS_CSR_BASE_ADDR + 0x248)
  446. +#define CLASS_BMU1_BUF_FREE (CLASS_CSR_BASE_ADDR + 0x24c)
  447. +#define CLASS_USE_TMU_INQ (CLASS_CSR_BASE_ADDR + 0x250)
  448. +#define CLASS_VLAN_ID1 (CLASS_CSR_BASE_ADDR + 0x254)
  449. +
  450. +#define CLASS_BUS_ACCESS_BASE (CLASS_CSR_BASE_ADDR + 0x258)
  451. +#define CLASS_BUS_ACCESS_BASE_MASK (0xFF000000)
  452. +/* bit 31:24 of PE peripheral address are stored in CLASS_BUS_ACCESS_BASE */
  453. +
  454. +#define CLASS_HIF_PARSE (CLASS_CSR_BASE_ADDR + 0x25c)
  455. +
  456. +#define CLASS_HOST_PE0_GP (CLASS_CSR_BASE_ADDR + 0x260)
  457. +#define CLASS_PE0_GP (CLASS_CSR_BASE_ADDR + 0x264)
  458. +#define CLASS_HOST_PE1_GP (CLASS_CSR_BASE_ADDR + 0x268)
  459. +#define CLASS_PE1_GP (CLASS_CSR_BASE_ADDR + 0x26c)
  460. +#define CLASS_HOST_PE2_GP (CLASS_CSR_BASE_ADDR + 0x270)
  461. +#define CLASS_PE2_GP (CLASS_CSR_BASE_ADDR + 0x274)
  462. +#define CLASS_HOST_PE3_GP (CLASS_CSR_BASE_ADDR + 0x278)
  463. +#define CLASS_PE3_GP (CLASS_CSR_BASE_ADDR + 0x27c)
  464. +#define CLASS_HOST_PE4_GP (CLASS_CSR_BASE_ADDR + 0x280)
  465. +#define CLASS_PE4_GP (CLASS_CSR_BASE_ADDR + 0x284)
  466. +#define CLASS_HOST_PE5_GP (CLASS_CSR_BASE_ADDR + 0x288)
  467. +#define CLASS_PE5_GP (CLASS_CSR_BASE_ADDR + 0x28c)
  468. +
  469. +#define CLASS_PE_INT_SRC (CLASS_CSR_BASE_ADDR + 0x290)
  470. +#define CLASS_PE_INT_ENABLE (CLASS_CSR_BASE_ADDR + 0x294)
  471. +
  472. +#define CLASS_TPID0_TPID1 (CLASS_CSR_BASE_ADDR + 0x298)
  473. +#define CLASS_TPID2 (CLASS_CSR_BASE_ADDR + 0x29c)
  474. +
  475. +#define CLASS_L4_CHKSUM_ADDR (CLASS_CSR_BASE_ADDR + 0x2a0)
  476. +
  477. +#define CLASS_PE0_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a4)
  478. +#define CLASS_PE1_DEBUG (CLASS_CSR_BASE_ADDR + 0x2a8)
  479. +#define CLASS_PE2_DEBUG (CLASS_CSR_BASE_ADDR + 0x2ac)
  480. +#define CLASS_PE3_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b0)
  481. +#define CLASS_PE4_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b4)
  482. +#define CLASS_PE5_DEBUG (CLASS_CSR_BASE_ADDR + 0x2b8)
  483. +
  484. +#define CLASS_STATE (CLASS_CSR_BASE_ADDR + 0x2bc)
  485. +
  486. +/* CLASS defines */
  487. +#define CLASS_PBUF_SIZE 0x100 /* Fixed by hardware */
  488. +#define CLASS_PBUF_HEADER_OFFSET 0x80 /* Can be configured */
  489. +
  490. +/* Can be configured */
  491. +#define CLASS_PBUF0_BASE_ADDR 0x000
  492. +/* Can be configured */
  493. +#define CLASS_PBUF1_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + CLASS_PBUF_SIZE)
  494. +/* Can be configured */
  495. +#define CLASS_PBUF2_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + CLASS_PBUF_SIZE)
  496. +/* Can be configured */
  497. +#define CLASS_PBUF3_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + CLASS_PBUF_SIZE)
  498. +
  499. +#define CLASS_PBUF0_HEADER_BASE_ADDR (CLASS_PBUF0_BASE_ADDR + \
  500. + CLASS_PBUF_HEADER_OFFSET)
  501. +#define CLASS_PBUF1_HEADER_BASE_ADDR (CLASS_PBUF1_BASE_ADDR + \
  502. + CLASS_PBUF_HEADER_OFFSET)
  503. +#define CLASS_PBUF2_HEADER_BASE_ADDR (CLASS_PBUF2_BASE_ADDR + \
  504. + CLASS_PBUF_HEADER_OFFSET)
  505. +#define CLASS_PBUF3_HEADER_BASE_ADDR (CLASS_PBUF3_BASE_ADDR + \
  506. + CLASS_PBUF_HEADER_OFFSET)
  507. +
  508. +#define CLASS_PE0_RO_DM_ADDR0_VAL ((CLASS_PBUF1_BASE_ADDR << 16) | \
  509. + CLASS_PBUF0_BASE_ADDR)
  510. +#define CLASS_PE0_RO_DM_ADDR1_VAL ((CLASS_PBUF3_BASE_ADDR << 16) | \
  511. + CLASS_PBUF2_BASE_ADDR)
  512. +
  513. +#define CLASS_PE0_QB_DM_ADDR0_VAL ((CLASS_PBUF1_HEADER_BASE_ADDR << 16) |\
  514. + CLASS_PBUF0_HEADER_BASE_ADDR)
  515. +#define CLASS_PE0_QB_DM_ADDR1_VAL ((CLASS_PBUF3_HEADER_BASE_ADDR << 16) |\
  516. + CLASS_PBUF2_HEADER_BASE_ADDR)
  517. +
  518. +#define CLASS_ROUTE_SIZE 128
  519. +#define CLASS_MAX_ROUTE_SIZE 256
  520. +#define CLASS_ROUTE_HASH_BITS 20
  521. +#define CLASS_ROUTE_HASH_MASK (BIT(CLASS_ROUTE_HASH_BITS) - 1)
  522. +
  523. +/* Can be configured */
  524. +#define CLASS_ROUTE0_BASE_ADDR 0x400
  525. +/* Can be configured */
  526. +#define CLASS_ROUTE1_BASE_ADDR (CLASS_ROUTE0_BASE_ADDR + CLASS_ROUTE_SIZE)
  527. +/* Can be configured */
  528. +#define CLASS_ROUTE2_BASE_ADDR (CLASS_ROUTE1_BASE_ADDR + CLASS_ROUTE_SIZE)
  529. +/* Can be configured */
  530. +#define CLASS_ROUTE3_BASE_ADDR (CLASS_ROUTE2_BASE_ADDR + CLASS_ROUTE_SIZE)
  531. +
  532. +#define CLASS_SA_SIZE 128
  533. +#define CLASS_IPSEC_SA0_BASE_ADDR 0x600
  534. +/* not used */
  535. +#define CLASS_IPSEC_SA1_BASE_ADDR (CLASS_IPSEC_SA0_BASE_ADDR + CLASS_SA_SIZE)
  536. +/* not used */
  537. +#define CLASS_IPSEC_SA2_BASE_ADDR (CLASS_IPSEC_SA1_BASE_ADDR + CLASS_SA_SIZE)
  538. +/* not used */
  539. +#define CLASS_IPSEC_SA3_BASE_ADDR (CLASS_IPSEC_SA2_BASE_ADDR + CLASS_SA_SIZE)
  540. +
  541. +/* generic purpose free dmem buffer, last portion of 2K dmem pbuf */
  542. +#define CLASS_GP_DMEM_BUF_SIZE (2048 - (CLASS_PBUF_SIZE * 4) - \
  543. + (CLASS_ROUTE_SIZE * 4) - (CLASS_SA_SIZE))
  544. +#define CLASS_GP_DMEM_BUF ((void *)(CLASS_IPSEC_SA0_BASE_ADDR + \
  545. + CLASS_SA_SIZE))
  546. +
  547. +#define TWO_LEVEL_ROUTE BIT(0)
  548. +#define PHYNO_IN_HASH BIT(1)
  549. +#define HW_ROUTE_FETCH BIT(3)
  550. +#define HW_BRIDGE_FETCH BIT(5)
  551. +#define IP_ALIGNED BIT(6)
  552. +#define ARC_HIT_CHECK_EN BIT(7)
  553. +#define CLASS_TOE BIT(11)
  554. +#define HASH_NORMAL (0 << 12)
  555. +#define HASH_CRC_PORT BIT(12)
  556. +#define HASH_CRC_IP (2 << 12)
  557. +#define HASH_CRC_PORT_IP (3 << 12)
  558. +#define QB2BUS_LE BIT(15)
  559. +
  560. +#define TCP_CHKSUM_DROP BIT(0)
  561. +#define UDP_CHKSUM_DROP BIT(1)
  562. +#define IPV4_CHKSUM_DROP BIT(9)
  563. +
  564. +/*CLASS_HIF_PARSE bits*/
  565. +#define HIF_PKT_CLASS_EN BIT(0)
  566. +#define HIF_PKT_OFFSET(ofst) (((ofst) & 0xF) << 1)
  567. +
  568. +struct class_cfg {
  569. + u32 toe_mode;
  570. + unsigned long route_table_baseaddr;
  571. + u32 route_table_hash_bits;
  572. + u32 pe_sys_clk_ratio;
  573. + u32 resume;
  574. +};
  575. +
  576. +#endif /* _CLASS_CSR_H_ */
  577. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
  578. new file mode 100644
  579. index 00000000..9c5d7919
  580. --- /dev/null
  581. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/emac_mtip.h
  582. @@ -0,0 +1,242 @@
  583. +/*
  584. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  585. + * Copyright 2017 NXP
  586. + *
  587. + * This program is free software; you can redistribute it and/or modify
  588. + * it under the terms of the GNU General Public License as published by
  589. + * the Free Software Foundation; either version 2 of the License, or
  590. + * (at your option) any later version.
  591. + *
  592. + * This program is distributed in the hope that it will be useful,
  593. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  594. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  595. + * GNU General Public License for more details.
  596. + *
  597. + * You should have received a copy of the GNU General Public License
  598. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  599. + */
  600. +
  601. +#ifndef _EMAC_H_
  602. +#define _EMAC_H_
  603. +
  604. +#include <linux/ethtool.h>
  605. +
  606. +#define EMAC_IEVENT_REG 0x004
  607. +#define EMAC_IMASK_REG 0x008
  608. +#define EMAC_R_DES_ACTIVE_REG 0x010
  609. +#define EMAC_X_DES_ACTIVE_REG 0x014
  610. +#define EMAC_ECNTRL_REG 0x024
  611. +#define EMAC_MII_DATA_REG 0x040
  612. +#define EMAC_MII_CTRL_REG 0x044
  613. +#define EMAC_MIB_CTRL_STS_REG 0x064
  614. +#define EMAC_RCNTRL_REG 0x084
  615. +#define EMAC_TCNTRL_REG 0x0C4
  616. +#define EMAC_PHY_ADDR_LOW 0x0E4
  617. +#define EMAC_PHY_ADDR_HIGH 0x0E8
  618. +#define EMAC_GAUR 0x120
  619. +#define EMAC_GALR 0x124
  620. +#define EMAC_TFWR_STR_FWD 0x144
  621. +#define EMAC_RX_SECTION_FULL 0x190
  622. +#define EMAC_RX_SECTION_EMPTY 0x194
  623. +#define EMAC_TX_SECTION_EMPTY 0x1A0
  624. +#define EMAC_TRUNC_FL 0x1B0
  625. +
  626. +#define RMON_T_DROP 0x200 /* Count of frames not cntd correctly */
  627. +#define RMON_T_PACKETS 0x204 /* RMON TX packet count */
  628. +#define RMON_T_BC_PKT 0x208 /* RMON TX broadcast pkts */
  629. +#define RMON_T_MC_PKT 0x20c /* RMON TX multicast pkts */
  630. +#define RMON_T_CRC_ALIGN 0x210 /* RMON TX pkts with CRC align err */
  631. +#define RMON_T_UNDERSIZE 0x214 /* RMON TX pkts < 64 bytes, good CRC */
  632. +#define RMON_T_OVERSIZE 0x218 /* RMON TX pkts > MAX_FL bytes good CRC */
  633. +#define RMON_T_FRAG 0x21c /* RMON TX pkts < 64 bytes, bad CRC */
  634. +#define RMON_T_JAB 0x220 /* RMON TX pkts > MAX_FL bytes, bad CRC */
  635. +#define RMON_T_COL 0x224 /* RMON TX collision count */
  636. +#define RMON_T_P64 0x228 /* RMON TX 64 byte pkts */
  637. +#define RMON_T_P65TO127 0x22c /* RMON TX 65 to 127 byte pkts */
  638. +#define RMON_T_P128TO255 0x230 /* RMON TX 128 to 255 byte pkts */
  639. +#define RMON_T_P256TO511 0x234 /* RMON TX 256 to 511 byte pkts */
  640. +#define RMON_T_P512TO1023 0x238 /* RMON TX 512 to 1023 byte pkts */
  641. +#define RMON_T_P1024TO2047 0x23c /* RMON TX 1024 to 2047 byte pkts */
  642. +#define RMON_T_P_GTE2048 0x240 /* RMON TX pkts > 2048 bytes */
  643. +#define RMON_T_OCTETS 0x244 /* RMON TX octets */
  644. +#define IEEE_T_DROP 0x248 /* Count of frames not counted crtly */
  645. +#define IEEE_T_FRAME_OK 0x24c /* Frames tx'd OK */
  646. +#define IEEE_T_1COL 0x250 /* Frames tx'd with single collision */
  647. +#define IEEE_T_MCOL 0x254 /* Frames tx'd with multiple collision */
  648. +#define IEEE_T_DEF 0x258 /* Frames tx'd after deferral delay */
  649. +#define IEEE_T_LCOL 0x25c /* Frames tx'd with late collision */
  650. +#define IEEE_T_EXCOL 0x260 /* Frames tx'd with excesv collisions */
  651. +#define IEEE_T_MACERR 0x264 /* Frames tx'd with TX FIFO underrun */
  652. +#define IEEE_T_CSERR 0x268 /* Frames tx'd with carrier sense err */
  653. +#define IEEE_T_SQE 0x26c /* Frames tx'd with SQE err */
  654. +#define IEEE_T_FDXFC 0x270 /* Flow control pause frames tx'd */
  655. +#define IEEE_T_OCTETS_OK 0x274 /* Octet count for frames tx'd w/o err */
  656. +#define RMON_R_PACKETS 0x284 /* RMON RX packet count */
  657. +#define RMON_R_BC_PKT 0x288 /* RMON RX broadcast pkts */
  658. +#define RMON_R_MC_PKT 0x28c /* RMON RX multicast pkts */
  659. +#define RMON_R_CRC_ALIGN 0x290 /* RMON RX pkts with CRC alignment err */
  660. +#define RMON_R_UNDERSIZE 0x294 /* RMON RX pkts < 64 bytes, good CRC */
  661. +#define RMON_R_OVERSIZE 0x298 /* RMON RX pkts > MAX_FL bytes good CRC */
  662. +#define RMON_R_FRAG 0x29c /* RMON RX pkts < 64 bytes, bad CRC */
  663. +#define RMON_R_JAB 0x2a0 /* RMON RX pkts > MAX_FL bytes, bad CRC */
  664. +#define RMON_R_RESVD_O 0x2a4 /* Reserved */
  665. +#define RMON_R_P64 0x2a8 /* RMON RX 64 byte pkts */
  666. +#define RMON_R_P65TO127 0x2ac /* RMON RX 65 to 127 byte pkts */
  667. +#define RMON_R_P128TO255 0x2b0 /* RMON RX 128 to 255 byte pkts */
  668. +#define RMON_R_P256TO511 0x2b4 /* RMON RX 256 to 511 byte pkts */
  669. +#define RMON_R_P512TO1023 0x2b8 /* RMON RX 512 to 1023 byte pkts */
  670. +#define RMON_R_P1024TO2047 0x2bc /* RMON RX 1024 to 2047 byte pkts */
  671. +#define RMON_R_P_GTE2048 0x2c0 /* RMON RX pkts > 2048 bytes */
  672. +#define RMON_R_OCTETS 0x2c4 /* RMON RX octets */
  673. +#define IEEE_R_DROP 0x2c8 /* Count frames not counted correctly */
  674. +#define IEEE_R_FRAME_OK 0x2cc /* Frames rx'd OK */
  675. +#define IEEE_R_CRC 0x2d0 /* Frames rx'd with CRC err */
  676. +#define IEEE_R_ALIGN 0x2d4 /* Frames rx'd with alignment err */
  677. +#define IEEE_R_MACERR 0x2d8 /* Receive FIFO overflow count */
  678. +#define IEEE_R_FDXFC 0x2dc /* Flow control pause frames rx'd */
  679. +#define IEEE_R_OCTETS_OK 0x2e0 /* Octet cnt for frames rx'd w/o err */
  680. +
  681. +#define EMAC_SMAC_0_0 0x500 /*Supplemental MAC Address 0 (RW).*/
  682. +#define EMAC_SMAC_0_1 0x504 /*Supplemental MAC Address 0 (RW).*/
  683. +
  684. +/* GEMAC definitions and settings */
  685. +
  686. +#define EMAC_PORT_0 0
  687. +#define EMAC_PORT_1 1
  688. +
  689. +/* GEMAC Bit definitions */
  690. +#define EMAC_IEVENT_HBERR 0x80000000
  691. +#define EMAC_IEVENT_BABR 0x40000000
  692. +#define EMAC_IEVENT_BABT 0x20000000
  693. +#define EMAC_IEVENT_GRA 0x10000000
  694. +#define EMAC_IEVENT_TXF 0x08000000
  695. +#define EMAC_IEVENT_TXB 0x04000000
  696. +#define EMAC_IEVENT_RXF 0x02000000
  697. +#define EMAC_IEVENT_RXB 0x01000000
  698. +#define EMAC_IEVENT_MII 0x00800000
  699. +#define EMAC_IEVENT_EBERR 0x00400000
  700. +#define EMAC_IEVENT_LC 0x00200000
  701. +#define EMAC_IEVENT_RL 0x00100000
  702. +#define EMAC_IEVENT_UN 0x00080000
  703. +
  704. +#define EMAC_IMASK_HBERR 0x80000000
  705. +#define EMAC_IMASK_BABR 0x40000000
  706. +#define EMAC_IMASKT_BABT 0x20000000
  707. +#define EMAC_IMASK_GRA 0x10000000
  708. +#define EMAC_IMASKT_TXF 0x08000000
  709. +#define EMAC_IMASK_TXB 0x04000000
  710. +#define EMAC_IMASKT_RXF 0x02000000
  711. +#define EMAC_IMASK_RXB 0x01000000
  712. +#define EMAC_IMASK_MII 0x00800000
  713. +#define EMAC_IMASK_EBERR 0x00400000
  714. +#define EMAC_IMASK_LC 0x00200000
  715. +#define EMAC_IMASKT_RL 0x00100000
  716. +#define EMAC_IMASK_UN 0x00080000
  717. +
  718. +#define EMAC_RCNTRL_MAX_FL_SHIFT 16
  719. +#define EMAC_RCNTRL_LOOP 0x00000001
  720. +#define EMAC_RCNTRL_DRT 0x00000002
  721. +#define EMAC_RCNTRL_MII_MODE 0x00000004
  722. +#define EMAC_RCNTRL_PROM 0x00000008
  723. +#define EMAC_RCNTRL_BC_REJ 0x00000010
  724. +#define EMAC_RCNTRL_FCE 0x00000020
  725. +#define EMAC_RCNTRL_RGMII 0x00000040
  726. +#define EMAC_RCNTRL_SGMII 0x00000080
  727. +#define EMAC_RCNTRL_RMII 0x00000100
  728. +#define EMAC_RCNTRL_RMII_10T 0x00000200
  729. +#define EMAC_RCNTRL_CRC_FWD 0x00004000
  730. +
  731. +#define EMAC_TCNTRL_GTS 0x00000001
  732. +#define EMAC_TCNTRL_HBC 0x00000002
  733. +#define EMAC_TCNTRL_FDEN 0x00000004
  734. +#define EMAC_TCNTRL_TFC_PAUSE 0x00000008
  735. +#define EMAC_TCNTRL_RFC_PAUSE 0x00000010
  736. +
  737. +#define EMAC_ECNTRL_RESET 0x00000001 /* reset the EMAC */
  738. +#define EMAC_ECNTRL_ETHER_EN 0x00000002 /* enable the EMAC */
  739. +#define EMAC_ECNTRL_MAGIC_ENA 0x00000004
  740. +#define EMAC_ECNTRL_SLEEP 0x00000008
  741. +#define EMAC_ECNTRL_SPEED 0x00000020
  742. +#define EMAC_ECNTRL_DBSWAP 0x00000100
  743. +
  744. +#define EMAC_X_WMRK_STRFWD 0x00000100
  745. +
  746. +#define EMAC_X_DES_ACTIVE_TDAR 0x01000000
  747. +#define EMAC_R_DES_ACTIVE_RDAR 0x01000000
  748. +
  749. +#define EMAC_RX_SECTION_EMPTY_V 0x00010006
  750. +/*
  751. + * The possible operating speeds of the MAC, currently supporting 10, 100 and
  752. + * 1000Mb modes.
  753. + */
  754. +enum mac_speed {SPEED_10M, SPEED_100M, SPEED_1000M, SPEED_1000M_PCS};
  755. +
  756. +/* MII-related definitios */
  757. +#define EMAC_MII_DATA_ST 0x40000000 /* Start of frame delimiter */
  758. +#define EMAC_MII_DATA_OP_RD 0x20000000 /* Perform a read operation */
  759. +#define EMAC_MII_DATA_OP_CL45_RD 0x30000000 /* Perform a read operation */
  760. +#define EMAC_MII_DATA_OP_WR 0x10000000 /* Perform a write operation */
  761. +#define EMAC_MII_DATA_OP_CL45_WR 0x10000000 /* Perform a write operation */
  762. +#define EMAC_MII_DATA_PA_MSK 0x0f800000 /* PHY Address field mask */
  763. +#define EMAC_MII_DATA_RA_MSK 0x007c0000 /* PHY Register field mask */
  764. +#define EMAC_MII_DATA_TA 0x00020000 /* Turnaround */
  765. +#define EMAC_MII_DATA_DATAMSK 0x0000ffff /* PHY data field */
  766. +
  767. +#define EMAC_MII_DATA_RA_SHIFT 18 /* MII Register address bits */
  768. +#define EMAC_MII_DATA_RA_MASK 0x1F /* MII Register address mask */
  769. +#define EMAC_MII_DATA_PA_SHIFT 23 /* MII PHY address bits */
  770. +#define EMAC_MII_DATA_PA_MASK 0x1F /* MII PHY address mask */
  771. +
  772. +#define EMAC_MII_DATA_RA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
  773. + EMAC_MII_DATA_RA_SHIFT)
  774. +#define EMAC_MII_DATA_PA(v) (((v) & EMAC_MII_DATA_RA_MASK) << \
  775. + EMAC_MII_DATA_PA_SHIFT)
  776. +#define EMAC_MII_DATA(v) ((v) & 0xffff)
  777. +
  778. +#define EMAC_MII_SPEED_SHIFT 1
  779. +#define EMAC_HOLDTIME_SHIFT 8
  780. +#define EMAC_HOLDTIME_MASK 0x7
  781. +#define EMAC_HOLDTIME(v) (((v) & EMAC_HOLDTIME_MASK) << \
  782. + EMAC_HOLDTIME_SHIFT)
  783. +
  784. +/*
  785. + * The Address organisation for the MAC device. All addresses are split into
  786. + * two 32-bit register fields. The first one (bottom) is the lower 32-bits of
  787. + * the address and the other field are the high order bits - this may be 16-bits
  788. + * in the case of MAC addresses, or 32-bits for the hash address.
  789. + * In terms of memory storage, the first item (bottom) is assumed to be at a
  790. + * lower address location than 'top'. i.e. top should be at address location of
  791. + * 'bottom' + 4 bytes.
  792. + */
  793. +struct pfe_mac_addr {
  794. + u32 bottom; /* Lower 32-bits of address. */
  795. + u32 top; /* Upper 32-bits of address. */
  796. +};
  797. +
  798. +/*
  799. + * The following is the organisation of the address filters section of the MAC
  800. + * registers. The Cadence MAC contains four possible specific address match
  801. + * addresses, if an incoming frame corresponds to any one of these four
  802. + * addresses then the frame will be copied to memory.
  803. + * It is not necessary for all four of the address match registers to be
  804. + * programmed, this is application dependent.
  805. + */
  806. +struct spec_addr {
  807. + struct pfe_mac_addr one; /* Specific address register 1. */
  808. + struct pfe_mac_addr two; /* Specific address register 2. */
  809. + struct pfe_mac_addr three; /* Specific address register 3. */
  810. + struct pfe_mac_addr four; /* Specific address register 4. */
  811. +};
  812. +
  813. +struct gemac_cfg {
  814. + u32 mode;
  815. + u32 speed;
  816. + u32 duplex;
  817. +};
  818. +
  819. +/* EMAC Hash size */
  820. +#define EMAC_HASH_REG_BITS 64
  821. +
  822. +#define EMAC_SPEC_ADDR_MAX 4
  823. +
  824. +#endif /* _EMAC_H_ */
  825. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
  826. new file mode 100644
  827. index 00000000..7b295830
  828. --- /dev/null
  829. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/gpi.h
  830. @@ -0,0 +1,86 @@
  831. +/*
  832. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  833. + * Copyright 2017 NXP
  834. + *
  835. + * This program is free software; you can redistribute it and/or modify
  836. + * it under the terms of the GNU General Public License as published by
  837. + * the Free Software Foundation; either version 2 of the License, or
  838. + * (at your option) any later version.
  839. + *
  840. + * This program is distributed in the hope that it will be useful,
  841. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  842. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  843. + * GNU General Public License for more details.
  844. + *
  845. + * You should have received a copy of the GNU General Public License
  846. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  847. + */
  848. +
  849. +#ifndef _GPI_H_
  850. +#define _GPI_H_
  851. +
  852. +#define GPI_VERSION 0x00
  853. +#define GPI_CTRL 0x04
  854. +#define GPI_RX_CONFIG 0x08
  855. +#define GPI_HDR_SIZE 0x0c
  856. +#define GPI_BUF_SIZE 0x10
  857. +#define GPI_LMEM_ALLOC_ADDR 0x14
  858. +#define GPI_LMEM_FREE_ADDR 0x18
  859. +#define GPI_DDR_ALLOC_ADDR 0x1c
  860. +#define GPI_DDR_FREE_ADDR 0x20
  861. +#define GPI_CLASS_ADDR 0x24
  862. +#define GPI_DRX_FIFO 0x28
  863. +#define GPI_TRX_FIFO 0x2c
  864. +#define GPI_INQ_PKTPTR 0x30
  865. +#define GPI_DDR_DATA_OFFSET 0x34
  866. +#define GPI_LMEM_DATA_OFFSET 0x38
  867. +#define GPI_TMLF_TX 0x4c
  868. +#define GPI_DTX_ASEQ 0x50
  869. +#define GPI_FIFO_STATUS 0x54
  870. +#define GPI_FIFO_DEBUG 0x58
  871. +#define GPI_TX_PAUSE_TIME 0x5c
  872. +#define GPI_LMEM_SEC_BUF_DATA_OFFSET 0x60
  873. +#define GPI_DDR_SEC_BUF_DATA_OFFSET 0x64
  874. +#define GPI_TOE_CHKSUM_EN 0x68
  875. +#define GPI_OVERRUN_DROPCNT 0x6c
  876. +#define GPI_CSR_MTIP_PAUSE_REG 0x74
  877. +#define GPI_CSR_MTIP_PAUSE_QUANTUM 0x78
  878. +#define GPI_CSR_RX_CNT 0x7c
  879. +#define GPI_CSR_TX_CNT 0x80
  880. +#define GPI_CSR_DEBUG1 0x84
  881. +#define GPI_CSR_DEBUG2 0x88
  882. +
  883. +struct gpi_cfg {
  884. + u32 lmem_rtry_cnt;
  885. + u32 tmlf_txthres;
  886. + u32 aseq_len;
  887. + u32 mtip_pause_reg;
  888. +};
  889. +
  890. +/* GPI commons defines */
  891. +#define GPI_LMEM_BUF_EN 0x1
  892. +#define GPI_DDR_BUF_EN 0x1
  893. +
  894. +/* EGPI 1 defines */
  895. +#define EGPI1_LMEM_RTRY_CNT 0x40
  896. +#define EGPI1_TMLF_TXTHRES 0xBC
  897. +#define EGPI1_ASEQ_LEN 0x50
  898. +
  899. +/* EGPI 2 defines */
  900. +#define EGPI2_LMEM_RTRY_CNT 0x40
  901. +#define EGPI2_TMLF_TXTHRES 0xBC
  902. +#define EGPI2_ASEQ_LEN 0x40
  903. +
  904. +/* EGPI 3 defines */
  905. +#define EGPI3_LMEM_RTRY_CNT 0x40
  906. +#define EGPI3_TMLF_TXTHRES 0xBC
  907. +#define EGPI3_ASEQ_LEN 0x40
  908. +
  909. +/* HGPI defines */
  910. +#define HGPI_LMEM_RTRY_CNT 0x40
  911. +#define HGPI_TMLF_TXTHRES 0xBC
  912. +#define HGPI_ASEQ_LEN 0x40
  913. +
  914. +#define EGPI_PAUSE_TIME 0x000007D0
  915. +#define EGPI_PAUSE_ENABLE 0x40000000
  916. +#endif /* _GPI_H_ */
  917. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
  918. new file mode 100644
  919. index 00000000..71cf81a7
  920. --- /dev/null
  921. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif.h
  922. @@ -0,0 +1,100 @@
  923. +/*
  924. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  925. + * Copyright 2017 NXP
  926. + *
  927. + * This program is free software; you can redistribute it and/or modify
  928. + * it under the terms of the GNU General Public License as published by
  929. + * the Free Software Foundation; either version 2 of the License, or
  930. + * (at your option) any later version.
  931. + *
  932. + * This program is distributed in the hope that it will be useful,
  933. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  934. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  935. + * GNU General Public License for more details.
  936. + *
  937. + * You should have received a copy of the GNU General Public License
  938. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  939. + */
  940. +
  941. +#ifndef _HIF_H_
  942. +#define _HIF_H_
  943. +
  944. +/* @file hif.h.
  945. + * hif - PFE hif block control and status register.
  946. + * Mapped on CBUS and accessible from all PE's and ARM.
  947. + */
  948. +#define HIF_VERSION (HIF_BASE_ADDR + 0x00)
  949. +#define HIF_TX_CTRL (HIF_BASE_ADDR + 0x04)
  950. +#define HIF_TX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x08)
  951. +#define HIF_TX_ALLOC (HIF_BASE_ADDR + 0x0c)
  952. +#define HIF_TX_BDP_ADDR (HIF_BASE_ADDR + 0x10)
  953. +#define HIF_TX_STATUS (HIF_BASE_ADDR + 0x14)
  954. +#define HIF_RX_CTRL (HIF_BASE_ADDR + 0x20)
  955. +#define HIF_RX_BDP_ADDR (HIF_BASE_ADDR + 0x24)
  956. +#define HIF_RX_STATUS (HIF_BASE_ADDR + 0x30)
  957. +#define HIF_INT_SRC (HIF_BASE_ADDR + 0x34)
  958. +#define HIF_INT_ENABLE (HIF_BASE_ADDR + 0x38)
  959. +#define HIF_POLL_CTRL (HIF_BASE_ADDR + 0x3c)
  960. +#define HIF_RX_CURR_BD_ADDR (HIF_BASE_ADDR + 0x40)
  961. +#define HIF_RX_ALLOC (HIF_BASE_ADDR + 0x44)
  962. +#define HIF_TX_DMA_STATUS (HIF_BASE_ADDR + 0x48)
  963. +#define HIF_RX_DMA_STATUS (HIF_BASE_ADDR + 0x4c)
  964. +#define HIF_INT_COAL (HIF_BASE_ADDR + 0x50)
  965. +
  966. +/* HIF_INT_SRC/ HIF_INT_ENABLE control bits */
  967. +#define HIF_INT BIT(0)
  968. +#define HIF_RXBD_INT BIT(1)
  969. +#define HIF_RXPKT_INT BIT(2)
  970. +#define HIF_TXBD_INT BIT(3)
  971. +#define HIF_TXPKT_INT BIT(4)
  972. +
  973. +/* HIF_TX_CTRL bits */
  974. +#define HIF_CTRL_DMA_EN BIT(0)
  975. +#define HIF_CTRL_BDP_POLL_CTRL_EN BIT(1)
  976. +#define HIF_CTRL_BDP_CH_START_WSTB BIT(2)
  977. +
  978. +/* HIF_RX_STATUS bits */
  979. +#define BDP_CSR_RX_DMA_ACTV BIT(16)
  980. +
  981. +/* HIF_INT_ENABLE bits */
  982. +#define HIF_INT_EN BIT(0)
  983. +#define HIF_RXBD_INT_EN BIT(1)
  984. +#define HIF_RXPKT_INT_EN BIT(2)
  985. +#define HIF_TXBD_INT_EN BIT(3)
  986. +#define HIF_TXPKT_INT_EN BIT(4)
  987. +
  988. +/* HIF_POLL_CTRL bits*/
  989. +#define HIF_RX_POLL_CTRL_CYCLE 0x0400
  990. +#define HIF_TX_POLL_CTRL_CYCLE 0x0400
  991. +
  992. +/* HIF_INT_COAL bits*/
  993. +#define HIF_INT_COAL_ENABLE BIT(31)
  994. +
  995. +/* Buffer descriptor control bits */
  996. +#define BD_CTRL_BUFLEN_MASK 0x3fff
  997. +#define BD_BUF_LEN(x) ((x) & BD_CTRL_BUFLEN_MASK)
  998. +#define BD_CTRL_CBD_INT_EN BIT(16)
  999. +#define BD_CTRL_PKT_INT_EN BIT(17)
  1000. +#define BD_CTRL_LIFM BIT(18)
  1001. +#define BD_CTRL_LAST_BD BIT(19)
  1002. +#define BD_CTRL_DIR BIT(20)
  1003. +#define BD_CTRL_LMEM_CPY BIT(21) /* Valid only for HIF_NOCPY */
  1004. +#define BD_CTRL_PKT_XFER BIT(24)
  1005. +#define BD_CTRL_DESC_EN BIT(31)
  1006. +#define BD_CTRL_PARSE_DISABLE BIT(25)
  1007. +#define BD_CTRL_BRFETCH_DISABLE BIT(26)
  1008. +#define BD_CTRL_RTFETCH_DISABLE BIT(27)
  1009. +
  1010. +/* Buffer descriptor status bits*/
  1011. +#define BD_STATUS_CONN_ID(x) ((x) & 0xffff)
  1012. +#define BD_STATUS_DIR_PROC_ID BIT(16)
  1013. +#define BD_STATUS_CONN_ID_EN BIT(17)
  1014. +#define BD_STATUS_PE2PROC_ID(x) (((x) & 7) << 18)
  1015. +#define BD_STATUS_LE_DATA BIT(21)
  1016. +#define BD_STATUS_CHKSUM_EN BIT(22)
  1017. +
  1018. +/* HIF Buffer descriptor status bits */
  1019. +#define DIR_PROC_ID BIT(16)
  1020. +#define PROC_ID(id) ((id) << 18)
  1021. +
  1022. +#endif /* _HIF_H_ */
  1023. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
  1024. new file mode 100644
  1025. index 00000000..3d4d43ce
  1026. --- /dev/null
  1027. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/hif_nocpy.h
  1028. @@ -0,0 +1,50 @@
  1029. +/*
  1030. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1031. + * Copyright 2017 NXP
  1032. + *
  1033. + * This program is free software; you can redistribute it and/or modify
  1034. + * it under the terms of the GNU General Public License as published by
  1035. + * the Free Software Foundation; either version 2 of the License, or
  1036. + * (at your option) any later version.
  1037. + *
  1038. + * This program is distributed in the hope that it will be useful,
  1039. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1040. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1041. + * GNU General Public License for more details.
  1042. + *
  1043. + * You should have received a copy of the GNU General Public License
  1044. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1045. + */
  1046. +
  1047. +#ifndef _HIF_NOCPY_H_
  1048. +#define _HIF_NOCPY_H_
  1049. +
  1050. +#define HIF_NOCPY_VERSION (HIF_NOCPY_BASE_ADDR + 0x00)
  1051. +#define HIF_NOCPY_TX_CTRL (HIF_NOCPY_BASE_ADDR + 0x04)
  1052. +#define HIF_NOCPY_TX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x08)
  1053. +#define HIF_NOCPY_TX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x0c)
  1054. +#define HIF_NOCPY_TX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x10)
  1055. +#define HIF_NOCPY_TX_STATUS (HIF_NOCPY_BASE_ADDR + 0x14)
  1056. +#define HIF_NOCPY_RX_CTRL (HIF_NOCPY_BASE_ADDR + 0x20)
  1057. +#define HIF_NOCPY_RX_BDP_ADDR (HIF_NOCPY_BASE_ADDR + 0x24)
  1058. +#define HIF_NOCPY_RX_STATUS (HIF_NOCPY_BASE_ADDR + 0x30)
  1059. +#define HIF_NOCPY_INT_SRC (HIF_NOCPY_BASE_ADDR + 0x34)
  1060. +#define HIF_NOCPY_INT_ENABLE (HIF_NOCPY_BASE_ADDR + 0x38)
  1061. +#define HIF_NOCPY_POLL_CTRL (HIF_NOCPY_BASE_ADDR + 0x3c)
  1062. +#define HIF_NOCPY_RX_CURR_BD_ADDR (HIF_NOCPY_BASE_ADDR + 0x40)
  1063. +#define HIF_NOCPY_RX_ALLOC (HIF_NOCPY_BASE_ADDR + 0x44)
  1064. +#define HIF_NOCPY_TX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x48)
  1065. +#define HIF_NOCPY_RX_DMA_STATUS (HIF_NOCPY_BASE_ADDR + 0x4c)
  1066. +#define HIF_NOCPY_RX_INQ0_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x50)
  1067. +#define HIF_NOCPY_RX_INQ1_PKTPTR (HIF_NOCPY_BASE_ADDR + 0x54)
  1068. +#define HIF_NOCPY_TX_PORT_NO (HIF_NOCPY_BASE_ADDR + 0x60)
  1069. +#define HIF_NOCPY_LMEM_ALLOC_ADDR (HIF_NOCPY_BASE_ADDR + 0x64)
  1070. +#define HIF_NOCPY_CLASS_ADDR (HIF_NOCPY_BASE_ADDR + 0x68)
  1071. +#define HIF_NOCPY_TMU_PORT0_ADDR (HIF_NOCPY_BASE_ADDR + 0x70)
  1072. +#define HIF_NOCPY_TMU_PORT1_ADDR (HIF_NOCPY_BASE_ADDR + 0x74)
  1073. +#define HIF_NOCPY_TMU_PORT2_ADDR (HIF_NOCPY_BASE_ADDR + 0x7c)
  1074. +#define HIF_NOCPY_TMU_PORT3_ADDR (HIF_NOCPY_BASE_ADDR + 0x80)
  1075. +#define HIF_NOCPY_TMU_PORT4_ADDR (HIF_NOCPY_BASE_ADDR + 0x84)
  1076. +#define HIF_NOCPY_INT_COAL (HIF_NOCPY_BASE_ADDR + 0x90)
  1077. +
  1078. +#endif /* _HIF_NOCPY_H_ */
  1079. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
  1080. new file mode 100644
  1081. index 00000000..05f3d681
  1082. --- /dev/null
  1083. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/tmu_csr.h
  1084. @@ -0,0 +1,168 @@
  1085. +/*
  1086. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1087. + * Copyright 2017 NXP
  1088. + *
  1089. + * This program is free software; you can redistribute it and/or modify
  1090. + * it under the terms of the GNU General Public License as published by
  1091. + * the Free Software Foundation; either version 2 of the License, or
  1092. + * (at your option) any later version.
  1093. + *
  1094. + * This program is distributed in the hope that it will be useful,
  1095. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1096. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1097. + * GNU General Public License for more details.
  1098. + *
  1099. + * You should have received a copy of the GNU General Public License
  1100. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1101. + */
  1102. +
  1103. +#ifndef _TMU_CSR_H_
  1104. +#define _TMU_CSR_H_
  1105. +
  1106. +#define TMU_VERSION (TMU_CSR_BASE_ADDR + 0x000)
  1107. +#define TMU_INQ_WATERMARK (TMU_CSR_BASE_ADDR + 0x004)
  1108. +#define TMU_PHY_INQ_PKTPTR (TMU_CSR_BASE_ADDR + 0x008)
  1109. +#define TMU_PHY_INQ_PKTINFO (TMU_CSR_BASE_ADDR + 0x00c)
  1110. +#define TMU_PHY_INQ_FIFO_CNT (TMU_CSR_BASE_ADDR + 0x010)
  1111. +#define TMU_SYS_GENERIC_CONTROL (TMU_CSR_BASE_ADDR + 0x014)
  1112. +#define TMU_SYS_GENERIC_STATUS (TMU_CSR_BASE_ADDR + 0x018)
  1113. +#define TMU_SYS_GEN_CON0 (TMU_CSR_BASE_ADDR + 0x01c)
  1114. +#define TMU_SYS_GEN_CON1 (TMU_CSR_BASE_ADDR + 0x020)
  1115. +#define TMU_SYS_GEN_CON2 (TMU_CSR_BASE_ADDR + 0x024)
  1116. +#define TMU_SYS_GEN_CON3 (TMU_CSR_BASE_ADDR + 0x028)
  1117. +#define TMU_SYS_GEN_CON4 (TMU_CSR_BASE_ADDR + 0x02c)
  1118. +#define TMU_TEQ_DISABLE_DROPCHK (TMU_CSR_BASE_ADDR + 0x030)
  1119. +#define TMU_TEQ_CTRL (TMU_CSR_BASE_ADDR + 0x034)
  1120. +#define TMU_TEQ_QCFG (TMU_CSR_BASE_ADDR + 0x038)
  1121. +#define TMU_TEQ_DROP_STAT (TMU_CSR_BASE_ADDR + 0x03c)
  1122. +#define TMU_TEQ_QAVG (TMU_CSR_BASE_ADDR + 0x040)
  1123. +#define TMU_TEQ_WREG_PROB (TMU_CSR_BASE_ADDR + 0x044)
  1124. +#define TMU_TEQ_TRANS_STAT (TMU_CSR_BASE_ADDR + 0x048)
  1125. +#define TMU_TEQ_HW_PROB_CFG0 (TMU_CSR_BASE_ADDR + 0x04c)
  1126. +#define TMU_TEQ_HW_PROB_CFG1 (TMU_CSR_BASE_ADDR + 0x050)
  1127. +#define TMU_TEQ_HW_PROB_CFG2 (TMU_CSR_BASE_ADDR + 0x054)
  1128. +#define TMU_TEQ_HW_PROB_CFG3 (TMU_CSR_BASE_ADDR + 0x058)
  1129. +#define TMU_TEQ_HW_PROB_CFG4 (TMU_CSR_BASE_ADDR + 0x05c)
  1130. +#define TMU_TEQ_HW_PROB_CFG5 (TMU_CSR_BASE_ADDR + 0x060)
  1131. +#define TMU_TEQ_HW_PROB_CFG6 (TMU_CSR_BASE_ADDR + 0x064)
  1132. +#define TMU_TEQ_HW_PROB_CFG7 (TMU_CSR_BASE_ADDR + 0x068)
  1133. +#define TMU_TEQ_HW_PROB_CFG8 (TMU_CSR_BASE_ADDR + 0x06c)
  1134. +#define TMU_TEQ_HW_PROB_CFG9 (TMU_CSR_BASE_ADDR + 0x070)
  1135. +#define TMU_TEQ_HW_PROB_CFG10 (TMU_CSR_BASE_ADDR + 0x074)
  1136. +#define TMU_TEQ_HW_PROB_CFG11 (TMU_CSR_BASE_ADDR + 0x078)
  1137. +#define TMU_TEQ_HW_PROB_CFG12 (TMU_CSR_BASE_ADDR + 0x07c)
  1138. +#define TMU_TEQ_HW_PROB_CFG13 (TMU_CSR_BASE_ADDR + 0x080)
  1139. +#define TMU_TEQ_HW_PROB_CFG14 (TMU_CSR_BASE_ADDR + 0x084)
  1140. +#define TMU_TEQ_HW_PROB_CFG15 (TMU_CSR_BASE_ADDR + 0x088)
  1141. +#define TMU_TEQ_HW_PROB_CFG16 (TMU_CSR_BASE_ADDR + 0x08c)
  1142. +#define TMU_TEQ_HW_PROB_CFG17 (TMU_CSR_BASE_ADDR + 0x090)
  1143. +#define TMU_TEQ_HW_PROB_CFG18 (TMU_CSR_BASE_ADDR + 0x094)
  1144. +#define TMU_TEQ_HW_PROB_CFG19 (TMU_CSR_BASE_ADDR + 0x098)
  1145. +#define TMU_TEQ_HW_PROB_CFG20 (TMU_CSR_BASE_ADDR + 0x09c)
  1146. +#define TMU_TEQ_HW_PROB_CFG21 (TMU_CSR_BASE_ADDR + 0x0a0)
  1147. +#define TMU_TEQ_HW_PROB_CFG22 (TMU_CSR_BASE_ADDR + 0x0a4)
  1148. +#define TMU_TEQ_HW_PROB_CFG23 (TMU_CSR_BASE_ADDR + 0x0a8)
  1149. +#define TMU_TEQ_HW_PROB_CFG24 (TMU_CSR_BASE_ADDR + 0x0ac)
  1150. +#define TMU_TEQ_HW_PROB_CFG25 (TMU_CSR_BASE_ADDR + 0x0b0)
  1151. +#define TMU_TDQ_IIFG_CFG (TMU_CSR_BASE_ADDR + 0x0b4)
  1152. +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
  1153. + * This is a global Enable for all schedulers in PHY0
  1154. + */
  1155. +#define TMU_TDQ0_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x0b8)
  1156. +
  1157. +#define TMU_LLM_CTRL (TMU_CSR_BASE_ADDR + 0x0bc)
  1158. +#define TMU_LLM_BASE_ADDR (TMU_CSR_BASE_ADDR + 0x0c0)
  1159. +#define TMU_LLM_QUE_LEN (TMU_CSR_BASE_ADDR + 0x0c4)
  1160. +#define TMU_LLM_QUE_HEADPTR (TMU_CSR_BASE_ADDR + 0x0c8)
  1161. +#define TMU_LLM_QUE_TAILPTR (TMU_CSR_BASE_ADDR + 0x0cc)
  1162. +#define TMU_LLM_QUE_DROPCNT (TMU_CSR_BASE_ADDR + 0x0d0)
  1163. +#define TMU_INT_EN (TMU_CSR_BASE_ADDR + 0x0d4)
  1164. +#define TMU_INT_SRC (TMU_CSR_BASE_ADDR + 0x0d8)
  1165. +#define TMU_INQ_STAT (TMU_CSR_BASE_ADDR + 0x0dc)
  1166. +#define TMU_CTRL (TMU_CSR_BASE_ADDR + 0x0e0)
  1167. +
  1168. +/* [31] Mem Access Command. 0 = Internal Memory Read, 1 = Internal memory
  1169. + * Write [27:24] Byte Enables of the Internal memory access [23:0] Address of
  1170. + * the internal memory. This address is used to access both the PM and DM of
  1171. + * all the PE's
  1172. + */
  1173. +#define TMU_MEM_ACCESS_ADDR (TMU_CSR_BASE_ADDR + 0x0e4)
  1174. +
  1175. +/* Internal Memory Access Write Data */
  1176. +#define TMU_MEM_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x0e8)
  1177. +/* Internal Memory Access Read Data. The commands are blocked
  1178. + * at the mem_access only
  1179. + */
  1180. +#define TMU_MEM_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x0ec)
  1181. +
  1182. +/* [31:0] PHY0 in queue address (must be initialized with one of the
  1183. + * xxx_INQ_PKTPTR cbus addresses)
  1184. + */
  1185. +#define TMU_PHY0_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f0)
  1186. +/* [31:0] PHY1 in queue address (must be initialized with one of the
  1187. + * xxx_INQ_PKTPTR cbus addresses)
  1188. + */
  1189. +#define TMU_PHY1_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f4)
  1190. +/* [31:0] PHY2 in queue address (must be initialized with one of the
  1191. + * xxx_INQ_PKTPTR cbus addresses)
  1192. + */
  1193. +#define TMU_PHY2_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0f8)
  1194. +/* [31:0] PHY3 in queue address (must be initialized with one of the
  1195. + * xxx_INQ_PKTPTR cbus addresses)
  1196. + */
  1197. +#define TMU_PHY3_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x0fc)
  1198. +#define TMU_BMU_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x100)
  1199. +#define TMU_TX_CTRL (TMU_CSR_BASE_ADDR + 0x104)
  1200. +
  1201. +#define TMU_BUS_ACCESS_WDATA (TMU_CSR_BASE_ADDR + 0x108)
  1202. +#define TMU_BUS_ACCESS (TMU_CSR_BASE_ADDR + 0x10c)
  1203. +#define TMU_BUS_ACCESS_RDATA (TMU_CSR_BASE_ADDR + 0x110)
  1204. +
  1205. +#define TMU_PE_SYS_CLK_RATIO (TMU_CSR_BASE_ADDR + 0x114)
  1206. +#define TMU_PE_STATUS (TMU_CSR_BASE_ADDR + 0x118)
  1207. +#define TMU_TEQ_MAX_THRESHOLD (TMU_CSR_BASE_ADDR + 0x11c)
  1208. +/* [31:0] PHY4 in queue address (must be initialized with one of the
  1209. + * xxx_INQ_PKTPTR cbus addresses)
  1210. + */
  1211. +#define TMU_PHY4_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x134)
  1212. +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
  1213. + * This is a global Enable for all schedulers in PHY1
  1214. + */
  1215. +#define TMU_TDQ1_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x138)
  1216. +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
  1217. + * This is a global Enable for all schedulers in PHY2
  1218. + */
  1219. +#define TMU_TDQ2_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x13c)
  1220. +/* [9:0] Scheduler Enable for each of the scheduler in the TDQ.
  1221. + * This is a global Enable for all schedulers in PHY3
  1222. + */
  1223. +#define TMU_TDQ3_SCH_CTRL (TMU_CSR_BASE_ADDR + 0x140)
  1224. +#define TMU_BMU_BUF_SIZE (TMU_CSR_BASE_ADDR + 0x144)
  1225. +/* [31:0] PHY5 in queue address (must be initialized with one of the
  1226. + * xxx_INQ_PKTPTR cbus addresses)
  1227. + */
  1228. +#define TMU_PHY5_INQ_ADDR (TMU_CSR_BASE_ADDR + 0x148)
  1229. +
  1230. +#define SW_RESET BIT(0) /* Global software reset */
  1231. +#define INQ_RESET BIT(2)
  1232. +#define TEQ_RESET BIT(3)
  1233. +#define TDQ_RESET BIT(4)
  1234. +#define PE_RESET BIT(5)
  1235. +#define MEM_INIT BIT(6)
  1236. +#define MEM_INIT_DONE BIT(7)
  1237. +#define LLM_INIT BIT(8)
  1238. +#define LLM_INIT_DONE BIT(9)
  1239. +#define ECC_MEM_INIT_DONE BIT(10)
  1240. +
  1241. +struct tmu_cfg {
  1242. + u32 pe_sys_clk_ratio;
  1243. + unsigned long llm_base_addr;
  1244. + u32 llm_queue_len;
  1245. +};
  1246. +
  1247. +/* Not HW related for pfe_ctrl / pfe common defines */
  1248. +#define DEFAULT_MAX_QDEPTH 80
  1249. +#define DEFAULT_Q0_QDEPTH 511 /*We keep one large queue for host tx qos */
  1250. +#define DEFAULT_TMU3_QDEPTH 127
  1251. +
  1252. +#endif /* _TMU_CSR_H_ */
  1253. diff --git a/drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h b/drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
  1254. new file mode 100644
  1255. index 00000000..ae623cda
  1256. --- /dev/null
  1257. +++ b/drivers/staging/fsl_ppfe/include/pfe/cbus/util_csr.h
  1258. @@ -0,0 +1,61 @@
  1259. +/*
  1260. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1261. + * Copyright 2017 NXP
  1262. + *
  1263. + * This program is free software; you can redistribute it and/or modify
  1264. + * it under the terms of the GNU General Public License as published by
  1265. + * the Free Software Foundation; either version 2 of the License, or
  1266. + * (at your option) any later version.
  1267. + *
  1268. + * This program is distributed in the hope that it will be useful,
  1269. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1270. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1271. + * GNU General Public License for more details.
  1272. + *
  1273. + * You should have received a copy of the GNU General Public License
  1274. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1275. + */
  1276. +
  1277. +#ifndef _UTIL_CSR_H_
  1278. +#define _UTIL_CSR_H_
  1279. +
  1280. +#define UTIL_VERSION (UTIL_CSR_BASE_ADDR + 0x000)
  1281. +#define UTIL_TX_CTRL (UTIL_CSR_BASE_ADDR + 0x004)
  1282. +#define UTIL_INQ_PKTPTR (UTIL_CSR_BASE_ADDR + 0x010)
  1283. +
  1284. +#define UTIL_HDR_SIZE (UTIL_CSR_BASE_ADDR + 0x014)
  1285. +
  1286. +#define UTIL_PE0_QB_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x020)
  1287. +#define UTIL_PE0_QB_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x024)
  1288. +#define UTIL_PE0_RO_DM_ADDR0 (UTIL_CSR_BASE_ADDR + 0x060)
  1289. +#define UTIL_PE0_RO_DM_ADDR1 (UTIL_CSR_BASE_ADDR + 0x064)
  1290. +
  1291. +#define UTIL_MEM_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x100)
  1292. +#define UTIL_MEM_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x104)
  1293. +#define UTIL_MEM_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x108)
  1294. +
  1295. +#define UTIL_TM_INQ_ADDR (UTIL_CSR_BASE_ADDR + 0x114)
  1296. +#define UTIL_PE_STATUS (UTIL_CSR_BASE_ADDR + 0x118)
  1297. +
  1298. +#define UTIL_PE_SYS_CLK_RATIO (UTIL_CSR_BASE_ADDR + 0x200)
  1299. +#define UTIL_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x204)
  1300. +#define UTIL_GAP_BETWEEN_READS (UTIL_CSR_BASE_ADDR + 0x208)
  1301. +#define UTIL_MAX_BUF_CNT (UTIL_CSR_BASE_ADDR + 0x20c)
  1302. +#define UTIL_TSQ_FIFO_THRES (UTIL_CSR_BASE_ADDR + 0x210)
  1303. +#define UTIL_TSQ_MAX_CNT (UTIL_CSR_BASE_ADDR + 0x214)
  1304. +#define UTIL_IRAM_DATA_0 (UTIL_CSR_BASE_ADDR + 0x218)
  1305. +#define UTIL_IRAM_DATA_1 (UTIL_CSR_BASE_ADDR + 0x21c)
  1306. +#define UTIL_IRAM_DATA_2 (UTIL_CSR_BASE_ADDR + 0x220)
  1307. +#define UTIL_IRAM_DATA_3 (UTIL_CSR_BASE_ADDR + 0x224)
  1308. +
  1309. +#define UTIL_BUS_ACCESS_ADDR (UTIL_CSR_BASE_ADDR + 0x228)
  1310. +#define UTIL_BUS_ACCESS_WDATA (UTIL_CSR_BASE_ADDR + 0x22c)
  1311. +#define UTIL_BUS_ACCESS_RDATA (UTIL_CSR_BASE_ADDR + 0x230)
  1312. +
  1313. +#define UTIL_INQ_AFULL_THRES (UTIL_CSR_BASE_ADDR + 0x234)
  1314. +
  1315. +struct util_cfg {
  1316. + u32 pe_sys_clk_ratio;
  1317. +};
  1318. +
  1319. +#endif /* _UTIL_CSR_H_ */
  1320. diff --git a/drivers/staging/fsl_ppfe/include/pfe/pfe.h b/drivers/staging/fsl_ppfe/include/pfe/pfe.h
  1321. new file mode 100644
  1322. index 00000000..d93ae4c6
  1323. --- /dev/null
  1324. +++ b/drivers/staging/fsl_ppfe/include/pfe/pfe.h
  1325. @@ -0,0 +1,372 @@
  1326. +/*
  1327. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1328. + * Copyright 2017 NXP
  1329. + *
  1330. + * This program is free software; you can redistribute it and/or modify
  1331. + * it under the terms of the GNU General Public License as published by
  1332. + * the Free Software Foundation; either version 2 of the License, or
  1333. + * (at your option) any later version.
  1334. + *
  1335. + * This program is distributed in the hope that it will be useful,
  1336. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1337. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1338. + * GNU General Public License for more details.
  1339. + *
  1340. + * You should have received a copy of the GNU General Public License
  1341. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1342. + */
  1343. +
  1344. +#ifndef _PFE_H_
  1345. +#define _PFE_H_
  1346. +
  1347. +#include "cbus.h"
  1348. +
  1349. +#define CLASS_DMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
  1350. +/*
  1351. + * Only valid for mem access register interface
  1352. + */
  1353. +#define CLASS_IMEM_BASE_ADDR(i) (0x00000000 | ((i) << 20))
  1354. +#define CLASS_DMEM_SIZE 0x00002000
  1355. +#define CLASS_IMEM_SIZE 0x00008000
  1356. +
  1357. +#define TMU_DMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
  1358. +/*
  1359. + * Only valid for mem access register interface
  1360. + */
  1361. +#define TMU_IMEM_BASE_ADDR(i) (0x00000000 + ((i) << 20))
  1362. +#define TMU_DMEM_SIZE 0x00000800
  1363. +#define TMU_IMEM_SIZE 0x00002000
  1364. +
  1365. +#define UTIL_DMEM_BASE_ADDR 0x00000000
  1366. +#define UTIL_DMEM_SIZE 0x00002000
  1367. +
  1368. +#define PE_LMEM_BASE_ADDR 0xc3010000
  1369. +#define PE_LMEM_SIZE 0x8000
  1370. +#define PE_LMEM_END (PE_LMEM_BASE_ADDR + PE_LMEM_SIZE)
  1371. +
  1372. +#define DMEM_BASE_ADDR 0x00000000
  1373. +#define DMEM_SIZE 0x2000 /* TMU has less... */
  1374. +#define DMEM_END (DMEM_BASE_ADDR + DMEM_SIZE)
  1375. +
  1376. +#define PMEM_BASE_ADDR 0x00010000
  1377. +#define PMEM_SIZE 0x8000 /* TMU has less... */
  1378. +#define PMEM_END (PMEM_BASE_ADDR + PMEM_SIZE)
  1379. +
  1380. +/* These check memory ranges from PE point of view/memory map */
  1381. +#define IS_DMEM(addr, len) \
  1382. + ({ typeof(addr) addr_ = (addr); \
  1383. + ((unsigned long)(addr_) >= DMEM_BASE_ADDR) && \
  1384. + (((unsigned long)(addr_) + (len)) <= DMEM_END); })
  1385. +
  1386. +#define IS_PMEM(addr, len) \
  1387. + ({ typeof(addr) addr_ = (addr); \
  1388. + ((unsigned long)(addr_) >= PMEM_BASE_ADDR) && \
  1389. + (((unsigned long)(addr_) + (len)) <= PMEM_END); })
  1390. +
  1391. +#define IS_PE_LMEM(addr, len) \
  1392. + ({ typeof(addr) addr_ = (addr); \
  1393. + ((unsigned long)(addr_) >= \
  1394. + PE_LMEM_BASE_ADDR) && \
  1395. + (((unsigned long)(addr_) + \
  1396. + (len)) <= PE_LMEM_END); })
  1397. +
  1398. +#define IS_PFE_LMEM(addr, len) \
  1399. + ({ typeof(addr) addr_ = (addr); \
  1400. + ((unsigned long)(addr_) >= \
  1401. + CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR)) && \
  1402. + (((unsigned long)(addr_) + (len)) <= \
  1403. + CBUS_VIRT_TO_PFE(LMEM_END)); })
  1404. +
  1405. +#define __IS_PHYS_DDR(addr, len) \
  1406. + ({ typeof(addr) addr_ = (addr); \
  1407. + ((unsigned long)(addr_) >= \
  1408. + DDR_PHYS_BASE_ADDR) && \
  1409. + (((unsigned long)(addr_) + (len)) <= \
  1410. + DDR_PHYS_END); })
  1411. +
  1412. +#define IS_PHYS_DDR(addr, len) __IS_PHYS_DDR(DDR_PFE_TO_PHYS(addr), len)
  1413. +
  1414. +/*
  1415. + * If using a run-time virtual address for the cbus base address use this code
  1416. + */
  1417. +extern void *cbus_base_addr;
  1418. +extern void *ddr_base_addr;
  1419. +extern unsigned long ddr_phys_base_addr;
  1420. +extern unsigned int ddr_size;
  1421. +
  1422. +#define CBUS_BASE_ADDR cbus_base_addr
  1423. +#define DDR_PHYS_BASE_ADDR ddr_phys_base_addr
  1424. +#define DDR_BASE_ADDR ddr_base_addr
  1425. +#define DDR_SIZE ddr_size
  1426. +
  1427. +#define DDR_PHYS_END (DDR_PHYS_BASE_ADDR + DDR_SIZE)
  1428. +
  1429. +#define LS1012A_PFE_RESET_WA /*
  1430. + * PFE doesn't have global reset and re-init
  1431. + * should takecare few things to make PFE
  1432. + * functional after reset
  1433. + */
  1434. +#define PFE_CBUS_PHYS_BASE_ADDR 0xc0000000 /* CBUS physical base address
  1435. + * as seen by PE's.
  1436. + */
  1437. +/* CBUS physical base address as seen by PE's. */
  1438. +#define PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE 0xc0000000
  1439. +
  1440. +#define DDR_PHYS_TO_PFE(p) (((unsigned long int)(p)) & 0x7FFFFFFF)
  1441. +#define DDR_PFE_TO_PHYS(p) (((unsigned long int)(p)) | 0x80000000)
  1442. +#define CBUS_PHYS_TO_PFE(p) (((p) - PFE_CBUS_PHYS_BASE_ADDR) + \
  1443. + PFE_CBUS_PHYS_BASE_ADDR_FROM_PFE)
  1444. +/* Translates to PFE address map */
  1445. +
  1446. +#define DDR_PHYS_TO_VIRT(p) (((p) - DDR_PHYS_BASE_ADDR) + DDR_BASE_ADDR)
  1447. +#define DDR_VIRT_TO_PHYS(v) (((v) - DDR_BASE_ADDR) + DDR_PHYS_BASE_ADDR)
  1448. +#define DDR_VIRT_TO_PFE(p) (DDR_PHYS_TO_PFE(DDR_VIRT_TO_PHYS(p)))
  1449. +
  1450. +#define CBUS_VIRT_TO_PFE(v) (((v) - CBUS_BASE_ADDR) + \
  1451. + PFE_CBUS_PHYS_BASE_ADDR)
  1452. +#define CBUS_PFE_TO_VIRT(p) (((unsigned long int)(p) - \
  1453. + PFE_CBUS_PHYS_BASE_ADDR) + CBUS_BASE_ADDR)
  1454. +
  1455. +/* The below part of the code is used in QOS control driver from host */
  1456. +#define TMU_APB_BASE_ADDR 0xc1000000 /* TMU base address seen by
  1457. + * pe's
  1458. + */
  1459. +
  1460. +enum {
  1461. + CLASS0_ID = 0,
  1462. + CLASS1_ID,
  1463. + CLASS2_ID,
  1464. + CLASS3_ID,
  1465. + CLASS4_ID,
  1466. + CLASS5_ID,
  1467. + TMU0_ID,
  1468. + TMU1_ID,
  1469. + TMU2_ID,
  1470. + TMU3_ID,
  1471. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1472. + UTIL_ID,
  1473. +#endif
  1474. + MAX_PE
  1475. +};
  1476. +
  1477. +#define CLASS_MASK (BIT(CLASS0_ID) | BIT(CLASS1_ID) |\
  1478. + BIT(CLASS2_ID) | BIT(CLASS3_ID) |\
  1479. + BIT(CLASS4_ID) | BIT(CLASS5_ID))
  1480. +#define CLASS_MAX_ID CLASS5_ID
  1481. +
  1482. +#define TMU_MASK (BIT(TMU0_ID) | BIT(TMU1_ID) |\
  1483. + BIT(TMU3_ID))
  1484. +
  1485. +#define TMU_MAX_ID TMU3_ID
  1486. +
  1487. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1488. +#define UTIL_MASK BIT(UTIL_ID)
  1489. +#endif
  1490. +
  1491. +struct pe_status {
  1492. + u32 cpu_state;
  1493. + u32 activity_counter;
  1494. + u32 rx;
  1495. + union {
  1496. + u32 tx;
  1497. + u32 tmu_qstatus;
  1498. + };
  1499. + u32 drop;
  1500. +#if defined(CFG_PE_DEBUG)
  1501. + u32 debug_indicator;
  1502. + u32 debug[16];
  1503. +#endif
  1504. +} __aligned(16);
  1505. +
  1506. +struct pe_sync_mailbox {
  1507. + u32 stop;
  1508. + u32 stopped;
  1509. +};
  1510. +
  1511. +/* Drop counter definitions */
  1512. +
  1513. +#define CLASS_NUM_DROP_COUNTERS 13
  1514. +#define UTIL_NUM_DROP_COUNTERS 8
  1515. +
  1516. +/* PE information.
  1517. + * Structure containing PE's specific information. It is used to create
  1518. + * generic C functions common to all PE's.
  1519. + * Before using the library functions this structure needs to be initialized
  1520. + * with the different registers virtual addresses
  1521. + * (according to the ARM MMU mmaping). The default initialization supports a
  1522. + * virtual == physical mapping.
  1523. + */
  1524. +struct pe_info {
  1525. + u32 dmem_base_addr; /* PE's dmem base address */
  1526. + u32 pmem_base_addr; /* PE's pmem base address */
  1527. + u32 pmem_size; /* PE's pmem size */
  1528. +
  1529. + void *mem_access_wdata; /* PE's _MEM_ACCESS_WDATA register
  1530. + * address
  1531. + */
  1532. + void *mem_access_addr; /* PE's _MEM_ACCESS_ADDR register
  1533. + * address
  1534. + */
  1535. + void *mem_access_rdata; /* PE's _MEM_ACCESS_RDATA register
  1536. + * address
  1537. + */
  1538. +};
  1539. +
  1540. +void pe_lmem_read(u32 *dst, u32 len, u32 offset);
  1541. +void pe_lmem_write(u32 *src, u32 len, u32 offset);
  1542. +
  1543. +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
  1544. +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len);
  1545. +
  1546. +u32 pe_pmem_read(int id, u32 addr, u8 size);
  1547. +
  1548. +void pe_dmem_write(int id, u32 val, u32 addr, u8 size);
  1549. +u32 pe_dmem_read(int id, u32 addr, u8 size);
  1550. +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len);
  1551. +void class_pe_lmem_memset(u32 dst, int val, unsigned int len);
  1552. +void class_bus_write(u32 val, u32 addr, u8 size);
  1553. +u32 class_bus_read(u32 addr, u8 size);
  1554. +
  1555. +#define class_bus_readl(addr) class_bus_read(addr, 4)
  1556. +#define class_bus_readw(addr) class_bus_read(addr, 2)
  1557. +#define class_bus_readb(addr) class_bus_read(addr, 1)
  1558. +
  1559. +#define class_bus_writel(val, addr) class_bus_write(val, addr, 4)
  1560. +#define class_bus_writew(val, addr) class_bus_write(val, addr, 2)
  1561. +#define class_bus_writeb(val, addr) class_bus_write(val, addr, 1)
  1562. +
  1563. +#define pe_dmem_readl(id, addr) pe_dmem_read(id, addr, 4)
  1564. +#define pe_dmem_readw(id, addr) pe_dmem_read(id, addr, 2)
  1565. +#define pe_dmem_readb(id, addr) pe_dmem_read(id, addr, 1)
  1566. +
  1567. +#define pe_dmem_writel(id, val, addr) pe_dmem_write(id, val, addr, 4)
  1568. +#define pe_dmem_writew(id, val, addr) pe_dmem_write(id, val, addr, 2)
  1569. +#define pe_dmem_writeb(id, val, addr) pe_dmem_write(id, val, addr, 1)
  1570. +
  1571. +/*int pe_load_elf_section(int id, const void *data, elf32_shdr *shdr); */
  1572. +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
  1573. + struct device *dev);
  1574. +
  1575. +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
  1576. + unsigned int ddr_size);
  1577. +void bmu_init(void *base, struct BMU_CFG *cfg);
  1578. +void bmu_reset(void *base);
  1579. +void bmu_enable(void *base);
  1580. +void bmu_disable(void *base);
  1581. +void bmu_set_config(void *base, struct BMU_CFG *cfg);
  1582. +
  1583. +/*
  1584. + * An enumerated type for loopback values. This can be one of three values, no
  1585. + * loopback -normal operation, local loopback with internal loopback module of
  1586. + * MAC or PHY loopback which is through the external PHY.
  1587. + */
  1588. +#ifndef __MAC_LOOP_ENUM__
  1589. +#define __MAC_LOOP_ENUM__
  1590. +enum mac_loop {LB_NONE, LB_EXT, LB_LOCAL};
  1591. +#endif
  1592. +
  1593. +void gemac_init(void *base, void *config);
  1594. +void gemac_disable_rx_checksum_offload(void *base);
  1595. +void gemac_enable_rx_checksum_offload(void *base);
  1596. +void gemac_set_mdc_div(void *base, int mdc_div);
  1597. +void gemac_set_speed(void *base, enum mac_speed gem_speed);
  1598. +void gemac_set_duplex(void *base, int duplex);
  1599. +void gemac_set_mode(void *base, int mode);
  1600. +void gemac_enable(void *base);
  1601. +void gemac_tx_disable(void *base);
  1602. +void gemac_tx_enable(void *base);
  1603. +void gemac_disable(void *base);
  1604. +void gemac_reset(void *base);
  1605. +void gemac_set_address(void *base, struct spec_addr *addr);
  1606. +struct spec_addr gemac_get_address(void *base);
  1607. +void gemac_set_loop(void *base, enum mac_loop gem_loop);
  1608. +void gemac_set_laddr1(void *base, struct pfe_mac_addr *address);
  1609. +void gemac_set_laddr2(void *base, struct pfe_mac_addr *address);
  1610. +void gemac_set_laddr3(void *base, struct pfe_mac_addr *address);
  1611. +void gemac_set_laddr4(void *base, struct pfe_mac_addr *address);
  1612. +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
  1613. + unsigned int entry_index);
  1614. +void gemac_clear_laddr1(void *base);
  1615. +void gemac_clear_laddr2(void *base);
  1616. +void gemac_clear_laddr3(void *base);
  1617. +void gemac_clear_laddr4(void *base);
  1618. +void gemac_clear_laddrN(void *base, unsigned int entry_index);
  1619. +struct pfe_mac_addr gemac_get_hash(void *base);
  1620. +void gemac_set_hash(void *base, struct pfe_mac_addr *hash);
  1621. +struct pfe_mac_addr gem_get_laddr1(void *base);
  1622. +struct pfe_mac_addr gem_get_laddr2(void *base);
  1623. +struct pfe_mac_addr gem_get_laddr3(void *base);
  1624. +struct pfe_mac_addr gem_get_laddr4(void *base);
  1625. +struct pfe_mac_addr gem_get_laddrN(void *base, unsigned int entry_index);
  1626. +void gemac_set_config(void *base, struct gemac_cfg *cfg);
  1627. +void gemac_allow_broadcast(void *base);
  1628. +void gemac_no_broadcast(void *base);
  1629. +void gemac_enable_1536_rx(void *base);
  1630. +void gemac_disable_1536_rx(void *base);
  1631. +void gemac_enable_rx_jmb(void *base);
  1632. +void gemac_disable_rx_jmb(void *base);
  1633. +void gemac_enable_stacked_vlan(void *base);
  1634. +void gemac_disable_stacked_vlan(void *base);
  1635. +void gemac_enable_pause_rx(void *base);
  1636. +void gemac_disable_pause_rx(void *base);
  1637. +void gemac_enable_copy_all(void *base);
  1638. +void gemac_disable_copy_all(void *base);
  1639. +void gemac_set_bus_width(void *base, int width);
  1640. +void gemac_set_wol(void *base, u32 wol_conf);
  1641. +
  1642. +void gpi_init(void *base, struct gpi_cfg *cfg);
  1643. +void gpi_reset(void *base);
  1644. +void gpi_enable(void *base);
  1645. +void gpi_disable(void *base);
  1646. +void gpi_set_config(void *base, struct gpi_cfg *cfg);
  1647. +
  1648. +void class_init(struct class_cfg *cfg);
  1649. +void class_reset(void);
  1650. +void class_enable(void);
  1651. +void class_disable(void);
  1652. +void class_set_config(struct class_cfg *cfg);
  1653. +
  1654. +void tmu_reset(void);
  1655. +void tmu_init(struct tmu_cfg *cfg);
  1656. +void tmu_enable(u32 pe_mask);
  1657. +void tmu_disable(u32 pe_mask);
  1658. +u32 tmu_qstatus(u32 if_id);
  1659. +u32 tmu_pkts_processed(u32 if_id);
  1660. +
  1661. +void util_init(struct util_cfg *cfg);
  1662. +void util_reset(void);
  1663. +void util_enable(void);
  1664. +void util_disable(void);
  1665. +
  1666. +void hif_init(void);
  1667. +void hif_tx_enable(void);
  1668. +void hif_tx_disable(void);
  1669. +void hif_rx_enable(void);
  1670. +void hif_rx_disable(void);
  1671. +
  1672. +/* Get Chip Revision level
  1673. + *
  1674. + */
  1675. +static inline unsigned int CHIP_REVISION(void)
  1676. +{
  1677. + /*For LS1012A return always 1 */
  1678. + return 1;
  1679. +}
  1680. +
  1681. +/* Start HIF rx DMA
  1682. + *
  1683. + */
  1684. +static inline void hif_rx_dma_start(void)
  1685. +{
  1686. + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_RX_CTRL);
  1687. +}
  1688. +
  1689. +/* Start HIF tx DMA
  1690. + *
  1691. + */
  1692. +static inline void hif_tx_dma_start(void)
  1693. +{
  1694. + writel(HIF_CTRL_DMA_EN | HIF_CTRL_BDP_CH_START_WSTB, HIF_TX_CTRL);
  1695. +}
  1696. +
  1697. +#endif /* _PFE_H_ */
  1698. diff --git a/drivers/staging/fsl_ppfe/pfe_ctrl.c b/drivers/staging/fsl_ppfe/pfe_ctrl.c
  1699. new file mode 100644
  1700. index 00000000..dfa8547c
  1701. --- /dev/null
  1702. +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.c
  1703. @@ -0,0 +1,238 @@
  1704. +/*
  1705. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1706. + * Copyright 2017 NXP
  1707. + *
  1708. + * This program is free software; you can redistribute it and/or modify
  1709. + * it under the terms of the GNU General Public License as published by
  1710. + * the Free Software Foundation; either version 2 of the License, or
  1711. + * (at your option) any later version.
  1712. + *
  1713. + * This program is distributed in the hope that it will be useful,
  1714. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1715. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1716. + * GNU General Public License for more details.
  1717. + *
  1718. + * You should have received a copy of the GNU General Public License
  1719. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1720. + */
  1721. +
  1722. +#include <linux/kernel.h>
  1723. +#include <linux/sched.h>
  1724. +#include <linux/module.h>
  1725. +#include <linux/list.h>
  1726. +#include <linux/kthread.h>
  1727. +
  1728. +#include "pfe_mod.h"
  1729. +#include "pfe_ctrl.h"
  1730. +
  1731. +#define TIMEOUT_MS 1000
  1732. +
  1733. +int relax(unsigned long end)
  1734. +{
  1735. + if (time_after(jiffies, end)) {
  1736. + if (time_after(jiffies, end + (TIMEOUT_MS * HZ) / 1000))
  1737. + return -1;
  1738. +
  1739. + if (need_resched())
  1740. + schedule();
  1741. + }
  1742. +
  1743. + return 0;
  1744. +}
  1745. +
  1746. +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl)
  1747. +{
  1748. + int id;
  1749. +
  1750. + mutex_lock(&ctrl->mutex);
  1751. +
  1752. + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++)
  1753. + pe_dmem_write(id, cpu_to_be32(0x1), CLASS_DM_RESUME, 4);
  1754. +
  1755. + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
  1756. + if (id == TMU2_ID)
  1757. + continue;
  1758. + pe_dmem_write(id, cpu_to_be32(0x1), TMU_DM_RESUME, 4);
  1759. + }
  1760. +
  1761. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1762. + pe_dmem_write(UTIL_ID, cpu_to_be32(0x1), UTIL_DM_RESUME, 4);
  1763. +#endif
  1764. + mutex_unlock(&ctrl->mutex);
  1765. +}
  1766. +
  1767. +void pfe_ctrl_resume(struct pfe_ctrl *ctrl)
  1768. +{
  1769. + int pe_mask = CLASS_MASK | TMU_MASK;
  1770. +
  1771. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1772. + pe_mask |= UTIL_MASK;
  1773. +#endif
  1774. + mutex_lock(&ctrl->mutex);
  1775. + pe_start(&pfe->ctrl, pe_mask);
  1776. + mutex_unlock(&ctrl->mutex);
  1777. +}
  1778. +
  1779. +/* PE sync stop.
  1780. + * Stops packet processing for a list of PE's (specified using a bitmask).
  1781. + * The caller must hold ctrl->mutex.
  1782. + *
  1783. + * @param ctrl Control context
  1784. + * @param pe_mask Mask of PE id's to stop
  1785. + *
  1786. + */
  1787. +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask)
  1788. +{
  1789. + struct pe_sync_mailbox *mbox;
  1790. + int pe_stopped = 0;
  1791. + unsigned long end = jiffies + 2;
  1792. + int i;
  1793. +
  1794. + pe_mask &= 0x2FF; /*Exclude Util + TMU2 */
  1795. +
  1796. + for (i = 0; i < MAX_PE; i++)
  1797. + if (pe_mask & (1 << i)) {
  1798. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1799. +
  1800. + pe_dmem_write(i, cpu_to_be32(0x1), (unsigned
  1801. + long)&mbox->stop, 4);
  1802. + }
  1803. +
  1804. + while (pe_stopped != pe_mask) {
  1805. + for (i = 0; i < MAX_PE; i++)
  1806. + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
  1807. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1808. +
  1809. + if (pe_dmem_read(i, (unsigned
  1810. + long)&mbox->stopped, 4) &
  1811. + cpu_to_be32(0x1))
  1812. + pe_stopped |= (1 << i);
  1813. + }
  1814. +
  1815. + if (relax(end) < 0)
  1816. + goto err;
  1817. + }
  1818. +
  1819. + return 0;
  1820. +
  1821. +err:
  1822. + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
  1823. +
  1824. + for (i = 0; i < MAX_PE; i++)
  1825. + if (pe_mask & (1 << i)) {
  1826. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1827. +
  1828. + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
  1829. + long)&mbox->stop, 4);
  1830. + }
  1831. +
  1832. + return -EIO;
  1833. +}
  1834. +
  1835. +/* PE start.
  1836. + * Starts packet processing for a list of PE's (specified using a bitmask).
  1837. + * The caller must hold ctrl->mutex.
  1838. + *
  1839. + * @param ctrl Control context
  1840. + * @param pe_mask Mask of PE id's to start
  1841. + *
  1842. + */
  1843. +void pe_start(struct pfe_ctrl *ctrl, int pe_mask)
  1844. +{
  1845. + struct pe_sync_mailbox *mbox;
  1846. + int i;
  1847. +
  1848. + for (i = 0; i < MAX_PE; i++)
  1849. + if (pe_mask & (1 << i)) {
  1850. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1851. +
  1852. + pe_dmem_write(i, cpu_to_be32(0x0), (unsigned
  1853. + long)&mbox->stop, 4);
  1854. + }
  1855. +}
  1856. +
  1857. +/* This function will ensure all PEs are put in to idle state */
  1858. +int pe_reset_all(struct pfe_ctrl *ctrl)
  1859. +{
  1860. + struct pe_sync_mailbox *mbox;
  1861. + int pe_stopped = 0;
  1862. + unsigned long end = jiffies + 2;
  1863. + int i;
  1864. + int pe_mask = CLASS_MASK | TMU_MASK;
  1865. +
  1866. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1867. + pe_mask |= UTIL_MASK;
  1868. +#endif
  1869. +
  1870. + for (i = 0; i < MAX_PE; i++)
  1871. + if (pe_mask & (1 << i)) {
  1872. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1873. +
  1874. + pe_dmem_write(i, cpu_to_be32(0x2), (unsigned
  1875. + long)&mbox->stop, 4);
  1876. + }
  1877. +
  1878. + while (pe_stopped != pe_mask) {
  1879. + for (i = 0; i < MAX_PE; i++)
  1880. + if ((pe_mask & (1 << i)) && !(pe_stopped & (1 << i))) {
  1881. + mbox = (void *)ctrl->sync_mailbox_baseaddr[i];
  1882. +
  1883. + if (pe_dmem_read(i, (unsigned long)
  1884. + &mbox->stopped, 4) &
  1885. + cpu_to_be32(0x1))
  1886. + pe_stopped |= (1 << i);
  1887. + }
  1888. +
  1889. + if (relax(end) < 0)
  1890. + goto err;
  1891. + }
  1892. +
  1893. + return 0;
  1894. +
  1895. +err:
  1896. + pr_err("%s: timeout, %x %x\n", __func__, pe_mask, pe_stopped);
  1897. + return -EIO;
  1898. +}
  1899. +
  1900. +int pfe_ctrl_init(struct pfe *pfe)
  1901. +{
  1902. + struct pfe_ctrl *ctrl = &pfe->ctrl;
  1903. + int id;
  1904. +
  1905. + pr_info("%s\n", __func__);
  1906. +
  1907. + mutex_init(&ctrl->mutex);
  1908. + spin_lock_init(&ctrl->lock);
  1909. +
  1910. + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
  1911. + ctrl->sync_mailbox_baseaddr[id] = CLASS_DM_SYNC_MBOX;
  1912. + ctrl->msg_mailbox_baseaddr[id] = CLASS_DM_MSG_MBOX;
  1913. + }
  1914. +
  1915. + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
  1916. + if (id == TMU2_ID)
  1917. + continue;
  1918. + ctrl->sync_mailbox_baseaddr[id] = TMU_DM_SYNC_MBOX;
  1919. + ctrl->msg_mailbox_baseaddr[id] = TMU_DM_MSG_MBOX;
  1920. + }
  1921. +
  1922. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  1923. + ctrl->sync_mailbox_baseaddr[UTIL_ID] = UTIL_DM_SYNC_MBOX;
  1924. + ctrl->msg_mailbox_baseaddr[UTIL_ID] = UTIL_DM_MSG_MBOX;
  1925. +#endif
  1926. +
  1927. + ctrl->hash_array_baseaddr = pfe->ddr_baseaddr + ROUTE_TABLE_BASEADDR;
  1928. + ctrl->hash_array_phys_baseaddr = pfe->ddr_phys_baseaddr +
  1929. + ROUTE_TABLE_BASEADDR;
  1930. +
  1931. + ctrl->dev = pfe->dev;
  1932. +
  1933. + pr_info("%s finished\n", __func__);
  1934. +
  1935. + return 0;
  1936. +}
  1937. +
  1938. +void pfe_ctrl_exit(struct pfe *pfe)
  1939. +{
  1940. + pr_info("%s\n", __func__);
  1941. +}
  1942. diff --git a/drivers/staging/fsl_ppfe/pfe_ctrl.h b/drivers/staging/fsl_ppfe/pfe_ctrl.h
  1943. new file mode 100644
  1944. index 00000000..22115c76
  1945. --- /dev/null
  1946. +++ b/drivers/staging/fsl_ppfe/pfe_ctrl.h
  1947. @@ -0,0 +1,112 @@
  1948. +/*
  1949. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  1950. + * Copyright 2017 NXP
  1951. + *
  1952. + * This program is free software; you can redistribute it and/or modify
  1953. + * it under the terms of the GNU General Public License as published by
  1954. + * the Free Software Foundation; either version 2 of the License, or
  1955. + * (at your option) any later version.
  1956. + *
  1957. + * This program is distributed in the hope that it will be useful,
  1958. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1959. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1960. + * GNU General Public License for more details.
  1961. + *
  1962. + * You should have received a copy of the GNU General Public License
  1963. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1964. + */
  1965. +
  1966. +#ifndef _PFE_CTRL_H_
  1967. +#define _PFE_CTRL_H_
  1968. +
  1969. +#include <linux/dmapool.h>
  1970. +
  1971. +#include "pfe_mod.h"
  1972. +#include "pfe/pfe.h"
  1973. +
  1974. +#define DMA_BUF_SIZE_128 0x80 /* enough for 1 conntracks */
  1975. +#define DMA_BUF_SIZE_256 0x100
  1976. +/* enough for 2 conntracks, 1 bridge entry or 1 multicast entry */
  1977. +#define DMA_BUF_SIZE_512 0x200
  1978. +/* 512bytes dma allocated buffers used by rtp relay feature */
  1979. +#define DMA_BUF_MIN_ALIGNMENT 8
  1980. +#define DMA_BUF_BOUNDARY (4 * 1024)
  1981. +/* bursts can not cross 4k boundary */
  1982. +
  1983. +#define CMD_TX_ENABLE 0x0501
  1984. +#define CMD_TX_DISABLE 0x0502
  1985. +
  1986. +#define CMD_RX_LRO 0x0011
  1987. +#define CMD_PKTCAP_ENABLE 0x0d01
  1988. +#define CMD_QM_EXPT_RATE 0x020c
  1989. +
  1990. +#define CLASS_DM_SH_STATIC (0x800)
  1991. +#define CLASS_DM_CPU_TICKS (CLASS_DM_SH_STATIC)
  1992. +#define CLASS_DM_SYNC_MBOX (0x808)
  1993. +#define CLASS_DM_MSG_MBOX (0x810)
  1994. +#define CLASS_DM_DROP_CNTR (0x820)
  1995. +#define CLASS_DM_RESUME (0x854)
  1996. +#define CLASS_DM_PESTATUS (0x860)
  1997. +
  1998. +#define TMU_DM_SH_STATIC (0x80)
  1999. +#define TMU_DM_CPU_TICKS (TMU_DM_SH_STATIC)
  2000. +#define TMU_DM_SYNC_MBOX (0x88)
  2001. +#define TMU_DM_MSG_MBOX (0x90)
  2002. +#define TMU_DM_RESUME (0xA0)
  2003. +#define TMU_DM_PESTATUS (0xB0)
  2004. +#define TMU_DM_CONTEXT (0x300)
  2005. +#define TMU_DM_TX_TRANS (0x480)
  2006. +
  2007. +#define UTIL_DM_SH_STATIC (0x0)
  2008. +#define UTIL_DM_CPU_TICKS (UTIL_DM_SH_STATIC)
  2009. +#define UTIL_DM_SYNC_MBOX (0x8)
  2010. +#define UTIL_DM_MSG_MBOX (0x10)
  2011. +#define UTIL_DM_DROP_CNTR (0x20)
  2012. +#define UTIL_DM_RESUME (0x40)
  2013. +#define UTIL_DM_PESTATUS (0x50)
  2014. +
  2015. +struct pfe_ctrl {
  2016. + struct mutex mutex; /* to serialize pfe control access */
  2017. + spinlock_t lock;
  2018. +
  2019. + void *dma_pool;
  2020. + void *dma_pool_512;
  2021. + void *dma_pool_128;
  2022. +
  2023. + struct device *dev;
  2024. +
  2025. + void *hash_array_baseaddr; /*
  2026. + * Virtual base address of
  2027. + * the conntrack hash array
  2028. + */
  2029. + unsigned long hash_array_phys_baseaddr; /*
  2030. + * Physical base address of
  2031. + * the conntrack hash array
  2032. + */
  2033. +
  2034. + int (*event_cb)(u16, u16, u16*);
  2035. +
  2036. + unsigned long sync_mailbox_baseaddr[MAX_PE]; /*
  2037. + * Sync mailbox PFE
  2038. + * internal address,
  2039. + * initialized
  2040. + * when parsing elf images
  2041. + */
  2042. + unsigned long msg_mailbox_baseaddr[MAX_PE]; /*
  2043. + * Msg mailbox PFE internal
  2044. + * address, initialized
  2045. + * when parsing elf images
  2046. + */
  2047. + unsigned int sys_clk; /* AXI clock value, in KHz */
  2048. +};
  2049. +
  2050. +int pfe_ctrl_init(struct pfe *pfe);
  2051. +void pfe_ctrl_exit(struct pfe *pfe);
  2052. +int pe_sync_stop(struct pfe_ctrl *ctrl, int pe_mask);
  2053. +void pe_start(struct pfe_ctrl *ctrl, int pe_mask);
  2054. +int pe_reset_all(struct pfe_ctrl *ctrl);
  2055. +void pfe_ctrl_suspend(struct pfe_ctrl *ctrl);
  2056. +void pfe_ctrl_resume(struct pfe_ctrl *ctrl);
  2057. +int relax(unsigned long end);
  2058. +
  2059. +#endif /* _PFE_CTRL_H_ */
  2060. diff --git a/drivers/staging/fsl_ppfe/pfe_debugfs.c b/drivers/staging/fsl_ppfe/pfe_debugfs.c
  2061. new file mode 100644
  2062. index 00000000..4156610d
  2063. --- /dev/null
  2064. +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.c
  2065. @@ -0,0 +1,111 @@
  2066. +/*
  2067. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  2068. + * Copyright 2017 NXP
  2069. + *
  2070. + * This program is free software; you can redistribute it and/or modify
  2071. + * it under the terms of the GNU General Public License as published by
  2072. + * the Free Software Foundation; either version 2 of the License, or
  2073. + * (at your option) any later version.
  2074. + *
  2075. + * This program is distributed in the hope that it will be useful,
  2076. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2077. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2078. + * GNU General Public License for more details.
  2079. + *
  2080. + * You should have received a copy of the GNU General Public License
  2081. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2082. + */
  2083. +
  2084. +#include <linux/module.h>
  2085. +#include <linux/debugfs.h>
  2086. +#include <linux/platform_device.h>
  2087. +
  2088. +#include "pfe_mod.h"
  2089. +
  2090. +static int dmem_show(struct seq_file *s, void *unused)
  2091. +{
  2092. + u32 dmem_addr, val;
  2093. + int id = (long int)s->private;
  2094. + int i;
  2095. +
  2096. + for (dmem_addr = 0; dmem_addr < CLASS_DMEM_SIZE; dmem_addr += 8 * 4) {
  2097. + seq_printf(s, "%04x:", dmem_addr);
  2098. +
  2099. + for (i = 0; i < 8; i++) {
  2100. + val = pe_dmem_read(id, dmem_addr + i * 4, 4);
  2101. + seq_printf(s, " %02x %02x %02x %02x", val & 0xff,
  2102. + (val >> 8) & 0xff, (val >> 16) & 0xff,
  2103. + (val >> 24) & 0xff);
  2104. + }
  2105. +
  2106. + seq_puts(s, "\n");
  2107. + }
  2108. +
  2109. + return 0;
  2110. +}
  2111. +
  2112. +static int dmem_open(struct inode *inode, struct file *file)
  2113. +{
  2114. + return single_open(file, dmem_show, inode->i_private);
  2115. +}
  2116. +
  2117. +static const struct file_operations dmem_fops = {
  2118. + .open = dmem_open,
  2119. + .read = seq_read,
  2120. + .llseek = seq_lseek,
  2121. + .release = single_release,
  2122. +};
  2123. +
  2124. +int pfe_debugfs_init(struct pfe *pfe)
  2125. +{
  2126. + struct dentry *d;
  2127. +
  2128. + pr_info("%s\n", __func__);
  2129. +
  2130. + pfe->dentry = debugfs_create_dir("pfe", NULL);
  2131. + if (IS_ERR_OR_NULL(pfe->dentry))
  2132. + goto err_dir;
  2133. +
  2134. + d = debugfs_create_file("pe0_dmem", 0444, pfe->dentry, (void *)0,
  2135. + &dmem_fops);
  2136. + if (IS_ERR_OR_NULL(d))
  2137. + goto err_pe;
  2138. +
  2139. + d = debugfs_create_file("pe1_dmem", 0444, pfe->dentry, (void *)1,
  2140. + &dmem_fops);
  2141. + if (IS_ERR_OR_NULL(d))
  2142. + goto err_pe;
  2143. +
  2144. + d = debugfs_create_file("pe2_dmem", 0444, pfe->dentry, (void *)2,
  2145. + &dmem_fops);
  2146. + if (IS_ERR_OR_NULL(d))
  2147. + goto err_pe;
  2148. +
  2149. + d = debugfs_create_file("pe3_dmem", 0444, pfe->dentry, (void *)3,
  2150. + &dmem_fops);
  2151. + if (IS_ERR_OR_NULL(d))
  2152. + goto err_pe;
  2153. +
  2154. + d = debugfs_create_file("pe4_dmem", 0444, pfe->dentry, (void *)4,
  2155. + &dmem_fops);
  2156. + if (IS_ERR_OR_NULL(d))
  2157. + goto err_pe;
  2158. +
  2159. + d = debugfs_create_file("pe5_dmem", 0444, pfe->dentry, (void *)5,
  2160. + &dmem_fops);
  2161. + if (IS_ERR_OR_NULL(d))
  2162. + goto err_pe;
  2163. +
  2164. + return 0;
  2165. +
  2166. +err_pe:
  2167. + debugfs_remove_recursive(pfe->dentry);
  2168. +
  2169. +err_dir:
  2170. + return -1;
  2171. +}
  2172. +
  2173. +void pfe_debugfs_exit(struct pfe *pfe)
  2174. +{
  2175. + debugfs_remove_recursive(pfe->dentry);
  2176. +}
  2177. diff --git a/drivers/staging/fsl_ppfe/pfe_debugfs.h b/drivers/staging/fsl_ppfe/pfe_debugfs.h
  2178. new file mode 100644
  2179. index 00000000..301d9fc2
  2180. --- /dev/null
  2181. +++ b/drivers/staging/fsl_ppfe/pfe_debugfs.h
  2182. @@ -0,0 +1,25 @@
  2183. +/*
  2184. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  2185. + * Copyright 2017 NXP
  2186. + *
  2187. + * This program is free software; you can redistribute it and/or modify
  2188. + * it under the terms of the GNU General Public License as published by
  2189. + * the Free Software Foundation; either version 2 of the License, or
  2190. + * (at your option) any later version.
  2191. + *
  2192. + * This program is distributed in the hope that it will be useful,
  2193. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2194. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2195. + * GNU General Public License for more details.
  2196. + *
  2197. + * You should have received a copy of the GNU General Public License
  2198. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2199. + */
  2200. +
  2201. +#ifndef _PFE_DEBUGFS_H_
  2202. +#define _PFE_DEBUGFS_H_
  2203. +
  2204. +int pfe_debugfs_init(struct pfe *pfe);
  2205. +void pfe_debugfs_exit(struct pfe *pfe);
  2206. +
  2207. +#endif /* _PFE_DEBUGFS_H_ */
  2208. diff --git a/drivers/staging/fsl_ppfe/pfe_eth.c b/drivers/staging/fsl_ppfe/pfe_eth.c
  2209. new file mode 100644
  2210. index 00000000..02cd7c52
  2211. --- /dev/null
  2212. +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
  2213. @@ -0,0 +1,2434 @@
  2214. +/*
  2215. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  2216. + * Copyright 2017 NXP
  2217. + *
  2218. + * This program is free software; you can redistribute it and/or modify
  2219. + * it under the terms of the GNU General Public License as published by
  2220. + * the Free Software Foundation; either version 2 of the License, or
  2221. + * (at your option) any later version.
  2222. + *
  2223. + * This program is distributed in the hope that it will be useful,
  2224. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2225. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2226. + * GNU General Public License for more details.
  2227. + *
  2228. + * You should have received a copy of the GNU General Public License
  2229. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2230. + */
  2231. +
  2232. +/* @pfe_eth.c.
  2233. + * Ethernet driver for to handle exception path for PFE.
  2234. + * - uses HIF functions to send/receive packets.
  2235. + * - uses ctrl function to start/stop interfaces.
  2236. + * - uses direct register accesses to control phy operation.
  2237. + */
  2238. +#include <linux/version.h>
  2239. +#include <linux/kernel.h>
  2240. +#include <linux/interrupt.h>
  2241. +#include <linux/dma-mapping.h>
  2242. +#include <linux/dmapool.h>
  2243. +#include <linux/netdevice.h>
  2244. +#include <linux/etherdevice.h>
  2245. +#include <linux/ethtool.h>
  2246. +#include <linux/mii.h>
  2247. +#include <linux/phy.h>
  2248. +#include <linux/timer.h>
  2249. +#include <linux/hrtimer.h>
  2250. +#include <linux/platform_device.h>
  2251. +
  2252. +#include <net/ip.h>
  2253. +#include <net/sock.h>
  2254. +
  2255. +#include <linux/io.h>
  2256. +#include <asm/irq.h>
  2257. +#include <linux/delay.h>
  2258. +#include <linux/regmap.h>
  2259. +#include <linux/i2c.h>
  2260. +
  2261. +#if defined(CONFIG_NF_CONNTRACK_MARK)
  2262. +#include <net/netfilter/nf_conntrack.h>
  2263. +#endif
  2264. +
  2265. +#include "pfe_mod.h"
  2266. +#include "pfe_eth.h"
  2267. +
  2268. +static void *cbus_emac_base[3];
  2269. +static void *cbus_gpi_base[3];
  2270. +
  2271. +/* Forward Declaration */
  2272. +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv);
  2273. +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv);
  2274. +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
  2275. + from_tx, int n_desc);
  2276. +
  2277. +unsigned int gemac_regs[] = {
  2278. + 0x0004, /* Interrupt event */
  2279. + 0x0008, /* Interrupt mask */
  2280. + 0x0024, /* Ethernet control */
  2281. + 0x0064, /* MIB Control/Status */
  2282. + 0x0084, /* Receive control/status */
  2283. + 0x00C4, /* Transmit control */
  2284. + 0x00E4, /* Physical address low */
  2285. + 0x00E8, /* Physical address high */
  2286. + 0x0144, /* Transmit FIFO Watermark and Store and Forward Control*/
  2287. + 0x0190, /* Receive FIFO Section Full Threshold */
  2288. + 0x01A0, /* Transmit FIFO Section Empty Threshold */
  2289. + 0x01B0, /* Frame Truncation Length */
  2290. +};
  2291. +
  2292. +/********************************************************************/
  2293. +/* SYSFS INTERFACE */
  2294. +/********************************************************************/
  2295. +
  2296. +#ifdef PFE_ETH_NAPI_STATS
  2297. +/*
  2298. + * pfe_eth_show_napi_stats
  2299. + */
  2300. +static ssize_t pfe_eth_show_napi_stats(struct device *dev,
  2301. + struct device_attribute *attr,
  2302. + char *buf)
  2303. +{
  2304. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2305. + ssize_t len = 0;
  2306. +
  2307. + len += sprintf(buf + len, "sched: %u\n",
  2308. + priv->napi_counters[NAPI_SCHED_COUNT]);
  2309. + len += sprintf(buf + len, "poll: %u\n",
  2310. + priv->napi_counters[NAPI_POLL_COUNT]);
  2311. + len += sprintf(buf + len, "packet: %u\n",
  2312. + priv->napi_counters[NAPI_PACKET_COUNT]);
  2313. + len += sprintf(buf + len, "budget: %u\n",
  2314. + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]);
  2315. + len += sprintf(buf + len, "desc: %u\n",
  2316. + priv->napi_counters[NAPI_DESC_COUNT]);
  2317. +
  2318. + return len;
  2319. +}
  2320. +
  2321. +/*
  2322. + * pfe_eth_set_napi_stats
  2323. + */
  2324. +static ssize_t pfe_eth_set_napi_stats(struct device *dev,
  2325. + struct device_attribute *attr,
  2326. + const char *buf, size_t count)
  2327. +{
  2328. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2329. +
  2330. + memset(priv->napi_counters, 0, sizeof(priv->napi_counters));
  2331. +
  2332. + return count;
  2333. +}
  2334. +#endif
  2335. +#ifdef PFE_ETH_TX_STATS
  2336. +/* pfe_eth_show_tx_stats
  2337. + *
  2338. + */
  2339. +static ssize_t pfe_eth_show_tx_stats(struct device *dev,
  2340. + struct device_attribute *attr,
  2341. + char *buf)
  2342. +{
  2343. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2344. + ssize_t len = 0;
  2345. + int i;
  2346. +
  2347. + len += sprintf(buf + len, "TX queues stats:\n");
  2348. +
  2349. + for (i = 0; i < emac_txq_cnt; i++) {
  2350. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  2351. + i);
  2352. +
  2353. + len += sprintf(buf + len, "\n");
  2354. + __netif_tx_lock_bh(tx_queue);
  2355. +
  2356. + hif_tx_lock(&pfe->hif);
  2357. + len += sprintf(buf + len,
  2358. + "Queue %2d : credits = %10d\n"
  2359. + , i, hif_lib_tx_credit_avail(pfe, priv->id, i));
  2360. + len += sprintf(buf + len,
  2361. + " tx packets = %10d\n"
  2362. + , pfe->tmu_credit.tx_packets[priv->id][i]);
  2363. + hif_tx_unlock(&pfe->hif);
  2364. +
  2365. + /* Don't output additionnal stats if queue never used */
  2366. + if (!pfe->tmu_credit.tx_packets[priv->id][i])
  2367. + goto skip;
  2368. +
  2369. + len += sprintf(buf + len,
  2370. + " clean_fail = %10d\n"
  2371. + , priv->clean_fail[i]);
  2372. + len += sprintf(buf + len,
  2373. + " stop_queue = %10d\n"
  2374. + , priv->stop_queue_total[i]);
  2375. + len += sprintf(buf + len,
  2376. + " stop_queue_hif = %10d\n"
  2377. + , priv->stop_queue_hif[i]);
  2378. + len += sprintf(buf + len,
  2379. + " stop_queue_hif_client = %10d\n"
  2380. + , priv->stop_queue_hif_client[i]);
  2381. + len += sprintf(buf + len,
  2382. + " stop_queue_credit = %10d\n"
  2383. + , priv->stop_queue_credit[i]);
  2384. +skip:
  2385. + __netif_tx_unlock_bh(tx_queue);
  2386. + }
  2387. + return len;
  2388. +}
  2389. +
  2390. +/* pfe_eth_set_tx_stats
  2391. + *
  2392. + */
  2393. +static ssize_t pfe_eth_set_tx_stats(struct device *dev,
  2394. + struct device_attribute *attr,
  2395. + const char *buf, size_t count)
  2396. +{
  2397. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2398. + int i;
  2399. +
  2400. + for (i = 0; i < emac_txq_cnt; i++) {
  2401. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  2402. + i);
  2403. +
  2404. + __netif_tx_lock_bh(tx_queue);
  2405. + priv->clean_fail[i] = 0;
  2406. + priv->stop_queue_total[i] = 0;
  2407. + priv->stop_queue_hif[i] = 0;
  2408. + priv->stop_queue_hif_client[i] = 0;
  2409. + priv->stop_queue_credit[i] = 0;
  2410. + __netif_tx_unlock_bh(tx_queue);
  2411. + }
  2412. +
  2413. + return count;
  2414. +}
  2415. +#endif
  2416. +/* pfe_eth_show_txavail
  2417. + *
  2418. + */
  2419. +static ssize_t pfe_eth_show_txavail(struct device *dev,
  2420. + struct device_attribute *attr,
  2421. + char *buf)
  2422. +{
  2423. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2424. + ssize_t len = 0;
  2425. + int i;
  2426. +
  2427. + for (i = 0; i < emac_txq_cnt; i++) {
  2428. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  2429. + i);
  2430. +
  2431. + __netif_tx_lock_bh(tx_queue);
  2432. +
  2433. + len += sprintf(buf + len, "%d",
  2434. + hif_lib_tx_avail(&priv->client, i));
  2435. +
  2436. + __netif_tx_unlock_bh(tx_queue);
  2437. +
  2438. + if (i == (emac_txq_cnt - 1))
  2439. + len += sprintf(buf + len, "\n");
  2440. + else
  2441. + len += sprintf(buf + len, " ");
  2442. + }
  2443. +
  2444. + return len;
  2445. +}
  2446. +
  2447. +/* pfe_eth_show_default_priority
  2448. + *
  2449. + */
  2450. +static ssize_t pfe_eth_show_default_priority(struct device *dev,
  2451. + struct device_attribute *attr,
  2452. + char *buf)
  2453. +{
  2454. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2455. + unsigned long flags;
  2456. + int rc;
  2457. +
  2458. + spin_lock_irqsave(&priv->lock, flags);
  2459. + rc = sprintf(buf, "%d\n", priv->default_priority);
  2460. + spin_unlock_irqrestore(&priv->lock, flags);
  2461. +
  2462. + return rc;
  2463. +}
  2464. +
  2465. +/* pfe_eth_set_default_priority
  2466. + *
  2467. + */
  2468. +
  2469. +static ssize_t pfe_eth_set_default_priority(struct device *dev,
  2470. + struct device_attribute *attr,
  2471. + const char *buf, size_t count)
  2472. +{
  2473. + struct pfe_eth_priv_s *priv = netdev_priv(to_net_dev(dev));
  2474. + unsigned long flags;
  2475. +
  2476. + spin_lock_irqsave(&priv->lock, flags);
  2477. + priv->default_priority = kstrtoul(buf, 0, 0);
  2478. + spin_unlock_irqrestore(&priv->lock, flags);
  2479. +
  2480. + return count;
  2481. +}
  2482. +
  2483. +static DEVICE_ATTR(txavail, 0444, pfe_eth_show_txavail, NULL);
  2484. +static DEVICE_ATTR(default_priority, 0644, pfe_eth_show_default_priority,
  2485. + pfe_eth_set_default_priority);
  2486. +
  2487. +#ifdef PFE_ETH_NAPI_STATS
  2488. +static DEVICE_ATTR(napi_stats, 0644, pfe_eth_show_napi_stats,
  2489. + pfe_eth_set_napi_stats);
  2490. +#endif
  2491. +
  2492. +#ifdef PFE_ETH_TX_STATS
  2493. +static DEVICE_ATTR(tx_stats, 0644, pfe_eth_show_tx_stats,
  2494. + pfe_eth_set_tx_stats);
  2495. +#endif
  2496. +
  2497. +/*
  2498. + * pfe_eth_sysfs_init
  2499. + *
  2500. + */
  2501. +static int pfe_eth_sysfs_init(struct net_device *ndev)
  2502. +{
  2503. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2504. + int err;
  2505. +
  2506. + /* Initialize the default values */
  2507. +
  2508. + /*
  2509. + * By default, packets without conntrack will use this default high
  2510. + * priority queue
  2511. + */
  2512. + priv->default_priority = 15;
  2513. +
  2514. + /* Create our sysfs files */
  2515. + err = device_create_file(&ndev->dev, &dev_attr_default_priority);
  2516. + if (err) {
  2517. + netdev_err(ndev,
  2518. + "failed to create default_priority sysfs files\n");
  2519. + goto err_priority;
  2520. + }
  2521. +
  2522. + err = device_create_file(&ndev->dev, &dev_attr_txavail);
  2523. + if (err) {
  2524. + netdev_err(ndev,
  2525. + "failed to create default_priority sysfs files\n");
  2526. + goto err_txavail;
  2527. + }
  2528. +
  2529. +#ifdef PFE_ETH_NAPI_STATS
  2530. + err = device_create_file(&ndev->dev, &dev_attr_napi_stats);
  2531. + if (err) {
  2532. + netdev_err(ndev, "failed to create napi stats sysfs files\n");
  2533. + goto err_napi;
  2534. + }
  2535. +#endif
  2536. +
  2537. +#ifdef PFE_ETH_TX_STATS
  2538. + err = device_create_file(&ndev->dev, &dev_attr_tx_stats);
  2539. + if (err) {
  2540. + netdev_err(ndev, "failed to create tx stats sysfs files\n");
  2541. + goto err_tx;
  2542. + }
  2543. +#endif
  2544. +
  2545. + return 0;
  2546. +
  2547. +#ifdef PFE_ETH_TX_STATS
  2548. +err_tx:
  2549. +#endif
  2550. +#ifdef PFE_ETH_NAPI_STATS
  2551. + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
  2552. +
  2553. +err_napi:
  2554. +#endif
  2555. + device_remove_file(&ndev->dev, &dev_attr_txavail);
  2556. +
  2557. +err_txavail:
  2558. + device_remove_file(&ndev->dev, &dev_attr_default_priority);
  2559. +
  2560. +err_priority:
  2561. + return -1;
  2562. +}
  2563. +
  2564. +/* pfe_eth_sysfs_exit
  2565. + *
  2566. + */
  2567. +void pfe_eth_sysfs_exit(struct net_device *ndev)
  2568. +{
  2569. +#ifdef PFE_ETH_TX_STATS
  2570. + device_remove_file(&ndev->dev, &dev_attr_tx_stats);
  2571. +#endif
  2572. +
  2573. +#ifdef PFE_ETH_NAPI_STATS
  2574. + device_remove_file(&ndev->dev, &dev_attr_napi_stats);
  2575. +#endif
  2576. + device_remove_file(&ndev->dev, &dev_attr_txavail);
  2577. + device_remove_file(&ndev->dev, &dev_attr_default_priority);
  2578. +}
  2579. +
  2580. +/*************************************************************************/
  2581. +/* ETHTOOL INTERCAE */
  2582. +/*************************************************************************/
  2583. +
  2584. +/*MTIP GEMAC */
  2585. +static const struct fec_stat {
  2586. + char name[ETH_GSTRING_LEN];
  2587. + u16 offset;
  2588. +} fec_stats[] = {
  2589. + /* RMON TX */
  2590. + { "tx_dropped", RMON_T_DROP },
  2591. + { "tx_packets", RMON_T_PACKETS },
  2592. + { "tx_broadcast", RMON_T_BC_PKT },
  2593. + { "tx_multicast", RMON_T_MC_PKT },
  2594. + { "tx_crc_errors", RMON_T_CRC_ALIGN },
  2595. + { "tx_undersize", RMON_T_UNDERSIZE },
  2596. + { "tx_oversize", RMON_T_OVERSIZE },
  2597. + { "tx_fragment", RMON_T_FRAG },
  2598. + { "tx_jabber", RMON_T_JAB },
  2599. + { "tx_collision", RMON_T_COL },
  2600. + { "tx_64byte", RMON_T_P64 },
  2601. + { "tx_65to127byte", RMON_T_P65TO127 },
  2602. + { "tx_128to255byte", RMON_T_P128TO255 },
  2603. + { "tx_256to511byte", RMON_T_P256TO511 },
  2604. + { "tx_512to1023byte", RMON_T_P512TO1023 },
  2605. + { "tx_1024to2047byte", RMON_T_P1024TO2047 },
  2606. + { "tx_GTE2048byte", RMON_T_P_GTE2048 },
  2607. + { "tx_octets", RMON_T_OCTETS },
  2608. +
  2609. + /* IEEE TX */
  2610. + { "IEEE_tx_drop", IEEE_T_DROP },
  2611. + { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK },
  2612. + { "IEEE_tx_1col", IEEE_T_1COL },
  2613. + { "IEEE_tx_mcol", IEEE_T_MCOL },
  2614. + { "IEEE_tx_def", IEEE_T_DEF },
  2615. + { "IEEE_tx_lcol", IEEE_T_LCOL },
  2616. + { "IEEE_tx_excol", IEEE_T_EXCOL },
  2617. + { "IEEE_tx_macerr", IEEE_T_MACERR },
  2618. + { "IEEE_tx_cserr", IEEE_T_CSERR },
  2619. + { "IEEE_tx_sqe", IEEE_T_SQE },
  2620. + { "IEEE_tx_fdxfc", IEEE_T_FDXFC },
  2621. + { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK },
  2622. +
  2623. + /* RMON RX */
  2624. + { "rx_packets", RMON_R_PACKETS },
  2625. + { "rx_broadcast", RMON_R_BC_PKT },
  2626. + { "rx_multicast", RMON_R_MC_PKT },
  2627. + { "rx_crc_errors", RMON_R_CRC_ALIGN },
  2628. + { "rx_undersize", RMON_R_UNDERSIZE },
  2629. + { "rx_oversize", RMON_R_OVERSIZE },
  2630. + { "rx_fragment", RMON_R_FRAG },
  2631. + { "rx_jabber", RMON_R_JAB },
  2632. + { "rx_64byte", RMON_R_P64 },
  2633. + { "rx_65to127byte", RMON_R_P65TO127 },
  2634. + { "rx_128to255byte", RMON_R_P128TO255 },
  2635. + { "rx_256to511byte", RMON_R_P256TO511 },
  2636. + { "rx_512to1023byte", RMON_R_P512TO1023 },
  2637. + { "rx_1024to2047byte", RMON_R_P1024TO2047 },
  2638. + { "rx_GTE2048byte", RMON_R_P_GTE2048 },
  2639. + { "rx_octets", RMON_R_OCTETS },
  2640. +
  2641. + /* IEEE RX */
  2642. + { "IEEE_rx_drop", IEEE_R_DROP },
  2643. + { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK },
  2644. + { "IEEE_rx_crc", IEEE_R_CRC },
  2645. + { "IEEE_rx_align", IEEE_R_ALIGN },
  2646. + { "IEEE_rx_macerr", IEEE_R_MACERR },
  2647. + { "IEEE_rx_fdxfc", IEEE_R_FDXFC },
  2648. + { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
  2649. +};
  2650. +
  2651. +static void pfe_eth_fill_stats(struct net_device *ndev, struct ethtool_stats
  2652. + *stats, u64 *data)
  2653. +{
  2654. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2655. + int i;
  2656. +
  2657. + for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
  2658. + data[i] = readl(priv->EMAC_baseaddr + fec_stats[i].offset);
  2659. +}
  2660. +
  2661. +static void pfe_eth_gstrings(struct net_device *netdev,
  2662. + u32 stringset, u8 *data)
  2663. +{
  2664. + int i;
  2665. +
  2666. + switch (stringset) {
  2667. + case ETH_SS_STATS:
  2668. + for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
  2669. + memcpy(data + i * ETH_GSTRING_LEN,
  2670. + fec_stats[i].name, ETH_GSTRING_LEN);
  2671. + break;
  2672. + }
  2673. +}
  2674. +
  2675. +static int pfe_eth_stats_count(struct net_device *ndev, int sset)
  2676. +{
  2677. + switch (sset) {
  2678. + case ETH_SS_STATS:
  2679. + return ARRAY_SIZE(fec_stats);
  2680. + default:
  2681. + return -EOPNOTSUPP;
  2682. + }
  2683. +}
  2684. +
  2685. +/*
  2686. + * pfe_eth_gemac_reglen - Return the length of the register structure.
  2687. + *
  2688. + */
  2689. +static int pfe_eth_gemac_reglen(struct net_device *ndev)
  2690. +{
  2691. + pr_info("%s()\n", __func__);
  2692. + return (sizeof(gemac_regs) / sizeof(u32));
  2693. +}
  2694. +
  2695. +/*
  2696. + * pfe_eth_gemac_get_regs - Return the gemac register structure.
  2697. + *
  2698. + */
  2699. +static void pfe_eth_gemac_get_regs(struct net_device *ndev, struct ethtool_regs
  2700. + *regs, void *regbuf)
  2701. +{
  2702. + int i;
  2703. +
  2704. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2705. + u32 *buf = (u32 *)regbuf;
  2706. +
  2707. + pr_info("%s()\n", __func__);
  2708. + for (i = 0; i < sizeof(gemac_regs) / sizeof(u32); i++)
  2709. + buf[i] = readl(priv->EMAC_baseaddr + gemac_regs[i]);
  2710. +}
  2711. +
  2712. +/*
  2713. + * pfe_eth_set_wol - Set the magic packet option, in WoL register.
  2714. + *
  2715. + */
  2716. +static int pfe_eth_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  2717. +{
  2718. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2719. +
  2720. + if (wol->wolopts & ~WAKE_MAGIC)
  2721. + return -EOPNOTSUPP;
  2722. +
  2723. + /* for MTIP we store wol->wolopts */
  2724. + priv->wol = wol->wolopts;
  2725. +
  2726. + device_set_wakeup_enable(&ndev->dev, wol->wolopts & WAKE_MAGIC);
  2727. +
  2728. + return 0;
  2729. +}
  2730. +
  2731. +/*
  2732. + *
  2733. + * pfe_eth_get_wol - Get the WoL options.
  2734. + *
  2735. + */
  2736. +static void pfe_eth_get_wol(struct net_device *ndev, struct ethtool_wolinfo
  2737. + *wol)
  2738. +{
  2739. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2740. +
  2741. + wol->supported = WAKE_MAGIC;
  2742. + wol->wolopts = 0;
  2743. +
  2744. + if (priv->wol & WAKE_MAGIC)
  2745. + wol->wolopts = WAKE_MAGIC;
  2746. +
  2747. + memset(&wol->sopass, 0, sizeof(wol->sopass));
  2748. +}
  2749. +
  2750. +/*
  2751. + * pfe_eth_get_drvinfo - Fills in the drvinfo structure with some basic info
  2752. + *
  2753. + */
  2754. +static void pfe_eth_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo
  2755. + *drvinfo)
  2756. +{
  2757. + strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  2758. + strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  2759. + strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  2760. + strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info));
  2761. +}
  2762. +
  2763. +/*
  2764. + * pfe_eth_set_settings - Used to send commands to PHY.
  2765. + *
  2766. + */
  2767. +static int pfe_eth_set_settings(struct net_device *ndev,
  2768. + const struct ethtool_link_ksettings *cmd)
  2769. +{
  2770. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2771. + struct phy_device *phydev = priv->phydev;
  2772. +
  2773. + if (!phydev)
  2774. + return -ENODEV;
  2775. +
  2776. + return phy_ethtool_ksettings_set(phydev, cmd);
  2777. +}
  2778. +
  2779. +/*
  2780. + * pfe_eth_getsettings - Return the current settings in the ethtool_cmd
  2781. + * structure.
  2782. + *
  2783. + */
  2784. +static int pfe_eth_get_settings(struct net_device *ndev,
  2785. + struct ethtool_link_ksettings *cmd)
  2786. +{
  2787. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2788. + struct phy_device *phydev = priv->phydev;
  2789. +
  2790. + if (!phydev)
  2791. + return -ENODEV;
  2792. +
  2793. + return phy_ethtool_ksettings_get(phydev, cmd);
  2794. +}
  2795. +
  2796. +/*
  2797. + * pfe_eth_get_msglevel - Gets the debug message mask.
  2798. + *
  2799. + */
  2800. +static uint32_t pfe_eth_get_msglevel(struct net_device *ndev)
  2801. +{
  2802. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2803. +
  2804. + return priv->msg_enable;
  2805. +}
  2806. +
  2807. +/*
  2808. + * pfe_eth_set_msglevel - Sets the debug message mask.
  2809. + *
  2810. + */
  2811. +static void pfe_eth_set_msglevel(struct net_device *ndev, uint32_t data)
  2812. +{
  2813. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2814. +
  2815. + priv->msg_enable = data;
  2816. +}
  2817. +
  2818. +#define HIF_RX_COAL_MAX_CLKS (~(1 << 31))
  2819. +#define HIF_RX_COAL_CLKS_PER_USEC (pfe->ctrl.sys_clk / 1000)
  2820. +#define HIF_RX_COAL_MAX_USECS (HIF_RX_COAL_MAX_CLKS / \
  2821. + HIF_RX_COAL_CLKS_PER_USEC)
  2822. +
  2823. +/*
  2824. + * pfe_eth_set_coalesce - Sets rx interrupt coalescing timer.
  2825. + *
  2826. + */
  2827. +static int pfe_eth_set_coalesce(struct net_device *ndev,
  2828. + struct ethtool_coalesce *ec)
  2829. +{
  2830. + if (ec->rx_coalesce_usecs > HIF_RX_COAL_MAX_USECS)
  2831. + return -EINVAL;
  2832. +
  2833. + if (!ec->rx_coalesce_usecs) {
  2834. + writel(0, HIF_INT_COAL);
  2835. + return 0;
  2836. + }
  2837. +
  2838. + writel((ec->rx_coalesce_usecs * HIF_RX_COAL_CLKS_PER_USEC) |
  2839. + HIF_INT_COAL_ENABLE, HIF_INT_COAL);
  2840. +
  2841. + return 0;
  2842. +}
  2843. +
  2844. +/*
  2845. + * pfe_eth_get_coalesce - Gets rx interrupt coalescing timer value.
  2846. + *
  2847. + */
  2848. +static int pfe_eth_get_coalesce(struct net_device *ndev,
  2849. + struct ethtool_coalesce *ec)
  2850. +{
  2851. + int reg_val = readl(HIF_INT_COAL);
  2852. +
  2853. + if (reg_val & HIF_INT_COAL_ENABLE)
  2854. + ec->rx_coalesce_usecs = (reg_val & HIF_RX_COAL_MAX_CLKS) /
  2855. + HIF_RX_COAL_CLKS_PER_USEC;
  2856. + else
  2857. + ec->rx_coalesce_usecs = 0;
  2858. +
  2859. + return 0;
  2860. +}
  2861. +
  2862. +/*
  2863. + * pfe_eth_set_pauseparam - Sets pause parameters
  2864. + *
  2865. + */
  2866. +static int pfe_eth_set_pauseparam(struct net_device *ndev,
  2867. + struct ethtool_pauseparam *epause)
  2868. +{
  2869. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2870. +
  2871. + if (epause->tx_pause != epause->rx_pause) {
  2872. + netdev_info(ndev,
  2873. + "hardware only support enable/disable both tx and rx\n");
  2874. + return -EINVAL;
  2875. + }
  2876. +
  2877. + priv->pause_flag = 0;
  2878. + priv->pause_flag |= epause->rx_pause ? PFE_PAUSE_FLAG_ENABLE : 0;
  2879. + priv->pause_flag |= epause->autoneg ? PFE_PAUSE_FLAG_AUTONEG : 0;
  2880. +
  2881. + if (epause->rx_pause || epause->autoneg) {
  2882. + gemac_enable_pause_rx(priv->EMAC_baseaddr);
  2883. + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) |
  2884. + EGPI_PAUSE_ENABLE),
  2885. + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
  2886. + if (priv->phydev) {
  2887. + priv->phydev->supported |= ADVERTISED_Pause |
  2888. + ADVERTISED_Asym_Pause;
  2889. + priv->phydev->advertising |= ADVERTISED_Pause |
  2890. + ADVERTISED_Asym_Pause;
  2891. + }
  2892. + } else {
  2893. + gemac_disable_pause_rx(priv->EMAC_baseaddr);
  2894. + writel((readl(priv->GPI_baseaddr + GPI_TX_PAUSE_TIME) &
  2895. + ~EGPI_PAUSE_ENABLE),
  2896. + priv->GPI_baseaddr + GPI_TX_PAUSE_TIME);
  2897. + if (priv->phydev) {
  2898. + priv->phydev->supported &= ~(ADVERTISED_Pause |
  2899. + ADVERTISED_Asym_Pause);
  2900. + priv->phydev->advertising &= ~(ADVERTISED_Pause |
  2901. + ADVERTISED_Asym_Pause);
  2902. + }
  2903. + }
  2904. +
  2905. + return 0;
  2906. +}
  2907. +
  2908. +/*
  2909. + * pfe_eth_get_pauseparam - Gets pause parameters
  2910. + *
  2911. + */
  2912. +static void pfe_eth_get_pauseparam(struct net_device *ndev,
  2913. + struct ethtool_pauseparam *epause)
  2914. +{
  2915. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  2916. +
  2917. + epause->autoneg = (priv->pause_flag & PFE_PAUSE_FLAG_AUTONEG) != 0;
  2918. + epause->tx_pause = (priv->pause_flag & PFE_PAUSE_FLAG_ENABLE) != 0;
  2919. + epause->rx_pause = epause->tx_pause;
  2920. +}
  2921. +
  2922. +/*
  2923. + * pfe_eth_get_hash
  2924. + */
  2925. +#define PFE_HASH_BITS 6 /* #bits in hash */
  2926. +#define CRC32_POLY 0xEDB88320
  2927. +
  2928. +static int pfe_eth_get_hash(u8 *addr)
  2929. +{
  2930. + unsigned int i, bit, data, crc, hash;
  2931. +
  2932. + /* calculate crc32 value of mac address */
  2933. + crc = 0xffffffff;
  2934. +
  2935. + for (i = 0; i < 6; i++) {
  2936. + data = addr[i];
  2937. + for (bit = 0; bit < 8; bit++, data >>= 1) {
  2938. + crc = (crc >> 1) ^
  2939. + (((crc ^ data) & 1) ? CRC32_POLY : 0);
  2940. + }
  2941. + }
  2942. +
  2943. + /*
  2944. + * only upper 6 bits (PFE_HASH_BITS) are used
  2945. + * which point to specific bit in the hash registers
  2946. + */
  2947. + hash = (crc >> (32 - PFE_HASH_BITS)) & 0x3f;
  2948. +
  2949. + return hash;
  2950. +}
  2951. +
  2952. +const struct ethtool_ops pfe_ethtool_ops = {
  2953. + .get_drvinfo = pfe_eth_get_drvinfo,
  2954. + .get_regs_len = pfe_eth_gemac_reglen,
  2955. + .get_regs = pfe_eth_gemac_get_regs,
  2956. + .get_link = ethtool_op_get_link,
  2957. + .get_wol = pfe_eth_get_wol,
  2958. + .set_wol = pfe_eth_set_wol,
  2959. + .set_pauseparam = pfe_eth_set_pauseparam,
  2960. + .get_pauseparam = pfe_eth_get_pauseparam,
  2961. + .get_strings = pfe_eth_gstrings,
  2962. + .get_sset_count = pfe_eth_stats_count,
  2963. + .get_ethtool_stats = pfe_eth_fill_stats,
  2964. + .get_msglevel = pfe_eth_get_msglevel,
  2965. + .set_msglevel = pfe_eth_set_msglevel,
  2966. + .set_coalesce = pfe_eth_set_coalesce,
  2967. + .get_coalesce = pfe_eth_get_coalesce,
  2968. + .get_link_ksettings = pfe_eth_get_settings,
  2969. + .set_link_ksettings = pfe_eth_set_settings,
  2970. +};
  2971. +
  2972. +/* pfe_eth_mdio_reset
  2973. + */
  2974. +int pfe_eth_mdio_reset(struct mii_bus *bus)
  2975. +{
  2976. + struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
  2977. + u32 phy_speed;
  2978. +
  2979. + netif_info(priv, hw, priv->ndev, "%s\n", __func__);
  2980. +
  2981. + mutex_lock(&bus->mdio_lock);
  2982. +
  2983. + /*
  2984. + * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
  2985. + *
  2986. + * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
  2987. + * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'.
  2988. + */
  2989. + phy_speed = (DIV_ROUND_UP((pfe->ctrl.sys_clk * 1000), 4000000)
  2990. + << EMAC_MII_SPEED_SHIFT);
  2991. + phy_speed |= EMAC_HOLDTIME(0x5);
  2992. + __raw_writel(phy_speed, priv->PHY_baseaddr + EMAC_MII_CTRL_REG);
  2993. +
  2994. + mutex_unlock(&bus->mdio_lock);
  2995. +
  2996. + return 0;
  2997. +}
  2998. +
  2999. +/* pfe_eth_gemac_phy_timeout
  3000. + *
  3001. + */
  3002. +static int pfe_eth_gemac_phy_timeout(struct pfe_eth_priv_s *priv, int timeout)
  3003. +{
  3004. + while (!(__raw_readl(priv->PHY_baseaddr + EMAC_IEVENT_REG) &
  3005. + EMAC_IEVENT_MII)) {
  3006. + if (timeout-- <= 0)
  3007. + return -1;
  3008. + usleep_range(10, 20);
  3009. + }
  3010. + __raw_writel(EMAC_IEVENT_MII, priv->PHY_baseaddr + EMAC_IEVENT_REG);
  3011. + return 0;
  3012. +}
  3013. +
  3014. +static int pfe_eth_mdio_mux(u8 muxval)
  3015. +{
  3016. + struct i2c_adapter *a;
  3017. + struct i2c_msg msg;
  3018. + unsigned char buf[2];
  3019. + int ret;
  3020. +
  3021. + a = i2c_get_adapter(0);
  3022. + if (!a)
  3023. + return -ENODEV;
  3024. +
  3025. + /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
  3026. + buf[0] = 0x54; /* reg number */
  3027. + buf[1] = (muxval << 6) | 0x3; /* data */
  3028. + msg.addr = 0x66;
  3029. + msg.buf = buf;
  3030. + msg.len = 2;
  3031. + msg.flags = 0;
  3032. + ret = i2c_transfer(a, &msg, 1);
  3033. + i2c_put_adapter(a);
  3034. + if (ret != 1)
  3035. + return -ENODEV;
  3036. + return 0;
  3037. +}
  3038. +
  3039. +static int pfe_eth_mdio_write_addr(struct mii_bus *bus, int mii_id,
  3040. + int dev_addr, int regnum)
  3041. +{
  3042. + struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
  3043. +
  3044. + __raw_writel(EMAC_MII_DATA_PA(mii_id) |
  3045. + EMAC_MII_DATA_RA(dev_addr) |
  3046. + EMAC_MII_DATA_TA | EMAC_MII_DATA(regnum),
  3047. + priv->PHY_baseaddr + EMAC_MII_DATA_REG);
  3048. +
  3049. + if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
  3050. + netdev_err(priv->ndev, "%s: phy MDIO address write timeout\n",
  3051. + __func__);
  3052. + return -1;
  3053. + }
  3054. +
  3055. + return 0;
  3056. +}
  3057. +
  3058. +static int pfe_eth_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
  3059. + u16 value)
  3060. +{
  3061. + struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
  3062. +
  3063. + /*To access external PHYs on QDS board mux needs to be configured*/
  3064. + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
  3065. + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
  3066. +
  3067. + if (regnum & MII_ADDR_C45) {
  3068. + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
  3069. + regnum & 0xffff);
  3070. + __raw_writel(EMAC_MII_DATA_OP_CL45_WR |
  3071. + EMAC_MII_DATA_PA(mii_id) |
  3072. + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
  3073. + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
  3074. + priv->PHY_baseaddr + EMAC_MII_DATA_REG);
  3075. + } else {
  3076. + /* start a write op */
  3077. + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_WR |
  3078. + EMAC_MII_DATA_PA(mii_id) |
  3079. + EMAC_MII_DATA_RA(regnum) |
  3080. + EMAC_MII_DATA_TA | EMAC_MII_DATA(value),
  3081. + priv->PHY_baseaddr + EMAC_MII_DATA_REG);
  3082. + }
  3083. +
  3084. + if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
  3085. + netdev_err(priv->ndev, "%s: phy MDIO write timeout\n",
  3086. + __func__);
  3087. + return -1;
  3088. + }
  3089. + netif_info(priv, hw, priv->ndev, "%s: phy %x reg %x val %x\n", __func__,
  3090. + mii_id, regnum, value);
  3091. +
  3092. + return 0;
  3093. +}
  3094. +
  3095. +static int pfe_eth_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
  3096. +{
  3097. + struct pfe_eth_priv_s *priv = (struct pfe_eth_priv_s *)bus->priv;
  3098. + u16 value = 0;
  3099. +
  3100. + /*To access external PHYs on QDS board mux needs to be configured*/
  3101. + if ((mii_id) && (pfe->mdio_muxval[mii_id]))
  3102. + pfe_eth_mdio_mux(pfe->mdio_muxval[mii_id]);
  3103. +
  3104. + if (regnum & MII_ADDR_C45) {
  3105. + pfe_eth_mdio_write_addr(bus, mii_id, (regnum >> 16) & 0x1f,
  3106. + regnum & 0xffff);
  3107. + __raw_writel(EMAC_MII_DATA_OP_CL45_RD |
  3108. + EMAC_MII_DATA_PA(mii_id) |
  3109. + EMAC_MII_DATA_RA((regnum >> 16) & 0x1f) |
  3110. + EMAC_MII_DATA_TA,
  3111. + priv->PHY_baseaddr + EMAC_MII_DATA_REG);
  3112. + } else {
  3113. + /* start a read op */
  3114. + __raw_writel(EMAC_MII_DATA_ST | EMAC_MII_DATA_OP_RD |
  3115. + EMAC_MII_DATA_PA(mii_id) |
  3116. + EMAC_MII_DATA_RA(regnum) |
  3117. + EMAC_MII_DATA_TA, priv->PHY_baseaddr +
  3118. + EMAC_MII_DATA_REG);
  3119. + }
  3120. +
  3121. + if (pfe_eth_gemac_phy_timeout(priv, EMAC_MDIO_TIMEOUT)) {
  3122. + netdev_err(priv->ndev, "%s: phy MDIO read timeout\n", __func__);
  3123. + return -1;
  3124. + }
  3125. +
  3126. + value = EMAC_MII_DATA(__raw_readl(priv->PHY_baseaddr +
  3127. + EMAC_MII_DATA_REG));
  3128. + netif_info(priv, hw, priv->ndev, "%s: phy %x reg %x val %x\n", __func__,
  3129. + mii_id, regnum, value);
  3130. + return value;
  3131. +}
  3132. +
  3133. +static int pfe_eth_mdio_init(struct pfe_eth_priv_s *priv,
  3134. + struct ls1012a_mdio_platform_data *minfo)
  3135. +{
  3136. + struct mii_bus *bus;
  3137. + int rc;
  3138. +
  3139. + netif_info(priv, drv, priv->ndev, "%s\n", __func__);
  3140. + pr_info("%s\n", __func__);
  3141. +
  3142. + bus = mdiobus_alloc();
  3143. + if (!bus) {
  3144. + netdev_err(priv->ndev, "mdiobus_alloc() failed\n");
  3145. + rc = -ENOMEM;
  3146. + goto err0;
  3147. + }
  3148. +
  3149. + bus->name = "ls1012a MDIO Bus";
  3150. + bus->read = &pfe_eth_mdio_read;
  3151. + bus->write = &pfe_eth_mdio_write;
  3152. + bus->reset = &pfe_eth_mdio_reset;
  3153. + snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
  3154. + bus->priv = priv;
  3155. +
  3156. + bus->phy_mask = minfo->phy_mask;
  3157. + priv->mdc_div = minfo->mdc_div;
  3158. +
  3159. + if (!priv->mdc_div)
  3160. + priv->mdc_div = 64;
  3161. +
  3162. + bus->irq[0] = minfo->irq[0];
  3163. +
  3164. + bus->parent = priv->pfe->dev;
  3165. +
  3166. + netif_info(priv, drv, priv->ndev, "%s: mdc_div: %d, phy_mask: %x\n",
  3167. + __func__, priv->mdc_div, bus->phy_mask);
  3168. + rc = mdiobus_register(bus);
  3169. + if (rc) {
  3170. + netdev_err(priv->ndev, "mdiobus_register(%s) failed\n",
  3171. + bus->name);
  3172. + goto err1;
  3173. + }
  3174. +
  3175. + priv->mii_bus = bus;
  3176. + pfe_eth_mdio_reset(bus);
  3177. +
  3178. + return 0;
  3179. +
  3180. +err1:
  3181. + mdiobus_free(bus);
  3182. +err0:
  3183. + return rc;
  3184. +}
  3185. +
  3186. +/* pfe_eth_mdio_exit
  3187. + */
  3188. +static void pfe_eth_mdio_exit(struct mii_bus *bus)
  3189. +{
  3190. + if (!bus)
  3191. + return;
  3192. +
  3193. + netif_info((struct pfe_eth_priv_s *)bus->priv, drv, ((struct
  3194. + pfe_eth_priv_s *)(bus->priv))->ndev, "%s\n", __func__);
  3195. +
  3196. + mdiobus_unregister(bus);
  3197. + mdiobus_free(bus);
  3198. +}
  3199. +
  3200. +/* pfe_get_phydev_speed
  3201. + */
  3202. +static int pfe_get_phydev_speed(struct phy_device *phydev)
  3203. +{
  3204. + switch (phydev->speed) {
  3205. + case 10:
  3206. + return SPEED_10M;
  3207. + case 100:
  3208. + return SPEED_100M;
  3209. + case 1000:
  3210. + default:
  3211. + return SPEED_1000M;
  3212. + }
  3213. +}
  3214. +
  3215. +/* pfe_set_rgmii_speed
  3216. + */
  3217. +#define RGMIIPCR 0x434
  3218. +/* RGMIIPCR bit definitions*/
  3219. +#define SCFG_RGMIIPCR_EN_AUTO (0x00000008)
  3220. +#define SCFG_RGMIIPCR_SETSP_1000M (0x00000004)
  3221. +#define SCFG_RGMIIPCR_SETSP_100M (0x00000000)
  3222. +#define SCFG_RGMIIPCR_SETSP_10M (0x00000002)
  3223. +#define SCFG_RGMIIPCR_SETFD (0x00000001)
  3224. +
  3225. +static void pfe_set_rgmii_speed(struct phy_device *phydev)
  3226. +{
  3227. + u32 rgmii_pcr;
  3228. +
  3229. + regmap_read(pfe->scfg, RGMIIPCR, &rgmii_pcr);
  3230. + rgmii_pcr &= ~(SCFG_RGMIIPCR_SETSP_1000M | SCFG_RGMIIPCR_SETSP_10M);
  3231. +
  3232. + switch (phydev->speed) {
  3233. + case 10:
  3234. + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_10M;
  3235. + break;
  3236. + case 1000:
  3237. + rgmii_pcr |= SCFG_RGMIIPCR_SETSP_1000M;
  3238. + break;
  3239. + case 100:
  3240. + default:
  3241. + /* Default is 100M */
  3242. + break;
  3243. + }
  3244. + regmap_write(pfe->scfg, RGMIIPCR, rgmii_pcr);
  3245. +}
  3246. +
  3247. +/* pfe_get_phydev_duplex
  3248. + */
  3249. +static int pfe_get_phydev_duplex(struct phy_device *phydev)
  3250. +{
  3251. + /*return (phydev->duplex == DUPLEX_HALF) ? DUP_HALF:DUP_FULL ; */
  3252. + return DUPLEX_FULL;
  3253. +}
  3254. +
  3255. +/* pfe_eth_adjust_link
  3256. + */
  3257. +static void pfe_eth_adjust_link(struct net_device *ndev)
  3258. +{
  3259. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3260. + unsigned long flags;
  3261. + struct phy_device *phydev = priv->phydev;
  3262. + int new_state = 0;
  3263. +
  3264. + netif_info(priv, drv, ndev, "%s\n", __func__);
  3265. +
  3266. + spin_lock_irqsave(&priv->lock, flags);
  3267. +
  3268. + if (phydev->link) {
  3269. + /*
  3270. + * Now we make sure that we can be in full duplex mode.
  3271. + * If not, we operate in half-duplex mode.
  3272. + */
  3273. + if (phydev->duplex != priv->oldduplex) {
  3274. + new_state = 1;
  3275. + gemac_set_duplex(priv->EMAC_baseaddr,
  3276. + pfe_get_phydev_duplex(phydev));
  3277. + priv->oldduplex = phydev->duplex;
  3278. + }
  3279. +
  3280. + if (phydev->speed != priv->oldspeed) {
  3281. + new_state = 1;
  3282. + gemac_set_speed(priv->EMAC_baseaddr,
  3283. + pfe_get_phydev_speed(phydev));
  3284. + if (priv->einfo->mii_config == PHY_INTERFACE_MODE_RGMII_TXID)
  3285. + pfe_set_rgmii_speed(phydev);
  3286. + priv->oldspeed = phydev->speed;
  3287. + }
  3288. +
  3289. + if (!priv->oldlink) {
  3290. + new_state = 1;
  3291. + priv->oldlink = 1;
  3292. + }
  3293. +
  3294. + } else if (priv->oldlink) {
  3295. + new_state = 1;
  3296. + priv->oldlink = 0;
  3297. + priv->oldspeed = 0;
  3298. + priv->oldduplex = -1;
  3299. + }
  3300. +
  3301. + if (new_state && netif_msg_link(priv))
  3302. + phy_print_status(phydev);
  3303. +
  3304. + spin_unlock_irqrestore(&priv->lock, flags);
  3305. +}
  3306. +
  3307. +/* pfe_phy_exit
  3308. + */
  3309. +static void pfe_phy_exit(struct net_device *ndev)
  3310. +{
  3311. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3312. +
  3313. + netif_info(priv, drv, ndev, "%s\n", __func__);
  3314. +
  3315. + phy_disconnect(priv->phydev);
  3316. + priv->phydev = NULL;
  3317. +}
  3318. +
  3319. +/* pfe_eth_stop
  3320. + */
  3321. +static void pfe_eth_stop(struct net_device *ndev, int wake)
  3322. +{
  3323. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3324. +
  3325. + netif_info(priv, drv, ndev, "%s\n", __func__);
  3326. +
  3327. + if (wake) {
  3328. + gemac_tx_disable(priv->EMAC_baseaddr);
  3329. + } else {
  3330. + gemac_disable(priv->EMAC_baseaddr);
  3331. + gpi_disable(priv->GPI_baseaddr);
  3332. +
  3333. + if (priv->phydev)
  3334. + phy_stop(priv->phydev);
  3335. + }
  3336. +}
  3337. +
  3338. +/* pfe_eth_start
  3339. + */
  3340. +static int pfe_eth_start(struct pfe_eth_priv_s *priv)
  3341. +{
  3342. + netif_info(priv, drv, priv->ndev, "%s\n", __func__);
  3343. +
  3344. + if (priv->phydev)
  3345. + phy_start(priv->phydev);
  3346. +
  3347. + gpi_enable(priv->GPI_baseaddr);
  3348. + gemac_enable(priv->EMAC_baseaddr);
  3349. +
  3350. + return 0;
  3351. +}
  3352. +
  3353. +/*
  3354. + * Configure on chip serdes through mdio
  3355. + */
  3356. +static void ls1012a_configure_serdes(struct net_device *ndev)
  3357. +{
  3358. + struct pfe_eth_priv_s *priv = pfe->eth.eth_priv[0];
  3359. + int sgmii_2500 = 0;
  3360. + struct mii_bus *bus = priv->mii_bus;
  3361. +
  3362. + if (priv->einfo->mii_config == PHY_INTERFACE_MODE_SGMII_2500)
  3363. + sgmii_2500 = 1;
  3364. +
  3365. + netif_info(priv, drv, ndev, "%s\n", __func__);
  3366. + /* PCS configuration done with corresponding GEMAC */
  3367. +
  3368. + pfe_eth_mdio_read(bus, 0, 0);
  3369. + pfe_eth_mdio_read(bus, 0, 1);
  3370. +
  3371. + /*These settings taken from validtion team */
  3372. + pfe_eth_mdio_write(bus, 0, 0x0, 0x8000);
  3373. + if (sgmii_2500) {
  3374. + pfe_eth_mdio_write(bus, 0, 0x14, 0x9);
  3375. + pfe_eth_mdio_write(bus, 0, 0x4, 0x4001);
  3376. + pfe_eth_mdio_write(bus, 0, 0x12, 0xa120);
  3377. + pfe_eth_mdio_write(bus, 0, 0x13, 0x7);
  3378. + } else {
  3379. + pfe_eth_mdio_write(bus, 0, 0x14, 0xb);
  3380. + pfe_eth_mdio_write(bus, 0, 0x4, 0x1a1);
  3381. + pfe_eth_mdio_write(bus, 0, 0x12, 0x400);
  3382. + pfe_eth_mdio_write(bus, 0, 0x13, 0x0);
  3383. + }
  3384. +
  3385. + pfe_eth_mdio_write(bus, 0, 0x0, 0x1140);
  3386. +}
  3387. +
  3388. +/*
  3389. + * pfe_phy_init
  3390. + *
  3391. + */
  3392. +static int pfe_phy_init(struct net_device *ndev)
  3393. +{
  3394. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3395. + struct phy_device *phydev;
  3396. + char phy_id[MII_BUS_ID_SIZE + 3];
  3397. + char bus_id[MII_BUS_ID_SIZE];
  3398. + phy_interface_t interface;
  3399. +
  3400. + priv->oldlink = 0;
  3401. + priv->oldspeed = 0;
  3402. + priv->oldduplex = -1;
  3403. +
  3404. + snprintf(bus_id, MII_BUS_ID_SIZE, "ls1012a-%d", 0);
  3405. + snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
  3406. + priv->einfo->phy_id);
  3407. +
  3408. + netif_info(priv, drv, ndev, "%s: %s\n", __func__, phy_id);
  3409. + interface = priv->einfo->mii_config;
  3410. + if ((interface == PHY_INTERFACE_MODE_SGMII) ||
  3411. + (interface == PHY_INTERFACE_MODE_SGMII_2500)) {
  3412. + /*Configure SGMII PCS */
  3413. + if (pfe->scfg) {
  3414. + /*Config MDIO from serdes */
  3415. + regmap_write(pfe->scfg, 0x484, 0x00000000);
  3416. + }
  3417. + ls1012a_configure_serdes(ndev);
  3418. + }
  3419. +
  3420. + if (pfe->scfg) {
  3421. + /*Config MDIO from PAD */
  3422. + regmap_write(pfe->scfg, 0x484, 0x80000000);
  3423. + }
  3424. +
  3425. + priv->oldlink = 0;
  3426. + priv->oldspeed = 0;
  3427. + priv->oldduplex = -1;
  3428. + pr_info("%s interface %x\n", __func__, interface);
  3429. + phydev = phy_connect(ndev, phy_id, &pfe_eth_adjust_link, interface);
  3430. +
  3431. + if (IS_ERR(phydev)) {
  3432. + netdev_err(ndev, "phy_connect() failed\n");
  3433. + return PTR_ERR(phydev);
  3434. + }
  3435. +
  3436. + priv->phydev = phydev;
  3437. + phydev->irq = PHY_POLL;
  3438. +
  3439. + return 0;
  3440. +}
  3441. +
  3442. +/* pfe_gemac_init
  3443. + */
  3444. +static int pfe_gemac_init(struct pfe_eth_priv_s *priv)
  3445. +{
  3446. + struct gemac_cfg cfg;
  3447. +
  3448. + netif_info(priv, ifup, priv->ndev, "%s\n", __func__);
  3449. +
  3450. + cfg.speed = SPEED_1000M;
  3451. + cfg.duplex = DUPLEX_FULL;
  3452. +
  3453. + gemac_set_config(priv->EMAC_baseaddr, &cfg);
  3454. + gemac_allow_broadcast(priv->EMAC_baseaddr);
  3455. + gemac_enable_1536_rx(priv->EMAC_baseaddr);
  3456. + gemac_enable_rx_jmb(priv->EMAC_baseaddr);
  3457. + gemac_enable_stacked_vlan(priv->EMAC_baseaddr);
  3458. + gemac_enable_pause_rx(priv->EMAC_baseaddr);
  3459. + gemac_set_bus_width(priv->EMAC_baseaddr, 64);
  3460. +
  3461. + /*GEM will perform checksum verifications*/
  3462. + if (priv->ndev->features & NETIF_F_RXCSUM)
  3463. + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
  3464. + else
  3465. + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
  3466. +
  3467. + return 0;
  3468. +}
  3469. +
  3470. +/* pfe_eth_event_handler
  3471. + */
  3472. +static int pfe_eth_event_handler(void *data, int event, int qno)
  3473. +{
  3474. + struct pfe_eth_priv_s *priv = data;
  3475. +
  3476. + switch (event) {
  3477. + case EVENT_RX_PKT_IND:
  3478. +
  3479. + if (qno == 0) {
  3480. + if (napi_schedule_prep(&priv->high_napi)) {
  3481. + netif_info(priv, intr, priv->ndev,
  3482. + "%s: schedule high prio poll\n"
  3483. + , __func__);
  3484. +
  3485. +#ifdef PFE_ETH_NAPI_STATS
  3486. + priv->napi_counters[NAPI_SCHED_COUNT]++;
  3487. +#endif
  3488. +
  3489. + __napi_schedule(&priv->high_napi);
  3490. + }
  3491. + } else if (qno == 1) {
  3492. + if (napi_schedule_prep(&priv->low_napi)) {
  3493. + netif_info(priv, intr, priv->ndev,
  3494. + "%s: schedule low prio poll\n"
  3495. + , __func__);
  3496. +
  3497. +#ifdef PFE_ETH_NAPI_STATS
  3498. + priv->napi_counters[NAPI_SCHED_COUNT]++;
  3499. +#endif
  3500. + __napi_schedule(&priv->low_napi);
  3501. + }
  3502. + } else if (qno == 2) {
  3503. + if (napi_schedule_prep(&priv->lro_napi)) {
  3504. + netif_info(priv, intr, priv->ndev,
  3505. + "%s: schedule lro prio poll\n"
  3506. + , __func__);
  3507. +
  3508. +#ifdef PFE_ETH_NAPI_STATS
  3509. + priv->napi_counters[NAPI_SCHED_COUNT]++;
  3510. +#endif
  3511. + __napi_schedule(&priv->lro_napi);
  3512. + }
  3513. + }
  3514. +
  3515. + break;
  3516. +
  3517. + case EVENT_TXDONE_IND:
  3518. + pfe_eth_flush_tx(priv);
  3519. + hif_lib_event_handler_start(&priv->client, EVENT_TXDONE_IND, 0);
  3520. + break;
  3521. + case EVENT_HIGH_RX_WM:
  3522. + default:
  3523. + break;
  3524. + }
  3525. +
  3526. + return 0;
  3527. +}
  3528. +
  3529. +/* pfe_eth_open
  3530. + */
  3531. +static int pfe_eth_open(struct net_device *ndev)
  3532. +{
  3533. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3534. + struct hif_client_s *client;
  3535. + int rc;
  3536. +
  3537. + netif_info(priv, ifup, ndev, "%s\n", __func__);
  3538. +
  3539. + /* Register client driver with HIF */
  3540. + client = &priv->client;
  3541. + memset(client, 0, sizeof(*client));
  3542. + client->id = PFE_CL_GEM0 + priv->id;
  3543. + client->tx_qn = emac_txq_cnt;
  3544. + client->rx_qn = EMAC_RXQ_CNT;
  3545. + client->priv = priv;
  3546. + client->pfe = priv->pfe;
  3547. + client->event_handler = pfe_eth_event_handler;
  3548. +
  3549. + client->tx_qsize = EMAC_TXQ_DEPTH;
  3550. + client->rx_qsize = EMAC_RXQ_DEPTH;
  3551. +
  3552. + rc = hif_lib_client_register(client);
  3553. + if (rc) {
  3554. + netdev_err(ndev, "%s: hif_lib_client_register(%d) failed\n",
  3555. + __func__, client->id);
  3556. + goto err0;
  3557. + }
  3558. +
  3559. + netif_info(priv, drv, ndev, "%s: registered client: %p\n", __func__,
  3560. + client);
  3561. +
  3562. + pfe_gemac_init(priv);
  3563. +
  3564. + if (!is_valid_ether_addr(ndev->dev_addr)) {
  3565. + netdev_err(ndev, "%s: invalid MAC address\n", __func__);
  3566. + rc = -EADDRNOTAVAIL;
  3567. + goto err1;
  3568. + }
  3569. +
  3570. + gemac_set_laddrN(priv->EMAC_baseaddr,
  3571. + (struct pfe_mac_addr *)ndev->dev_addr, 1);
  3572. +
  3573. + napi_enable(&priv->high_napi);
  3574. + napi_enable(&priv->low_napi);
  3575. + napi_enable(&priv->lro_napi);
  3576. +
  3577. + rc = pfe_eth_start(priv);
  3578. +
  3579. + netif_tx_wake_all_queues(ndev);
  3580. +
  3581. + return rc;
  3582. +
  3583. +err1:
  3584. + hif_lib_client_unregister(&priv->client);
  3585. +
  3586. +err0:
  3587. + return rc;
  3588. +}
  3589. +
  3590. +/*
  3591. + * pfe_eth_shutdown
  3592. + */
  3593. +int pfe_eth_shutdown(struct net_device *ndev, int wake)
  3594. +{
  3595. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3596. + int i, qstatus;
  3597. + unsigned long next_poll = jiffies + 1, end = jiffies +
  3598. + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
  3599. + int tx_pkts, prv_tx_pkts;
  3600. +
  3601. + netif_info(priv, ifdown, ndev, "%s\n", __func__);
  3602. +
  3603. + for (i = 0; i < emac_txq_cnt; i++)
  3604. + hrtimer_cancel(&priv->fast_tx_timeout[i].timer);
  3605. +
  3606. + netif_tx_stop_all_queues(ndev);
  3607. +
  3608. + do {
  3609. + tx_pkts = 0;
  3610. + pfe_eth_flush_tx(priv);
  3611. +
  3612. + for (i = 0; i < emac_txq_cnt; i++)
  3613. + tx_pkts += hif_lib_tx_pending(&priv->client, i);
  3614. +
  3615. + if (tx_pkts) {
  3616. + /*Don't wait forever, break if we cross max timeout */
  3617. + if (time_after(jiffies, end)) {
  3618. + pr_err(
  3619. + "(%s)Tx is not complete after %dmsec\n",
  3620. + ndev->name, TX_POLL_TIMEOUT_MS);
  3621. + break;
  3622. + }
  3623. +
  3624. + pr_info("%s : (%s) Waiting for tx packets to free. Pending tx pkts = %d.\n"
  3625. + , __func__, ndev->name, tx_pkts);
  3626. + if (need_resched())
  3627. + schedule();
  3628. + }
  3629. +
  3630. + } while (tx_pkts);
  3631. +
  3632. + end = jiffies + (TX_POLL_TIMEOUT_MS * HZ) / 1000;
  3633. +
  3634. + prv_tx_pkts = tmu_pkts_processed(priv->id);
  3635. + /*
  3636. + * Wait till TMU transmits all pending packets
  3637. + * poll tmu_qstatus and pkts processed by TMU for every 10ms
  3638. + * Consider TMU is busy, If we see TMU qeueu pending or any packets
  3639. + * processed by TMU
  3640. + */
  3641. + while (1) {
  3642. + if (time_after(jiffies, next_poll)) {
  3643. + tx_pkts = tmu_pkts_processed(priv->id);
  3644. + qstatus = tmu_qstatus(priv->id) & 0x7ffff;
  3645. +
  3646. + if (!qstatus && (tx_pkts == prv_tx_pkts))
  3647. + break;
  3648. + /* Don't wait forever, break if we cross max
  3649. + * timeout(TX_POLL_TIMEOUT_MS)
  3650. + */
  3651. + if (time_after(jiffies, end)) {
  3652. + pr_err("TMU%d is busy after %dmsec\n",
  3653. + priv->id, TX_POLL_TIMEOUT_MS);
  3654. + break;
  3655. + }
  3656. + prv_tx_pkts = tx_pkts;
  3657. + next_poll++;
  3658. + }
  3659. + if (need_resched())
  3660. + schedule();
  3661. + }
  3662. + /* Wait for some more time to complete transmitting packet if any */
  3663. + next_poll = jiffies + 1;
  3664. + while (1) {
  3665. + if (time_after(jiffies, next_poll))
  3666. + break;
  3667. + if (need_resched())
  3668. + schedule();
  3669. + }
  3670. +
  3671. + pfe_eth_stop(ndev, wake);
  3672. +
  3673. + napi_disable(&priv->lro_napi);
  3674. + napi_disable(&priv->low_napi);
  3675. + napi_disable(&priv->high_napi);
  3676. +
  3677. + hif_lib_client_unregister(&priv->client);
  3678. +
  3679. + return 0;
  3680. +}
  3681. +
  3682. +/* pfe_eth_close
  3683. + *
  3684. + */
  3685. +static int pfe_eth_close(struct net_device *ndev)
  3686. +{
  3687. + pfe_eth_shutdown(ndev, 0);
  3688. +
  3689. + return 0;
  3690. +}
  3691. +
  3692. +/* pfe_eth_suspend
  3693. + *
  3694. + * return value : 1 if netdevice is configured to wakeup system
  3695. + * 0 otherwise
  3696. + */
  3697. +int pfe_eth_suspend(struct net_device *ndev)
  3698. +{
  3699. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3700. + int retval = 0;
  3701. +
  3702. + if (priv->wol) {
  3703. + gemac_set_wol(priv->EMAC_baseaddr, priv->wol);
  3704. + retval = 1;
  3705. + }
  3706. + pfe_eth_shutdown(ndev, priv->wol);
  3707. +
  3708. + return retval;
  3709. +}
  3710. +
  3711. +/* pfe_eth_resume
  3712. + *
  3713. + */
  3714. +int pfe_eth_resume(struct net_device *ndev)
  3715. +{
  3716. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3717. +
  3718. + if (priv->wol)
  3719. + gemac_set_wol(priv->EMAC_baseaddr, 0);
  3720. + gemac_tx_enable(priv->EMAC_baseaddr);
  3721. +
  3722. + return pfe_eth_open(ndev);
  3723. +}
  3724. +
  3725. +/* pfe_eth_get_queuenum
  3726. + */
  3727. +static int pfe_eth_get_queuenum(struct pfe_eth_priv_s *priv, struct sk_buff
  3728. + *skb)
  3729. +{
  3730. + int queuenum = 0;
  3731. + unsigned long flags;
  3732. +
  3733. + /* Get the Fast Path queue number */
  3734. + /*
  3735. + * Use conntrack mark (if conntrack exists), then packet mark (if any),
  3736. + * then fallback to default
  3737. + */
  3738. +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
  3739. + if (skb->nfct) {
  3740. + enum ip_conntrack_info cinfo;
  3741. + struct nf_conn *ct;
  3742. +
  3743. + ct = nf_ct_get(skb, &cinfo);
  3744. +
  3745. + if (ct) {
  3746. + u32 connmark;
  3747. +
  3748. + connmark = ct->mark;
  3749. +
  3750. + if ((connmark & 0x80000000) && priv->id != 0)
  3751. + connmark >>= 16;
  3752. +
  3753. + queuenum = connmark & EMAC_QUEUENUM_MASK;
  3754. + }
  3755. + } else {/* continued after #endif ... */
  3756. +#endif
  3757. + if (skb->mark) {
  3758. + queuenum = skb->mark & EMAC_QUEUENUM_MASK;
  3759. + } else {
  3760. + spin_lock_irqsave(&priv->lock, flags);
  3761. + queuenum = priv->default_priority & EMAC_QUEUENUM_MASK;
  3762. + spin_unlock_irqrestore(&priv->lock, flags);
  3763. + }
  3764. +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) || defined(CONFIG_NF_CONNTRACK_MARK)
  3765. + }
  3766. +#endif
  3767. + return queuenum;
  3768. +}
  3769. +
  3770. +/* pfe_eth_might_stop_tx
  3771. + *
  3772. + */
  3773. +static int pfe_eth_might_stop_tx(struct pfe_eth_priv_s *priv, int queuenum,
  3774. + struct netdev_queue *tx_queue,
  3775. + unsigned int n_desc,
  3776. + unsigned int n_segs)
  3777. +{
  3778. + ktime_t kt;
  3779. +
  3780. + if (unlikely((__hif_tx_avail(&pfe->hif) < n_desc) ||
  3781. + (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) ||
  3782. + (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) < n_segs))) {
  3783. +#ifdef PFE_ETH_TX_STATS
  3784. + if (__hif_tx_avail(&pfe->hif) < n_desc) {
  3785. + priv->stop_queue_hif[queuenum]++;
  3786. + } else if (hif_lib_tx_avail(&priv->client, queuenum) < n_desc) {
  3787. + priv->stop_queue_hif_client[queuenum]++;
  3788. + } else if (hif_lib_tx_credit_avail(pfe, priv->id, queuenum) <
  3789. + n_segs) {
  3790. + priv->stop_queue_credit[queuenum]++;
  3791. + }
  3792. + priv->stop_queue_total[queuenum]++;
  3793. +#endif
  3794. + netif_tx_stop_queue(tx_queue);
  3795. +
  3796. + kt = ktime_set(0, LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS *
  3797. + NSEC_PER_MSEC);
  3798. + hrtimer_start(&priv->fast_tx_timeout[queuenum].timer, kt,
  3799. + HRTIMER_MODE_REL);
  3800. + return -1;
  3801. + } else {
  3802. + return 0;
  3803. + }
  3804. +}
  3805. +
  3806. +#define SA_MAX_OP 2
  3807. +/* pfe_hif_send_packet
  3808. + *
  3809. + * At this level if TX fails we drop the packet
  3810. + */
  3811. +static void pfe_hif_send_packet(struct sk_buff *skb, struct pfe_eth_priv_s
  3812. + *priv, int queuenum)
  3813. +{
  3814. + struct skb_shared_info *sh = skb_shinfo(skb);
  3815. + unsigned int nr_frags;
  3816. + u32 ctrl = 0;
  3817. +
  3818. + netif_info(priv, tx_queued, priv->ndev, "%s\n", __func__);
  3819. +
  3820. + if (skb_is_gso(skb)) {
  3821. + priv->stats.tx_dropped++;
  3822. + return;
  3823. + }
  3824. +
  3825. + if (skb->ip_summed == CHECKSUM_PARTIAL)
  3826. + ctrl = HIF_CTRL_TX_CHECKSUM;
  3827. +
  3828. + nr_frags = sh->nr_frags;
  3829. +
  3830. + if (nr_frags) {
  3831. + skb_frag_t *f;
  3832. + int i;
  3833. +
  3834. + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
  3835. + skb_headlen(skb), ctrl, HIF_FIRST_BUFFER,
  3836. + skb);
  3837. +
  3838. + for (i = 0; i < nr_frags - 1; i++) {
  3839. + f = &sh->frags[i];
  3840. + __hif_lib_xmit_pkt(&priv->client, queuenum,
  3841. + skb_frag_address(f),
  3842. + skb_frag_size(f),
  3843. + 0x0, 0x0, skb);
  3844. + }
  3845. +
  3846. + f = &sh->frags[i];
  3847. +
  3848. + __hif_lib_xmit_pkt(&priv->client, queuenum,
  3849. + skb_frag_address(f), skb_frag_size(f),
  3850. + 0x0, HIF_LAST_BUFFER | HIF_DATA_VALID,
  3851. + skb);
  3852. +
  3853. + netif_info(priv, tx_queued, priv->ndev,
  3854. + "%s: pkt sent successfully skb:%p nr_frags:%d len:%d\n",
  3855. + __func__, skb, nr_frags, skb->len);
  3856. + } else {
  3857. + __hif_lib_xmit_pkt(&priv->client, queuenum, skb->data,
  3858. + skb->len, ctrl, HIF_FIRST_BUFFER |
  3859. + HIF_LAST_BUFFER | HIF_DATA_VALID,
  3860. + skb);
  3861. + netif_info(priv, tx_queued, priv->ndev,
  3862. + "%s: pkt sent successfully skb:%p len:%d\n",
  3863. + __func__, skb, skb->len);
  3864. + }
  3865. + hif_tx_dma_start();
  3866. + priv->stats.tx_packets++;
  3867. + priv->stats.tx_bytes += skb->len;
  3868. + hif_lib_tx_credit_use(pfe, priv->id, queuenum, 1);
  3869. +}
  3870. +
  3871. +/* pfe_eth_flush_txQ
  3872. + */
  3873. +static void pfe_eth_flush_txQ(struct pfe_eth_priv_s *priv, int tx_q_num, int
  3874. + from_tx, int n_desc)
  3875. +{
  3876. + struct sk_buff *skb;
  3877. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  3878. + tx_q_num);
  3879. + unsigned int flags;
  3880. +
  3881. + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
  3882. +
  3883. + if (!from_tx)
  3884. + __netif_tx_lock_bh(tx_queue);
  3885. +
  3886. + /* Clean HIF and client queue */
  3887. + while ((skb = hif_lib_tx_get_next_complete(&priv->client,
  3888. + tx_q_num, &flags,
  3889. + HIF_TX_DESC_NT))) {
  3890. + if (flags & HIF_DATA_VALID)
  3891. + dev_kfree_skb_any(skb);
  3892. + }
  3893. + if (!from_tx)
  3894. + __netif_tx_unlock_bh(tx_queue);
  3895. +}
  3896. +
  3897. +/* pfe_eth_flush_tx
  3898. + */
  3899. +static void pfe_eth_flush_tx(struct pfe_eth_priv_s *priv)
  3900. +{
  3901. + int ii;
  3902. +
  3903. + netif_info(priv, tx_done, priv->ndev, "%s\n", __func__);
  3904. +
  3905. + for (ii = 0; ii < emac_txq_cnt; ii++)
  3906. + pfe_eth_flush_txQ(priv, ii, 0, 0);
  3907. +}
  3908. +
  3909. +void pfe_tx_get_req_desc(struct sk_buff *skb, unsigned int *n_desc, unsigned int
  3910. + *n_segs)
  3911. +{
  3912. + struct skb_shared_info *sh = skb_shinfo(skb);
  3913. +
  3914. + /* Scattered data */
  3915. + if (sh->nr_frags) {
  3916. + *n_desc = sh->nr_frags + 1;
  3917. + *n_segs = 1;
  3918. + /* Regular case */
  3919. + } else {
  3920. + *n_desc = 1;
  3921. + *n_segs = 1;
  3922. + }
  3923. +}
  3924. +
  3925. +/* pfe_eth_send_packet
  3926. + */
  3927. +static int pfe_eth_send_packet(struct sk_buff *skb, struct net_device *ndev)
  3928. +{
  3929. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3930. + int tx_q_num = skb_get_queue_mapping(skb);
  3931. + int n_desc, n_segs;
  3932. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  3933. + tx_q_num);
  3934. +
  3935. + netif_info(priv, tx_queued, ndev, "%s\n", __func__);
  3936. +
  3937. + if ((!skb_is_gso(skb)) && (skb_headroom(skb) < (PFE_PKT_HEADER_SZ +
  3938. + sizeof(unsigned long)))) {
  3939. + netif_warn(priv, tx_err, priv->ndev, "%s: copying skb\n",
  3940. + __func__);
  3941. +
  3942. + if (pskb_expand_head(skb, (PFE_PKT_HEADER_SZ + sizeof(unsigned
  3943. + long)), 0, GFP_ATOMIC)) {
  3944. + /* No need to re-transmit, no way to recover*/
  3945. + kfree_skb(skb);
  3946. + priv->stats.tx_dropped++;
  3947. + return NETDEV_TX_OK;
  3948. + }
  3949. + }
  3950. +
  3951. + pfe_tx_get_req_desc(skb, &n_desc, &n_segs);
  3952. +
  3953. + hif_tx_lock(&pfe->hif);
  3954. + if (unlikely(pfe_eth_might_stop_tx(priv, tx_q_num, tx_queue, n_desc,
  3955. + n_segs))) {
  3956. +#ifdef PFE_ETH_TX_STATS
  3957. + if (priv->was_stopped[tx_q_num]) {
  3958. + priv->clean_fail[tx_q_num]++;
  3959. + priv->was_stopped[tx_q_num] = 0;
  3960. + }
  3961. +#endif
  3962. + hif_tx_unlock(&pfe->hif);
  3963. + return NETDEV_TX_BUSY;
  3964. + }
  3965. +
  3966. + pfe_hif_send_packet(skb, priv, tx_q_num);
  3967. +
  3968. + hif_tx_unlock(&pfe->hif);
  3969. +
  3970. + tx_queue->trans_start = jiffies;
  3971. +
  3972. +#ifdef PFE_ETH_TX_STATS
  3973. + priv->was_stopped[tx_q_num] = 0;
  3974. +#endif
  3975. +
  3976. + return NETDEV_TX_OK;
  3977. +}
  3978. +
  3979. +/* pfe_eth_select_queue
  3980. + *
  3981. + */
  3982. +static u16 pfe_eth_select_queue(struct net_device *ndev, struct sk_buff *skb,
  3983. + void *accel_priv,
  3984. + select_queue_fallback_t fallback)
  3985. +{
  3986. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3987. +
  3988. + return pfe_eth_get_queuenum(priv, skb);
  3989. +}
  3990. +
  3991. +/* pfe_eth_get_stats
  3992. + */
  3993. +static struct net_device_stats *pfe_eth_get_stats(struct net_device *ndev)
  3994. +{
  3995. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  3996. +
  3997. + netif_info(priv, drv, ndev, "%s\n", __func__);
  3998. +
  3999. + return &priv->stats;
  4000. +}
  4001. +
  4002. +/* pfe_eth_set_mac_address
  4003. + */
  4004. +static int pfe_eth_set_mac_address(struct net_device *ndev, void *addr)
  4005. +{
  4006. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  4007. + struct sockaddr *sa = addr;
  4008. +
  4009. + netif_info(priv, drv, ndev, "%s\n", __func__);
  4010. +
  4011. + if (!is_valid_ether_addr(sa->sa_data))
  4012. + return -EADDRNOTAVAIL;
  4013. +
  4014. + memcpy(ndev->dev_addr, sa->sa_data, ETH_ALEN);
  4015. +
  4016. + gemac_set_laddrN(priv->EMAC_baseaddr,
  4017. + (struct pfe_mac_addr *)ndev->dev_addr, 1);
  4018. +
  4019. + return 0;
  4020. +}
  4021. +
  4022. +/* pfe_eth_enet_addr_byte_mac
  4023. + */
  4024. +int pfe_eth_enet_addr_byte_mac(u8 *enet_byte_addr,
  4025. + struct pfe_mac_addr *enet_addr)
  4026. +{
  4027. + if (!enet_byte_addr || !enet_addr) {
  4028. + return -1;
  4029. +
  4030. + } else {
  4031. + enet_addr->bottom = enet_byte_addr[0] |
  4032. + (enet_byte_addr[1] << 8) |
  4033. + (enet_byte_addr[2] << 16) |
  4034. + (enet_byte_addr[3] << 24);
  4035. + enet_addr->top = enet_byte_addr[4] |
  4036. + (enet_byte_addr[5] << 8);
  4037. + return 0;
  4038. + }
  4039. +}
  4040. +
  4041. +/* pfe_eth_set_multi
  4042. + */
  4043. +static void pfe_eth_set_multi(struct net_device *ndev)
  4044. +{
  4045. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  4046. + struct pfe_mac_addr hash_addr; /* hash register structure */
  4047. + /* specific mac address register structure */
  4048. + struct pfe_mac_addr spec_addr;
  4049. + int result; /* index into hash register to set.. */
  4050. + int uc_count = 0;
  4051. + struct netdev_hw_addr *ha;
  4052. +
  4053. + if (ndev->flags & IFF_PROMISC) {
  4054. + netif_info(priv, drv, ndev, "entering promiscuous mode\n");
  4055. +
  4056. + priv->promisc = 1;
  4057. + gemac_enable_copy_all(priv->EMAC_baseaddr);
  4058. + } else {
  4059. + priv->promisc = 0;
  4060. + gemac_disable_copy_all(priv->EMAC_baseaddr);
  4061. + }
  4062. +
  4063. + /* Enable broadcast frame reception if required. */
  4064. + if (ndev->flags & IFF_BROADCAST) {
  4065. + gemac_allow_broadcast(priv->EMAC_baseaddr);
  4066. + } else {
  4067. + netif_info(priv, drv, ndev,
  4068. + "disabling broadcast frame reception\n");
  4069. +
  4070. + gemac_no_broadcast(priv->EMAC_baseaddr);
  4071. + }
  4072. +
  4073. + if (ndev->flags & IFF_ALLMULTI) {
  4074. + /* Set the hash to rx all multicast frames */
  4075. + hash_addr.bottom = 0xFFFFFFFF;
  4076. + hash_addr.top = 0xFFFFFFFF;
  4077. + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
  4078. + netdev_for_each_uc_addr(ha, ndev) {
  4079. + if (uc_count >= MAX_UC_SPEC_ADDR_REG)
  4080. + break;
  4081. + pfe_eth_enet_addr_byte_mac(ha->addr, &spec_addr);
  4082. + gemac_set_laddrN(priv->EMAC_baseaddr, &spec_addr,
  4083. + uc_count + 2);
  4084. + uc_count++;
  4085. + }
  4086. + } else if ((netdev_mc_count(ndev) > 0) || (netdev_uc_count(ndev))) {
  4087. + u8 *addr;
  4088. +
  4089. + hash_addr.bottom = 0;
  4090. + hash_addr.top = 0;
  4091. +
  4092. + netdev_for_each_mc_addr(ha, ndev) {
  4093. + addr = ha->addr;
  4094. +
  4095. + netif_info(priv, drv, ndev,
  4096. + "adding multicast address %X:%X:%X:%X:%X:%X to gem filter\n",
  4097. + addr[0], addr[1], addr[2],
  4098. + addr[3], addr[4], addr[5]);
  4099. +
  4100. + result = pfe_eth_get_hash(addr);
  4101. +
  4102. + if (result < EMAC_HASH_REG_BITS) {
  4103. + if (result < 32)
  4104. + hash_addr.bottom |= (1 << result);
  4105. + else
  4106. + hash_addr.top |= (1 << (result - 32));
  4107. + } else {
  4108. + break;
  4109. + }
  4110. + }
  4111. +
  4112. + uc_count = -1;
  4113. + netdev_for_each_uc_addr(ha, ndev) {
  4114. + addr = ha->addr;
  4115. +
  4116. + if (++uc_count < MAX_UC_SPEC_ADDR_REG) {
  4117. + netdev_info(ndev,
  4118. + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem filter\n",
  4119. + addr[0], addr[1], addr[2],
  4120. + addr[3], addr[4], addr[5]);
  4121. + pfe_eth_enet_addr_byte_mac(addr, &spec_addr);
  4122. + gemac_set_laddrN(priv->EMAC_baseaddr,
  4123. + &spec_addr, uc_count + 2);
  4124. + } else {
  4125. + netif_info(priv, drv, ndev,
  4126. + "adding unicast address %02x:%02x:%02x:%02x:%02x:%02x to gem hash\n",
  4127. + addr[0], addr[1], addr[2],
  4128. + addr[3], addr[4], addr[5]);
  4129. +
  4130. + result = pfe_eth_get_hash(addr);
  4131. + if (result >= EMAC_HASH_REG_BITS) {
  4132. + break;
  4133. +
  4134. + } else {
  4135. + if (result < 32)
  4136. + hash_addr.bottom |= (1 <<
  4137. + result);
  4138. + else
  4139. + hash_addr.top |= (1 <<
  4140. + (result - 32));
  4141. + }
  4142. + }
  4143. + }
  4144. +
  4145. + gemac_set_hash(priv->EMAC_baseaddr, &hash_addr);
  4146. + }
  4147. +
  4148. + if (!(netdev_uc_count(ndev) >= MAX_UC_SPEC_ADDR_REG)) {
  4149. + /*
  4150. + * Check if there are any specific address HW registers that
  4151. + * need to be flushed
  4152. + */
  4153. + for (uc_count = netdev_uc_count(ndev); uc_count <
  4154. + MAX_UC_SPEC_ADDR_REG; uc_count++)
  4155. + gemac_clear_laddrN(priv->EMAC_baseaddr, uc_count + 2);
  4156. + }
  4157. +
  4158. + if (ndev->flags & IFF_LOOPBACK)
  4159. + gemac_set_loop(priv->EMAC_baseaddr, LB_LOCAL);
  4160. +}
  4161. +
  4162. +/* pfe_eth_set_features
  4163. + */
  4164. +static int pfe_eth_set_features(struct net_device *ndev, netdev_features_t
  4165. + features)
  4166. +{
  4167. + struct pfe_eth_priv_s *priv = netdev_priv(ndev);
  4168. + int rc = 0;
  4169. +
  4170. + if (features & NETIF_F_RXCSUM)
  4171. + gemac_enable_rx_checksum_offload(priv->EMAC_baseaddr);
  4172. + else
  4173. + gemac_disable_rx_checksum_offload(priv->EMAC_baseaddr);
  4174. + return rc;
  4175. +}
  4176. +
  4177. +/* pfe_eth_fast_tx_timeout
  4178. + */
  4179. +static enum hrtimer_restart pfe_eth_fast_tx_timeout(struct hrtimer *timer)
  4180. +{
  4181. + struct pfe_eth_fast_timer *fast_tx_timeout = container_of(timer, struct
  4182. + pfe_eth_fast_timer,
  4183. + timer);
  4184. + struct pfe_eth_priv_s *priv = container_of(fast_tx_timeout->base,
  4185. + struct pfe_eth_priv_s,
  4186. + fast_tx_timeout);
  4187. + struct netdev_queue *tx_queue = netdev_get_tx_queue(priv->ndev,
  4188. + fast_tx_timeout->queuenum);
  4189. +
  4190. + if (netif_tx_queue_stopped(tx_queue)) {
  4191. +#ifdef PFE_ETH_TX_STATS
  4192. + priv->was_stopped[fast_tx_timeout->queuenum] = 1;
  4193. +#endif
  4194. + netif_tx_wake_queue(tx_queue);
  4195. + }
  4196. +
  4197. + return HRTIMER_NORESTART;
  4198. +}
  4199. +
  4200. +/* pfe_eth_fast_tx_timeout_init
  4201. + */
  4202. +static void pfe_eth_fast_tx_timeout_init(struct pfe_eth_priv_s *priv)
  4203. +{
  4204. + int i;
  4205. +
  4206. + for (i = 0; i < emac_txq_cnt; i++) {
  4207. + priv->fast_tx_timeout[i].queuenum = i;
  4208. + hrtimer_init(&priv->fast_tx_timeout[i].timer, CLOCK_MONOTONIC,
  4209. + HRTIMER_MODE_REL);
  4210. + priv->fast_tx_timeout[i].timer.function =
  4211. + pfe_eth_fast_tx_timeout;
  4212. + priv->fast_tx_timeout[i].base = priv->fast_tx_timeout;
  4213. + }
  4214. +}
  4215. +
  4216. +static struct sk_buff *pfe_eth_rx_skb(struct net_device *ndev,
  4217. + struct pfe_eth_priv_s *priv,
  4218. + unsigned int qno)
  4219. +{
  4220. + void *buf_addr;
  4221. + unsigned int rx_ctrl;
  4222. + unsigned int desc_ctrl = 0;
  4223. + struct hif_ipsec_hdr *ipsec_hdr = NULL;
  4224. + struct sk_buff *skb;
  4225. + struct sk_buff *skb_frag, *skb_frag_last = NULL;
  4226. + int length = 0, offset;
  4227. +
  4228. + skb = priv->skb_inflight[qno];
  4229. +
  4230. + if (skb) {
  4231. + skb_frag_last = skb_shinfo(skb)->frag_list;
  4232. + if (skb_frag_last) {
  4233. + while (skb_frag_last->next)
  4234. + skb_frag_last = skb_frag_last->next;
  4235. + }
  4236. + }
  4237. +
  4238. + while (!(desc_ctrl & CL_DESC_LAST)) {
  4239. + buf_addr = hif_lib_receive_pkt(&priv->client, qno, &length,
  4240. + &offset, &rx_ctrl, &desc_ctrl,
  4241. + (void **)&ipsec_hdr);
  4242. + if (!buf_addr)
  4243. + goto incomplete;
  4244. +
  4245. +#ifdef PFE_ETH_NAPI_STATS
  4246. + priv->napi_counters[NAPI_DESC_COUNT]++;
  4247. +#endif
  4248. +
  4249. + /* First frag */
  4250. + if (desc_ctrl & CL_DESC_FIRST) {
  4251. + skb = build_skb(buf_addr, 0);
  4252. + if (unlikely(!skb))
  4253. + goto pkt_drop;
  4254. +
  4255. + skb_reserve(skb, offset);
  4256. + skb_put(skb, length);
  4257. + skb->dev = ndev;
  4258. +
  4259. + if ((ndev->features & NETIF_F_RXCSUM) && (rx_ctrl &
  4260. + HIF_CTRL_RX_CHECKSUMMED))
  4261. + skb->ip_summed = CHECKSUM_UNNECESSARY;
  4262. + else
  4263. + skb_checksum_none_assert(skb);
  4264. +
  4265. + } else {
  4266. + /* Next frags */
  4267. + if (unlikely(!skb)) {
  4268. + pr_err("%s: NULL skb_inflight\n",
  4269. + __func__);
  4270. + goto pkt_drop;
  4271. + }
  4272. +
  4273. + skb_frag = build_skb(buf_addr, 0);
  4274. +
  4275. + if (unlikely(!skb_frag)) {
  4276. + kfree(buf_addr);
  4277. + goto pkt_drop;
  4278. + }
  4279. +
  4280. + skb_reserve(skb_frag, offset);
  4281. + skb_put(skb_frag, length);
  4282. +
  4283. + skb_frag->dev = ndev;
  4284. +
  4285. + if (skb_shinfo(skb)->frag_list)
  4286. + skb_frag_last->next = skb_frag;
  4287. + else
  4288. + skb_shinfo(skb)->frag_list = skb_frag;
  4289. +
  4290. + skb->truesize += skb_frag->truesize;
  4291. + skb->data_len += length;
  4292. + skb->len += length;
  4293. + skb_frag_last = skb_frag;
  4294. + }
  4295. + }
  4296. +
  4297. + priv->skb_inflight[qno] = NULL;
  4298. + return skb;
  4299. +
  4300. +incomplete:
  4301. + priv->skb_inflight[qno] = skb;
  4302. + return NULL;
  4303. +
  4304. +pkt_drop:
  4305. + priv->skb_inflight[qno] = NULL;
  4306. +
  4307. + if (skb)
  4308. + kfree_skb(skb);
  4309. + else
  4310. + kfree(buf_addr);
  4311. +
  4312. + priv->stats.rx_errors++;
  4313. +
  4314. + return NULL;
  4315. +}
  4316. +
  4317. +/* pfe_eth_poll
  4318. + */
  4319. +static int pfe_eth_poll(struct pfe_eth_priv_s *priv, struct napi_struct *napi,
  4320. + unsigned int qno, int budget)
  4321. +{
  4322. + struct net_device *ndev = priv->ndev;
  4323. + struct sk_buff *skb;
  4324. + int work_done = 0;
  4325. + unsigned int len;
  4326. +
  4327. + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
  4328. +
  4329. +#ifdef PFE_ETH_NAPI_STATS
  4330. + priv->napi_counters[NAPI_POLL_COUNT]++;
  4331. +#endif
  4332. +
  4333. + do {
  4334. + skb = pfe_eth_rx_skb(ndev, priv, qno);
  4335. +
  4336. + if (!skb)
  4337. + break;
  4338. +
  4339. + len = skb->len;
  4340. +
  4341. + /* Packet will be processed */
  4342. + skb->protocol = eth_type_trans(skb, ndev);
  4343. +
  4344. + netif_receive_skb(skb);
  4345. +
  4346. + priv->stats.rx_packets++;
  4347. + priv->stats.rx_bytes += len;
  4348. +
  4349. + work_done++;
  4350. +
  4351. +#ifdef PFE_ETH_NAPI_STATS
  4352. + priv->napi_counters[NAPI_PACKET_COUNT]++;
  4353. +#endif
  4354. +
  4355. + } while (work_done < budget);
  4356. +
  4357. + /*
  4358. + * If no Rx receive nor cleanup work was done, exit polling mode.
  4359. + * No more netif_running(dev) check is required here , as this is
  4360. + * checked in net/core/dev.c (2.6.33.5 kernel specific).
  4361. + */
  4362. + if (work_done < budget) {
  4363. + napi_complete(napi);
  4364. +
  4365. + hif_lib_event_handler_start(&priv->client, EVENT_RX_PKT_IND,
  4366. + qno);
  4367. + }
  4368. +#ifdef PFE_ETH_NAPI_STATS
  4369. + else
  4370. + priv->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
  4371. +#endif
  4372. +
  4373. + return work_done;
  4374. +}
  4375. +
  4376. +/*
  4377. + * pfe_eth_lro_poll
  4378. + */
  4379. +static int pfe_eth_lro_poll(struct napi_struct *napi, int budget)
  4380. +{
  4381. + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
  4382. + lro_napi);
  4383. +
  4384. + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
  4385. +
  4386. + return pfe_eth_poll(priv, napi, 2, budget);
  4387. +}
  4388. +
  4389. +/* pfe_eth_low_poll
  4390. + */
  4391. +static int pfe_eth_low_poll(struct napi_struct *napi, int budget)
  4392. +{
  4393. + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
  4394. + low_napi);
  4395. +
  4396. + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
  4397. +
  4398. + return pfe_eth_poll(priv, napi, 1, budget);
  4399. +}
  4400. +
  4401. +/* pfe_eth_high_poll
  4402. + */
  4403. +static int pfe_eth_high_poll(struct napi_struct *napi, int budget)
  4404. +{
  4405. + struct pfe_eth_priv_s *priv = container_of(napi, struct pfe_eth_priv_s,
  4406. + high_napi);
  4407. +
  4408. + netif_info(priv, intr, priv->ndev, "%s\n", __func__);
  4409. +
  4410. + return pfe_eth_poll(priv, napi, 0, budget);
  4411. +}
  4412. +
  4413. +static const struct net_device_ops pfe_netdev_ops = {
  4414. + .ndo_open = pfe_eth_open,
  4415. + .ndo_stop = pfe_eth_close,
  4416. + .ndo_start_xmit = pfe_eth_send_packet,
  4417. + .ndo_select_queue = pfe_eth_select_queue,
  4418. + .ndo_get_stats = pfe_eth_get_stats,
  4419. + .ndo_set_mac_address = pfe_eth_set_mac_address,
  4420. + .ndo_set_rx_mode = pfe_eth_set_multi,
  4421. + .ndo_set_features = pfe_eth_set_features,
  4422. + .ndo_validate_addr = eth_validate_addr,
  4423. +};
  4424. +
  4425. +/* pfe_eth_init_one
  4426. + */
  4427. +static int pfe_eth_init_one(struct pfe *pfe, int id)
  4428. +{
  4429. + struct net_device *ndev = NULL;
  4430. + struct pfe_eth_priv_s *priv = NULL;
  4431. + struct ls1012a_eth_platform_data *einfo;
  4432. + struct ls1012a_mdio_platform_data *minfo;
  4433. + struct ls1012a_pfe_platform_data *pfe_info;
  4434. + int err;
  4435. +
  4436. + /* Extract pltform data */
  4437. + pfe_info = (struct ls1012a_pfe_platform_data *)
  4438. + pfe->dev->platform_data;
  4439. + if (!pfe_info) {
  4440. + pr_err(
  4441. + "%s: pfe missing additional platform data\n"
  4442. + , __func__);
  4443. + err = -ENODEV;
  4444. + goto err0;
  4445. + }
  4446. +
  4447. + einfo = (struct ls1012a_eth_platform_data *)
  4448. + pfe_info->ls1012a_eth_pdata;
  4449. +
  4450. + /* einfo never be NULL, but no harm in having this check */
  4451. + if (!einfo) {
  4452. + pr_err(
  4453. + "%s: pfe missing additional gemacs platform data\n"
  4454. + , __func__);
  4455. + err = -ENODEV;
  4456. + goto err0;
  4457. + }
  4458. +
  4459. + minfo = (struct ls1012a_mdio_platform_data *)
  4460. + pfe_info->ls1012a_mdio_pdata;
  4461. +
  4462. + /* einfo never be NULL, but no harm in having this check */
  4463. + if (!minfo) {
  4464. + pr_err(
  4465. + "%s: pfe missing additional mdios platform data\n",
  4466. + __func__);
  4467. + err = -ENODEV;
  4468. + goto err0;
  4469. + }
  4470. +
  4471. + /* Create an ethernet device instance */
  4472. + ndev = alloc_etherdev_mq(sizeof(*priv), emac_txq_cnt);
  4473. +
  4474. + if (!ndev) {
  4475. + pr_err("%s: gemac %d device allocation failed\n",
  4476. + __func__, einfo[id].gem_id);
  4477. + err = -ENOMEM;
  4478. + goto err0;
  4479. + }
  4480. +
  4481. + priv = netdev_priv(ndev);
  4482. + priv->ndev = ndev;
  4483. + priv->id = einfo[id].gem_id;
  4484. + priv->pfe = pfe;
  4485. +
  4486. + SET_NETDEV_DEV(priv->ndev, priv->pfe->dev);
  4487. +
  4488. + pfe->eth.eth_priv[id] = priv;
  4489. +
  4490. + /* Set the info in the priv to the current info */
  4491. + priv->einfo = &einfo[id];
  4492. + priv->EMAC_baseaddr = cbus_emac_base[id];
  4493. + priv->PHY_baseaddr = cbus_emac_base[0];
  4494. + priv->GPI_baseaddr = cbus_gpi_base[id];
  4495. +
  4496. +#define HIF_GEMAC_TMUQ_BASE 6
  4497. + priv->low_tmu_q = HIF_GEMAC_TMUQ_BASE + (id * 2);
  4498. + priv->high_tmu_q = priv->low_tmu_q + 1;
  4499. +
  4500. + spin_lock_init(&priv->lock);
  4501. +
  4502. + pfe_eth_fast_tx_timeout_init(priv);
  4503. +
  4504. + /* Copy the station address into the dev structure, */
  4505. + memcpy(ndev->dev_addr, einfo[id].mac_addr, ETH_ALEN);
  4506. +
  4507. + /* Initialize mdio */
  4508. + if (minfo[id].enabled) {
  4509. + err = pfe_eth_mdio_init(priv, &minfo[id]);
  4510. + if (err) {
  4511. + netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n",
  4512. + __func__);
  4513. + goto err2;
  4514. + }
  4515. + }
  4516. +
  4517. + ndev->mtu = 1500;
  4518. +
  4519. + /* Set MTU limits */
  4520. + ndev->min_mtu = ETH_MIN_MTU;
  4521. + ndev->max_mtu = JUMBO_FRAME_SIZE;
  4522. +
  4523. + /* supported features */
  4524. + ndev->hw_features = NETIF_F_SG;
  4525. +
  4526. + /*Enable after checksum offload is validated */
  4527. + ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
  4528. + NETIF_F_IPV6_CSUM | NETIF_F_SG;
  4529. +
  4530. + /* enabled by default */
  4531. + ndev->features = ndev->hw_features;
  4532. +
  4533. + priv->usr_features = ndev->features;
  4534. +
  4535. + ndev->netdev_ops = &pfe_netdev_ops;
  4536. +
  4537. + ndev->ethtool_ops = &pfe_ethtool_ops;
  4538. +
  4539. + /* Enable basic messages by default */
  4540. + priv->msg_enable = NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_LINK |
  4541. + NETIF_MSG_PROBE;
  4542. +
  4543. + netif_napi_add(ndev, &priv->low_napi, pfe_eth_low_poll,
  4544. + HIF_RX_POLL_WEIGHT - 16);
  4545. + netif_napi_add(ndev, &priv->high_napi, pfe_eth_high_poll,
  4546. + HIF_RX_POLL_WEIGHT - 16);
  4547. + netif_napi_add(ndev, &priv->lro_napi, pfe_eth_lro_poll,
  4548. + HIF_RX_POLL_WEIGHT - 16);
  4549. +
  4550. + err = register_netdev(ndev);
  4551. +
  4552. + if (err) {
  4553. + netdev_err(ndev, "register_netdev() failed\n");
  4554. + goto err3;
  4555. + }
  4556. + device_init_wakeup(&ndev->dev, WAKE_MAGIC);
  4557. +
  4558. + if (!(priv->einfo->phy_flags & GEMAC_NO_PHY)) {
  4559. + err = pfe_phy_init(ndev);
  4560. + if (err) {
  4561. + netdev_err(ndev, "%s: pfe_phy_init() failed\n",
  4562. + __func__);
  4563. + goto err4;
  4564. + }
  4565. + }
  4566. +
  4567. + netif_carrier_on(ndev);
  4568. +
  4569. + /* Create all the sysfs files */
  4570. + if (pfe_eth_sysfs_init(ndev))
  4571. + goto err4;
  4572. +
  4573. + netif_info(priv, probe, ndev, "%s: created interface, baseaddr: %p\n",
  4574. + __func__, priv->EMAC_baseaddr);
  4575. +
  4576. + return 0;
  4577. +err4:
  4578. + unregister_netdev(ndev);
  4579. +err3:
  4580. + pfe_eth_mdio_exit(priv->mii_bus);
  4581. +err2:
  4582. + free_netdev(priv->ndev);
  4583. +err0:
  4584. + return err;
  4585. +}
  4586. +
  4587. +/* pfe_eth_init
  4588. + */
  4589. +int pfe_eth_init(struct pfe *pfe)
  4590. +{
  4591. + int ii = 0;
  4592. + int err;
  4593. +
  4594. + pr_info("%s\n", __func__);
  4595. +
  4596. + cbus_emac_base[0] = EMAC1_BASE_ADDR;
  4597. + cbus_emac_base[1] = EMAC2_BASE_ADDR;
  4598. +
  4599. + cbus_gpi_base[0] = EGPI1_BASE_ADDR;
  4600. + cbus_gpi_base[1] = EGPI2_BASE_ADDR;
  4601. +
  4602. + for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
  4603. + err = pfe_eth_init_one(pfe, ii);
  4604. + if (err)
  4605. + goto err0;
  4606. + }
  4607. +
  4608. + return 0;
  4609. +
  4610. +err0:
  4611. + while (ii--)
  4612. + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
  4613. +
  4614. + /* Register three network devices in the kernel */
  4615. + return err;
  4616. +}
  4617. +
  4618. +/* pfe_eth_exit_one
  4619. + */
  4620. +static void pfe_eth_exit_one(struct pfe_eth_priv_s *priv)
  4621. +{
  4622. + netif_info(priv, probe, priv->ndev, "%s\n", __func__);
  4623. +
  4624. + pfe_eth_sysfs_exit(priv->ndev);
  4625. +
  4626. + unregister_netdev(priv->ndev);
  4627. +
  4628. + if (!(priv->einfo->phy_flags & GEMAC_NO_PHY))
  4629. + pfe_phy_exit(priv->ndev);
  4630. +
  4631. + if (priv->mii_bus)
  4632. + pfe_eth_mdio_exit(priv->mii_bus);
  4633. +
  4634. + free_netdev(priv->ndev);
  4635. +}
  4636. +
  4637. +/* pfe_eth_exit
  4638. + */
  4639. +void pfe_eth_exit(struct pfe *pfe)
  4640. +{
  4641. + int ii;
  4642. +
  4643. + pr_info("%s\n", __func__);
  4644. +
  4645. + for (ii = NUM_GEMAC_SUPPORT - 1; ii >= 0; ii--)
  4646. + pfe_eth_exit_one(pfe->eth.eth_priv[ii]);
  4647. +}
  4648. diff --git a/drivers/staging/fsl_ppfe/pfe_eth.h b/drivers/staging/fsl_ppfe/pfe_eth.h
  4649. new file mode 100644
  4650. index 00000000..721bef3e
  4651. --- /dev/null
  4652. +++ b/drivers/staging/fsl_ppfe/pfe_eth.h
  4653. @@ -0,0 +1,184 @@
  4654. +/*
  4655. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  4656. + * Copyright 2017 NXP
  4657. + *
  4658. + * This program is free software; you can redistribute it and/or modify
  4659. + * it under the terms of the GNU General Public License as published by
  4660. + * the Free Software Foundation; either version 2 of the License, or
  4661. + * (at your option) any later version.
  4662. + *
  4663. + * This program is distributed in the hope that it will be useful,
  4664. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4665. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4666. + * GNU General Public License for more details.
  4667. + *
  4668. + * You should have received a copy of the GNU General Public License
  4669. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  4670. + */
  4671. +
  4672. +#ifndef _PFE_ETH_H_
  4673. +#define _PFE_ETH_H_
  4674. +#include <linux/kernel.h>
  4675. +#include <linux/netdevice.h>
  4676. +#include <linux/etherdevice.h>
  4677. +#include <linux/ethtool.h>
  4678. +#include <linux/mii.h>
  4679. +#include <linux/phy.h>
  4680. +#include <linux/clk.h>
  4681. +#include <linux/interrupt.h>
  4682. +#include <linux/time.h>
  4683. +
  4684. +#define PFE_ETH_NAPI_STATS
  4685. +#define PFE_ETH_TX_STATS
  4686. +
  4687. +#define PFE_ETH_FRAGS_MAX (65536 / HIF_RX_PKT_MIN_SIZE)
  4688. +#define LRO_LEN_COUNT_MAX 32
  4689. +#define LRO_NB_COUNT_MAX 32
  4690. +
  4691. +#define PFE_PAUSE_FLAG_ENABLE 1
  4692. +#define PFE_PAUSE_FLAG_AUTONEG 2
  4693. +
  4694. +/* GEMAC configured by SW */
  4695. +/* GEMAC configured by phy lines (not for MII/GMII) */
  4696. +
  4697. +#define GEMAC_SW_FULL_DUPLEX BIT(9)
  4698. +#define GEMAC_SW_SPEED_10M (0 << 12)
  4699. +#define GEMAC_SW_SPEED_100M BIT(12)
  4700. +#define GEMAC_SW_SPEED_1G (2 << 12)
  4701. +
  4702. +#define GEMAC_NO_PHY BIT(0)
  4703. +
  4704. +struct ls1012a_eth_platform_data {
  4705. + /* device specific information */
  4706. + u32 device_flags;
  4707. + char name[16];
  4708. +
  4709. + /* board specific information */
  4710. + u32 mii_config;
  4711. + u32 phy_flags;
  4712. + u32 gem_id;
  4713. + u32 bus_id;
  4714. + u32 phy_id;
  4715. + u32 mdio_muxval;
  4716. + u8 mac_addr[ETH_ALEN];
  4717. +};
  4718. +
  4719. +struct ls1012a_mdio_platform_data {
  4720. + int enabled;
  4721. + int irq[32];
  4722. + u32 phy_mask;
  4723. + int mdc_div;
  4724. +};
  4725. +
  4726. +struct ls1012a_pfe_platform_data {
  4727. + struct ls1012a_eth_platform_data ls1012a_eth_pdata[3];
  4728. + struct ls1012a_mdio_platform_data ls1012a_mdio_pdata[3];
  4729. +};
  4730. +
  4731. +#define NUM_GEMAC_SUPPORT 2
  4732. +#define DRV_NAME "pfe-eth"
  4733. +#define DRV_VERSION "1.0"
  4734. +
  4735. +#define LS1012A_TX_FAST_RECOVERY_TIMEOUT_MS 3
  4736. +#define TX_POLL_TIMEOUT_MS 1000
  4737. +
  4738. +#define EMAC_TXQ_CNT 16
  4739. +#define EMAC_TXQ_DEPTH (HIF_TX_DESC_NT)
  4740. +
  4741. +#define JUMBO_FRAME_SIZE 10258
  4742. +/*
  4743. + * Client Tx queue threshold, for txQ flush condition.
  4744. + * It must be smaller than the queue size (in case we ever change it in the
  4745. + * future).
  4746. + */
  4747. +#define HIF_CL_TX_FLUSH_MARK 32
  4748. +
  4749. +/*
  4750. + * Max number of TX resources (HIF descriptors or skbs) that will be released
  4751. + * in a single go during batch recycling.
  4752. + * Should be lower than the flush mark so the SW can provide the HW with a
  4753. + * continuous stream of packets instead of bursts.
  4754. + */
  4755. +#define TX_FREE_MAX_COUNT 16
  4756. +#define EMAC_RXQ_CNT 3
  4757. +#define EMAC_RXQ_DEPTH HIF_RX_DESC_NT
  4758. +/* make sure clients can receive a full burst of packets */
  4759. +#define EMAC_RMON_TXBYTES_POS 0x00
  4760. +#define EMAC_RMON_RXBYTES_POS 0x14
  4761. +
  4762. +#define EMAC_QUEUENUM_MASK (emac_txq_cnt - 1)
  4763. +#define EMAC_MDIO_TIMEOUT 1000
  4764. +#define MAX_UC_SPEC_ADDR_REG 31
  4765. +
  4766. +struct pfe_eth_fast_timer {
  4767. + int queuenum;
  4768. + struct hrtimer timer;
  4769. + void *base;
  4770. +};
  4771. +
  4772. +struct pfe_eth_priv_s {
  4773. + struct pfe *pfe;
  4774. + struct hif_client_s client;
  4775. + struct napi_struct lro_napi;
  4776. + struct napi_struct low_napi;
  4777. + struct napi_struct high_napi;
  4778. + int low_tmu_q;
  4779. + int high_tmu_q;
  4780. + struct net_device_stats stats;
  4781. + struct net_device *ndev;
  4782. + int id;
  4783. + int promisc;
  4784. + unsigned int msg_enable;
  4785. + unsigned int usr_features;
  4786. +
  4787. + spinlock_t lock; /* protect member variables */
  4788. + unsigned int event_status;
  4789. + int irq;
  4790. + void *EMAC_baseaddr;
  4791. + /* This points to the EMAC base from where we access PHY */
  4792. + void *PHY_baseaddr;
  4793. + void *GPI_baseaddr;
  4794. + /* PHY stuff */
  4795. + struct phy_device *phydev;
  4796. + int oldspeed;
  4797. + int oldduplex;
  4798. + int oldlink;
  4799. + /* mdio info */
  4800. + int mdc_div;
  4801. + struct mii_bus *mii_bus;
  4802. + struct clk *gemtx_clk;
  4803. + int wol;
  4804. + int pause_flag;
  4805. +
  4806. + int default_priority;
  4807. + struct pfe_eth_fast_timer fast_tx_timeout[EMAC_TXQ_CNT];
  4808. +
  4809. + struct ls1012a_eth_platform_data *einfo;
  4810. + struct sk_buff *skb_inflight[EMAC_RXQ_CNT + 6];
  4811. +
  4812. +#ifdef PFE_ETH_TX_STATS
  4813. + unsigned int stop_queue_total[EMAC_TXQ_CNT];
  4814. + unsigned int stop_queue_hif[EMAC_TXQ_CNT];
  4815. + unsigned int stop_queue_hif_client[EMAC_TXQ_CNT];
  4816. + unsigned int stop_queue_credit[EMAC_TXQ_CNT];
  4817. + unsigned int clean_fail[EMAC_TXQ_CNT];
  4818. + unsigned int was_stopped[EMAC_TXQ_CNT];
  4819. +#endif
  4820. +
  4821. +#ifdef PFE_ETH_NAPI_STATS
  4822. + unsigned int napi_counters[NAPI_MAX_COUNT];
  4823. +#endif
  4824. + unsigned int frags_inflight[EMAC_RXQ_CNT + 6];
  4825. +};
  4826. +
  4827. +struct pfe_eth {
  4828. + struct pfe_eth_priv_s *eth_priv[3];
  4829. +};
  4830. +
  4831. +int pfe_eth_init(struct pfe *pfe);
  4832. +void pfe_eth_exit(struct pfe *pfe);
  4833. +int pfe_eth_suspend(struct net_device *dev);
  4834. +int pfe_eth_resume(struct net_device *dev);
  4835. +int pfe_eth_mdio_reset(struct mii_bus *bus);
  4836. +
  4837. +#endif /* _PFE_ETH_H_ */
  4838. diff --git a/drivers/staging/fsl_ppfe/pfe_firmware.c b/drivers/staging/fsl_ppfe/pfe_firmware.c
  4839. new file mode 100644
  4840. index 00000000..47462b9f
  4841. --- /dev/null
  4842. +++ b/drivers/staging/fsl_ppfe/pfe_firmware.c
  4843. @@ -0,0 +1,314 @@
  4844. +/*
  4845. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  4846. + * Copyright 2017 NXP
  4847. + *
  4848. + * This program is free software; you can redistribute it and/or modify
  4849. + * it under the terms of the GNU General Public License as published by
  4850. + * the Free Software Foundation; either version 2 of the License, or
  4851. + * (at your option) any later version.
  4852. + *
  4853. + * This program is distributed in the hope that it will be useful,
  4854. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4855. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4856. + * GNU General Public License for more details.
  4857. + *
  4858. + * You should have received a copy of the GNU General Public License
  4859. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  4860. + */
  4861. +
  4862. +/*
  4863. + * @file
  4864. + * Contains all the functions to handle parsing and loading of PE firmware
  4865. + * files.
  4866. + */
  4867. +#include <linux/firmware.h>
  4868. +
  4869. +#include "pfe_mod.h"
  4870. +#include "pfe_firmware.h"
  4871. +#include "pfe/pfe.h"
  4872. +
  4873. +static struct elf32_shdr *get_elf_section_header(const struct firmware *fw,
  4874. + const char *section)
  4875. +{
  4876. + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw->data;
  4877. + struct elf32_shdr *shdr;
  4878. + struct elf32_shdr *shdr_shstr;
  4879. + Elf32_Off e_shoff = be32_to_cpu(elf_hdr->e_shoff);
  4880. + Elf32_Half e_shentsize = be16_to_cpu(elf_hdr->e_shentsize);
  4881. + Elf32_Half e_shnum = be16_to_cpu(elf_hdr->e_shnum);
  4882. + Elf32_Half e_shstrndx = be16_to_cpu(elf_hdr->e_shstrndx);
  4883. + Elf32_Off shstr_offset;
  4884. + Elf32_Word sh_name;
  4885. + const char *name;
  4886. + int i;
  4887. +
  4888. + /* Section header strings */
  4889. + shdr_shstr = (struct elf32_shdr *)(fw->data + e_shoff + e_shstrndx *
  4890. + e_shentsize);
  4891. + shstr_offset = be32_to_cpu(shdr_shstr->sh_offset);
  4892. +
  4893. + for (i = 0; i < e_shnum; i++) {
  4894. + shdr = (struct elf32_shdr *)(fw->data + e_shoff
  4895. + + i * e_shentsize);
  4896. +
  4897. + sh_name = be32_to_cpu(shdr->sh_name);
  4898. +
  4899. + name = (const char *)(fw->data + shstr_offset + sh_name);
  4900. +
  4901. + if (!strcmp(name, section))
  4902. + return shdr;
  4903. + }
  4904. +
  4905. + pr_err("%s: didn't find section %s\n", __func__, section);
  4906. +
  4907. + return NULL;
  4908. +}
  4909. +
  4910. +#if defined(CFG_DIAGS)
  4911. +static int pfe_get_diags_info(const struct firmware *fw, struct pfe_diags_info
  4912. + *diags_info)
  4913. +{
  4914. + struct elf32_shdr *shdr;
  4915. + unsigned long offset, size;
  4916. +
  4917. + shdr = get_elf_section_header(fw, ".pfe_diags_str");
  4918. + if (shdr) {
  4919. + offset = be32_to_cpu(shdr->sh_offset);
  4920. + size = be32_to_cpu(shdr->sh_size);
  4921. + diags_info->diags_str_base = be32_to_cpu(shdr->sh_addr);
  4922. + diags_info->diags_str_size = size;
  4923. + diags_info->diags_str_array = kmalloc(size, GFP_KERNEL);
  4924. + memcpy(diags_info->diags_str_array, fw->data + offset, size);
  4925. +
  4926. + return 0;
  4927. + } else {
  4928. + return -1;
  4929. + }
  4930. +}
  4931. +#endif
  4932. +
  4933. +static void pfe_check_version_info(const struct firmware *fw)
  4934. +{
  4935. + /*static char *version = NULL;*/
  4936. + static char *version;
  4937. +
  4938. + struct elf32_shdr *shdr = get_elf_section_header(fw, ".version");
  4939. +
  4940. + if (shdr) {
  4941. + if (!version) {
  4942. + /*
  4943. + * this is the first fw we load, use its version
  4944. + * string as reference (whatever it is)
  4945. + */
  4946. + version = (char *)(fw->data +
  4947. + be32_to_cpu(shdr->sh_offset));
  4948. +
  4949. + pr_info("PFE binary version: %s\n", version);
  4950. + } else {
  4951. + /*
  4952. + * already have loaded at least one firmware, check
  4953. + * sequence can start now
  4954. + */
  4955. + if (strcmp(version, (char *)(fw->data +
  4956. + be32_to_cpu(shdr->sh_offset)))) {
  4957. + pr_info(
  4958. + "WARNING: PFE firmware binaries from incompatible version\n");
  4959. + }
  4960. + }
  4961. + } else {
  4962. + /*
  4963. + * version cannot be verified, a potential issue that should
  4964. + * be reported
  4965. + */
  4966. + pr_info(
  4967. + "WARNING: PFE firmware binaries from incompatible version\n");
  4968. + }
  4969. +}
  4970. +
  4971. +/* PFE elf firmware loader.
  4972. + * Loads an elf firmware image into a list of PE's (specified using a bitmask)
  4973. + *
  4974. + * @param pe_mask Mask of PE id's to load firmware to
  4975. + * @param fw Pointer to the firmware image
  4976. + *
  4977. + * @return 0 on success, a negative value on error
  4978. + *
  4979. + */
  4980. +int pfe_load_elf(int pe_mask, const struct firmware *fw, struct pfe *pfe)
  4981. +{
  4982. + struct elf32_hdr *elf_hdr = (struct elf32_hdr *)fw->data;
  4983. + Elf32_Half sections = be16_to_cpu(elf_hdr->e_shnum);
  4984. + struct elf32_shdr *shdr = (struct elf32_shdr *)(fw->data +
  4985. + be32_to_cpu(elf_hdr->e_shoff));
  4986. + int id, section;
  4987. + int rc;
  4988. +
  4989. + pr_info("%s\n", __func__);
  4990. +
  4991. + /* Some sanity checks */
  4992. + if (strncmp(&elf_hdr->e_ident[EI_MAG0], ELFMAG, SELFMAG)) {
  4993. + pr_err("%s: incorrect elf magic number\n", __func__);
  4994. + return -EINVAL;
  4995. + }
  4996. +
  4997. + if (elf_hdr->e_ident[EI_CLASS] != ELFCLASS32) {
  4998. + pr_err("%s: incorrect elf class(%x)\n", __func__,
  4999. + elf_hdr->e_ident[EI_CLASS]);
  5000. + return -EINVAL;
  5001. + }
  5002. +
  5003. + if (elf_hdr->e_ident[EI_DATA] != ELFDATA2MSB) {
  5004. + pr_err("%s: incorrect elf data(%x)\n", __func__,
  5005. + elf_hdr->e_ident[EI_DATA]);
  5006. + return -EINVAL;
  5007. + }
  5008. +
  5009. + if (be16_to_cpu(elf_hdr->e_type) != ET_EXEC) {
  5010. + pr_err("%s: incorrect elf file type(%x)\n", __func__,
  5011. + be16_to_cpu(elf_hdr->e_type));
  5012. + return -EINVAL;
  5013. + }
  5014. +
  5015. + for (section = 0; section < sections; section++, shdr++) {
  5016. + if (!(be32_to_cpu(shdr->sh_flags) & (SHF_WRITE | SHF_ALLOC |
  5017. + SHF_EXECINSTR)))
  5018. + continue;
  5019. +
  5020. + for (id = 0; id < MAX_PE; id++)
  5021. + if (pe_mask & (1 << id)) {
  5022. + rc = pe_load_elf_section(id, fw->data, shdr,
  5023. + pfe->dev);
  5024. + if (rc < 0)
  5025. + goto err;
  5026. + }
  5027. + }
  5028. +
  5029. + pfe_check_version_info(fw);
  5030. +
  5031. + return 0;
  5032. +
  5033. +err:
  5034. + return rc;
  5035. +}
  5036. +
  5037. +/* PFE firmware initialization.
  5038. + * Loads different firmware files from filesystem.
  5039. + * Initializes PE IMEM/DMEM and UTIL-PE DDR
  5040. + * Initializes control path symbol addresses (by looking them up in the elf
  5041. + * firmware files
  5042. + * Takes PE's out of reset
  5043. + *
  5044. + * @return 0 on success, a negative value on error
  5045. + *
  5046. + */
  5047. +int pfe_firmware_init(struct pfe *pfe)
  5048. +{
  5049. + const struct firmware *class_fw, *tmu_fw;
  5050. + int rc = 0;
  5051. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5052. + const char *util_fw_name;
  5053. + const struct firmware *util_fw;
  5054. +#endif
  5055. +
  5056. + pr_info("%s\n", __func__);
  5057. +
  5058. + if (request_firmware(&class_fw, CLASS_FIRMWARE_FILENAME, pfe->dev)) {
  5059. + pr_err("%s: request firmware %s failed\n", __func__,
  5060. + CLASS_FIRMWARE_FILENAME);
  5061. + rc = -ETIMEDOUT;
  5062. + goto err0;
  5063. + }
  5064. +
  5065. + if (request_firmware(&tmu_fw, TMU_FIRMWARE_FILENAME, pfe->dev)) {
  5066. + pr_err("%s: request firmware %s failed\n", __func__,
  5067. + TMU_FIRMWARE_FILENAME);
  5068. + rc = -ETIMEDOUT;
  5069. + goto err1;
  5070. +}
  5071. +
  5072. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5073. + util_fw_name = UTIL_FIRMWARE_FILENAME;
  5074. +
  5075. + if (request_firmware(&util_fw, util_fw_name, pfe->dev)) {
  5076. + pr_err("%s: request firmware %s failed\n", __func__,
  5077. + util_fw_name);
  5078. + rc = -ETIMEDOUT;
  5079. + goto err2;
  5080. + }
  5081. +#endif
  5082. + rc = pfe_load_elf(CLASS_MASK, class_fw, pfe);
  5083. + if (rc < 0) {
  5084. + pr_err("%s: class firmware load failed\n", __func__);
  5085. + goto err3;
  5086. + }
  5087. +
  5088. +#if defined(CFG_DIAGS)
  5089. + rc = pfe_get_diags_info(class_fw, &pfe->diags.class_diags_info);
  5090. + if (rc < 0) {
  5091. + pr_warn(
  5092. + "PFE diags won't be available for class PEs\n");
  5093. + rc = 0;
  5094. + }
  5095. +#endif
  5096. +
  5097. + rc = pfe_load_elf(TMU_MASK, tmu_fw, pfe);
  5098. + if (rc < 0) {
  5099. + pr_err("%s: tmu firmware load failed\n", __func__);
  5100. + goto err3;
  5101. + }
  5102. +
  5103. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5104. + rc = pfe_load_elf(UTIL_MASK, util_fw, pfe);
  5105. + if (rc < 0) {
  5106. + pr_err("%s: util firmware load failed\n", __func__);
  5107. + goto err3;
  5108. + }
  5109. +
  5110. +#if defined(CFG_DIAGS)
  5111. + rc = pfe_get_diags_info(util_fw, &pfe->diags.util_diags_info);
  5112. + if (rc < 0) {
  5113. + pr_warn(
  5114. + "PFE diags won't be available for util PE\n");
  5115. + rc = 0;
  5116. + }
  5117. +#endif
  5118. +
  5119. + util_enable();
  5120. +#endif
  5121. +
  5122. + tmu_enable(0xf);
  5123. + class_enable();
  5124. +
  5125. +err3:
  5126. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5127. + release_firmware(util_fw);
  5128. +
  5129. +err2:
  5130. +#endif
  5131. + release_firmware(tmu_fw);
  5132. +
  5133. +err1:
  5134. + release_firmware(class_fw);
  5135. +
  5136. +err0:
  5137. + return rc;
  5138. +}
  5139. +
  5140. +/* PFE firmware cleanup
  5141. + * Puts PE's in reset
  5142. + *
  5143. + *
  5144. + */
  5145. +void pfe_firmware_exit(struct pfe *pfe)
  5146. +{
  5147. + pr_info("%s\n", __func__);
  5148. +
  5149. + if (pe_reset_all(&pfe->ctrl) != 0)
  5150. + pr_err("Error: Failed to stop PEs, PFE reload may not work correctly\n");
  5151. +
  5152. + class_disable();
  5153. + tmu_disable(0xf);
  5154. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5155. + util_disable();
  5156. +#endif
  5157. +}
  5158. diff --git a/drivers/staging/fsl_ppfe/pfe_firmware.h b/drivers/staging/fsl_ppfe/pfe_firmware.h
  5159. new file mode 100644
  5160. index 00000000..5ade848b
  5161. --- /dev/null
  5162. +++ b/drivers/staging/fsl_ppfe/pfe_firmware.h
  5163. @@ -0,0 +1,32 @@
  5164. +/*
  5165. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  5166. + * Copyright 2017 NXP
  5167. + *
  5168. + * This program is free software; you can redistribute it and/or modify
  5169. + * it under the terms of the GNU General Public License as published by
  5170. + * the Free Software Foundation; either version 2 of the License, or
  5171. + * (at your option) any later version.
  5172. + *
  5173. + * This program is distributed in the hope that it will be useful,
  5174. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5175. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5176. + * GNU General Public License for more details.
  5177. + *
  5178. + * You should have received a copy of the GNU General Public License
  5179. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  5180. + */
  5181. +
  5182. +#ifndef _PFE_FIRMWARE_H_
  5183. +#define _PFE_FIRMWARE_H_
  5184. +
  5185. +#define CLASS_FIRMWARE_FILENAME "ppfe_class_ls1012a.elf"
  5186. +#define TMU_FIRMWARE_FILENAME "ppfe_tmu_ls1012a.elf"
  5187. +
  5188. +#define PFE_FW_CHECK_PASS 0
  5189. +#define PFE_FW_CHECK_FAIL 1
  5190. +#define NUM_PFE_FW 3
  5191. +
  5192. +int pfe_firmware_init(struct pfe *pfe);
  5193. +void pfe_firmware_exit(struct pfe *pfe);
  5194. +
  5195. +#endif /* _PFE_FIRMWARE_H_ */
  5196. diff --git a/drivers/staging/fsl_ppfe/pfe_hal.c b/drivers/staging/fsl_ppfe/pfe_hal.c
  5197. new file mode 100644
  5198. index 00000000..0915034b
  5199. --- /dev/null
  5200. +++ b/drivers/staging/fsl_ppfe/pfe_hal.c
  5201. @@ -0,0 +1,1516 @@
  5202. +/*
  5203. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  5204. + * Copyright 2017 NXP
  5205. + *
  5206. + * This program is free software; you can redistribute it and/or modify
  5207. + * it under the terms of the GNU General Public License as published by
  5208. + * the Free Software Foundation; either version 2 of the License, or
  5209. + * (at your option) any later version.
  5210. + *
  5211. + * This program is distributed in the hope that it will be useful,
  5212. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5213. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5214. + * GNU General Public License for more details.
  5215. + *
  5216. + * You should have received a copy of the GNU General Public License
  5217. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  5218. + */
  5219. +
  5220. +#include "pfe_mod.h"
  5221. +#include "pfe/pfe.h"
  5222. +
  5223. +void *cbus_base_addr;
  5224. +void *ddr_base_addr;
  5225. +unsigned long ddr_phys_base_addr;
  5226. +unsigned int ddr_size;
  5227. +
  5228. +static struct pe_info pe[MAX_PE];
  5229. +
  5230. +/* Initializes the PFE library.
  5231. + * Must be called before using any of the library functions.
  5232. + *
  5233. + * @param[in] cbus_base CBUS virtual base address (as mapped in
  5234. + * the host CPU address space)
  5235. + * @param[in] ddr_base PFE DDR range virtual base address (as
  5236. + * mapped in the host CPU address space)
  5237. + * @param[in] ddr_phys_base PFE DDR range physical base address (as
  5238. + * mapped in platform)
  5239. + * @param[in] size PFE DDR range size (as defined by the host
  5240. + * software)
  5241. + */
  5242. +void pfe_lib_init(void *cbus_base, void *ddr_base, unsigned long ddr_phys_base,
  5243. + unsigned int size)
  5244. +{
  5245. + cbus_base_addr = cbus_base;
  5246. + ddr_base_addr = ddr_base;
  5247. + ddr_phys_base_addr = ddr_phys_base;
  5248. + ddr_size = size;
  5249. +
  5250. + pe[CLASS0_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(0);
  5251. + pe[CLASS0_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(0);
  5252. + pe[CLASS0_ID].pmem_size = CLASS_IMEM_SIZE;
  5253. + pe[CLASS0_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5254. + pe[CLASS0_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5255. + pe[CLASS0_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5256. +
  5257. + pe[CLASS1_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(1);
  5258. + pe[CLASS1_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(1);
  5259. + pe[CLASS1_ID].pmem_size = CLASS_IMEM_SIZE;
  5260. + pe[CLASS1_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5261. + pe[CLASS1_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5262. + pe[CLASS1_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5263. +
  5264. + pe[CLASS2_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(2);
  5265. + pe[CLASS2_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(2);
  5266. + pe[CLASS2_ID].pmem_size = CLASS_IMEM_SIZE;
  5267. + pe[CLASS2_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5268. + pe[CLASS2_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5269. + pe[CLASS2_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5270. +
  5271. + pe[CLASS3_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(3);
  5272. + pe[CLASS3_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(3);
  5273. + pe[CLASS3_ID].pmem_size = CLASS_IMEM_SIZE;
  5274. + pe[CLASS3_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5275. + pe[CLASS3_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5276. + pe[CLASS3_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5277. +
  5278. + pe[CLASS4_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(4);
  5279. + pe[CLASS4_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(4);
  5280. + pe[CLASS4_ID].pmem_size = CLASS_IMEM_SIZE;
  5281. + pe[CLASS4_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5282. + pe[CLASS4_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5283. + pe[CLASS4_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5284. +
  5285. + pe[CLASS5_ID].dmem_base_addr = CLASS_DMEM_BASE_ADDR(5);
  5286. + pe[CLASS5_ID].pmem_base_addr = CLASS_IMEM_BASE_ADDR(5);
  5287. + pe[CLASS5_ID].pmem_size = CLASS_IMEM_SIZE;
  5288. + pe[CLASS5_ID].mem_access_wdata = CLASS_MEM_ACCESS_WDATA;
  5289. + pe[CLASS5_ID].mem_access_addr = CLASS_MEM_ACCESS_ADDR;
  5290. + pe[CLASS5_ID].mem_access_rdata = CLASS_MEM_ACCESS_RDATA;
  5291. +
  5292. + pe[TMU0_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(0);
  5293. + pe[TMU0_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(0);
  5294. + pe[TMU0_ID].pmem_size = TMU_IMEM_SIZE;
  5295. + pe[TMU0_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
  5296. + pe[TMU0_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
  5297. + pe[TMU0_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
  5298. +
  5299. + pe[TMU1_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(1);
  5300. + pe[TMU1_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(1);
  5301. + pe[TMU1_ID].pmem_size = TMU_IMEM_SIZE;
  5302. + pe[TMU1_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
  5303. + pe[TMU1_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
  5304. + pe[TMU1_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
  5305. +
  5306. + pe[TMU3_ID].dmem_base_addr = TMU_DMEM_BASE_ADDR(3);
  5307. + pe[TMU3_ID].pmem_base_addr = TMU_IMEM_BASE_ADDR(3);
  5308. + pe[TMU3_ID].pmem_size = TMU_IMEM_SIZE;
  5309. + pe[TMU3_ID].mem_access_wdata = TMU_MEM_ACCESS_WDATA;
  5310. + pe[TMU3_ID].mem_access_addr = TMU_MEM_ACCESS_ADDR;
  5311. + pe[TMU3_ID].mem_access_rdata = TMU_MEM_ACCESS_RDATA;
  5312. +
  5313. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5314. + pe[UTIL_ID].dmem_base_addr = UTIL_DMEM_BASE_ADDR;
  5315. + pe[UTIL_ID].mem_access_wdata = UTIL_MEM_ACCESS_WDATA;
  5316. + pe[UTIL_ID].mem_access_addr = UTIL_MEM_ACCESS_ADDR;
  5317. + pe[UTIL_ID].mem_access_rdata = UTIL_MEM_ACCESS_RDATA;
  5318. +#endif
  5319. +}
  5320. +
  5321. +/* Writes a buffer to PE internal memory from the host
  5322. + * through indirect access registers.
  5323. + *
  5324. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5325. + * ..., UTIL_ID)
  5326. + * @param[in] src Buffer source address
  5327. + * @param[in] mem_access_addr DMEM destination address (must be 32bit
  5328. + * aligned)
  5329. + * @param[in] len Number of bytes to copy
  5330. + */
  5331. +void pe_mem_memcpy_to32(int id, u32 mem_access_addr, const void *src, unsigned
  5332. +int len)
  5333. +{
  5334. + u32 offset = 0, val, addr;
  5335. + unsigned int len32 = len >> 2;
  5336. + int i;
  5337. +
  5338. + addr = mem_access_addr | PE_MEM_ACCESS_WRITE |
  5339. + PE_MEM_ACCESS_BYTE_ENABLE(0, 4);
  5340. +
  5341. + for (i = 0; i < len32; i++, offset += 4, src += 4) {
  5342. + val = *(u32 *)src;
  5343. + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
  5344. + writel(addr + offset, pe[id].mem_access_addr);
  5345. + }
  5346. +
  5347. + len = (len & 0x3);
  5348. + if (len) {
  5349. + val = 0;
  5350. +
  5351. + addr = (mem_access_addr | PE_MEM_ACCESS_WRITE |
  5352. + PE_MEM_ACCESS_BYTE_ENABLE(0, len)) + offset;
  5353. +
  5354. + for (i = 0; i < len; i++, src++)
  5355. + val |= (*(u8 *)src) << (8 * i);
  5356. +
  5357. + writel(cpu_to_be32(val), pe[id].mem_access_wdata);
  5358. + writel(addr, pe[id].mem_access_addr);
  5359. + }
  5360. +}
  5361. +
  5362. +/* Writes a buffer to PE internal data memory (DMEM) from the host
  5363. + * through indirect access registers.
  5364. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5365. + * ..., UTIL_ID)
  5366. + * @param[in] src Buffer source address
  5367. + * @param[in] dst DMEM destination address (must be 32bit
  5368. + * aligned)
  5369. + * @param[in] len Number of bytes to copy
  5370. + */
  5371. +void pe_dmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
  5372. +{
  5373. + pe_mem_memcpy_to32(id, pe[id].dmem_base_addr | dst |
  5374. + PE_MEM_ACCESS_DMEM, src, len);
  5375. +}
  5376. +
  5377. +/* Writes a buffer to PE internal program memory (PMEM) from the host
  5378. + * through indirect access registers.
  5379. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5380. + * ..., TMU3_ID)
  5381. + * @param[in] src Buffer source address
  5382. + * @param[in] dst PMEM destination address (must be 32bit
  5383. + * aligned)
  5384. + * @param[in] len Number of bytes to copy
  5385. + */
  5386. +void pe_pmem_memcpy_to32(int id, u32 dst, const void *src, unsigned int len)
  5387. +{
  5388. + pe_mem_memcpy_to32(id, pe[id].pmem_base_addr | (dst & (pe[id].pmem_size
  5389. + - 1)) | PE_MEM_ACCESS_IMEM, src, len);
  5390. +}
  5391. +
  5392. +/* Reads PE internal program memory (IMEM) from the host
  5393. + * through indirect access registers.
  5394. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5395. + * ..., TMU3_ID)
  5396. + * @param[in] addr PMEM read address (must be aligned on size)
  5397. + * @param[in] size Number of bytes to read (maximum 4, must not
  5398. + * cross 32bit boundaries)
  5399. + * @return the data read (in PE endianness, i.e BE).
  5400. + */
  5401. +u32 pe_pmem_read(int id, u32 addr, u8 size)
  5402. +{
  5403. + u32 offset = addr & 0x3;
  5404. + u32 mask = 0xffffffff >> ((4 - size) << 3);
  5405. + u32 val;
  5406. +
  5407. + addr = pe[id].pmem_base_addr | ((addr & ~0x3) & (pe[id].pmem_size - 1))
  5408. + | PE_MEM_ACCESS_IMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
  5409. +
  5410. + writel(addr, pe[id].mem_access_addr);
  5411. + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
  5412. +
  5413. + return (val >> (offset << 3)) & mask;
  5414. +}
  5415. +
  5416. +/* Writes PE internal data memory (DMEM) from the host
  5417. + * through indirect access registers.
  5418. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5419. + * ..., UTIL_ID)
  5420. + * @param[in] addr DMEM write address (must be aligned on size)
  5421. + * @param[in] val Value to write (in PE endianness, i.e BE)
  5422. + * @param[in] size Number of bytes to write (maximum 4, must not
  5423. + * cross 32bit boundaries)
  5424. + */
  5425. +void pe_dmem_write(int id, u32 val, u32 addr, u8 size)
  5426. +{
  5427. + u32 offset = addr & 0x3;
  5428. +
  5429. + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_WRITE |
  5430. + PE_MEM_ACCESS_DMEM | PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
  5431. +
  5432. + /* Indirect access interface is byte swapping data being written */
  5433. + writel(cpu_to_be32(val << (offset << 3)), pe[id].mem_access_wdata);
  5434. + writel(addr, pe[id].mem_access_addr);
  5435. +}
  5436. +
  5437. +/* Reads PE internal data memory (DMEM) from the host
  5438. + * through indirect access registers.
  5439. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5440. + * ..., UTIL_ID)
  5441. + * @param[in] addr DMEM read address (must be aligned on size)
  5442. + * @param[in] size Number of bytes to read (maximum 4, must not
  5443. + * cross 32bit boundaries)
  5444. + * @return the data read (in PE endianness, i.e BE).
  5445. + */
  5446. +u32 pe_dmem_read(int id, u32 addr, u8 size)
  5447. +{
  5448. + u32 offset = addr & 0x3;
  5449. + u32 mask = 0xffffffff >> ((4 - size) << 3);
  5450. + u32 val;
  5451. +
  5452. + addr = pe[id].dmem_base_addr | (addr & ~0x3) | PE_MEM_ACCESS_DMEM |
  5453. + PE_MEM_ACCESS_BYTE_ENABLE(offset, size);
  5454. +
  5455. + writel(addr, pe[id].mem_access_addr);
  5456. +
  5457. + /* Indirect access interface is byte swapping data being read */
  5458. + val = be32_to_cpu(readl(pe[id].mem_access_rdata));
  5459. +
  5460. + return (val >> (offset << 3)) & mask;
  5461. +}
  5462. +
  5463. +/* This function is used to write to CLASS internal bus peripherals (ccu,
  5464. + * pe-lem) from the host
  5465. + * through indirect access registers.
  5466. + * @param[in] val value to write
  5467. + * @param[in] addr Address to write to (must be aligned on size)
  5468. + * @param[in] size Number of bytes to write (1, 2 or 4)
  5469. + *
  5470. + */
  5471. +void class_bus_write(u32 val, u32 addr, u8 size)
  5472. +{
  5473. + u32 offset = addr & 0x3;
  5474. +
  5475. + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
  5476. +
  5477. + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | PE_MEM_ACCESS_WRITE |
  5478. + (size << 24);
  5479. +
  5480. + writel(cpu_to_be32(val << (offset << 3)), CLASS_BUS_ACCESS_WDATA);
  5481. + writel(addr, CLASS_BUS_ACCESS_ADDR);
  5482. +}
  5483. +
  5484. +/* Reads from CLASS internal bus peripherals (ccu, pe-lem) from the host
  5485. + * through indirect access registers.
  5486. + * @param[in] addr Address to read from (must be aligned on size)
  5487. + * @param[in] size Number of bytes to read (1, 2 or 4)
  5488. + * @return the read data
  5489. + *
  5490. + */
  5491. +u32 class_bus_read(u32 addr, u8 size)
  5492. +{
  5493. + u32 offset = addr & 0x3;
  5494. + u32 mask = 0xffffffff >> ((4 - size) << 3);
  5495. + u32 val;
  5496. +
  5497. + writel((addr & CLASS_BUS_ACCESS_BASE_MASK), CLASS_BUS_ACCESS_BASE);
  5498. +
  5499. + addr = (addr & ~CLASS_BUS_ACCESS_BASE_MASK) | (size << 24);
  5500. +
  5501. + writel(addr, CLASS_BUS_ACCESS_ADDR);
  5502. + val = be32_to_cpu(readl(CLASS_BUS_ACCESS_RDATA));
  5503. +
  5504. + return (val >> (offset << 3)) & mask;
  5505. +}
  5506. +
  5507. +/* Writes data to the cluster memory (PE_LMEM)
  5508. + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
  5509. + * @param[in] src Buffer source address
  5510. + * @param[in] len Number of bytes to copy
  5511. + */
  5512. +void class_pe_lmem_memcpy_to32(u32 dst, const void *src, unsigned int len)
  5513. +{
  5514. + u32 len32 = len >> 2;
  5515. + int i;
  5516. +
  5517. + for (i = 0; i < len32; i++, src += 4, dst += 4)
  5518. + class_bus_write(*(u32 *)src, dst, 4);
  5519. +
  5520. + if (len & 0x2) {
  5521. + class_bus_write(*(u16 *)src, dst, 2);
  5522. + src += 2;
  5523. + dst += 2;
  5524. + }
  5525. +
  5526. + if (len & 0x1) {
  5527. + class_bus_write(*(u8 *)src, dst, 1);
  5528. + src++;
  5529. + dst++;
  5530. + }
  5531. +}
  5532. +
  5533. +/* Writes value to the cluster memory (PE_LMEM)
  5534. + * @param[in] dst PE LMEM destination address (must be 32bit aligned)
  5535. + * @param[in] val Value to write
  5536. + * @param[in] len Number of bytes to write
  5537. + */
  5538. +void class_pe_lmem_memset(u32 dst, int val, unsigned int len)
  5539. +{
  5540. + u32 len32 = len >> 2;
  5541. + int i;
  5542. +
  5543. + val = val | (val << 8) | (val << 16) | (val << 24);
  5544. +
  5545. + for (i = 0; i < len32; i++, dst += 4)
  5546. + class_bus_write(val, dst, 4);
  5547. +
  5548. + if (len & 0x2) {
  5549. + class_bus_write(val, dst, 2);
  5550. + dst += 2;
  5551. + }
  5552. +
  5553. + if (len & 0x1) {
  5554. + class_bus_write(val, dst, 1);
  5555. + dst++;
  5556. + }
  5557. +}
  5558. +
  5559. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5560. +
  5561. +/* Writes UTIL program memory (DDR) from the host.
  5562. + *
  5563. + * @param[in] addr Address to write (virtual, must be aligned on size)
  5564. + * @param[in] val Value to write (in PE endianness, i.e BE)
  5565. + * @param[in] size Number of bytes to write (2 or 4)
  5566. + */
  5567. +static void util_pmem_write(u32 val, void *addr, u8 size)
  5568. +{
  5569. + void *addr64 = (void *)((unsigned long)addr & ~0x7);
  5570. + unsigned long off = 8 - ((unsigned long)addr & 0x7) - size;
  5571. +
  5572. + /*
  5573. + * IMEM should be loaded as a 64bit swapped value in a 64bit aligned
  5574. + * location
  5575. + */
  5576. + if (size == 4)
  5577. + writel(be32_to_cpu(val), addr64 + off);
  5578. + else
  5579. + writew(be16_to_cpu((u16)val), addr64 + off);
  5580. +}
  5581. +
  5582. +/* Writes a buffer to UTIL program memory (DDR) from the host.
  5583. + *
  5584. + * @param[in] dst Address to write (virtual, must be at least 16bit
  5585. + * aligned)
  5586. + * @param[in] src Buffer to write (in PE endianness, i.e BE, must have
  5587. + * same alignment as dst)
  5588. + * @param[in] len Number of bytes to write (must be at least 16bit
  5589. + * aligned)
  5590. + */
  5591. +static void util_pmem_memcpy(void *dst, const void *src, unsigned int len)
  5592. +{
  5593. + unsigned int len32;
  5594. + int i;
  5595. +
  5596. + if ((unsigned long)src & 0x2) {
  5597. + util_pmem_write(*(u16 *)src, dst, 2);
  5598. + src += 2;
  5599. + dst += 2;
  5600. + len -= 2;
  5601. + }
  5602. +
  5603. + len32 = len >> 2;
  5604. +
  5605. + for (i = 0; i < len32; i++, dst += 4, src += 4)
  5606. + util_pmem_write(*(u32 *)src, dst, 4);
  5607. +
  5608. + if (len & 0x2)
  5609. + util_pmem_write(*(u16 *)src, dst, len & 0x2);
  5610. +}
  5611. +#endif
  5612. +
  5613. +/* Loads an elf section into pmem
  5614. + * Code needs to be at least 16bit aligned and only PROGBITS sections are
  5615. + * supported
  5616. + *
  5617. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID, ...,
  5618. + * TMU3_ID)
  5619. + * @param[in] data pointer to the elf firmware
  5620. + * @param[in] shdr pointer to the elf section header
  5621. + *
  5622. + */
  5623. +static int pe_load_pmem_section(int id, const void *data,
  5624. + struct elf32_shdr *shdr)
  5625. +{
  5626. + u32 offset = be32_to_cpu(shdr->sh_offset);
  5627. + u32 addr = be32_to_cpu(shdr->sh_addr);
  5628. + u32 size = be32_to_cpu(shdr->sh_size);
  5629. + u32 type = be32_to_cpu(shdr->sh_type);
  5630. +
  5631. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5632. + if (id == UTIL_ID) {
  5633. + pr_err("%s: unsupported pmem section for UTIL\n",
  5634. + __func__);
  5635. + return -EINVAL;
  5636. + }
  5637. +#endif
  5638. +
  5639. + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
  5640. + pr_err(
  5641. + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
  5642. + , __func__, addr, (unsigned long)data + offset);
  5643. +
  5644. + return -EINVAL;
  5645. + }
  5646. +
  5647. + if (addr & 0x1) {
  5648. + pr_err("%s: load address(%x) is not 16bit aligned\n",
  5649. + __func__, addr);
  5650. + return -EINVAL;
  5651. + }
  5652. +
  5653. + if (size & 0x1) {
  5654. + pr_err("%s: load size(%x) is not 16bit aligned\n",
  5655. + __func__, size);
  5656. + return -EINVAL;
  5657. + }
  5658. +
  5659. + switch (type) {
  5660. + case SHT_PROGBITS:
  5661. + pe_pmem_memcpy_to32(id, addr, data + offset, size);
  5662. +
  5663. + break;
  5664. +
  5665. + default:
  5666. + pr_err("%s: unsupported section type(%x)\n", __func__,
  5667. + type);
  5668. + return -EINVAL;
  5669. + }
  5670. +
  5671. + return 0;
  5672. +}
  5673. +
  5674. +/* Loads an elf section into dmem
  5675. + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
  5676. + * initialized to 0
  5677. + *
  5678. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5679. + * ..., UTIL_ID)
  5680. + * @param[in] data pointer to the elf firmware
  5681. + * @param[in] shdr pointer to the elf section header
  5682. + *
  5683. + */
  5684. +static int pe_load_dmem_section(int id, const void *data,
  5685. + struct elf32_shdr *shdr)
  5686. +{
  5687. + u32 offset = be32_to_cpu(shdr->sh_offset);
  5688. + u32 addr = be32_to_cpu(shdr->sh_addr);
  5689. + u32 size = be32_to_cpu(shdr->sh_size);
  5690. + u32 type = be32_to_cpu(shdr->sh_type);
  5691. + u32 size32 = size >> 2;
  5692. + int i;
  5693. +
  5694. + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
  5695. + pr_err(
  5696. + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
  5697. + __func__, addr, (unsigned long)data + offset);
  5698. +
  5699. + return -EINVAL;
  5700. + }
  5701. +
  5702. + if (addr & 0x3) {
  5703. + pr_err("%s: load address(%x) is not 32bit aligned\n",
  5704. + __func__, addr);
  5705. + return -EINVAL;
  5706. + }
  5707. +
  5708. + switch (type) {
  5709. + case SHT_PROGBITS:
  5710. + pe_dmem_memcpy_to32(id, addr, data + offset, size);
  5711. + break;
  5712. +
  5713. + case SHT_NOBITS:
  5714. + for (i = 0; i < size32; i++, addr += 4)
  5715. + pe_dmem_write(id, 0, addr, 4);
  5716. +
  5717. + if (size & 0x3)
  5718. + pe_dmem_write(id, 0, addr, size & 0x3);
  5719. +
  5720. + break;
  5721. +
  5722. + default:
  5723. + pr_err("%s: unsupported section type(%x)\n", __func__,
  5724. + type);
  5725. + return -EINVAL;
  5726. + }
  5727. +
  5728. + return 0;
  5729. +}
  5730. +
  5731. +/* Loads an elf section into DDR
  5732. + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
  5733. + * initialized to 0
  5734. + *
  5735. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5736. + * ..., UTIL_ID)
  5737. + * @param[in] data pointer to the elf firmware
  5738. + * @param[in] shdr pointer to the elf section header
  5739. + *
  5740. + */
  5741. +static int pe_load_ddr_section(int id, const void *data,
  5742. + struct elf32_shdr *shdr,
  5743. + struct device *dev) {
  5744. + u32 offset = be32_to_cpu(shdr->sh_offset);
  5745. + u32 addr = be32_to_cpu(shdr->sh_addr);
  5746. + u32 size = be32_to_cpu(shdr->sh_size);
  5747. + u32 type = be32_to_cpu(shdr->sh_type);
  5748. + u32 flags = be32_to_cpu(shdr->sh_flags);
  5749. +
  5750. + switch (type) {
  5751. + case SHT_PROGBITS:
  5752. + if (flags & SHF_EXECINSTR) {
  5753. + if (id <= CLASS_MAX_ID) {
  5754. + /* DO the loading only once in DDR */
  5755. + if (id == CLASS0_ID) {
  5756. + pr_err(
  5757. + "%s: load address(%x) and elf file address(%lx) rcvd\n",
  5758. + __func__, addr,
  5759. + (unsigned long)data + offset);
  5760. + if (((unsigned long)(data + offset)
  5761. + & 0x3) != (addr & 0x3)) {
  5762. + pr_err(
  5763. + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
  5764. + , __func__, addr,
  5765. + (unsigned long)data + offset);
  5766. +
  5767. + return -EINVAL;
  5768. + }
  5769. +
  5770. + if (addr & 0x1) {
  5771. + pr_err(
  5772. + "%s: load address(%x) is not 16bit aligned\n"
  5773. + , __func__, addr);
  5774. + return -EINVAL;
  5775. + }
  5776. +
  5777. + if (size & 0x1) {
  5778. + pr_err(
  5779. + "%s: load length(%x) is not 16bit aligned\n"
  5780. + , __func__, size);
  5781. + return -EINVAL;
  5782. + }
  5783. + memcpy(DDR_PHYS_TO_VIRT(
  5784. + DDR_PFE_TO_PHYS(addr)),
  5785. + data + offset, size);
  5786. + }
  5787. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  5788. + } else if (id == UTIL_ID) {
  5789. + if (((unsigned long)(data + offset) & 0x3)
  5790. + != (addr & 0x3)) {
  5791. + pr_err(
  5792. + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n"
  5793. + , __func__, addr,
  5794. + (unsigned long)data + offset);
  5795. +
  5796. + return -EINVAL;
  5797. + }
  5798. +
  5799. + if (addr & 0x1) {
  5800. + pr_err(
  5801. + "%s: load address(%x) is not 16bit aligned\n"
  5802. + , __func__, addr);
  5803. + return -EINVAL;
  5804. + }
  5805. +
  5806. + if (size & 0x1) {
  5807. + pr_err(
  5808. + "%s: load length(%x) is not 16bit aligned\n"
  5809. + , __func__, size);
  5810. + return -EINVAL;
  5811. + }
  5812. +
  5813. + util_pmem_memcpy(DDR_PHYS_TO_VIRT(
  5814. + DDR_PFE_TO_PHYS(addr)),
  5815. + data + offset, size);
  5816. + }
  5817. +#endif
  5818. + } else {
  5819. + pr_err(
  5820. + "%s: unsupported ddr section type(%x) for PE(%d)\n"
  5821. + , __func__, type, id);
  5822. + return -EINVAL;
  5823. + }
  5824. +
  5825. + } else {
  5826. + memcpy(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), data
  5827. + + offset, size);
  5828. + }
  5829. +
  5830. + break;
  5831. +
  5832. + case SHT_NOBITS:
  5833. + memset(DDR_PHYS_TO_VIRT(DDR_PFE_TO_PHYS(addr)), 0, size);
  5834. +
  5835. + break;
  5836. +
  5837. + default:
  5838. + pr_err("%s: unsupported section type(%x)\n", __func__,
  5839. + type);
  5840. + return -EINVAL;
  5841. + }
  5842. +
  5843. + return 0;
  5844. +}
  5845. +
  5846. +/* Loads an elf section into pe lmem
  5847. + * Data needs to be at least 32bit aligned, NOBITS sections are correctly
  5848. + * initialized to 0
  5849. + *
  5850. + * @param[in] id PE identification (CLASS0_ID,..., CLASS5_ID)
  5851. + * @param[in] data pointer to the elf firmware
  5852. + * @param[in] shdr pointer to the elf section header
  5853. + *
  5854. + */
  5855. +static int pe_load_pe_lmem_section(int id, const void *data,
  5856. + struct elf32_shdr *shdr)
  5857. +{
  5858. + u32 offset = be32_to_cpu(shdr->sh_offset);
  5859. + u32 addr = be32_to_cpu(shdr->sh_addr);
  5860. + u32 size = be32_to_cpu(shdr->sh_size);
  5861. + u32 type = be32_to_cpu(shdr->sh_type);
  5862. +
  5863. + if (id > CLASS_MAX_ID) {
  5864. + pr_err(
  5865. + "%s: unsupported pe-lmem section type(%x) for PE(%d)\n",
  5866. + __func__, type, id);
  5867. + return -EINVAL;
  5868. + }
  5869. +
  5870. + if (((unsigned long)(data + offset) & 0x3) != (addr & 0x3)) {
  5871. + pr_err(
  5872. + "%s: load address(%x) and elf file address(%lx) don't have the same alignment\n",
  5873. + __func__, addr, (unsigned long)data + offset);
  5874. +
  5875. + return -EINVAL;
  5876. + }
  5877. +
  5878. + if (addr & 0x3) {
  5879. + pr_err("%s: load address(%x) is not 32bit aligned\n",
  5880. + __func__, addr);
  5881. + return -EINVAL;
  5882. + }
  5883. +
  5884. + switch (type) {
  5885. + case SHT_PROGBITS:
  5886. + class_pe_lmem_memcpy_to32(addr, data + offset, size);
  5887. + break;
  5888. +
  5889. + case SHT_NOBITS:
  5890. + class_pe_lmem_memset(addr, 0, size);
  5891. + break;
  5892. +
  5893. + default:
  5894. + pr_err("%s: unsupported section type(%x)\n", __func__,
  5895. + type);
  5896. + return -EINVAL;
  5897. + }
  5898. +
  5899. + return 0;
  5900. +}
  5901. +
  5902. +/* Loads an elf section into a PE
  5903. + * For now only supports loading a section to dmem (all PE's), pmem (class and
  5904. + * tmu PE's),
  5905. + * DDDR (util PE code)
  5906. + *
  5907. + * @param[in] id PE identification (CLASS0_ID, ..., TMU0_ID,
  5908. + * ..., UTIL_ID)
  5909. + * @param[in] data pointer to the elf firmware
  5910. + * @param[in] shdr pointer to the elf section header
  5911. + *
  5912. + */
  5913. +int pe_load_elf_section(int id, const void *data, struct elf32_shdr *shdr,
  5914. + struct device *dev) {
  5915. + u32 addr = be32_to_cpu(shdr->sh_addr);
  5916. + u32 size = be32_to_cpu(shdr->sh_size);
  5917. +
  5918. + if (IS_DMEM(addr, size))
  5919. + return pe_load_dmem_section(id, data, shdr);
  5920. + else if (IS_PMEM(addr, size))
  5921. + return pe_load_pmem_section(id, data, shdr);
  5922. + else if (IS_PFE_LMEM(addr, size))
  5923. + return 0;
  5924. + else if (IS_PHYS_DDR(addr, size))
  5925. + return pe_load_ddr_section(id, data, shdr, dev);
  5926. + else if (IS_PE_LMEM(addr, size))
  5927. + return pe_load_pe_lmem_section(id, data, shdr);
  5928. +
  5929. + pr_err("%s: unsupported memory range(%x)\n", __func__,
  5930. + addr);
  5931. + return 0;
  5932. +}
  5933. +
  5934. +/**************************** BMU ***************************/
  5935. +
  5936. +/* Initializes a BMU block.
  5937. + * @param[in] base BMU block base address
  5938. + * @param[in] cfg BMU configuration
  5939. + */
  5940. +void bmu_init(void *base, struct BMU_CFG *cfg)
  5941. +{
  5942. + bmu_disable(base);
  5943. +
  5944. + bmu_set_config(base, cfg);
  5945. +
  5946. + bmu_reset(base);
  5947. +}
  5948. +
  5949. +/* Resets a BMU block.
  5950. + * @param[in] base BMU block base address
  5951. + */
  5952. +void bmu_reset(void *base)
  5953. +{
  5954. + writel(CORE_SW_RESET, base + BMU_CTRL);
  5955. +
  5956. + /* Wait for self clear */
  5957. + while (readl(base + BMU_CTRL) & CORE_SW_RESET)
  5958. + ;
  5959. +}
  5960. +
  5961. +/* Enabled a BMU block.
  5962. + * @param[in] base BMU block base address
  5963. + */
  5964. +void bmu_enable(void *base)
  5965. +{
  5966. + writel(CORE_ENABLE, base + BMU_CTRL);
  5967. +}
  5968. +
  5969. +/* Disables a BMU block.
  5970. + * @param[in] base BMU block base address
  5971. + */
  5972. +void bmu_disable(void *base)
  5973. +{
  5974. + writel(CORE_DISABLE, base + BMU_CTRL);
  5975. +}
  5976. +
  5977. +/* Sets the configuration of a BMU block.
  5978. + * @param[in] base BMU block base address
  5979. + * @param[in] cfg BMU configuration
  5980. + */
  5981. +void bmu_set_config(void *base, struct BMU_CFG *cfg)
  5982. +{
  5983. + writel(cfg->baseaddr, base + BMU_UCAST_BASE_ADDR);
  5984. + writel(cfg->count & 0xffff, base + BMU_UCAST_CONFIG);
  5985. + writel(cfg->size & 0xffff, base + BMU_BUF_SIZE);
  5986. +
  5987. + /* Interrupts are never used */
  5988. + writel(cfg->low_watermark, base + BMU_LOW_WATERMARK);
  5989. + writel(cfg->high_watermark, base + BMU_HIGH_WATERMARK);
  5990. + writel(0x0, base + BMU_INT_ENABLE);
  5991. +}
  5992. +
  5993. +/**************************** MTIP GEMAC ***************************/
  5994. +
  5995. +/* Enable Rx Checksum Engine. With this enabled, Frame with bad IP,
  5996. + * TCP or UDP checksums are discarded
  5997. + *
  5998. + * @param[in] base GEMAC base address.
  5999. + */
  6000. +void gemac_enable_rx_checksum_offload(void *base)
  6001. +{
  6002. + /*Do not find configuration to do this */
  6003. +}
  6004. +
  6005. +/* Disable Rx Checksum Engine.
  6006. + *
  6007. + * @param[in] base GEMAC base address.
  6008. + */
  6009. +void gemac_disable_rx_checksum_offload(void *base)
  6010. +{
  6011. + /*Do not find configuration to do this */
  6012. +}
  6013. +
  6014. +/* GEMAC set speed.
  6015. + * @param[in] base GEMAC base address
  6016. + * @param[in] speed GEMAC speed (10, 100 or 1000 Mbps)
  6017. + */
  6018. +void gemac_set_speed(void *base, enum mac_speed gem_speed)
  6019. +{
  6020. + u32 ecr = readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_SPEED;
  6021. + u32 rcr = readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_RMII_10T;
  6022. +
  6023. + switch (gem_speed) {
  6024. + case SPEED_10M:
  6025. + rcr |= EMAC_RCNTRL_RMII_10T;
  6026. + break;
  6027. +
  6028. + case SPEED_1000M:
  6029. + ecr |= EMAC_ECNTRL_SPEED;
  6030. + break;
  6031. +
  6032. + case SPEED_100M:
  6033. + default:
  6034. + /*It is in 100M mode */
  6035. + break;
  6036. + }
  6037. + writel(ecr, (base + EMAC_ECNTRL_REG));
  6038. + writel(rcr, (base + EMAC_RCNTRL_REG));
  6039. +}
  6040. +
  6041. +/* GEMAC set duplex.
  6042. + * @param[in] base GEMAC base address
  6043. + * @param[in] duplex GEMAC duplex mode (Full, Half)
  6044. + */
  6045. +void gemac_set_duplex(void *base, int duplex)
  6046. +{
  6047. + if (duplex == DUPLEX_HALF) {
  6048. + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_FDEN, base
  6049. + + EMAC_TCNTRL_REG);
  6050. + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_DRT, (base
  6051. + + EMAC_RCNTRL_REG));
  6052. + } else{
  6053. + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_FDEN, base
  6054. + + EMAC_TCNTRL_REG);
  6055. + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_DRT, (base
  6056. + + EMAC_RCNTRL_REG));
  6057. + }
  6058. +}
  6059. +
  6060. +/* GEMAC set mode.
  6061. + * @param[in] base GEMAC base address
  6062. + * @param[in] mode GEMAC operation mode (MII, RMII, RGMII, SGMII)
  6063. + */
  6064. +void gemac_set_mode(void *base, int mode)
  6065. +{
  6066. + u32 val = readl(base + EMAC_RCNTRL_REG);
  6067. +
  6068. + /*Remove loopbank*/
  6069. + val &= ~EMAC_RCNTRL_LOOP;
  6070. +
  6071. + /*Enable flow control and MII mode*/
  6072. + val |= (EMAC_RCNTRL_FCE | EMAC_RCNTRL_MII_MODE);
  6073. +
  6074. + writel(val, base + EMAC_RCNTRL_REG);
  6075. +}
  6076. +
  6077. +/* GEMAC enable function.
  6078. + * @param[in] base GEMAC base address
  6079. + */
  6080. +void gemac_enable(void *base)
  6081. +{
  6082. + writel(readl(base + EMAC_ECNTRL_REG) | EMAC_ECNTRL_ETHER_EN, base +
  6083. + EMAC_ECNTRL_REG);
  6084. +}
  6085. +
  6086. +/* GEMAC disable function.
  6087. + * @param[in] base GEMAC base address
  6088. + */
  6089. +void gemac_disable(void *base)
  6090. +{
  6091. + writel(readl(base + EMAC_ECNTRL_REG) & ~EMAC_ECNTRL_ETHER_EN, base +
  6092. + EMAC_ECNTRL_REG);
  6093. +}
  6094. +
  6095. +/* GEMAC TX disable function.
  6096. + * @param[in] base GEMAC base address
  6097. + */
  6098. +void gemac_tx_disable(void *base)
  6099. +{
  6100. + writel(readl(base + EMAC_TCNTRL_REG) | EMAC_TCNTRL_GTS, base +
  6101. + EMAC_TCNTRL_REG);
  6102. +}
  6103. +
  6104. +void gemac_tx_enable(void *base)
  6105. +{
  6106. + writel(readl(base + EMAC_TCNTRL_REG) & ~EMAC_TCNTRL_GTS, base +
  6107. + EMAC_TCNTRL_REG);
  6108. +}
  6109. +
  6110. +/* Sets the hash register of the MAC.
  6111. + * This register is used for matching unicast and multicast frames.
  6112. + *
  6113. + * @param[in] base GEMAC base address.
  6114. + * @param[in] hash 64-bit hash to be configured.
  6115. + */
  6116. +void gemac_set_hash(void *base, struct pfe_mac_addr *hash)
  6117. +{
  6118. + writel(hash->bottom, base + EMAC_GALR);
  6119. + writel(hash->top, base + EMAC_GAUR);
  6120. +}
  6121. +
  6122. +void gemac_set_laddrN(void *base, struct pfe_mac_addr *address,
  6123. + unsigned int entry_index)
  6124. +{
  6125. + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
  6126. + return;
  6127. +
  6128. + entry_index = entry_index - 1;
  6129. + if (entry_index < 1) {
  6130. + writel(htonl(address->bottom), base + EMAC_PHY_ADDR_LOW);
  6131. + writel((htonl(address->top) | 0x8808), base +
  6132. + EMAC_PHY_ADDR_HIGH);
  6133. + } else {
  6134. + writel(htonl(address->bottom), base + ((entry_index - 1) * 8)
  6135. + + EMAC_SMAC_0_0);
  6136. + writel((htonl(address->top) | 0x8808), base + ((entry_index -
  6137. + 1) * 8) + EMAC_SMAC_0_1);
  6138. + }
  6139. +}
  6140. +
  6141. +void gemac_clear_laddrN(void *base, unsigned int entry_index)
  6142. +{
  6143. + if ((entry_index < 1) || (entry_index > EMAC_SPEC_ADDR_MAX))
  6144. + return;
  6145. +
  6146. + entry_index = entry_index - 1;
  6147. + if (entry_index < 1) {
  6148. + writel(0, base + EMAC_PHY_ADDR_LOW);
  6149. + writel(0, base + EMAC_PHY_ADDR_HIGH);
  6150. + } else {
  6151. + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_0);
  6152. + writel(0, base + ((entry_index - 1) * 8) + EMAC_SMAC_0_1);
  6153. + }
  6154. +}
  6155. +
  6156. +/* Set the loopback mode of the MAC. This can be either no loopback for
  6157. + * normal operation, local loopback through MAC internal loopback module or PHY
  6158. + * loopback for external loopback through a PHY. This asserts the external
  6159. + * loop pin.
  6160. + *
  6161. + * @param[in] base GEMAC base address.
  6162. + * @param[in] gem_loop Loopback mode to be enabled. LB_LOCAL - MAC
  6163. + * Loopback,
  6164. + * LB_EXT - PHY Loopback.
  6165. + */
  6166. +void gemac_set_loop(void *base, enum mac_loop gem_loop)
  6167. +{
  6168. + pr_info("%s()\n", __func__);
  6169. + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_LOOP, (base +
  6170. + EMAC_RCNTRL_REG));
  6171. +}
  6172. +
  6173. +/* GEMAC allow frames
  6174. + * @param[in] base GEMAC base address
  6175. + */
  6176. +void gemac_enable_copy_all(void *base)
  6177. +{
  6178. + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_PROM, (base +
  6179. + EMAC_RCNTRL_REG));
  6180. +}
  6181. +
  6182. +/* GEMAC do not allow frames
  6183. + * @param[in] base GEMAC base address
  6184. + */
  6185. +void gemac_disable_copy_all(void *base)
  6186. +{
  6187. + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_PROM, (base +
  6188. + EMAC_RCNTRL_REG));
  6189. +}
  6190. +
  6191. +/* GEMAC allow broadcast function.
  6192. + * @param[in] base GEMAC base address
  6193. + */
  6194. +void gemac_allow_broadcast(void *base)
  6195. +{
  6196. + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_BC_REJ, base +
  6197. + EMAC_RCNTRL_REG);
  6198. +}
  6199. +
  6200. +/* GEMAC no broadcast function.
  6201. + * @param[in] base GEMAC base address
  6202. + */
  6203. +void gemac_no_broadcast(void *base)
  6204. +{
  6205. + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_BC_REJ, base +
  6206. + EMAC_RCNTRL_REG);
  6207. +}
  6208. +
  6209. +/* GEMAC enable 1536 rx function.
  6210. + * @param[in] base GEMAC base address
  6211. + */
  6212. +void gemac_enable_1536_rx(void *base)
  6213. +{
  6214. + /* Set 1536 as Maximum frame length */
  6215. + writel(readl(base + EMAC_RCNTRL_REG) | (1536 << 16), base +
  6216. + EMAC_RCNTRL_REG);
  6217. +}
  6218. +
  6219. +/* GEMAC enable jumbo function.
  6220. + * @param[in] base GEMAC base address
  6221. + */
  6222. +void gemac_enable_rx_jmb(void *base)
  6223. +{
  6224. + writel(readl(base + EMAC_RCNTRL_REG) | (JUMBO_FRAME_SIZE << 16), base
  6225. + + EMAC_RCNTRL_REG);
  6226. +}
  6227. +
  6228. +/* GEMAC enable stacked vlan function.
  6229. + * @param[in] base GEMAC base address
  6230. + */
  6231. +void gemac_enable_stacked_vlan(void *base)
  6232. +{
  6233. + /* MTIP doesn't support stacked vlan */
  6234. +}
  6235. +
  6236. +/* GEMAC enable pause rx function.
  6237. + * @param[in] base GEMAC base address
  6238. + */
  6239. +void gemac_enable_pause_rx(void *base)
  6240. +{
  6241. + writel(readl(base + EMAC_RCNTRL_REG) | EMAC_RCNTRL_FCE,
  6242. + base + EMAC_RCNTRL_REG);
  6243. +}
  6244. +
  6245. +/* GEMAC disable pause rx function.
  6246. + * @param[in] base GEMAC base address
  6247. + */
  6248. +void gemac_disable_pause_rx(void *base)
  6249. +{
  6250. + writel(readl(base + EMAC_RCNTRL_REG) & ~EMAC_RCNTRL_FCE,
  6251. + base + EMAC_RCNTRL_REG);
  6252. +}
  6253. +
  6254. +/* GEMAC enable pause tx function.
  6255. + * @param[in] base GEMAC base address
  6256. + */
  6257. +void gemac_enable_pause_tx(void *base)
  6258. +{
  6259. + writel(EMAC_RX_SECTION_EMPTY_V, base + EMAC_RX_SECTION_EMPTY);
  6260. +}
  6261. +
  6262. +/* GEMAC disable pause tx function.
  6263. + * @param[in] base GEMAC base address
  6264. + */
  6265. +void gemac_disable_pause_tx(void *base)
  6266. +{
  6267. + writel(0x0, base + EMAC_RX_SECTION_EMPTY);
  6268. +}
  6269. +
  6270. +/* GEMAC wol configuration
  6271. + * @param[in] base GEMAC base address
  6272. + * @param[in] wol_conf WoL register configuration
  6273. + */
  6274. +void gemac_set_wol(void *base, u32 wol_conf)
  6275. +{
  6276. + u32 val = readl(base + EMAC_ECNTRL_REG);
  6277. +
  6278. + if (wol_conf)
  6279. + val |= (EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
  6280. + else
  6281. + val &= ~(EMAC_ECNTRL_MAGIC_ENA | EMAC_ECNTRL_SLEEP);
  6282. + writel(val, base + EMAC_ECNTRL_REG);
  6283. +}
  6284. +
  6285. +/* Sets Gemac bus width to 64bit
  6286. + * @param[in] base GEMAC base address
  6287. + * @param[in] width gemac bus width to be set possible values are 32/64/128
  6288. + */
  6289. +void gemac_set_bus_width(void *base, int width)
  6290. +{
  6291. +}
  6292. +
  6293. +/* Sets Gemac configuration.
  6294. + * @param[in] base GEMAC base address
  6295. + * @param[in] cfg GEMAC configuration
  6296. + */
  6297. +void gemac_set_config(void *base, struct gemac_cfg *cfg)
  6298. +{
  6299. + /*GEMAC config taken from VLSI */
  6300. + writel(0x00000004, base + EMAC_TFWR_STR_FWD);
  6301. + writel(0x00000005, base + EMAC_RX_SECTION_FULL);
  6302. + writel(0x00003fff, base + EMAC_TRUNC_FL);
  6303. + writel(0x00000030, base + EMAC_TX_SECTION_EMPTY);
  6304. + writel(0x00000000, base + EMAC_MIB_CTRL_STS_REG);
  6305. +
  6306. + gemac_set_mode(base, cfg->mode);
  6307. +
  6308. + gemac_set_speed(base, cfg->speed);
  6309. +
  6310. + gemac_set_duplex(base, cfg->duplex);
  6311. +}
  6312. +
  6313. +/**************************** GPI ***************************/
  6314. +
  6315. +/* Initializes a GPI block.
  6316. + * @param[in] base GPI base address
  6317. + * @param[in] cfg GPI configuration
  6318. + */
  6319. +void gpi_init(void *base, struct gpi_cfg *cfg)
  6320. +{
  6321. + gpi_reset(base);
  6322. +
  6323. + gpi_disable(base);
  6324. +
  6325. + gpi_set_config(base, cfg);
  6326. +}
  6327. +
  6328. +/* Resets a GPI block.
  6329. + * @param[in] base GPI base address
  6330. + */
  6331. +void gpi_reset(void *base)
  6332. +{
  6333. + writel(CORE_SW_RESET, base + GPI_CTRL);
  6334. +}
  6335. +
  6336. +/* Enables a GPI block.
  6337. + * @param[in] base GPI base address
  6338. + */
  6339. +void gpi_enable(void *base)
  6340. +{
  6341. + writel(CORE_ENABLE, base + GPI_CTRL);
  6342. +}
  6343. +
  6344. +/* Disables a GPI block.
  6345. + * @param[in] base GPI base address
  6346. + */
  6347. +void gpi_disable(void *base)
  6348. +{
  6349. + writel(CORE_DISABLE, base + GPI_CTRL);
  6350. +}
  6351. +
  6352. +/* Sets the configuration of a GPI block.
  6353. + * @param[in] base GPI base address
  6354. + * @param[in] cfg GPI configuration
  6355. + */
  6356. +void gpi_set_config(void *base, struct gpi_cfg *cfg)
  6357. +{
  6358. + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_ALLOC_CTRL), base
  6359. + + GPI_LMEM_ALLOC_ADDR);
  6360. + writel(CBUS_VIRT_TO_PFE(BMU1_BASE_ADDR + BMU_FREE_CTRL), base
  6361. + + GPI_LMEM_FREE_ADDR);
  6362. + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_ALLOC_CTRL), base
  6363. + + GPI_DDR_ALLOC_ADDR);
  6364. + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL), base
  6365. + + GPI_DDR_FREE_ADDR);
  6366. + writel(CBUS_VIRT_TO_PFE(CLASS_INQ_PKTPTR), base + GPI_CLASS_ADDR);
  6367. + writel(DDR_HDR_SIZE, base + GPI_DDR_DATA_OFFSET);
  6368. + writel(LMEM_HDR_SIZE, base + GPI_LMEM_DATA_OFFSET);
  6369. + writel(0, base + GPI_LMEM_SEC_BUF_DATA_OFFSET);
  6370. + writel(0, base + GPI_DDR_SEC_BUF_DATA_OFFSET);
  6371. + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, base + GPI_HDR_SIZE);
  6372. + writel((DDR_BUF_SIZE << 16) | LMEM_BUF_SIZE, base + GPI_BUF_SIZE);
  6373. +
  6374. + writel(((cfg->lmem_rtry_cnt << 16) | (GPI_DDR_BUF_EN << 1) |
  6375. + GPI_LMEM_BUF_EN), base + GPI_RX_CONFIG);
  6376. + writel(cfg->tmlf_txthres, base + GPI_TMLF_TX);
  6377. + writel(cfg->aseq_len, base + GPI_DTX_ASEQ);
  6378. + writel(1, base + GPI_TOE_CHKSUM_EN);
  6379. +
  6380. + if (cfg->mtip_pause_reg) {
  6381. + writel(cfg->mtip_pause_reg, base + GPI_CSR_MTIP_PAUSE_REG);
  6382. + writel(EGPI_PAUSE_TIME, base + GPI_TX_PAUSE_TIME);
  6383. + }
  6384. +}
  6385. +
  6386. +/**************************** CLASSIFIER ***************************/
  6387. +
  6388. +/* Initializes CLASSIFIER block.
  6389. + * @param[in] cfg CLASSIFIER configuration
  6390. + */
  6391. +void class_init(struct class_cfg *cfg)
  6392. +{
  6393. + class_reset();
  6394. +
  6395. + class_disable();
  6396. +
  6397. + class_set_config(cfg);
  6398. +}
  6399. +
  6400. +/* Resets CLASSIFIER block.
  6401. + *
  6402. + */
  6403. +void class_reset(void)
  6404. +{
  6405. + writel(CORE_SW_RESET, CLASS_TX_CTRL);
  6406. +}
  6407. +
  6408. +/* Enables all CLASS-PE's cores.
  6409. + *
  6410. + */
  6411. +void class_enable(void)
  6412. +{
  6413. + writel(CORE_ENABLE, CLASS_TX_CTRL);
  6414. +}
  6415. +
  6416. +/* Disables all CLASS-PE's cores.
  6417. + *
  6418. + */
  6419. +void class_disable(void)
  6420. +{
  6421. + writel(CORE_DISABLE, CLASS_TX_CTRL);
  6422. +}
  6423. +
  6424. +/*
  6425. + * Sets the configuration of the CLASSIFIER block.
  6426. + * @param[in] cfg CLASSIFIER configuration
  6427. + */
  6428. +void class_set_config(struct class_cfg *cfg)
  6429. +{
  6430. + u32 val;
  6431. +
  6432. + /* Initialize route table */
  6433. + if (!cfg->resume)
  6434. + memset(DDR_PHYS_TO_VIRT(cfg->route_table_baseaddr), 0, (1 <<
  6435. + cfg->route_table_hash_bits) * CLASS_ROUTE_SIZE);
  6436. +
  6437. +#if !defined(LS1012A_PFE_RESET_WA)
  6438. + writel(cfg->pe_sys_clk_ratio, CLASS_PE_SYS_CLK_RATIO);
  6439. +#endif
  6440. +
  6441. + writel((DDR_HDR_SIZE << 16) | LMEM_HDR_SIZE, CLASS_HDR_SIZE);
  6442. + writel(LMEM_BUF_SIZE, CLASS_LMEM_BUF_SIZE);
  6443. + writel(CLASS_ROUTE_ENTRY_SIZE(CLASS_ROUTE_SIZE) |
  6444. + CLASS_ROUTE_HASH_SIZE(cfg->route_table_hash_bits),
  6445. + CLASS_ROUTE_HASH_ENTRY_SIZE);
  6446. + writel(HIF_PKT_CLASS_EN | HIF_PKT_OFFSET(sizeof(struct hif_hdr)),
  6447. + CLASS_HIF_PARSE);
  6448. +
  6449. + val = HASH_CRC_PORT_IP | QB2BUS_LE;
  6450. +
  6451. +#if defined(CONFIG_IP_ALIGNED)
  6452. + val |= IP_ALIGNED;
  6453. +#endif
  6454. +
  6455. + /*
  6456. + * Class PE packet steering will only work if TOE mode, bridge fetch or
  6457. + * route fetch are enabled (see class/qb_fet.v). Route fetch would
  6458. + * trigger additional memory copies (likely from DDR because of hash
  6459. + * table size, which cannot be reduced because PE software still
  6460. + * relies on hash value computed in HW), so when not in TOE mode we
  6461. + * simply enable HW bridge fetch even though we don't use it.
  6462. + */
  6463. + if (cfg->toe_mode)
  6464. + val |= CLASS_TOE;
  6465. + else
  6466. + val |= HW_BRIDGE_FETCH;
  6467. +
  6468. + writel(val, CLASS_ROUTE_MULTI);
  6469. +
  6470. + writel(DDR_PHYS_TO_PFE(cfg->route_table_baseaddr),
  6471. + CLASS_ROUTE_TABLE_BASE);
  6472. + writel(CLASS_PE0_RO_DM_ADDR0_VAL, CLASS_PE0_RO_DM_ADDR0);
  6473. + writel(CLASS_PE0_RO_DM_ADDR1_VAL, CLASS_PE0_RO_DM_ADDR1);
  6474. + writel(CLASS_PE0_QB_DM_ADDR0_VAL, CLASS_PE0_QB_DM_ADDR0);
  6475. + writel(CLASS_PE0_QB_DM_ADDR1_VAL, CLASS_PE0_QB_DM_ADDR1);
  6476. + writel(CBUS_VIRT_TO_PFE(TMU_PHY_INQ_PKTPTR), CLASS_TM_INQ_ADDR);
  6477. +
  6478. + writel(23, CLASS_AFULL_THRES);
  6479. + writel(23, CLASS_TSQ_FIFO_THRES);
  6480. +
  6481. + writel(24, CLASS_MAX_BUF_CNT);
  6482. + writel(24, CLASS_TSQ_MAX_CNT);
  6483. +}
  6484. +
  6485. +/**************************** TMU ***************************/
  6486. +
  6487. +void tmu_reset(void)
  6488. +{
  6489. + writel(SW_RESET, TMU_CTRL);
  6490. +}
  6491. +
  6492. +/* Initializes TMU block.
  6493. + * @param[in] cfg TMU configuration
  6494. + */
  6495. +void tmu_init(struct tmu_cfg *cfg)
  6496. +{
  6497. + int q, phyno;
  6498. +
  6499. + tmu_disable(0xF);
  6500. + mdelay(10);
  6501. +
  6502. +#if !defined(LS1012A_PFE_RESET_WA)
  6503. + /* keep in soft reset */
  6504. + writel(SW_RESET, TMU_CTRL);
  6505. +#endif
  6506. + writel(0x3, TMU_SYS_GENERIC_CONTROL);
  6507. + writel(750, TMU_INQ_WATERMARK);
  6508. + writel(CBUS_VIRT_TO_PFE(EGPI1_BASE_ADDR +
  6509. + GPI_INQ_PKTPTR), TMU_PHY0_INQ_ADDR);
  6510. + writel(CBUS_VIRT_TO_PFE(EGPI2_BASE_ADDR +
  6511. + GPI_INQ_PKTPTR), TMU_PHY1_INQ_ADDR);
  6512. + writel(CBUS_VIRT_TO_PFE(HGPI_BASE_ADDR +
  6513. + GPI_INQ_PKTPTR), TMU_PHY3_INQ_ADDR);
  6514. + writel(CBUS_VIRT_TO_PFE(HIF_NOCPY_RX_INQ0_PKTPTR), TMU_PHY4_INQ_ADDR);
  6515. + writel(CBUS_VIRT_TO_PFE(UTIL_INQ_PKTPTR), TMU_PHY5_INQ_ADDR);
  6516. + writel(CBUS_VIRT_TO_PFE(BMU2_BASE_ADDR + BMU_FREE_CTRL),
  6517. + TMU_BMU_INQ_ADDR);
  6518. +
  6519. + writel(0x3FF, TMU_TDQ0_SCH_CTRL); /*
  6520. + * enabling all 10
  6521. + * schedulers [9:0] of each TDQ
  6522. + */
  6523. + writel(0x3FF, TMU_TDQ1_SCH_CTRL);
  6524. + writel(0x3FF, TMU_TDQ3_SCH_CTRL);
  6525. +
  6526. +#if !defined(LS1012A_PFE_RESET_WA)
  6527. + writel(cfg->pe_sys_clk_ratio, TMU_PE_SYS_CLK_RATIO);
  6528. +#endif
  6529. +
  6530. +#if !defined(LS1012A_PFE_RESET_WA)
  6531. + writel(DDR_PHYS_TO_PFE(cfg->llm_base_addr), TMU_LLM_BASE_ADDR);
  6532. + /* Extra packet pointers will be stored from this address onwards */
  6533. +
  6534. + writel(cfg->llm_queue_len, TMU_LLM_QUE_LEN);
  6535. + writel(5, TMU_TDQ_IIFG_CFG);
  6536. + writel(DDR_BUF_SIZE, TMU_BMU_BUF_SIZE);
  6537. +
  6538. + writel(0x0, TMU_CTRL);
  6539. +
  6540. + /* MEM init */
  6541. + pr_info("%s: mem init\n", __func__);
  6542. + writel(MEM_INIT, TMU_CTRL);
  6543. +
  6544. + while (!(readl(TMU_CTRL) & MEM_INIT_DONE))
  6545. + ;
  6546. +
  6547. + /* LLM init */
  6548. + pr_info("%s: lmem init\n", __func__);
  6549. + writel(LLM_INIT, TMU_CTRL);
  6550. +
  6551. + while (!(readl(TMU_CTRL) & LLM_INIT_DONE))
  6552. + ;
  6553. +#endif
  6554. + /* set up each queue for tail drop */
  6555. + for (phyno = 0; phyno < 4; phyno++) {
  6556. + if (phyno == 2)
  6557. + continue;
  6558. + for (q = 0; q < 16; q++) {
  6559. + u32 qdepth;
  6560. +
  6561. + writel((phyno << 8) | q, TMU_TEQ_CTRL);
  6562. + writel(1 << 22, TMU_TEQ_QCFG); /*Enable tail drop */
  6563. +
  6564. + if (phyno == 3)
  6565. + qdepth = DEFAULT_TMU3_QDEPTH;
  6566. + else
  6567. + qdepth = (q == 0) ? DEFAULT_Q0_QDEPTH :
  6568. + DEFAULT_MAX_QDEPTH;
  6569. +
  6570. + /* LOG: 68855 */
  6571. + /*
  6572. + * The following is a workaround for the reordered
  6573. + * packet and BMU2 buffer leakage issue.
  6574. + */
  6575. + if (CHIP_REVISION() == 0)
  6576. + qdepth = 31;
  6577. +
  6578. + writel(qdepth << 18, TMU_TEQ_HW_PROB_CFG2);
  6579. + writel(qdepth >> 14, TMU_TEQ_HW_PROB_CFG3);
  6580. + }
  6581. + }
  6582. +
  6583. +#ifdef CFG_LRO
  6584. + /* Set TMU-3 queue 5 (LRO) in no-drop mode */
  6585. + writel((3 << 8) | TMU_QUEUE_LRO, TMU_TEQ_CTRL);
  6586. + writel(0, TMU_TEQ_QCFG);
  6587. +#endif
  6588. +
  6589. + writel(0x05, TMU_TEQ_DISABLE_DROPCHK);
  6590. +
  6591. + writel(0x0, TMU_CTRL);
  6592. +}
  6593. +
  6594. +/* Enables TMU-PE cores.
  6595. + * @param[in] pe_mask TMU PE mask
  6596. + */
  6597. +void tmu_enable(u32 pe_mask)
  6598. +{
  6599. + writel(readl(TMU_TX_CTRL) | (pe_mask & 0xF), TMU_TX_CTRL);
  6600. +}
  6601. +
  6602. +/* Disables TMU cores.
  6603. + * @param[in] pe_mask TMU PE mask
  6604. + */
  6605. +void tmu_disable(u32 pe_mask)
  6606. +{
  6607. + writel(readl(TMU_TX_CTRL) & ~(pe_mask & 0xF), TMU_TX_CTRL);
  6608. +}
  6609. +
  6610. +/* This will return the tmu queue status
  6611. + * @param[in] if_id gem interface id or TMU index
  6612. + * @return returns the bit mask of busy queues, zero means all
  6613. + * queues are empty
  6614. + */
  6615. +u32 tmu_qstatus(u32 if_id)
  6616. +{
  6617. + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
  6618. + offsetof(struct pe_status, tmu_qstatus), 4));
  6619. +}
  6620. +
  6621. +u32 tmu_pkts_processed(u32 if_id)
  6622. +{
  6623. + return cpu_to_be32(pe_dmem_read(TMU0_ID + if_id, TMU_DM_PESTATUS +
  6624. + offsetof(struct pe_status, rx), 4));
  6625. +}
  6626. +
  6627. +/**************************** UTIL ***************************/
  6628. +
  6629. +/* Resets UTIL block.
  6630. + */
  6631. +void util_reset(void)
  6632. +{
  6633. + writel(CORE_SW_RESET, UTIL_TX_CTRL);
  6634. +}
  6635. +
  6636. +/* Initializes UTIL block.
  6637. + * @param[in] cfg UTIL configuration
  6638. + */
  6639. +void util_init(struct util_cfg *cfg)
  6640. +{
  6641. + writel(cfg->pe_sys_clk_ratio, UTIL_PE_SYS_CLK_RATIO);
  6642. +}
  6643. +
  6644. +/* Enables UTIL-PE core.
  6645. + *
  6646. + */
  6647. +void util_enable(void)
  6648. +{
  6649. + writel(CORE_ENABLE, UTIL_TX_CTRL);
  6650. +}
  6651. +
  6652. +/* Disables UTIL-PE core.
  6653. + *
  6654. + */
  6655. +void util_disable(void)
  6656. +{
  6657. + writel(CORE_DISABLE, UTIL_TX_CTRL);
  6658. +}
  6659. +
  6660. +/**************************** HIF ***************************/
  6661. +/* Initializes HIF copy block.
  6662. + *
  6663. + */
  6664. +void hif_init(void)
  6665. +{
  6666. + /*Initialize HIF registers*/
  6667. + writel((HIF_RX_POLL_CTRL_CYCLE << 16) | HIF_TX_POLL_CTRL_CYCLE,
  6668. + HIF_POLL_CTRL);
  6669. +}
  6670. +
  6671. +/* Enable hif tx DMA and interrupt
  6672. + *
  6673. + */
  6674. +void hif_tx_enable(void)
  6675. +{
  6676. + writel(HIF_CTRL_DMA_EN, HIF_TX_CTRL);
  6677. + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_TXPKT_INT_EN),
  6678. + HIF_INT_ENABLE);
  6679. +}
  6680. +
  6681. +/* Disable hif tx DMA and interrupt
  6682. + *
  6683. + */
  6684. +void hif_tx_disable(void)
  6685. +{
  6686. + u32 hif_int;
  6687. +
  6688. + writel(0, HIF_TX_CTRL);
  6689. +
  6690. + hif_int = readl(HIF_INT_ENABLE);
  6691. + hif_int &= HIF_TXPKT_INT_EN;
  6692. + writel(hif_int, HIF_INT_ENABLE);
  6693. +}
  6694. +
  6695. +/* Enable hif rx DMA and interrupt
  6696. + *
  6697. + */
  6698. +void hif_rx_enable(void)
  6699. +{
  6700. + hif_rx_dma_start();
  6701. + writel((readl(HIF_INT_ENABLE) | HIF_INT_EN | HIF_RXPKT_INT_EN),
  6702. + HIF_INT_ENABLE);
  6703. +}
  6704. +
  6705. +/* Disable hif rx DMA and interrupt
  6706. + *
  6707. + */
  6708. +void hif_rx_disable(void)
  6709. +{
  6710. + u32 hif_int;
  6711. +
  6712. + writel(0, HIF_RX_CTRL);
  6713. +
  6714. + hif_int = readl(HIF_INT_ENABLE);
  6715. + hif_int &= HIF_RXPKT_INT_EN;
  6716. + writel(hif_int, HIF_INT_ENABLE);
  6717. +}
  6718. diff --git a/drivers/staging/fsl_ppfe/pfe_hif.c b/drivers/staging/fsl_ppfe/pfe_hif.c
  6719. new file mode 100644
  6720. index 00000000..6835e140
  6721. --- /dev/null
  6722. +++ b/drivers/staging/fsl_ppfe/pfe_hif.c
  6723. @@ -0,0 +1,1072 @@
  6724. +/*
  6725. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  6726. + * Copyright 2017 NXP
  6727. + *
  6728. + * This program is free software; you can redistribute it and/or modify
  6729. + * it under the terms of the GNU General Public License as published by
  6730. + * the Free Software Foundation; either version 2 of the License, or
  6731. + * (at your option) any later version.
  6732. + *
  6733. + * This program is distributed in the hope that it will be useful,
  6734. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6735. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6736. + * GNU General Public License for more details.
  6737. + *
  6738. + * You should have received a copy of the GNU General Public License
  6739. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  6740. + */
  6741. +
  6742. +#include <linux/kernel.h>
  6743. +#include <linux/interrupt.h>
  6744. +#include <linux/dma-mapping.h>
  6745. +#include <linux/dmapool.h>
  6746. +#include <linux/sched.h>
  6747. +#include <linux/module.h>
  6748. +#include <linux/list.h>
  6749. +#include <linux/kthread.h>
  6750. +#include <linux/slab.h>
  6751. +
  6752. +#include <linux/io.h>
  6753. +#include <asm/irq.h>
  6754. +
  6755. +#include "pfe_mod.h"
  6756. +
  6757. +#define HIF_INT_MASK (HIF_INT | HIF_RXPKT_INT | HIF_TXPKT_INT)
  6758. +
  6759. +unsigned char napi_first_batch;
  6760. +
  6761. +static void pfe_tx_do_cleanup(unsigned long data);
  6762. +
  6763. +static int pfe_hif_alloc_descr(struct pfe_hif *hif)
  6764. +{
  6765. + void *addr;
  6766. + dma_addr_t dma_addr;
  6767. + int err = 0;
  6768. +
  6769. + pr_info("%s\n", __func__);
  6770. + addr = dma_alloc_coherent(pfe->dev,
  6771. + HIF_RX_DESC_NT * sizeof(struct hif_desc) +
  6772. + HIF_TX_DESC_NT * sizeof(struct hif_desc),
  6773. + &dma_addr, GFP_KERNEL);
  6774. +
  6775. + if (!addr) {
  6776. + pr_err("%s: Could not allocate buffer descriptors!\n"
  6777. + , __func__);
  6778. + err = -ENOMEM;
  6779. + goto err0;
  6780. + }
  6781. +
  6782. + hif->descr_baseaddr_p = dma_addr;
  6783. + hif->descr_baseaddr_v = addr;
  6784. + hif->rx_ring_size = HIF_RX_DESC_NT;
  6785. + hif->tx_ring_size = HIF_TX_DESC_NT;
  6786. +
  6787. + return 0;
  6788. +
  6789. +err0:
  6790. + return err;
  6791. +}
  6792. +
  6793. +#if defined(LS1012A_PFE_RESET_WA)
  6794. +static void pfe_hif_disable_rx_desc(struct pfe_hif *hif)
  6795. +{
  6796. + int ii;
  6797. + struct hif_desc *desc = hif->rx_base;
  6798. +
  6799. + /*Mark all descriptors as LAST_BD */
  6800. + for (ii = 0; ii < hif->rx_ring_size; ii++) {
  6801. + desc->ctrl |= BD_CTRL_LAST_BD;
  6802. + desc++;
  6803. + }
  6804. +}
  6805. +
  6806. +struct class_rx_hdr_t {
  6807. + u32 next_ptr; /* ptr to the start of the first DDR buffer */
  6808. + u16 length; /* total packet length */
  6809. + u16 phyno; /* input physical port number */
  6810. + u32 status; /* gemac status bits */
  6811. + u32 status2; /* reserved for software usage */
  6812. +};
  6813. +
  6814. +/* STATUS_BAD_FRAME_ERR is set for all errors (including checksums if enabled)
  6815. + * except overflow
  6816. + */
  6817. +#define STATUS_BAD_FRAME_ERR BIT(16)
  6818. +#define STATUS_LENGTH_ERR BIT(17)
  6819. +#define STATUS_CRC_ERR BIT(18)
  6820. +#define STATUS_TOO_SHORT_ERR BIT(19)
  6821. +#define STATUS_TOO_LONG_ERR BIT(20)
  6822. +#define STATUS_CODE_ERR BIT(21)
  6823. +#define STATUS_MC_HASH_MATCH BIT(22)
  6824. +#define STATUS_CUMULATIVE_ARC_HIT BIT(23)
  6825. +#define STATUS_UNICAST_HASH_MATCH BIT(24)
  6826. +#define STATUS_IP_CHECKSUM_CORRECT BIT(25)
  6827. +#define STATUS_TCP_CHECKSUM_CORRECT BIT(26)
  6828. +#define STATUS_UDP_CHECKSUM_CORRECT BIT(27)
  6829. +#define STATUS_OVERFLOW_ERR BIT(28) /* GPI error */
  6830. +#define MIN_PKT_SIZE 64
  6831. +
  6832. +static inline void copy_to_lmem(u32 *dst, u32 *src, int len)
  6833. +{
  6834. + int i;
  6835. +
  6836. + for (i = 0; i < len; i += sizeof(u32)) {
  6837. + *dst = htonl(*src);
  6838. + dst++; src++;
  6839. + }
  6840. +}
  6841. +
  6842. +static void send_dummy_pkt_to_hif(void)
  6843. +{
  6844. + void *lmem_ptr, *ddr_ptr, *lmem_virt_addr;
  6845. + u32 physaddr;
  6846. + struct class_rx_hdr_t local_hdr;
  6847. + static u32 dummy_pkt[] = {
  6848. + 0x33221100, 0x2b785544, 0xd73093cb, 0x01000608,
  6849. + 0x04060008, 0x2b780200, 0xd73093cb, 0x0a01a8c0,
  6850. + 0x33221100, 0xa8c05544, 0x00000301, 0x00000000,
  6851. + 0x00000000, 0x00000000, 0x00000000, 0xbe86c51f };
  6852. +
  6853. + ddr_ptr = (void *)((u64)readl(BMU2_BASE_ADDR + BMU_ALLOC_CTRL));
  6854. + if (!ddr_ptr)
  6855. + return;
  6856. +
  6857. + lmem_ptr = (void *)((u64)readl(BMU1_BASE_ADDR + BMU_ALLOC_CTRL));
  6858. + if (!lmem_ptr)
  6859. + return;
  6860. +
  6861. + pr_info("Sending a dummy pkt to HIF %p %p\n", ddr_ptr, lmem_ptr);
  6862. + physaddr = (u32)DDR_VIRT_TO_PFE(ddr_ptr);
  6863. +
  6864. + lmem_virt_addr = (void *)CBUS_PFE_TO_VIRT((unsigned long int)lmem_ptr);
  6865. +
  6866. + local_hdr.phyno = htons(0); /* RX_PHY_0 */
  6867. + local_hdr.length = htons(MIN_PKT_SIZE);
  6868. +
  6869. + local_hdr.next_ptr = htonl((u32)physaddr);
  6870. + /*Mark checksum is correct */
  6871. + local_hdr.status = htonl((STATUS_IP_CHECKSUM_CORRECT |
  6872. + STATUS_UDP_CHECKSUM_CORRECT |
  6873. + STATUS_TCP_CHECKSUM_CORRECT |
  6874. + STATUS_UNICAST_HASH_MATCH |
  6875. + STATUS_CUMULATIVE_ARC_HIT));
  6876. + copy_to_lmem((u32 *)lmem_virt_addr, (u32 *)&local_hdr,
  6877. + sizeof(local_hdr));
  6878. +
  6879. + copy_to_lmem((u32 *)(lmem_virt_addr + LMEM_HDR_SIZE), (u32 *)dummy_pkt,
  6880. + 0x40);
  6881. +
  6882. + writel((unsigned long int)lmem_ptr, CLASS_INQ_PKTPTR);
  6883. +}
  6884. +
  6885. +void pfe_hif_rx_idle(struct pfe_hif *hif)
  6886. +{
  6887. + int hif_stop_loop = 10;
  6888. + u32 rx_status;
  6889. +
  6890. + pfe_hif_disable_rx_desc(hif);
  6891. + pr_info("Bringing hif to idle state...");
  6892. + writel(0, HIF_INT_ENABLE);
  6893. + /*If HIF Rx BDP is busy send a dummy packet */
  6894. + do {
  6895. + rx_status = readl(HIF_RX_STATUS);
  6896. + if (rx_status & BDP_CSR_RX_DMA_ACTV)
  6897. + send_dummy_pkt_to_hif();
  6898. +
  6899. + usleep_range(100, 150);
  6900. + } while (--hif_stop_loop);
  6901. +
  6902. + if (readl(HIF_RX_STATUS) & BDP_CSR_RX_DMA_ACTV)
  6903. + pr_info("Failed\n");
  6904. + else
  6905. + pr_info("Done\n");
  6906. +}
  6907. +#endif
  6908. +
  6909. +static void pfe_hif_free_descr(struct pfe_hif *hif)
  6910. +{
  6911. + pr_info("%s\n", __func__);
  6912. +
  6913. + dma_free_coherent(pfe->dev,
  6914. + hif->rx_ring_size * sizeof(struct hif_desc) +
  6915. + hif->tx_ring_size * sizeof(struct hif_desc),
  6916. + hif->descr_baseaddr_v, hif->descr_baseaddr_p);
  6917. +}
  6918. +
  6919. +void pfe_hif_desc_dump(struct pfe_hif *hif)
  6920. +{
  6921. + struct hif_desc *desc;
  6922. + unsigned long desc_p;
  6923. + int ii = 0;
  6924. +
  6925. + pr_info("%s\n", __func__);
  6926. +
  6927. + desc = hif->rx_base;
  6928. + desc_p = (u32)((u64)desc - (u64)hif->descr_baseaddr_v +
  6929. + hif->descr_baseaddr_p);
  6930. +
  6931. + pr_info("HIF Rx desc base %p physical %x\n", desc, (u32)desc_p);
  6932. + for (ii = 0; ii < hif->rx_ring_size; ii++) {
  6933. + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
  6934. + readl(&desc->status), readl(&desc->ctrl),
  6935. + readl(&desc->data), readl(&desc->next));
  6936. + desc++;
  6937. + }
  6938. +
  6939. + desc = hif->tx_base;
  6940. + desc_p = ((u64)desc - (u64)hif->descr_baseaddr_v +
  6941. + hif->descr_baseaddr_p);
  6942. +
  6943. + pr_info("HIF Tx desc base %p physical %x\n", desc, (u32)desc_p);
  6944. + for (ii = 0; ii < hif->tx_ring_size; ii++) {
  6945. + pr_info("status: %08x, ctrl: %08x, data: %08x, next: %x\n",
  6946. + readl(&desc->status), readl(&desc->ctrl),
  6947. + readl(&desc->data), readl(&desc->next));
  6948. + desc++;
  6949. + }
  6950. +}
  6951. +
  6952. +/* pfe_hif_release_buffers */
  6953. +static void pfe_hif_release_buffers(struct pfe_hif *hif)
  6954. +{
  6955. + struct hif_desc *desc;
  6956. + int i = 0;
  6957. +
  6958. + hif->rx_base = hif->descr_baseaddr_v;
  6959. +
  6960. + pr_info("%s\n", __func__);
  6961. +
  6962. + /*Free Rx buffers */
  6963. + desc = hif->rx_base;
  6964. + for (i = 0; i < hif->rx_ring_size; i++) {
  6965. + if (readl(&desc->data)) {
  6966. + if ((i < hif->shm->rx_buf_pool_cnt) &&
  6967. + (!hif->shm->rx_buf_pool[i])) {
  6968. + /*
  6969. + * dma_unmap_single(hif->dev, desc->data,
  6970. + * hif->rx_buf_len[i], DMA_FROM_DEVICE);
  6971. + */
  6972. + dma_unmap_single(hif->dev,
  6973. + DDR_PFE_TO_PHYS(
  6974. + readl(&desc->data)),
  6975. + hif->rx_buf_len[i],
  6976. + DMA_FROM_DEVICE);
  6977. + hif->shm->rx_buf_pool[i] = hif->rx_buf_addr[i];
  6978. + } else {
  6979. + pr_err("%s: buffer pool already full\n"
  6980. + , __func__);
  6981. + }
  6982. + }
  6983. +
  6984. + writel(0, &desc->data);
  6985. + writel(0, &desc->status);
  6986. + writel(0, &desc->ctrl);
  6987. + desc++;
  6988. + }
  6989. +}
  6990. +
  6991. +/*
  6992. + * pfe_hif_init_buffers
  6993. + * This function initializes the HIF Rx/Tx ring descriptors and
  6994. + * initialize Rx queue with buffers.
  6995. + */
  6996. +static int pfe_hif_init_buffers(struct pfe_hif *hif)
  6997. +{
  6998. + struct hif_desc *desc, *first_desc_p;
  6999. + u32 data;
  7000. + int i = 0;
  7001. +
  7002. + pr_info("%s\n", __func__);
  7003. +
  7004. + /* Check enough Rx buffers available in the shared memory */
  7005. + if (hif->shm->rx_buf_pool_cnt < hif->rx_ring_size)
  7006. + return -ENOMEM;
  7007. +
  7008. + hif->rx_base = hif->descr_baseaddr_v;
  7009. + memset(hif->rx_base, 0, hif->rx_ring_size * sizeof(struct hif_desc));
  7010. +
  7011. + /*Initialize Rx descriptors */
  7012. + desc = hif->rx_base;
  7013. + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p;
  7014. +
  7015. + for (i = 0; i < hif->rx_ring_size; i++) {
  7016. + /* Initialize Rx buffers from the shared memory */
  7017. +
  7018. + data = (u32)dma_map_single(hif->dev, hif->shm->rx_buf_pool[i],
  7019. + pfe_pkt_size, DMA_FROM_DEVICE);
  7020. + hif->rx_buf_addr[i] = hif->shm->rx_buf_pool[i];
  7021. + hif->rx_buf_len[i] = pfe_pkt_size;
  7022. + hif->shm->rx_buf_pool[i] = NULL;
  7023. +
  7024. + if (likely(dma_mapping_error(hif->dev, data) == 0)) {
  7025. + writel(DDR_PHYS_TO_PFE(data), &desc->data);
  7026. + } else {
  7027. + pr_err("%s : low on mem\n", __func__);
  7028. +
  7029. + goto err;
  7030. + }
  7031. +
  7032. + writel(0, &desc->status);
  7033. +
  7034. + /*
  7035. + * Ensure everything else is written to DDR before
  7036. + * writing bd->ctrl
  7037. + */
  7038. + wmb();
  7039. +
  7040. + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM
  7041. + | BD_CTRL_DIR | BD_CTRL_DESC_EN
  7042. + | BD_BUF_LEN(pfe_pkt_size)), &desc->ctrl);
  7043. +
  7044. + /* Chain descriptors */
  7045. + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
  7046. + desc++;
  7047. + }
  7048. +
  7049. + /* Overwrite last descriptor to chain it to first one*/
  7050. + desc--;
  7051. + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
  7052. +
  7053. + hif->rxtoclean_index = 0;
  7054. +
  7055. + /*Initialize Rx buffer descriptor ring base address */
  7056. + writel(DDR_PHYS_TO_PFE(hif->descr_baseaddr_p), HIF_RX_BDP_ADDR);
  7057. +
  7058. + hif->tx_base = hif->rx_base + hif->rx_ring_size;
  7059. + first_desc_p = (struct hif_desc *)hif->descr_baseaddr_p +
  7060. + hif->rx_ring_size;
  7061. + memset(hif->tx_base, 0, hif->tx_ring_size * sizeof(struct hif_desc));
  7062. +
  7063. + /*Initialize tx descriptors */
  7064. + desc = hif->tx_base;
  7065. +
  7066. + for (i = 0; i < hif->tx_ring_size; i++) {
  7067. + /* Chain descriptors */
  7068. + writel((u32)DDR_PHYS_TO_PFE(first_desc_p + i + 1), &desc->next);
  7069. + writel(0, &desc->ctrl);
  7070. + desc++;
  7071. + }
  7072. +
  7073. + /* Overwrite last descriptor to chain it to first one */
  7074. + desc--;
  7075. + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), &desc->next);
  7076. + hif->txavail = hif->tx_ring_size;
  7077. + hif->txtosend = 0;
  7078. + hif->txtoclean = 0;
  7079. + hif->txtoflush = 0;
  7080. +
  7081. + /*Initialize Tx buffer descriptor ring base address */
  7082. + writel((u32)DDR_PHYS_TO_PFE(first_desc_p), HIF_TX_BDP_ADDR);
  7083. +
  7084. + return 0;
  7085. +
  7086. +err:
  7087. + pfe_hif_release_buffers(hif);
  7088. + return -ENOMEM;
  7089. +}
  7090. +
  7091. +/*
  7092. + * pfe_hif_client_register
  7093. + *
  7094. + * This function used to register a client driver with the HIF driver.
  7095. + *
  7096. + * Return value:
  7097. + * 0 - on Successful registration
  7098. + */
  7099. +static int pfe_hif_client_register(struct pfe_hif *hif, u32 client_id,
  7100. + struct hif_client_shm *client_shm)
  7101. +{
  7102. + struct hif_client *client = &hif->client[client_id];
  7103. + u32 i, cnt;
  7104. + struct rx_queue_desc *rx_qbase;
  7105. + struct tx_queue_desc *tx_qbase;
  7106. + struct hif_rx_queue *rx_queue;
  7107. + struct hif_tx_queue *tx_queue;
  7108. + int err = 0;
  7109. +
  7110. + pr_info("%s\n", __func__);
  7111. +
  7112. + spin_lock_bh(&hif->tx_lock);
  7113. +
  7114. + if (test_bit(client_id, &hif->shm->g_client_status[0])) {
  7115. + pr_err("%s: client %d already registered\n",
  7116. + __func__, client_id);
  7117. + err = -1;
  7118. + goto unlock;
  7119. + }
  7120. +
  7121. + memset(client, 0, sizeof(struct hif_client));
  7122. +
  7123. + /* Initialize client Rx queues baseaddr, size */
  7124. +
  7125. + cnt = CLIENT_CTRL_RX_Q_CNT(client_shm->ctrl);
  7126. + /* Check if client is requesting for more queues than supported */
  7127. + if (cnt > HIF_CLIENT_QUEUES_MAX)
  7128. + cnt = HIF_CLIENT_QUEUES_MAX;
  7129. +
  7130. + client->rx_qn = cnt;
  7131. + rx_qbase = (struct rx_queue_desc *)client_shm->rx_qbase;
  7132. + for (i = 0; i < cnt; i++) {
  7133. + rx_queue = &client->rx_q[i];
  7134. + rx_queue->base = rx_qbase + i * client_shm->rx_qsize;
  7135. + rx_queue->size = client_shm->rx_qsize;
  7136. + rx_queue->write_idx = 0;
  7137. + }
  7138. +
  7139. + /* Initialize client Tx queues baseaddr, size */
  7140. + cnt = CLIENT_CTRL_TX_Q_CNT(client_shm->ctrl);
  7141. +
  7142. + /* Check if client is requesting for more queues than supported */
  7143. + if (cnt > HIF_CLIENT_QUEUES_MAX)
  7144. + cnt = HIF_CLIENT_QUEUES_MAX;
  7145. +
  7146. + client->tx_qn = cnt;
  7147. + tx_qbase = (struct tx_queue_desc *)client_shm->tx_qbase;
  7148. + for (i = 0; i < cnt; i++) {
  7149. + tx_queue = &client->tx_q[i];
  7150. + tx_queue->base = tx_qbase + i * client_shm->tx_qsize;
  7151. + tx_queue->size = client_shm->tx_qsize;
  7152. + tx_queue->ack_idx = 0;
  7153. + }
  7154. +
  7155. + set_bit(client_id, &hif->shm->g_client_status[0]);
  7156. +
  7157. +unlock:
  7158. + spin_unlock_bh(&hif->tx_lock);
  7159. +
  7160. + return err;
  7161. +}
  7162. +
  7163. +/*
  7164. + * pfe_hif_client_unregister
  7165. + *
  7166. + * This function used to unregister a client from the HIF driver.
  7167. + *
  7168. + */
  7169. +static void pfe_hif_client_unregister(struct pfe_hif *hif, u32 client_id)
  7170. +{
  7171. + pr_info("%s\n", __func__);
  7172. +
  7173. + /*
  7174. + * Mark client as no longer available (which prevents further packet
  7175. + * receive for this client)
  7176. + */
  7177. + spin_lock_bh(&hif->tx_lock);
  7178. +
  7179. + if (!test_bit(client_id, &hif->shm->g_client_status[0])) {
  7180. + pr_err("%s: client %d not registered\n", __func__,
  7181. + client_id);
  7182. +
  7183. + spin_unlock_bh(&hif->tx_lock);
  7184. + return;
  7185. + }
  7186. +
  7187. + clear_bit(client_id, &hif->shm->g_client_status[0]);
  7188. +
  7189. + spin_unlock_bh(&hif->tx_lock);
  7190. +}
  7191. +
  7192. +/*
  7193. + * client_put_rxpacket-
  7194. + * This functions puts the Rx pkt in the given client Rx queue.
  7195. + * It actually swap the Rx pkt in the client Rx descriptor buffer
  7196. + * and returns the free buffer from it.
  7197. + *
  7198. + * If the function returns NULL means client Rx queue is full and
  7199. + * packet couldn't send to client queue.
  7200. + */
  7201. +static void *client_put_rxpacket(struct hif_rx_queue *queue, void *pkt, u32 len,
  7202. + u32 flags, u32 client_ctrl, u32 *rem_len)
  7203. +{
  7204. + void *free_pkt = NULL;
  7205. + struct rx_queue_desc *desc = queue->base + queue->write_idx;
  7206. +
  7207. + if (readl(&desc->ctrl) & CL_DESC_OWN) {
  7208. + if (page_mode) {
  7209. + int rem_page_size = PAGE_SIZE -
  7210. + PRESENT_OFST_IN_PAGE(pkt);
  7211. + int cur_pkt_size = ROUND_MIN_RX_SIZE(len +
  7212. + pfe_pkt_headroom);
  7213. + *rem_len = (rem_page_size - cur_pkt_size);
  7214. + if (*rem_len) {
  7215. + free_pkt = pkt + cur_pkt_size;
  7216. + get_page(virt_to_page(free_pkt));
  7217. + } else {
  7218. + free_pkt = (void
  7219. + *)__get_free_page(GFP_ATOMIC | GFP_DMA_PFE);
  7220. + *rem_len = pfe_pkt_size;
  7221. + }
  7222. + } else {
  7223. + free_pkt = kmalloc(PFE_BUF_SIZE, GFP_ATOMIC |
  7224. + GFP_DMA_PFE);
  7225. + *rem_len = PFE_BUF_SIZE - pfe_pkt_headroom;
  7226. + }
  7227. +
  7228. + if (free_pkt) {
  7229. + desc->data = pkt;
  7230. + desc->client_ctrl = client_ctrl;
  7231. + /*
  7232. + * Ensure everything else is written to DDR before
  7233. + * writing bd->ctrl
  7234. + */
  7235. + smp_wmb();
  7236. + writel(CL_DESC_BUF_LEN(len) | flags, &desc->ctrl);
  7237. + queue->write_idx = (queue->write_idx + 1)
  7238. + & (queue->size - 1);
  7239. +
  7240. + free_pkt += pfe_pkt_headroom;
  7241. + }
  7242. + }
  7243. +
  7244. + return free_pkt;
  7245. +}
  7246. +
  7247. +/*
  7248. + * pfe_hif_rx_process-
  7249. + * This function does pfe hif rx queue processing.
  7250. + * Dequeue packet from Rx queue and send it to corresponding client queue
  7251. + */
  7252. +static int pfe_hif_rx_process(struct pfe_hif *hif, int budget)
  7253. +{
  7254. + struct hif_desc *desc;
  7255. + struct hif_hdr *pkt_hdr;
  7256. + struct __hif_hdr hif_hdr;
  7257. + void *free_buf;
  7258. + int rtc, len, rx_processed = 0;
  7259. + struct __hif_desc local_desc;
  7260. + int flags;
  7261. + unsigned int desc_p;
  7262. + unsigned int buf_size = 0;
  7263. +
  7264. + spin_lock_bh(&hif->lock);
  7265. +
  7266. + rtc = hif->rxtoclean_index;
  7267. +
  7268. + while (rx_processed < budget) {
  7269. + desc = hif->rx_base + rtc;
  7270. +
  7271. + __memcpy12(&local_desc, desc);
  7272. +
  7273. + /* ACK pending Rx interrupt */
  7274. + if (local_desc.ctrl & BD_CTRL_DESC_EN) {
  7275. + writel(HIF_INT | HIF_RXPKT_INT, HIF_INT_SRC);
  7276. +
  7277. + if (rx_processed == 0) {
  7278. + if (napi_first_batch == 1) {
  7279. + desc_p = hif->descr_baseaddr_p +
  7280. + ((unsigned long int)(desc) -
  7281. + (unsigned long
  7282. + int)hif->descr_baseaddr_v);
  7283. + napi_first_batch = 0;
  7284. + }
  7285. + }
  7286. +
  7287. + __memcpy12(&local_desc, desc);
  7288. +
  7289. + if (local_desc.ctrl & BD_CTRL_DESC_EN)
  7290. + break;
  7291. + }
  7292. +
  7293. + napi_first_batch = 0;
  7294. +
  7295. +#ifdef HIF_NAPI_STATS
  7296. + hif->napi_counters[NAPI_DESC_COUNT]++;
  7297. +#endif
  7298. + len = BD_BUF_LEN(local_desc.ctrl);
  7299. + /*
  7300. + * dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
  7301. + * hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
  7302. + */
  7303. + dma_unmap_single(hif->dev, DDR_PFE_TO_PHYS(local_desc.data),
  7304. + hif->rx_buf_len[rtc], DMA_FROM_DEVICE);
  7305. +
  7306. + pkt_hdr = (struct hif_hdr *)hif->rx_buf_addr[rtc];
  7307. +
  7308. + /* Track last HIF header received */
  7309. + if (!hif->started) {
  7310. + hif->started = 1;
  7311. +
  7312. + __memcpy8(&hif_hdr, pkt_hdr);
  7313. +
  7314. + hif->qno = hif_hdr.hdr.q_num;
  7315. + hif->client_id = hif_hdr.hdr.client_id;
  7316. + hif->client_ctrl = (hif_hdr.hdr.client_ctrl1 << 16) |
  7317. + hif_hdr.hdr.client_ctrl;
  7318. + flags = CL_DESC_FIRST;
  7319. +
  7320. + } else {
  7321. + flags = 0;
  7322. + }
  7323. +
  7324. + if (local_desc.ctrl & BD_CTRL_LIFM)
  7325. + flags |= CL_DESC_LAST;
  7326. +
  7327. + /* Check for valid client id and still registered */
  7328. + if ((hif->client_id >= HIF_CLIENTS_MAX) ||
  7329. + !(test_bit(hif->client_id,
  7330. + &hif->shm->g_client_status[0]))) {
  7331. + printk_ratelimited("%s: packet with invalid client id %d q_num %d\n",
  7332. + __func__,
  7333. + hif->client_id,
  7334. + hif->qno);
  7335. +
  7336. + free_buf = pkt_hdr;
  7337. +
  7338. + goto pkt_drop;
  7339. + }
  7340. +
  7341. + /* Check to valid queue number */
  7342. + if (hif->client[hif->client_id].rx_qn <= hif->qno) {
  7343. + pr_info("%s: packet with invalid queue: %d\n"
  7344. + , __func__, hif->qno);
  7345. + hif->qno = 0;
  7346. + }
  7347. +
  7348. + free_buf =
  7349. + client_put_rxpacket(&hif->client[hif->client_id].rx_q[hif->qno],
  7350. + (void *)pkt_hdr, len, flags,
  7351. + hif->client_ctrl, &buf_size);
  7352. +
  7353. + hif_lib_indicate_client(hif->client_id, EVENT_RX_PKT_IND,
  7354. + hif->qno);
  7355. +
  7356. + if (unlikely(!free_buf)) {
  7357. +#ifdef HIF_NAPI_STATS
  7358. + hif->napi_counters[NAPI_CLIENT_FULL_COUNT]++;
  7359. +#endif
  7360. + /*
  7361. + * If we want to keep in polling mode to retry later,
  7362. + * we need to tell napi that we consumed
  7363. + * the full budget or we will hit a livelock scenario.
  7364. + * The core code keeps this napi instance
  7365. + * at the head of the list and none of the other
  7366. + * instances get to run
  7367. + */
  7368. + rx_processed = budget;
  7369. +
  7370. + if (flags & CL_DESC_FIRST)
  7371. + hif->started = 0;
  7372. +
  7373. + break;
  7374. + }
  7375. +
  7376. +pkt_drop:
  7377. + /*Fill free buffer in the descriptor */
  7378. + hif->rx_buf_addr[rtc] = free_buf;
  7379. + hif->rx_buf_len[rtc] = min(pfe_pkt_size, buf_size);
  7380. + writel((DDR_PHYS_TO_PFE
  7381. + ((u32)dma_map_single(hif->dev,
  7382. + free_buf, hif->rx_buf_len[rtc], DMA_FROM_DEVICE))),
  7383. + &desc->data);
  7384. + /*
  7385. + * Ensure everything else is written to DDR before
  7386. + * writing bd->ctrl
  7387. + */
  7388. + wmb();
  7389. + writel((BD_CTRL_PKT_INT_EN | BD_CTRL_LIFM | BD_CTRL_DIR |
  7390. + BD_CTRL_DESC_EN | BD_BUF_LEN(hif->rx_buf_len[rtc])),
  7391. + &desc->ctrl);
  7392. +
  7393. + rtc = (rtc + 1) & (hif->rx_ring_size - 1);
  7394. +
  7395. + if (local_desc.ctrl & BD_CTRL_LIFM) {
  7396. + if (!(hif->client_ctrl & HIF_CTRL_RX_CONTINUED)) {
  7397. + rx_processed++;
  7398. +
  7399. +#ifdef HIF_NAPI_STATS
  7400. + hif->napi_counters[NAPI_PACKET_COUNT]++;
  7401. +#endif
  7402. + }
  7403. + hif->started = 0;
  7404. + }
  7405. + }
  7406. +
  7407. + hif->rxtoclean_index = rtc;
  7408. + spin_unlock_bh(&hif->lock);
  7409. +
  7410. + /* we made some progress, re-start rx dma in case it stopped */
  7411. + hif_rx_dma_start();
  7412. +
  7413. + return rx_processed;
  7414. +}
  7415. +
  7416. +/*
  7417. + * client_ack_txpacket-
  7418. + * This function ack the Tx packet in the give client Tx queue by resetting
  7419. + * ownership bit in the descriptor.
  7420. + */
  7421. +static int client_ack_txpacket(struct pfe_hif *hif, unsigned int client_id,
  7422. + unsigned int q_no)
  7423. +{
  7424. + struct hif_tx_queue *queue = &hif->client[client_id].tx_q[q_no];
  7425. + struct tx_queue_desc *desc = queue->base + queue->ack_idx;
  7426. +
  7427. + if (readl(&desc->ctrl) & CL_DESC_OWN) {
  7428. + writel((readl(&desc->ctrl) & ~CL_DESC_OWN), &desc->ctrl);
  7429. + queue->ack_idx = (queue->ack_idx + 1) & (queue->size - 1);
  7430. +
  7431. + return 0;
  7432. +
  7433. + } else {
  7434. + /*This should not happen */
  7435. + pr_err("%s: %d %d %d %d %d %p %d\n", __func__,
  7436. + hif->txtosend, hif->txtoclean, hif->txavail,
  7437. + client_id, q_no, queue, queue->ack_idx);
  7438. + WARN(1, "%s: doesn't own this descriptor", __func__);
  7439. + return 1;
  7440. + }
  7441. +}
  7442. +
  7443. +void __hif_tx_done_process(struct pfe_hif *hif, int count)
  7444. +{
  7445. + struct hif_desc *desc;
  7446. + struct hif_desc_sw *desc_sw;
  7447. + int ttc, tx_avl;
  7448. + int pkts_done[HIF_CLIENTS_MAX] = {0, 0};
  7449. +
  7450. + ttc = hif->txtoclean;
  7451. + tx_avl = hif->txavail;
  7452. +
  7453. + while ((tx_avl < hif->tx_ring_size) && count--) {
  7454. + desc = hif->tx_base + ttc;
  7455. +
  7456. + if (readl(&desc->ctrl) & BD_CTRL_DESC_EN)
  7457. + break;
  7458. +
  7459. + desc_sw = &hif->tx_sw_queue[ttc];
  7460. +
  7461. + if (desc_sw->data) {
  7462. + /*
  7463. + * dmap_unmap_single(hif->dev, desc_sw->data,
  7464. + * desc_sw->len, DMA_TO_DEVICE);
  7465. + */
  7466. + dma_unmap_single(hif->dev, desc_sw->data,
  7467. + desc_sw->len, DMA_TO_DEVICE);
  7468. + }
  7469. +
  7470. + if (desc_sw->client_id > HIF_CLIENTS_MAX)
  7471. + pr_err("Invalid cl id %d\n", desc_sw->client_id);
  7472. +
  7473. + pkts_done[desc_sw->client_id]++;
  7474. +
  7475. + client_ack_txpacket(hif, desc_sw->client_id, desc_sw->q_no);
  7476. +
  7477. + ttc = (ttc + 1) & (hif->tx_ring_size - 1);
  7478. + tx_avl++;
  7479. + }
  7480. +
  7481. + if (pkts_done[0])
  7482. + hif_lib_indicate_client(0, EVENT_TXDONE_IND, 0);
  7483. + if (pkts_done[1])
  7484. + hif_lib_indicate_client(1, EVENT_TXDONE_IND, 0);
  7485. +
  7486. + hif->txtoclean = ttc;
  7487. + hif->txavail = tx_avl;
  7488. +
  7489. + if (!count) {
  7490. + tasklet_schedule(&hif->tx_cleanup_tasklet);
  7491. + } else {
  7492. + /*Enable Tx done interrupt */
  7493. + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_TXPKT_INT,
  7494. + HIF_INT_ENABLE);
  7495. + }
  7496. +}
  7497. +
  7498. +static void pfe_tx_do_cleanup(unsigned long data)
  7499. +{
  7500. + struct pfe_hif *hif = (struct pfe_hif *)data;
  7501. +
  7502. + writel(HIF_INT | HIF_TXPKT_INT, HIF_INT_SRC);
  7503. +
  7504. + hif_tx_done_process(hif, 64);
  7505. +}
  7506. +
  7507. +/*
  7508. + * __hif_xmit_pkt -
  7509. + * This function puts one packet in the HIF Tx queue
  7510. + */
  7511. +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
  7512. + q_no, void *data, u32 len, unsigned int flags)
  7513. +{
  7514. + struct hif_desc *desc;
  7515. + struct hif_desc_sw *desc_sw;
  7516. +
  7517. + desc = hif->tx_base + hif->txtosend;
  7518. + desc_sw = &hif->tx_sw_queue[hif->txtosend];
  7519. +
  7520. + desc_sw->len = len;
  7521. + desc_sw->client_id = client_id;
  7522. + desc_sw->q_no = q_no;
  7523. + desc_sw->flags = flags;
  7524. +
  7525. + if (flags & HIF_DONT_DMA_MAP) {
  7526. + desc_sw->data = 0;
  7527. + writel((u32)DDR_PHYS_TO_PFE(data), &desc->data);
  7528. + } else {
  7529. + desc_sw->data = dma_map_single(hif->dev, data, len,
  7530. + DMA_TO_DEVICE);
  7531. + writel((u32)DDR_PHYS_TO_PFE(desc_sw->data), &desc->data);
  7532. + }
  7533. +
  7534. + hif->txtosend = (hif->txtosend + 1) & (hif->tx_ring_size - 1);
  7535. + hif->txavail--;
  7536. +
  7537. + if ((!((flags & HIF_DATA_VALID) && (flags &
  7538. + HIF_LAST_BUFFER))))
  7539. + goto skip_tx;
  7540. +
  7541. + /*
  7542. + * Ensure everything else is written to DDR before
  7543. + * writing bd->ctrl
  7544. + */
  7545. + wmb();
  7546. +
  7547. + do {
  7548. + desc_sw = &hif->tx_sw_queue[hif->txtoflush];
  7549. + desc = hif->tx_base + hif->txtoflush;
  7550. +
  7551. + if (desc_sw->flags & HIF_LAST_BUFFER) {
  7552. + writel((BD_CTRL_LIFM |
  7553. + BD_CTRL_BRFETCH_DISABLE | BD_CTRL_RTFETCH_DISABLE
  7554. + | BD_CTRL_PARSE_DISABLE | BD_CTRL_DESC_EN |
  7555. + BD_CTRL_PKT_INT_EN | BD_BUF_LEN(desc_sw->len)),
  7556. + &desc->ctrl);
  7557. + } else {
  7558. + writel((BD_CTRL_DESC_EN |
  7559. + BD_BUF_LEN(desc_sw->len)), &desc->ctrl);
  7560. + }
  7561. + hif->txtoflush = (hif->txtoflush + 1) & (hif->tx_ring_size - 1);
  7562. + }
  7563. + while (hif->txtoflush != hif->txtosend)
  7564. + ;
  7565. +
  7566. +skip_tx:
  7567. + return;
  7568. +}
  7569. +
  7570. +static irqreturn_t wol_isr(int irq, void *dev_id)
  7571. +{
  7572. + pr_info("WoL\n");
  7573. + gemac_set_wol(EMAC1_BASE_ADDR, 0);
  7574. + gemac_set_wol(EMAC2_BASE_ADDR, 0);
  7575. + return IRQ_HANDLED;
  7576. +}
  7577. +
  7578. +/*
  7579. + * hif_isr-
  7580. + * This ISR routine processes Rx/Tx done interrupts from the HIF hardware block
  7581. + */
  7582. +static irqreturn_t hif_isr(int irq, void *dev_id)
  7583. +{
  7584. + struct pfe_hif *hif = (struct pfe_hif *)dev_id;
  7585. + int int_status;
  7586. + int int_enable_mask;
  7587. +
  7588. + /*Read hif interrupt source register */
  7589. + int_status = readl_relaxed(HIF_INT_SRC);
  7590. + int_enable_mask = readl_relaxed(HIF_INT_ENABLE);
  7591. +
  7592. + if ((int_status & HIF_INT) == 0)
  7593. + return IRQ_NONE;
  7594. +
  7595. + int_status &= ~(HIF_INT);
  7596. +
  7597. + if (int_status & HIF_RXPKT_INT) {
  7598. + int_status &= ~(HIF_RXPKT_INT);
  7599. + int_enable_mask &= ~(HIF_RXPKT_INT);
  7600. +
  7601. + napi_first_batch = 1;
  7602. +
  7603. + if (napi_schedule_prep(&hif->napi)) {
  7604. +#ifdef HIF_NAPI_STATS
  7605. + hif->napi_counters[NAPI_SCHED_COUNT]++;
  7606. +#endif
  7607. + __napi_schedule(&hif->napi);
  7608. + }
  7609. + }
  7610. +
  7611. + if (int_status & HIF_TXPKT_INT) {
  7612. + int_status &= ~(HIF_TXPKT_INT);
  7613. + int_enable_mask &= ~(HIF_TXPKT_INT);
  7614. + /*Schedule tx cleanup tassklet */
  7615. + tasklet_schedule(&hif->tx_cleanup_tasklet);
  7616. + }
  7617. +
  7618. + /*Disable interrupts, they will be enabled after they are serviced */
  7619. + writel_relaxed(int_enable_mask, HIF_INT_ENABLE);
  7620. +
  7621. + if (int_status) {
  7622. + pr_info("%s : Invalid interrupt : %d\n", __func__,
  7623. + int_status);
  7624. + writel(int_status, HIF_INT_SRC);
  7625. + }
  7626. +
  7627. + return IRQ_HANDLED;
  7628. +}
  7629. +
  7630. +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int data2)
  7631. +{
  7632. + unsigned int client_id = data1;
  7633. +
  7634. + if (client_id >= HIF_CLIENTS_MAX) {
  7635. + pr_err("%s: client id %d out of bounds\n", __func__,
  7636. + client_id);
  7637. + return;
  7638. + }
  7639. +
  7640. + switch (req) {
  7641. + case REQUEST_CL_REGISTER:
  7642. + /* Request for register a client */
  7643. + pr_info("%s: register client_id %d\n",
  7644. + __func__, client_id);
  7645. + pfe_hif_client_register(hif, client_id, (struct
  7646. + hif_client_shm *)&hif->shm->client[client_id]);
  7647. + break;
  7648. +
  7649. + case REQUEST_CL_UNREGISTER:
  7650. + pr_info("%s: unregister client_id %d\n",
  7651. + __func__, client_id);
  7652. +
  7653. + /* Request for unregister a client */
  7654. + pfe_hif_client_unregister(hif, client_id);
  7655. +
  7656. + break;
  7657. +
  7658. + default:
  7659. + pr_err("%s: unsupported request %d\n",
  7660. + __func__, req);
  7661. + break;
  7662. + }
  7663. +
  7664. + /*
  7665. + * Process client Tx queues
  7666. + * Currently we don't have checking for tx pending
  7667. + */
  7668. +}
  7669. +
  7670. +/*
  7671. + * pfe_hif_rx_poll
  7672. + * This function is NAPI poll function to process HIF Rx queue.
  7673. + */
  7674. +static int pfe_hif_rx_poll(struct napi_struct *napi, int budget)
  7675. +{
  7676. + struct pfe_hif *hif = container_of(napi, struct pfe_hif, napi);
  7677. + int work_done;
  7678. +
  7679. +#ifdef HIF_NAPI_STATS
  7680. + hif->napi_counters[NAPI_POLL_COUNT]++;
  7681. +#endif
  7682. +
  7683. + work_done = pfe_hif_rx_process(hif, budget);
  7684. +
  7685. + if (work_done < budget) {
  7686. + napi_complete(napi);
  7687. + writel(readl_relaxed(HIF_INT_ENABLE) | HIF_RXPKT_INT,
  7688. + HIF_INT_ENABLE);
  7689. + }
  7690. +#ifdef HIF_NAPI_STATS
  7691. + else
  7692. + hif->napi_counters[NAPI_FULL_BUDGET_COUNT]++;
  7693. +#endif
  7694. +
  7695. + return work_done;
  7696. +}
  7697. +
  7698. +/*
  7699. + * pfe_hif_init
  7700. + * This function initializes the baseaddresses and irq, etc.
  7701. + */
  7702. +int pfe_hif_init(struct pfe *pfe)
  7703. +{
  7704. + struct pfe_hif *hif = &pfe->hif;
  7705. + int err;
  7706. +
  7707. + pr_info("%s\n", __func__);
  7708. +
  7709. + hif->dev = pfe->dev;
  7710. + hif->irq = pfe->hif_irq;
  7711. +
  7712. + err = pfe_hif_alloc_descr(hif);
  7713. + if (err)
  7714. + goto err0;
  7715. +
  7716. + if (pfe_hif_init_buffers(hif)) {
  7717. + pr_err("%s: Could not initialize buffer descriptors\n"
  7718. + , __func__);
  7719. + err = -ENOMEM;
  7720. + goto err1;
  7721. + }
  7722. +
  7723. + /* Initialize NAPI for Rx processing */
  7724. + init_dummy_netdev(&hif->dummy_dev);
  7725. + netif_napi_add(&hif->dummy_dev, &hif->napi, pfe_hif_rx_poll,
  7726. + HIF_RX_POLL_WEIGHT);
  7727. + napi_enable(&hif->napi);
  7728. +
  7729. + spin_lock_init(&hif->tx_lock);
  7730. + spin_lock_init(&hif->lock);
  7731. +
  7732. + hif_init();
  7733. + hif_rx_enable();
  7734. + hif_tx_enable();
  7735. +
  7736. + /* Disable tx done interrupt */
  7737. + writel(HIF_INT_MASK, HIF_INT_ENABLE);
  7738. +
  7739. + gpi_enable(HGPI_BASE_ADDR);
  7740. +
  7741. + err = request_irq(hif->irq, hif_isr, 0, "pfe_hif", hif);
  7742. + if (err) {
  7743. + pr_err("%s: failed to get the hif IRQ = %d\n",
  7744. + __func__, hif->irq);
  7745. + goto err1;
  7746. + }
  7747. +
  7748. + err = request_irq(pfe->wol_irq, wol_isr, 0, "pfe_wol", pfe);
  7749. + if (err) {
  7750. + pr_err("%s: failed to get the wol IRQ = %d\n",
  7751. + __func__, pfe->wol_irq);
  7752. + goto err1;
  7753. + }
  7754. +
  7755. + tasklet_init(&hif->tx_cleanup_tasklet,
  7756. + (void(*)(unsigned long))pfe_tx_do_cleanup,
  7757. + (unsigned long)hif);
  7758. +
  7759. + return 0;
  7760. +err1:
  7761. + pfe_hif_free_descr(hif);
  7762. +err0:
  7763. + return err;
  7764. +}
  7765. +
  7766. +/* pfe_hif_exit- */
  7767. +void pfe_hif_exit(struct pfe *pfe)
  7768. +{
  7769. + struct pfe_hif *hif = &pfe->hif;
  7770. +
  7771. + pr_info("%s\n", __func__);
  7772. +
  7773. + tasklet_kill(&hif->tx_cleanup_tasklet);
  7774. +
  7775. + spin_lock_bh(&hif->lock);
  7776. + hif->shm->g_client_status[0] = 0;
  7777. + /* Make sure all clients are disabled*/
  7778. + hif->shm->g_client_status[1] = 0;
  7779. +
  7780. + spin_unlock_bh(&hif->lock);
  7781. +
  7782. + /*Disable Rx/Tx */
  7783. + gpi_disable(HGPI_BASE_ADDR);
  7784. + hif_rx_disable();
  7785. + hif_tx_disable();
  7786. +
  7787. + napi_disable(&hif->napi);
  7788. + netif_napi_del(&hif->napi);
  7789. +
  7790. + free_irq(pfe->wol_irq, pfe);
  7791. + free_irq(hif->irq, hif);
  7792. +
  7793. + pfe_hif_release_buffers(hif);
  7794. + pfe_hif_free_descr(hif);
  7795. +}
  7796. diff --git a/drivers/staging/fsl_ppfe/pfe_hif.h b/drivers/staging/fsl_ppfe/pfe_hif.h
  7797. new file mode 100644
  7798. index 00000000..6e36f0c1
  7799. --- /dev/null
  7800. +++ b/drivers/staging/fsl_ppfe/pfe_hif.h
  7801. @@ -0,0 +1,211 @@
  7802. +/*
  7803. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  7804. + * Copyright 2017 NXP
  7805. + *
  7806. + * This program is free software; you can redistribute it and/or modify
  7807. + * it under the terms of the GNU General Public License as published by
  7808. + * the Free Software Foundation; either version 2 of the License, or
  7809. + * (at your option) any later version.
  7810. + *
  7811. + * This program is distributed in the hope that it will be useful,
  7812. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7813. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7814. + * GNU General Public License for more details.
  7815. + *
  7816. + * You should have received a copy of the GNU General Public License
  7817. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  7818. + */
  7819. +
  7820. +#ifndef _PFE_HIF_H_
  7821. +#define _PFE_HIF_H_
  7822. +
  7823. +#include <linux/netdevice.h>
  7824. +
  7825. +#define HIF_NAPI_STATS
  7826. +
  7827. +#define HIF_CLIENT_QUEUES_MAX 16
  7828. +#define HIF_RX_POLL_WEIGHT 64
  7829. +
  7830. +#define HIF_RX_PKT_MIN_SIZE 0x800 /* 2KB */
  7831. +#define HIF_RX_PKT_MIN_SIZE_MASK ~(HIF_RX_PKT_MIN_SIZE - 1)
  7832. +#define ROUND_MIN_RX_SIZE(_sz) (((_sz) + (HIF_RX_PKT_MIN_SIZE - 1)) \
  7833. + & HIF_RX_PKT_MIN_SIZE_MASK)
  7834. +#define PRESENT_OFST_IN_PAGE(_buf) (((unsigned long int)(_buf) & (PAGE_SIZE \
  7835. + - 1)) & HIF_RX_PKT_MIN_SIZE_MASK)
  7836. +
  7837. +enum {
  7838. + NAPI_SCHED_COUNT = 0,
  7839. + NAPI_POLL_COUNT,
  7840. + NAPI_PACKET_COUNT,
  7841. + NAPI_DESC_COUNT,
  7842. + NAPI_FULL_BUDGET_COUNT,
  7843. + NAPI_CLIENT_FULL_COUNT,
  7844. + NAPI_MAX_COUNT
  7845. +};
  7846. +
  7847. +/*
  7848. + * HIF_TX_DESC_NT value should be always greter than 4,
  7849. + * Otherwise HIF_TX_POLL_MARK will become zero.
  7850. + */
  7851. +#define HIF_RX_DESC_NT 256
  7852. +#define HIF_TX_DESC_NT 2048
  7853. +
  7854. +#define HIF_FIRST_BUFFER BIT(0)
  7855. +#define HIF_LAST_BUFFER BIT(1)
  7856. +#define HIF_DONT_DMA_MAP BIT(2)
  7857. +#define HIF_DATA_VALID BIT(3)
  7858. +#define HIF_TSO BIT(4)
  7859. +
  7860. +enum {
  7861. + PFE_CL_GEM0 = 0,
  7862. + PFE_CL_GEM1,
  7863. + HIF_CLIENTS_MAX
  7864. +};
  7865. +
  7866. +/*structure to store client queue info */
  7867. +struct hif_rx_queue {
  7868. + struct rx_queue_desc *base;
  7869. + u32 size;
  7870. + u32 write_idx;
  7871. +};
  7872. +
  7873. +struct hif_tx_queue {
  7874. + struct tx_queue_desc *base;
  7875. + u32 size;
  7876. + u32 ack_idx;
  7877. +};
  7878. +
  7879. +/*Structure to store the client info */
  7880. +struct hif_client {
  7881. + int rx_qn;
  7882. + struct hif_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
  7883. + int tx_qn;
  7884. + struct hif_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
  7885. +};
  7886. +
  7887. +/*HIF hardware buffer descriptor */
  7888. +struct hif_desc {
  7889. + u32 ctrl;
  7890. + u32 status;
  7891. + u32 data;
  7892. + u32 next;
  7893. +};
  7894. +
  7895. +struct __hif_desc {
  7896. + u32 ctrl;
  7897. + u32 status;
  7898. + u32 data;
  7899. +};
  7900. +
  7901. +struct hif_desc_sw {
  7902. + dma_addr_t data;
  7903. + u16 len;
  7904. + u8 client_id;
  7905. + u8 q_no;
  7906. + u16 flags;
  7907. +};
  7908. +
  7909. +struct hif_hdr {
  7910. + u8 client_id;
  7911. + u8 q_num;
  7912. + u16 client_ctrl;
  7913. + u16 client_ctrl1;
  7914. +};
  7915. +
  7916. +struct __hif_hdr {
  7917. + union {
  7918. + struct hif_hdr hdr;
  7919. + u32 word[2];
  7920. + };
  7921. +};
  7922. +
  7923. +struct hif_ipsec_hdr {
  7924. + u16 sa_handle[2];
  7925. +} __packed;
  7926. +
  7927. +/* HIF_CTRL_TX... defines */
  7928. +#define HIF_CTRL_TX_CHECKSUM BIT(2)
  7929. +
  7930. +/* HIF_CTRL_RX... defines */
  7931. +#define HIF_CTRL_RX_OFFSET_OFST (24)
  7932. +#define HIF_CTRL_RX_CHECKSUMMED BIT(2)
  7933. +#define HIF_CTRL_RX_CONTINUED BIT(1)
  7934. +
  7935. +struct pfe_hif {
  7936. + /* To store registered clients in hif layer */
  7937. + struct hif_client client[HIF_CLIENTS_MAX];
  7938. + struct hif_shm *shm;
  7939. + int irq;
  7940. +
  7941. + void *descr_baseaddr_v;
  7942. + unsigned long descr_baseaddr_p;
  7943. +
  7944. + struct hif_desc *rx_base;
  7945. + u32 rx_ring_size;
  7946. + u32 rxtoclean_index;
  7947. + void *rx_buf_addr[HIF_RX_DESC_NT];
  7948. + int rx_buf_len[HIF_RX_DESC_NT];
  7949. + unsigned int qno;
  7950. + unsigned int client_id;
  7951. + unsigned int client_ctrl;
  7952. + unsigned int started;
  7953. +
  7954. + struct hif_desc *tx_base;
  7955. + u32 tx_ring_size;
  7956. + u32 txtosend;
  7957. + u32 txtoclean;
  7958. + u32 txavail;
  7959. + u32 txtoflush;
  7960. + struct hif_desc_sw tx_sw_queue[HIF_TX_DESC_NT];
  7961. +
  7962. +/* tx_lock synchronizes hif packet tx as well as pfe_hif structure access */
  7963. + spinlock_t tx_lock;
  7964. +/* lock synchronizes hif rx queue processing */
  7965. + spinlock_t lock;
  7966. + struct net_device dummy_dev;
  7967. + struct napi_struct napi;
  7968. + struct device *dev;
  7969. +
  7970. +#ifdef HIF_NAPI_STATS
  7971. + unsigned int napi_counters[NAPI_MAX_COUNT];
  7972. +#endif
  7973. + struct tasklet_struct tx_cleanup_tasklet;
  7974. +};
  7975. +
  7976. +void __hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int
  7977. + q_no, void *data, u32 len, unsigned int flags);
  7978. +int hif_xmit_pkt(struct pfe_hif *hif, unsigned int client_id, unsigned int q_no,
  7979. + void *data, unsigned int len);
  7980. +void __hif_tx_done_process(struct pfe_hif *hif, int count);
  7981. +void hif_process_client_req(struct pfe_hif *hif, int req, int data1, int
  7982. + data2);
  7983. +int pfe_hif_init(struct pfe *pfe);
  7984. +void pfe_hif_exit(struct pfe *pfe);
  7985. +void pfe_hif_rx_idle(struct pfe_hif *hif);
  7986. +static inline void hif_tx_done_process(struct pfe_hif *hif, int count)
  7987. +{
  7988. + spin_lock_bh(&hif->tx_lock);
  7989. + __hif_tx_done_process(hif, count);
  7990. + spin_unlock_bh(&hif->tx_lock);
  7991. +}
  7992. +
  7993. +static inline void hif_tx_lock(struct pfe_hif *hif)
  7994. +{
  7995. + spin_lock_bh(&hif->tx_lock);
  7996. +}
  7997. +
  7998. +static inline void hif_tx_unlock(struct pfe_hif *hif)
  7999. +{
  8000. + spin_unlock_bh(&hif->tx_lock);
  8001. +}
  8002. +
  8003. +static inline int __hif_tx_avail(struct pfe_hif *hif)
  8004. +{
  8005. + return hif->txavail;
  8006. +}
  8007. +
  8008. +#define __memcpy8(dst, src) memcpy(dst, src, 8)
  8009. +#define __memcpy12(dst, src) memcpy(dst, src, 12)
  8010. +#define __memcpy(dst, src, len) memcpy(dst, src, len)
  8011. +
  8012. +#endif /* _PFE_HIF_H_ */
  8013. diff --git a/drivers/staging/fsl_ppfe/pfe_hif_lib.c b/drivers/staging/fsl_ppfe/pfe_hif_lib.c
  8014. new file mode 100644
  8015. index 00000000..837eaa24
  8016. --- /dev/null
  8017. +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.c
  8018. @@ -0,0 +1,601 @@
  8019. +/*
  8020. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  8021. + * Copyright 2017 NXP
  8022. + *
  8023. + * This program is free software; you can redistribute it and/or modify
  8024. + * it under the terms of the GNU General Public License as published by
  8025. + * the Free Software Foundation; either version 2 of the License, or
  8026. + * (at your option) any later version.
  8027. + *
  8028. + * This program is distributed in the hope that it will be useful,
  8029. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8030. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8031. + * GNU General Public License for more details.
  8032. + *
  8033. + * You should have received a copy of the GNU General Public License
  8034. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8035. + */
  8036. +
  8037. +#include <linux/version.h>
  8038. +#include <linux/kernel.h>
  8039. +#include <linux/slab.h>
  8040. +#include <linux/interrupt.h>
  8041. +#include <linux/workqueue.h>
  8042. +#include <linux/dma-mapping.h>
  8043. +#include <linux/dmapool.h>
  8044. +#include <linux/sched.h>
  8045. +#include <linux/skbuff.h>
  8046. +#include <linux/moduleparam.h>
  8047. +#include <linux/cpu.h>
  8048. +
  8049. +#include "pfe_mod.h"
  8050. +#include "pfe_hif.h"
  8051. +#include "pfe_hif_lib.h"
  8052. +
  8053. +unsigned int lro_mode;
  8054. +unsigned int page_mode;
  8055. +unsigned int tx_qos;
  8056. +unsigned int pfe_pkt_size;
  8057. +unsigned int pfe_pkt_headroom;
  8058. +unsigned int emac_txq_cnt;
  8059. +
  8060. +/*
  8061. + * @pfe_hal_lib.c.
  8062. + * Common functions used by HIF client drivers
  8063. + */
  8064. +
  8065. +/*HIF shared memory Global variable */
  8066. +struct hif_shm ghif_shm;
  8067. +
  8068. +/* Cleanup the HIF shared memory, release HIF rx_buffer_pool.
  8069. + * This function should be called after pfe_hif_exit
  8070. + *
  8071. + * @param[in] hif_shm Shared memory address location in DDR
  8072. + */
  8073. +static void pfe_hif_shm_clean(struct hif_shm *hif_shm)
  8074. +{
  8075. + int i;
  8076. + void *pkt;
  8077. +
  8078. + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
  8079. + pkt = hif_shm->rx_buf_pool[i];
  8080. + if (pkt) {
  8081. + hif_shm->rx_buf_pool[i] = NULL;
  8082. + pkt -= pfe_pkt_headroom;
  8083. +
  8084. + if (page_mode)
  8085. + put_page(virt_to_page(pkt));
  8086. + else
  8087. + kfree(pkt);
  8088. + }
  8089. + }
  8090. +}
  8091. +
  8092. +/* Initialize shared memory used between HIF driver and clients,
  8093. + * allocate rx_buffer_pool required for HIF Rx descriptors.
  8094. + * This function should be called before initializing HIF driver.
  8095. + *
  8096. + * @param[in] hif_shm Shared memory address location in DDR
  8097. + * @rerurn 0 - on succes, <0 on fail to initialize
  8098. + */
  8099. +static int pfe_hif_shm_init(struct hif_shm *hif_shm)
  8100. +{
  8101. + int i;
  8102. + void *pkt;
  8103. +
  8104. + memset(hif_shm, 0, sizeof(struct hif_shm));
  8105. + hif_shm->rx_buf_pool_cnt = HIF_RX_DESC_NT;
  8106. +
  8107. + for (i = 0; i < hif_shm->rx_buf_pool_cnt; i++) {
  8108. + if (page_mode) {
  8109. + pkt = (void *)__get_free_page(GFP_KERNEL |
  8110. + GFP_DMA_PFE);
  8111. + } else {
  8112. + pkt = kmalloc(PFE_BUF_SIZE, GFP_KERNEL | GFP_DMA_PFE);
  8113. + }
  8114. +
  8115. + if (pkt)
  8116. + hif_shm->rx_buf_pool[i] = pkt + pfe_pkt_headroom;
  8117. + else
  8118. + goto err0;
  8119. + }
  8120. +
  8121. + return 0;
  8122. +
  8123. +err0:
  8124. + pr_err("%s Low memory\n", __func__);
  8125. + pfe_hif_shm_clean(hif_shm);
  8126. + return -ENOMEM;
  8127. +}
  8128. +
  8129. +/*This function sends indication to HIF driver
  8130. + *
  8131. + * @param[in] hif hif context
  8132. + */
  8133. +static void hif_lib_indicate_hif(struct pfe_hif *hif, int req, int data1, int
  8134. + data2)
  8135. +{
  8136. + hif_process_client_req(hif, req, data1, data2);
  8137. +}
  8138. +
  8139. +void hif_lib_indicate_client(int client_id, int event_type, int qno)
  8140. +{
  8141. + struct hif_client_s *client = pfe->hif_client[client_id];
  8142. +
  8143. + if (!client || (event_type >= HIF_EVENT_MAX) || (qno >=
  8144. + HIF_CLIENT_QUEUES_MAX))
  8145. + return;
  8146. +
  8147. + if (!test_and_set_bit(qno, &client->queue_mask[event_type]))
  8148. + client->event_handler(client->priv, event_type, qno);
  8149. +}
  8150. +
  8151. +/*This function releases Rx queue descriptors memory and pre-filled buffers
  8152. + *
  8153. + * @param[in] client hif_client context
  8154. + */
  8155. +static void hif_lib_client_release_rx_buffers(struct hif_client_s *client)
  8156. +{
  8157. + struct rx_queue_desc *desc;
  8158. + int qno, ii;
  8159. + void *buf;
  8160. +
  8161. + for (qno = 0; qno < client->rx_qn; qno++) {
  8162. + desc = client->rx_q[qno].base;
  8163. +
  8164. + for (ii = 0; ii < client->rx_q[qno].size; ii++) {
  8165. + buf = (void *)desc->data;
  8166. + if (buf) {
  8167. + buf -= pfe_pkt_headroom;
  8168. +
  8169. + if (page_mode)
  8170. + free_page((unsigned long)buf);
  8171. + else
  8172. + kfree(buf);
  8173. +
  8174. + desc->ctrl = 0;
  8175. + }
  8176. +
  8177. + desc++;
  8178. + }
  8179. + }
  8180. +
  8181. + kfree(client->rx_qbase);
  8182. +}
  8183. +
  8184. +/*This function allocates memory for the rxq descriptors and pre-fill rx queues
  8185. + * with buffers.
  8186. + * @param[in] client client context
  8187. + * @param[in] q_size size of the rxQ, all queues are of same size
  8188. + */
  8189. +static int hif_lib_client_init_rx_buffers(struct hif_client_s *client, int
  8190. + q_size)
  8191. +{
  8192. + struct rx_queue_desc *desc;
  8193. + struct hif_client_rx_queue *queue;
  8194. + int ii, qno;
  8195. +
  8196. + /*Allocate memory for the client queues */
  8197. + client->rx_qbase = kzalloc(client->rx_qn * q_size * sizeof(struct
  8198. + rx_queue_desc), GFP_KERNEL);
  8199. + if (!client->rx_qbase)
  8200. + goto err;
  8201. +
  8202. + for (qno = 0; qno < client->rx_qn; qno++) {
  8203. + queue = &client->rx_q[qno];
  8204. +
  8205. + queue->base = client->rx_qbase + qno * q_size * sizeof(struct
  8206. + rx_queue_desc);
  8207. + queue->size = q_size;
  8208. + queue->read_idx = 0;
  8209. + queue->write_idx = 0;
  8210. +
  8211. + pr_debug("rx queue: %d, base: %p, size: %d\n", qno,
  8212. + queue->base, queue->size);
  8213. + }
  8214. +
  8215. + for (qno = 0; qno < client->rx_qn; qno++) {
  8216. + queue = &client->rx_q[qno];
  8217. + desc = queue->base;
  8218. +
  8219. + for (ii = 0; ii < queue->size; ii++) {
  8220. + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) |
  8221. + CL_DESC_OWN;
  8222. + desc++;
  8223. + }
  8224. + }
  8225. +
  8226. + return 0;
  8227. +
  8228. +err:
  8229. + return 1;
  8230. +}
  8231. +
  8232. +
  8233. +static void hif_lib_client_cleanup_tx_queue(struct hif_client_tx_queue *queue)
  8234. +{
  8235. + pr_debug("%s\n", __func__);
  8236. +
  8237. + /*
  8238. + * Check if there are any pending packets. Client must flush the tx
  8239. + * queues before unregistering, by calling by calling
  8240. + * hif_lib_tx_get_next_complete()
  8241. + *
  8242. + * Hif no longer calls since we are no longer registered
  8243. + */
  8244. + if (queue->tx_pending)
  8245. + pr_err("%s: pending transmit packets\n", __func__);
  8246. +}
  8247. +
  8248. +static void hif_lib_client_release_tx_buffers(struct hif_client_s *client)
  8249. +{
  8250. + int qno;
  8251. +
  8252. + pr_debug("%s\n", __func__);
  8253. +
  8254. + for (qno = 0; qno < client->tx_qn; qno++)
  8255. + hif_lib_client_cleanup_tx_queue(&client->tx_q[qno]);
  8256. +
  8257. + kfree(client->tx_qbase);
  8258. +}
  8259. +
  8260. +static int hif_lib_client_init_tx_buffers(struct hif_client_s *client, int
  8261. + q_size)
  8262. +{
  8263. + struct hif_client_tx_queue *queue;
  8264. + int qno;
  8265. +
  8266. + client->tx_qbase = kzalloc(client->tx_qn * q_size * sizeof(struct
  8267. + tx_queue_desc), GFP_KERNEL);
  8268. + if (!client->tx_qbase)
  8269. + return 1;
  8270. +
  8271. + for (qno = 0; qno < client->tx_qn; qno++) {
  8272. + queue = &client->tx_q[qno];
  8273. +
  8274. + queue->base = client->tx_qbase + qno * q_size * sizeof(struct
  8275. + tx_queue_desc);
  8276. + queue->size = q_size;
  8277. + queue->read_idx = 0;
  8278. + queue->write_idx = 0;
  8279. + queue->tx_pending = 0;
  8280. + queue->nocpy_flag = 0;
  8281. + queue->prev_tmu_tx_pkts = 0;
  8282. + queue->done_tmu_tx_pkts = 0;
  8283. +
  8284. + pr_debug("tx queue: %d, base: %p, size: %d\n", qno,
  8285. + queue->base, queue->size);
  8286. + }
  8287. +
  8288. + return 0;
  8289. +}
  8290. +
  8291. +static int hif_lib_event_dummy(void *priv, int event_type, int qno)
  8292. +{
  8293. + return 0;
  8294. +}
  8295. +
  8296. +int hif_lib_client_register(struct hif_client_s *client)
  8297. +{
  8298. + struct hif_shm *hif_shm;
  8299. + struct hif_client_shm *client_shm;
  8300. + int err, i;
  8301. + /* int loop_cnt = 0; */
  8302. +
  8303. + pr_debug("%s\n", __func__);
  8304. +
  8305. + /*Allocate memory before spin_lock*/
  8306. + if (hif_lib_client_init_rx_buffers(client, client->rx_qsize)) {
  8307. + err = -ENOMEM;
  8308. + goto err_rx;
  8309. + }
  8310. +
  8311. + if (hif_lib_client_init_tx_buffers(client, client->tx_qsize)) {
  8312. + err = -ENOMEM;
  8313. + goto err_tx;
  8314. + }
  8315. +
  8316. + spin_lock_bh(&pfe->hif.lock);
  8317. + if (!(client->pfe) || (client->id >= HIF_CLIENTS_MAX) ||
  8318. + (pfe->hif_client[client->id])) {
  8319. + err = -EINVAL;
  8320. + goto err;
  8321. + }
  8322. +
  8323. + hif_shm = client->pfe->hif.shm;
  8324. +
  8325. + if (!client->event_handler)
  8326. + client->event_handler = hif_lib_event_dummy;
  8327. +
  8328. + /*Initialize client specific shared memory */
  8329. + client_shm = (struct hif_client_shm *)&hif_shm->client[client->id];
  8330. + client_shm->rx_qbase = (unsigned long int)client->rx_qbase;
  8331. + client_shm->rx_qsize = client->rx_qsize;
  8332. + client_shm->tx_qbase = (unsigned long int)client->tx_qbase;
  8333. + client_shm->tx_qsize = client->tx_qsize;
  8334. + client_shm->ctrl = (client->tx_qn << CLIENT_CTRL_TX_Q_CNT_OFST) |
  8335. + (client->rx_qn << CLIENT_CTRL_RX_Q_CNT_OFST);
  8336. + /* spin_lock_init(&client->rx_lock); */
  8337. +
  8338. + for (i = 0; i < HIF_EVENT_MAX; i++) {
  8339. + client->queue_mask[i] = 0; /*
  8340. + * By default all events are
  8341. + * unmasked
  8342. + */
  8343. + }
  8344. +
  8345. + /*Indicate to HIF driver*/
  8346. + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_REGISTER, client->id, 0);
  8347. +
  8348. + pr_debug("%s: client: %p, client_id: %d, tx_qsize: %d, rx_qsize: %d\n",
  8349. + __func__, client, client->id, client->tx_qsize,
  8350. + client->rx_qsize);
  8351. +
  8352. + client->cpu_id = -1;
  8353. +
  8354. + pfe->hif_client[client->id] = client;
  8355. + spin_unlock_bh(&pfe->hif.lock);
  8356. +
  8357. + return 0;
  8358. +
  8359. +err:
  8360. + spin_unlock_bh(&pfe->hif.lock);
  8361. + hif_lib_client_release_tx_buffers(client);
  8362. +
  8363. +err_tx:
  8364. + hif_lib_client_release_rx_buffers(client);
  8365. +
  8366. +err_rx:
  8367. + return err;
  8368. +}
  8369. +
  8370. +int hif_lib_client_unregister(struct hif_client_s *client)
  8371. +{
  8372. + struct pfe *pfe = client->pfe;
  8373. + u32 client_id = client->id;
  8374. +
  8375. + pr_info(
  8376. + "%s : client: %p, client_id: %d, txQ_depth: %d, rxQ_depth: %d\n"
  8377. + , __func__, client, client->id, client->tx_qsize,
  8378. + client->rx_qsize);
  8379. +
  8380. + spin_lock_bh(&pfe->hif.lock);
  8381. + hif_lib_indicate_hif(&pfe->hif, REQUEST_CL_UNREGISTER, client->id, 0);
  8382. +
  8383. + hif_lib_client_release_tx_buffers(client);
  8384. + hif_lib_client_release_rx_buffers(client);
  8385. + pfe->hif_client[client_id] = NULL;
  8386. + spin_unlock_bh(&pfe->hif.lock);
  8387. +
  8388. + return 0;
  8389. +}
  8390. +
  8391. +int hif_lib_event_handler_start(struct hif_client_s *client, int event,
  8392. + int qno)
  8393. +{
  8394. + struct hif_client_rx_queue *queue = &client->rx_q[qno];
  8395. + struct rx_queue_desc *desc = queue->base + queue->read_idx;
  8396. +
  8397. + if ((event >= HIF_EVENT_MAX) || (qno >= HIF_CLIENT_QUEUES_MAX)) {
  8398. + pr_debug("%s: Unsupported event : %d queue number : %d\n",
  8399. + __func__, event, qno);
  8400. + return -1;
  8401. + }
  8402. +
  8403. + test_and_clear_bit(qno, &client->queue_mask[event]);
  8404. +
  8405. + switch (event) {
  8406. + case EVENT_RX_PKT_IND:
  8407. + if (!(desc->ctrl & CL_DESC_OWN))
  8408. + hif_lib_indicate_client(client->id,
  8409. + EVENT_RX_PKT_IND, qno);
  8410. + break;
  8411. +
  8412. + case EVENT_HIGH_RX_WM:
  8413. + case EVENT_TXDONE_IND:
  8414. + default:
  8415. + break;
  8416. + }
  8417. +
  8418. + return 0;
  8419. +}
  8420. +
  8421. +/*
  8422. + * This function gets one packet from the specified client queue
  8423. + * It also refill the rx buffer
  8424. + */
  8425. +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
  8426. + *ofst, unsigned int *rx_ctrl,
  8427. + unsigned int *desc_ctrl, void **priv_data)
  8428. +{
  8429. + struct hif_client_rx_queue *queue = &client->rx_q[qno];
  8430. + struct rx_queue_desc *desc;
  8431. + void *pkt = NULL;
  8432. +
  8433. + /*
  8434. + * Following lock is to protect rx queue access from,
  8435. + * hif_lib_event_handler_start.
  8436. + * In general below lock is not required, because hif_lib_xmit_pkt and
  8437. + * hif_lib_event_handler_start are called from napi poll and which is
  8438. + * not re-entrant. But if some client use in different way this lock is
  8439. + * required.
  8440. + */
  8441. + /*spin_lock_irqsave(&client->rx_lock, flags); */
  8442. + desc = queue->base + queue->read_idx;
  8443. + if (!(desc->ctrl & CL_DESC_OWN)) {
  8444. + pkt = desc->data - pfe_pkt_headroom;
  8445. +
  8446. + *rx_ctrl = desc->client_ctrl;
  8447. + *desc_ctrl = desc->ctrl;
  8448. +
  8449. + if (desc->ctrl & CL_DESC_FIRST) {
  8450. + u16 size = *rx_ctrl >> HIF_CTRL_RX_OFFSET_OFST;
  8451. +
  8452. + if (size) {
  8453. + *len = CL_DESC_BUF_LEN(desc->ctrl) -
  8454. + PFE_PKT_HEADER_SZ - size;
  8455. + *ofst = pfe_pkt_headroom + PFE_PKT_HEADER_SZ
  8456. + + size;
  8457. + *priv_data = desc->data + PFE_PKT_HEADER_SZ;
  8458. + } else {
  8459. + *len = CL_DESC_BUF_LEN(desc->ctrl) -
  8460. + PFE_PKT_HEADER_SZ;
  8461. + *ofst = pfe_pkt_headroom + PFE_PKT_HEADER_SZ;
  8462. + *priv_data = NULL;
  8463. + }
  8464. +
  8465. + } else {
  8466. + *len = CL_DESC_BUF_LEN(desc->ctrl);
  8467. + *ofst = pfe_pkt_headroom;
  8468. + }
  8469. +
  8470. + /*
  8471. + * Needed so we don't free a buffer/page
  8472. + * twice on module_exit
  8473. + */
  8474. + desc->data = NULL;
  8475. +
  8476. + /*
  8477. + * Ensure everything else is written to DDR before
  8478. + * writing bd->ctrl
  8479. + */
  8480. + smp_wmb();
  8481. +
  8482. + desc->ctrl = CL_DESC_BUF_LEN(pfe_pkt_size) | CL_DESC_OWN;
  8483. + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
  8484. + }
  8485. +
  8486. + /*spin_unlock_irqrestore(&client->rx_lock, flags); */
  8487. + return pkt;
  8488. +}
  8489. +
  8490. +static inline void hif_hdr_write(struct hif_hdr *pkt_hdr, unsigned int
  8491. + client_id, unsigned int qno,
  8492. + u32 client_ctrl)
  8493. +{
  8494. + /* Optimize the write since the destinaton may be non-cacheable */
  8495. + if (!((unsigned long)pkt_hdr & 0x3)) {
  8496. + ((u32 *)pkt_hdr)[0] = (client_ctrl << 16) | (qno << 8) |
  8497. + client_id;
  8498. + } else {
  8499. + ((u16 *)pkt_hdr)[0] = (qno << 8) | (client_id & 0xFF);
  8500. + ((u16 *)pkt_hdr)[1] = (client_ctrl & 0xFFFF);
  8501. + }
  8502. +}
  8503. +
  8504. +/*This function puts the given packet in the specific client queue */
  8505. +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
  8506. + *data, unsigned int len, u32 client_ctrl,
  8507. + unsigned int flags, void *client_data)
  8508. +{
  8509. + struct hif_client_tx_queue *queue = &client->tx_q[qno];
  8510. + struct tx_queue_desc *desc = queue->base + queue->write_idx;
  8511. +
  8512. + /* First buffer */
  8513. + if (flags & HIF_FIRST_BUFFER) {
  8514. + data -= sizeof(struct hif_hdr);
  8515. + len += sizeof(struct hif_hdr);
  8516. +
  8517. + hif_hdr_write(data, client->id, qno, client_ctrl);
  8518. + }
  8519. +
  8520. + desc->data = client_data;
  8521. + desc->ctrl = CL_DESC_OWN | CL_DESC_FLAGS(flags);
  8522. +
  8523. + __hif_xmit_pkt(&pfe->hif, client->id, qno, data, len, flags);
  8524. +
  8525. + queue->write_idx = (queue->write_idx + 1) & (queue->size - 1);
  8526. + queue->tx_pending++;
  8527. + queue->jiffies_last_packet = jiffies;
  8528. +}
  8529. +
  8530. +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
  8531. + unsigned int *flags, int count)
  8532. +{
  8533. + struct hif_client_tx_queue *queue = &client->tx_q[qno];
  8534. + struct tx_queue_desc *desc = queue->base + queue->read_idx;
  8535. +
  8536. + pr_debug("%s: qno : %d rd_indx: %d pending:%d\n", __func__, qno,
  8537. + queue->read_idx, queue->tx_pending);
  8538. +
  8539. + if (!queue->tx_pending)
  8540. + return NULL;
  8541. +
  8542. + if (queue->nocpy_flag && !queue->done_tmu_tx_pkts) {
  8543. + u32 tmu_tx_pkts = be32_to_cpu(pe_dmem_read(TMU0_ID +
  8544. + client->id, TMU_DM_TX_TRANS, 4));
  8545. +
  8546. + if (queue->prev_tmu_tx_pkts > tmu_tx_pkts)
  8547. + queue->done_tmu_tx_pkts = UINT_MAX -
  8548. + queue->prev_tmu_tx_pkts + tmu_tx_pkts;
  8549. + else
  8550. + queue->done_tmu_tx_pkts = tmu_tx_pkts -
  8551. + queue->prev_tmu_tx_pkts;
  8552. +
  8553. + queue->prev_tmu_tx_pkts = tmu_tx_pkts;
  8554. +
  8555. + if (!queue->done_tmu_tx_pkts)
  8556. + return NULL;
  8557. + }
  8558. +
  8559. + if (desc->ctrl & CL_DESC_OWN)
  8560. + return NULL;
  8561. +
  8562. + queue->read_idx = (queue->read_idx + 1) & (queue->size - 1);
  8563. + queue->tx_pending--;
  8564. +
  8565. + *flags = CL_DESC_GET_FLAGS(desc->ctrl);
  8566. +
  8567. + if (queue->done_tmu_tx_pkts && (*flags & HIF_LAST_BUFFER))
  8568. + queue->done_tmu_tx_pkts--;
  8569. +
  8570. + return desc->data;
  8571. +}
  8572. +
  8573. +static void hif_lib_tmu_credit_init(struct pfe *pfe)
  8574. +{
  8575. + int i, q;
  8576. +
  8577. + for (i = 0; i < NUM_GEMAC_SUPPORT; i++)
  8578. + for (q = 0; q < emac_txq_cnt; q++) {
  8579. + pfe->tmu_credit.tx_credit_max[i][q] = (q == 0) ?
  8580. + DEFAULT_Q0_QDEPTH : DEFAULT_MAX_QDEPTH;
  8581. + pfe->tmu_credit.tx_credit[i][q] =
  8582. + pfe->tmu_credit.tx_credit_max[i][q];
  8583. + }
  8584. +}
  8585. +
  8586. +int pfe_hif_lib_init(struct pfe *pfe)
  8587. +{
  8588. + int rc;
  8589. +
  8590. + pr_info("%s\n", __func__);
  8591. +
  8592. + if (lro_mode) {
  8593. + page_mode = 1;
  8594. + pfe_pkt_size = min(PAGE_SIZE, MAX_PFE_PKT_SIZE);
  8595. + pfe_pkt_headroom = 0;
  8596. + } else {
  8597. + page_mode = 0;
  8598. + pfe_pkt_size = PFE_PKT_SIZE;
  8599. + pfe_pkt_headroom = PFE_PKT_HEADROOM;
  8600. + }
  8601. +
  8602. + if (tx_qos)
  8603. + emac_txq_cnt = EMAC_TXQ_CNT / 2;
  8604. + else
  8605. + emac_txq_cnt = EMAC_TXQ_CNT;
  8606. +
  8607. + hif_lib_tmu_credit_init(pfe);
  8608. + pfe->hif.shm = &ghif_shm;
  8609. + rc = pfe_hif_shm_init(pfe->hif.shm);
  8610. +
  8611. + return rc;
  8612. +}
  8613. +
  8614. +void pfe_hif_lib_exit(struct pfe *pfe)
  8615. +{
  8616. + pr_info("%s\n", __func__);
  8617. +
  8618. + pfe_hif_shm_clean(pfe->hif.shm);
  8619. +}
  8620. diff --git a/drivers/staging/fsl_ppfe/pfe_hif_lib.h b/drivers/staging/fsl_ppfe/pfe_hif_lib.h
  8621. new file mode 100644
  8622. index 00000000..49e7b5f1
  8623. --- /dev/null
  8624. +++ b/drivers/staging/fsl_ppfe/pfe_hif_lib.h
  8625. @@ -0,0 +1,239 @@
  8626. +/*
  8627. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  8628. + * Copyright 2017 NXP
  8629. + *
  8630. + * This program is free software; you can redistribute it and/or modify
  8631. + * it under the terms of the GNU General Public License as published by
  8632. + * the Free Software Foundation; either version 2 of the License, or
  8633. + * (at your option) any later version.
  8634. + *
  8635. + * This program is distributed in the hope that it will be useful,
  8636. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8637. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8638. + * GNU General Public License for more details.
  8639. + *
  8640. + * You should have received a copy of the GNU General Public License
  8641. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8642. + */
  8643. +
  8644. +#ifndef _PFE_HIF_LIB_H_
  8645. +#define _PFE_HIF_LIB_H_
  8646. +
  8647. +#include "pfe_hif.h"
  8648. +
  8649. +#define HIF_CL_REQ_TIMEOUT 10
  8650. +#define GFP_DMA_PFE 0
  8651. +
  8652. +enum {
  8653. + REQUEST_CL_REGISTER = 0,
  8654. + REQUEST_CL_UNREGISTER,
  8655. + HIF_REQUEST_MAX
  8656. +};
  8657. +
  8658. +enum {
  8659. + /* Event to indicate that client rx queue is reached water mark level */
  8660. + EVENT_HIGH_RX_WM = 0,
  8661. + /* Event to indicate that, packet received for client */
  8662. + EVENT_RX_PKT_IND,
  8663. + /* Event to indicate that, packet tx done for client */
  8664. + EVENT_TXDONE_IND,
  8665. + HIF_EVENT_MAX
  8666. +};
  8667. +
  8668. +/*structure to store client queue info */
  8669. +
  8670. +/*structure to store client queue info */
  8671. +struct hif_client_rx_queue {
  8672. + struct rx_queue_desc *base;
  8673. + u32 size;
  8674. + u32 read_idx;
  8675. + u32 write_idx;
  8676. +};
  8677. +
  8678. +struct hif_client_tx_queue {
  8679. + struct tx_queue_desc *base;
  8680. + u32 size;
  8681. + u32 read_idx;
  8682. + u32 write_idx;
  8683. + u32 tx_pending;
  8684. + unsigned long jiffies_last_packet;
  8685. + u32 nocpy_flag;
  8686. + u32 prev_tmu_tx_pkts;
  8687. + u32 done_tmu_tx_pkts;
  8688. +};
  8689. +
  8690. +struct hif_client_s {
  8691. + int id;
  8692. + int tx_qn;
  8693. + int rx_qn;
  8694. + void *rx_qbase;
  8695. + void *tx_qbase;
  8696. + int tx_qsize;
  8697. + int rx_qsize;
  8698. + int cpu_id;
  8699. + struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
  8700. + struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
  8701. + int (*event_handler)(void *priv, int event, int data);
  8702. + unsigned long queue_mask[HIF_EVENT_MAX];
  8703. + struct pfe *pfe;
  8704. + void *priv;
  8705. +};
  8706. +
  8707. +/*
  8708. + * Client specific shared memory
  8709. + * It contains number of Rx/Tx queues, base addresses and queue sizes
  8710. + */
  8711. +struct hif_client_shm {
  8712. + u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
  8713. + unsigned long rx_qbase; /*Rx queue base address */
  8714. + u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
  8715. + unsigned long tx_qbase; /* Tx queue base address */
  8716. + u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
  8717. +};
  8718. +
  8719. +/*Client shared memory ctrl bit description */
  8720. +#define CLIENT_CTRL_RX_Q_CNT_OFST 0
  8721. +#define CLIENT_CTRL_TX_Q_CNT_OFST 8
  8722. +#define CLIENT_CTRL_RX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
  8723. + & 0xFF)
  8724. +#define CLIENT_CTRL_TX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
  8725. + & 0xFF)
  8726. +
  8727. +/*
  8728. + * Shared memory used to communicate between HIF driver and host/client drivers
  8729. + * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
  8730. + * initialized with host buffers and buffers count in the pool.
  8731. + * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
  8732. + *
  8733. + */
  8734. +struct hif_shm {
  8735. + u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
  8736. + /*Rx buffers required to initialize HIF rx descriptors */
  8737. + void *rx_buf_pool[HIF_RX_DESC_NT];
  8738. + unsigned long g_client_status[2]; /*Global client status bit mask */
  8739. + /* Client specific shared memory */
  8740. + struct hif_client_shm client[HIF_CLIENTS_MAX];
  8741. +};
  8742. +
  8743. +#define CL_DESC_OWN BIT(31)
  8744. +/* This sets owner ship to HIF driver */
  8745. +#define CL_DESC_LAST BIT(30)
  8746. +/* This indicates last packet for multi buffers handling */
  8747. +#define CL_DESC_FIRST BIT(29)
  8748. +/* This indicates first packet for multi buffers handling */
  8749. +
  8750. +#define CL_DESC_BUF_LEN(x) ((x) & 0xFFFF)
  8751. +#define CL_DESC_FLAGS(x) (((x) & 0xF) << 16)
  8752. +#define CL_DESC_GET_FLAGS(x) (((x) >> 16) & 0xF)
  8753. +
  8754. +struct rx_queue_desc {
  8755. + void *data;
  8756. + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
  8757. + u32 client_ctrl;
  8758. +};
  8759. +
  8760. +struct tx_queue_desc {
  8761. + void *data;
  8762. + u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
  8763. +};
  8764. +
  8765. +/* HIF Rx is not working properly for 2-byte aligned buffers and
  8766. + * ip_header should be 4byte aligned for better iperformance.
  8767. + * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
  8768. + */
  8769. +#define PFE_PKT_HEADER_SZ sizeof(struct hif_hdr)
  8770. +/* must be big enough for headroom, pkt size and skb shared info */
  8771. +#define PFE_BUF_SIZE 2048
  8772. +#define PFE_PKT_HEADROOM 128
  8773. +
  8774. +#define SKB_SHARED_INFO_SIZE (sizeof(struct skb_shared_info))
  8775. +#define PFE_PKT_SIZE (PFE_BUF_SIZE - PFE_PKT_HEADROOM \
  8776. + - SKB_SHARED_INFO_SIZE)
  8777. +#define MAX_L2_HDR_SIZE 14 /* Not correct for VLAN/PPPoE */
  8778. +#define MAX_L3_HDR_SIZE 20 /* Not correct for IPv6 */
  8779. +#define MAX_L4_HDR_SIZE 60 /* TCP with maximum options */
  8780. +#define MAX_HDR_SIZE (MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
  8781. + + MAX_L4_HDR_SIZE)
  8782. +/* Used in page mode to clamp packet size to the maximum supported by the hif
  8783. + *hw interface (<16KiB)
  8784. + */
  8785. +#define MAX_PFE_PKT_SIZE 16380UL
  8786. +
  8787. +extern unsigned int pfe_pkt_size;
  8788. +extern unsigned int pfe_pkt_headroom;
  8789. +extern unsigned int page_mode;
  8790. +extern unsigned int lro_mode;
  8791. +extern unsigned int tx_qos;
  8792. +extern unsigned int emac_txq_cnt;
  8793. +
  8794. +int pfe_hif_lib_init(struct pfe *pfe);
  8795. +void pfe_hif_lib_exit(struct pfe *pfe);
  8796. +int hif_lib_client_register(struct hif_client_s *client);
  8797. +int hif_lib_client_unregister(struct hif_client_s *client);
  8798. +void __hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void
  8799. + *data, unsigned int len, u32 client_ctrl,
  8800. + unsigned int flags, void *client_data);
  8801. +int hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno, void *data,
  8802. + unsigned int len, u32 client_ctrl, void *client_data);
  8803. +void hif_lib_indicate_client(int cl_id, int event, int data);
  8804. +int hif_lib_event_handler_start(struct hif_client_s *client, int event, int
  8805. + data);
  8806. +int hif_lib_tmu_queue_start(struct hif_client_s *client, int qno);
  8807. +int hif_lib_tmu_queue_stop(struct hif_client_s *client, int qno);
  8808. +void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
  8809. + unsigned int *flags, int count);
  8810. +void *hif_lib_receive_pkt(struct hif_client_s *client, int qno, int *len, int
  8811. + *ofst, unsigned int *rx_ctrl,
  8812. + unsigned int *desc_ctrl, void **priv_data);
  8813. +void hif_lib_set_rx_cpu_affinity(struct hif_client_s *client, int cpu_id);
  8814. +void hif_lib_set_tx_queue_nocpy(struct hif_client_s *client, int qno, int
  8815. + enable);
  8816. +static inline int hif_lib_tx_avail(struct hif_client_s *client, unsigned int
  8817. + qno)
  8818. +{
  8819. + struct hif_client_tx_queue *queue = &client->tx_q[qno];
  8820. +
  8821. + return (queue->size - queue->tx_pending);
  8822. +}
  8823. +
  8824. +static inline int hif_lib_get_tx_wr_index(struct hif_client_s *client, unsigned
  8825. + int qno)
  8826. +{
  8827. + struct hif_client_tx_queue *queue = &client->tx_q[qno];
  8828. +
  8829. + return queue->write_idx;
  8830. +}
  8831. +
  8832. +static inline int hif_lib_tx_pending(struct hif_client_s *client, unsigned int
  8833. + qno)
  8834. +{
  8835. + struct hif_client_tx_queue *queue = &client->tx_q[qno];
  8836. +
  8837. + return queue->tx_pending;
  8838. +}
  8839. +
  8840. +#define hif_lib_tx_credit_avail(pfe, id, qno) \
  8841. + ((pfe)->tmu_credit.tx_credit[id][qno])
  8842. +
  8843. +#define hif_lib_tx_credit_max(pfe, id, qno) \
  8844. + ((pfe)->tmu_credit.tx_credit_max[id][qno])
  8845. +
  8846. +/*
  8847. + * Test comment
  8848. + */
  8849. +#define hif_lib_tx_credit_use(pfe, id, qno, credit) \
  8850. + ({ typeof(pfe) pfe_ = pfe; \
  8851. + typeof(id) id_ = id; \
  8852. + typeof(qno) qno_ = qno_; \
  8853. + typeof(credit) credit_ = credit; \
  8854. + do { \
  8855. + if (tx_qos) { \
  8856. + (pfe_)->tmu_credit.tx_credit[id_][qno_]\
  8857. + -= credit_; \
  8858. + (pfe_)->tmu_credit.tx_packets[id_][qno_]\
  8859. + += credit_; \
  8860. + } \
  8861. + } while (0); \
  8862. + })
  8863. +
  8864. +#endif /* _PFE_HIF_LIB_H_ */
  8865. diff --git a/drivers/staging/fsl_ppfe/pfe_hw.c b/drivers/staging/fsl_ppfe/pfe_hw.c
  8866. new file mode 100644
  8867. index 00000000..16ea2c65
  8868. --- /dev/null
  8869. +++ b/drivers/staging/fsl_ppfe/pfe_hw.c
  8870. @@ -0,0 +1,176 @@
  8871. +/*
  8872. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  8873. + * Copyright 2017 NXP
  8874. + *
  8875. + * This program is free software; you can redistribute it and/or modify
  8876. + * it under the terms of the GNU General Public License as published by
  8877. + * the Free Software Foundation; either version 2 of the License, or
  8878. + * (at your option) any later version.
  8879. + *
  8880. + * This program is distributed in the hope that it will be useful,
  8881. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8882. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8883. + * GNU General Public License for more details.
  8884. + *
  8885. + * You should have received a copy of the GNU General Public License
  8886. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  8887. + */
  8888. +
  8889. +#include "pfe_mod.h"
  8890. +#include "pfe_hw.h"
  8891. +
  8892. +/* Functions to handle most of pfe hw register initialization */
  8893. +int pfe_hw_init(struct pfe *pfe, int resume)
  8894. +{
  8895. + struct class_cfg class_cfg = {
  8896. + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
  8897. + .route_table_baseaddr = pfe->ddr_phys_baseaddr +
  8898. + ROUTE_TABLE_BASEADDR,
  8899. + .route_table_hash_bits = ROUTE_TABLE_HASH_BITS,
  8900. + };
  8901. +
  8902. + struct tmu_cfg tmu_cfg = {
  8903. + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
  8904. + .llm_base_addr = pfe->ddr_phys_baseaddr + TMU_LLM_BASEADDR,
  8905. + .llm_queue_len = TMU_LLM_QUEUE_LEN,
  8906. + };
  8907. +
  8908. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  8909. + struct util_cfg util_cfg = {
  8910. + .pe_sys_clk_ratio = PE_SYS_CLK_RATIO,
  8911. + };
  8912. +#endif
  8913. +
  8914. + struct BMU_CFG bmu1_cfg = {
  8915. + .baseaddr = CBUS_VIRT_TO_PFE(LMEM_BASE_ADDR +
  8916. + BMU1_LMEM_BASEADDR),
  8917. + .count = BMU1_BUF_COUNT,
  8918. + .size = BMU1_BUF_SIZE,
  8919. + .low_watermark = 10,
  8920. + .high_watermark = 15,
  8921. + };
  8922. +
  8923. + struct BMU_CFG bmu2_cfg = {
  8924. + .baseaddr = DDR_PHYS_TO_PFE(pfe->ddr_phys_baseaddr +
  8925. + BMU2_DDR_BASEADDR),
  8926. + .count = BMU2_BUF_COUNT,
  8927. + .size = BMU2_BUF_SIZE,
  8928. + .low_watermark = 250,
  8929. + .high_watermark = 253,
  8930. + };
  8931. +
  8932. + struct gpi_cfg egpi1_cfg = {
  8933. + .lmem_rtry_cnt = EGPI1_LMEM_RTRY_CNT,
  8934. + .tmlf_txthres = EGPI1_TMLF_TXTHRES,
  8935. + .aseq_len = EGPI1_ASEQ_LEN,
  8936. + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC1_BASE_ADDR +
  8937. + EMAC_TCNTRL_REG),
  8938. + };
  8939. +
  8940. + struct gpi_cfg egpi2_cfg = {
  8941. + .lmem_rtry_cnt = EGPI2_LMEM_RTRY_CNT,
  8942. + .tmlf_txthres = EGPI2_TMLF_TXTHRES,
  8943. + .aseq_len = EGPI2_ASEQ_LEN,
  8944. + .mtip_pause_reg = CBUS_VIRT_TO_PFE(EMAC2_BASE_ADDR +
  8945. + EMAC_TCNTRL_REG),
  8946. + };
  8947. +
  8948. + struct gpi_cfg hgpi_cfg = {
  8949. + .lmem_rtry_cnt = HGPI_LMEM_RTRY_CNT,
  8950. + .tmlf_txthres = HGPI_TMLF_TXTHRES,
  8951. + .aseq_len = HGPI_ASEQ_LEN,
  8952. + .mtip_pause_reg = 0,
  8953. + };
  8954. +
  8955. + pr_info("%s\n", __func__);
  8956. +
  8957. +#if !defined(LS1012A_PFE_RESET_WA)
  8958. + /* LS1012A needs this to make PE work correctly */
  8959. + writel(0x3, CLASS_PE_SYS_CLK_RATIO);
  8960. + writel(0x3, TMU_PE_SYS_CLK_RATIO);
  8961. + writel(0x3, UTIL_PE_SYS_CLK_RATIO);
  8962. + usleep_range(10, 20);
  8963. +#endif
  8964. +
  8965. + pr_info("CLASS version: %x\n", readl(CLASS_VERSION));
  8966. + pr_info("TMU version: %x\n", readl(TMU_VERSION));
  8967. +
  8968. + pr_info("BMU1 version: %x\n", readl(BMU1_BASE_ADDR +
  8969. + BMU_VERSION));
  8970. + pr_info("BMU2 version: %x\n", readl(BMU2_BASE_ADDR +
  8971. + BMU_VERSION));
  8972. +
  8973. + pr_info("EGPI1 version: %x\n", readl(EGPI1_BASE_ADDR +
  8974. + GPI_VERSION));
  8975. + pr_info("EGPI2 version: %x\n", readl(EGPI2_BASE_ADDR +
  8976. + GPI_VERSION));
  8977. + pr_info("HGPI version: %x\n", readl(HGPI_BASE_ADDR +
  8978. + GPI_VERSION));
  8979. +
  8980. + pr_info("HIF version: %x\n", readl(HIF_VERSION));
  8981. + pr_info("HIF NOPCY version: %x\n", readl(HIF_NOCPY_VERSION));
  8982. +
  8983. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  8984. + pr_info("UTIL version: %x\n", readl(UTIL_VERSION));
  8985. +#endif
  8986. + while (!(readl(TMU_CTRL) & ECC_MEM_INIT_DONE))
  8987. + ;
  8988. +
  8989. + hif_rx_disable();
  8990. + hif_tx_disable();
  8991. +
  8992. + bmu_init(BMU1_BASE_ADDR, &bmu1_cfg);
  8993. +
  8994. + pr_info("bmu_init(1) done\n");
  8995. +
  8996. + bmu_init(BMU2_BASE_ADDR, &bmu2_cfg);
  8997. +
  8998. + pr_info("bmu_init(2) done\n");
  8999. +
  9000. + class_cfg.resume = resume ? 1 : 0;
  9001. +
  9002. + class_init(&class_cfg);
  9003. +
  9004. + pr_info("class_init() done\n");
  9005. +
  9006. + tmu_init(&tmu_cfg);
  9007. +
  9008. + pr_info("tmu_init() done\n");
  9009. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  9010. + util_init(&util_cfg);
  9011. +
  9012. + pr_info("util_init() done\n");
  9013. +#endif
  9014. + gpi_init(EGPI1_BASE_ADDR, &egpi1_cfg);
  9015. +
  9016. + pr_info("gpi_init(1) done\n");
  9017. +
  9018. + gpi_init(EGPI2_BASE_ADDR, &egpi2_cfg);
  9019. +
  9020. + pr_info("gpi_init(2) done\n");
  9021. +
  9022. + gpi_init(HGPI_BASE_ADDR, &hgpi_cfg);
  9023. +
  9024. + pr_info("gpi_init(hif) done\n");
  9025. +
  9026. + bmu_enable(BMU1_BASE_ADDR);
  9027. +
  9028. + pr_info("bmu_enable(1) done\n");
  9029. +
  9030. + bmu_enable(BMU2_BASE_ADDR);
  9031. +
  9032. + pr_info("bmu_enable(2) done\n");
  9033. +
  9034. + return 0;
  9035. +}
  9036. +
  9037. +void pfe_hw_exit(struct pfe *pfe)
  9038. +{
  9039. + pr_info("%s\n", __func__);
  9040. +
  9041. + bmu_disable(BMU1_BASE_ADDR);
  9042. + bmu_reset(BMU1_BASE_ADDR);
  9043. +
  9044. + bmu_disable(BMU2_BASE_ADDR);
  9045. + bmu_reset(BMU2_BASE_ADDR);
  9046. +}
  9047. diff --git a/drivers/staging/fsl_ppfe/pfe_hw.h b/drivers/staging/fsl_ppfe/pfe_hw.h
  9048. new file mode 100644
  9049. index 00000000..53b5fe14
  9050. --- /dev/null
  9051. +++ b/drivers/staging/fsl_ppfe/pfe_hw.h
  9052. @@ -0,0 +1,27 @@
  9053. +/*
  9054. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9055. + * Copyright 2017 NXP
  9056. + *
  9057. + * This program is free software; you can redistribute it and/or modify
  9058. + * it under the terms of the GNU General Public License as published by
  9059. + * the Free Software Foundation; either version 2 of the License, or
  9060. + * (at your option) any later version.
  9061. + *
  9062. + * This program is distributed in the hope that it will be useful,
  9063. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9064. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9065. + * GNU General Public License for more details.
  9066. + *
  9067. + * You should have received a copy of the GNU General Public License
  9068. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9069. + */
  9070. +
  9071. +#ifndef _PFE_HW_H_
  9072. +#define _PFE_HW_H_
  9073. +
  9074. +#define PE_SYS_CLK_RATIO 1 /* SYS/AXI = 250MHz, HFE = 500MHz */
  9075. +
  9076. +int pfe_hw_init(struct pfe *pfe, int resume);
  9077. +void pfe_hw_exit(struct pfe *pfe);
  9078. +
  9079. +#endif /* _PFE_HW_H_ */
  9080. diff --git a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
  9081. new file mode 100644
  9082. index 00000000..c579eb58
  9083. --- /dev/null
  9084. +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
  9085. @@ -0,0 +1,394 @@
  9086. +/*
  9087. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9088. + * Copyright 2017 NXP
  9089. + *
  9090. + * This program is free software; you can redistribute it and/or modify
  9091. + * it under the terms of the GNU General Public License as published by
  9092. + * the Free Software Foundation; either version 2 of the License, or
  9093. + * (at your option) any later version.
  9094. + *
  9095. + * This program is distributed in the hope that it will be useful,
  9096. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9097. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9098. + * GNU General Public License for more details.
  9099. + *
  9100. + * You should have received a copy of the GNU General Public License
  9101. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9102. + */
  9103. +
  9104. +#include <linux/module.h>
  9105. +#include <linux/device.h>
  9106. +#include <linux/of_net.h>
  9107. +#include <linux/of_address.h>
  9108. +#include <linux/platform_device.h>
  9109. +#include <linux/slab.h>
  9110. +#include <linux/clk.h>
  9111. +#include <linux/mfd/syscon.h>
  9112. +#include <linux/regmap.h>
  9113. +
  9114. +#include "pfe_mod.h"
  9115. +
  9116. +struct ls1012a_pfe_platform_data pfe_platform_data;
  9117. +
  9118. +static int pfe_get_gemac_if_proprties(struct device_node *parent, int port, int
  9119. + if_cnt,
  9120. + struct ls1012a_pfe_platform_data
  9121. + *pdata)
  9122. +{
  9123. + struct device_node *gem = NULL, *phy = NULL;
  9124. + int size;
  9125. + int ii = 0, phy_id = 0;
  9126. + const u32 *addr;
  9127. + const void *mac_addr;
  9128. +
  9129. + for (ii = 0; ii < if_cnt; ii++) {
  9130. + gem = of_get_next_child(parent, gem);
  9131. + if (!gem)
  9132. + goto err;
  9133. + addr = of_get_property(gem, "reg", &size);
  9134. + if (addr && (be32_to_cpup(addr) == port))
  9135. + break;
  9136. + }
  9137. +
  9138. + if (ii >= if_cnt) {
  9139. + pr_err("%s:%d Failed to find interface = %d\n",
  9140. + __func__, __LINE__, if_cnt);
  9141. + goto err;
  9142. + }
  9143. +
  9144. + pdata->ls1012a_eth_pdata[port].gem_id = port;
  9145. +
  9146. + mac_addr = of_get_mac_address(gem);
  9147. +
  9148. + if (mac_addr) {
  9149. + memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
  9150. + ETH_ALEN);
  9151. + }
  9152. +
  9153. + pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
  9154. +
  9155. + if ((pdata->ls1012a_eth_pdata[port].mii_config) < 0)
  9156. + pr_err("%s:%d Incorrect Phy mode....\n", __func__,
  9157. + __LINE__);
  9158. +
  9159. + addr = of_get_property(gem, "fsl,gemac-bus-id", &size);
  9160. + if (!addr)
  9161. + pr_err("%s:%d Invalid gemac-bus-id....\n", __func__,
  9162. + __LINE__);
  9163. + else
  9164. + pdata->ls1012a_eth_pdata[port].bus_id = be32_to_cpup(addr);
  9165. +
  9166. + addr = of_get_property(gem, "fsl,gemac-phy-id", &size);
  9167. + if (!addr) {
  9168. + pr_err("%s:%d Invalid gemac-phy-id....\n", __func__,
  9169. + __LINE__);
  9170. + } else {
  9171. + phy_id = be32_to_cpup(addr);
  9172. + pdata->ls1012a_eth_pdata[port].phy_id = phy_id;
  9173. + pdata->ls1012a_mdio_pdata[0].phy_mask &= ~(1 << phy_id);
  9174. + }
  9175. +
  9176. + addr = of_get_property(gem, "fsl,mdio-mux-val", &size);
  9177. + if (!addr)
  9178. + pr_err("%s: Invalid mdio-mux-val....\n", __func__);
  9179. + else
  9180. + phy_id = be32_to_cpup(addr);
  9181. + pdata->ls1012a_eth_pdata[port].mdio_muxval = phy_id;
  9182. +
  9183. + if (pdata->ls1012a_eth_pdata[port].phy_id < 32)
  9184. + pfe->mdio_muxval[pdata->ls1012a_eth_pdata[port].phy_id] =
  9185. + pdata->ls1012a_eth_pdata[port].mdio_muxval;
  9186. +
  9187. + addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
  9188. + if (!addr)
  9189. + pr_err("%s:%d Invalid pfe-phy-if-flags....\n",
  9190. + __func__, __LINE__);
  9191. + else
  9192. + pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);
  9193. +
  9194. + /* If PHY is enabled, read mdio properties */
  9195. + if (pdata->ls1012a_eth_pdata[port].phy_flags & GEMAC_NO_PHY)
  9196. + goto done;
  9197. +
  9198. + phy = of_get_next_child(gem, NULL);
  9199. +
  9200. + addr = of_get_property(phy, "reg", &size);
  9201. +
  9202. + if (!addr)
  9203. + pr_err("%s:%d Invalid phy enable flag....\n",
  9204. + __func__, __LINE__);
  9205. + else
  9206. + pdata->ls1012a_mdio_pdata[port].enabled = be32_to_cpup(addr);
  9207. +
  9208. + pdata->ls1012a_mdio_pdata[port].irq[0] = PHY_POLL;
  9209. +
  9210. +done:
  9211. +
  9212. + return 0;
  9213. +
  9214. +err:
  9215. + return -1;
  9216. +}
  9217. +
  9218. +/*
  9219. + *
  9220. + * pfe_platform_probe -
  9221. + *
  9222. + *
  9223. + */
  9224. +static int pfe_platform_probe(struct platform_device *pdev)
  9225. +{
  9226. + struct resource res;
  9227. + int ii, rc, interface_count = 0, size = 0;
  9228. + const u32 *prop;
  9229. + struct device_node *np;
  9230. + struct clk *pfe_clk;
  9231. +
  9232. + np = pdev->dev.of_node;
  9233. +
  9234. + if (!np) {
  9235. + pr_err("Invalid device node\n");
  9236. + return -EINVAL;
  9237. + }
  9238. +
  9239. + pfe = kzalloc(sizeof(*pfe), GFP_KERNEL);
  9240. + if (!pfe) {
  9241. + rc = -ENOMEM;
  9242. + goto err_alloc;
  9243. + }
  9244. +
  9245. + platform_set_drvdata(pdev, pfe);
  9246. +
  9247. + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9248. +
  9249. + if (of_address_to_resource(np, 1, &res)) {
  9250. + rc = -ENOMEM;
  9251. + pr_err("failed to get ddr resource\n");
  9252. + goto err_ddr;
  9253. + }
  9254. +
  9255. + pfe->ddr_phys_baseaddr = res.start;
  9256. + pfe->ddr_size = resource_size(&res);
  9257. +
  9258. + pfe->ddr_baseaddr = phys_to_virt(res.start);
  9259. + if (!pfe->ddr_baseaddr) {
  9260. + pr_err("ioremap() ddr failed\n");
  9261. + rc = -ENOMEM;
  9262. + goto err_ddr;
  9263. + }
  9264. +
  9265. + pfe->scfg =
  9266. + syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  9267. + "fsl,pfe-scfg");
  9268. + if (IS_ERR(pfe->scfg)) {
  9269. + dev_err(&pdev->dev, "No syscfg phandle specified\n");
  9270. + return PTR_ERR(pfe->scfg);
  9271. + }
  9272. +
  9273. + pfe->cbus_baseaddr = of_iomap(np, 0);
  9274. + if (!pfe->cbus_baseaddr) {
  9275. + rc = -ENOMEM;
  9276. + pr_err("failed to get axi resource\n");
  9277. + goto err_axi;
  9278. + }
  9279. +
  9280. + pfe->hif_irq = platform_get_irq(pdev, 0);
  9281. + if (pfe->hif_irq < 0) {
  9282. + pr_err("platform_get_irq for hif failed\n");
  9283. + rc = pfe->hif_irq;
  9284. + goto err_hif_irq;
  9285. + }
  9286. +
  9287. + pfe->wol_irq = platform_get_irq(pdev, 2);
  9288. + if (pfe->wol_irq < 0) {
  9289. + pr_err("platform_get_irq for WoL failed\n");
  9290. + rc = pfe->wol_irq;
  9291. + goto err_hif_irq;
  9292. + }
  9293. +
  9294. + /* Read interface count */
  9295. + prop = of_get_property(np, "fsl,pfe-num-interfaces", &size);
  9296. + if (!prop) {
  9297. + pr_err("Failed to read number of interfaces\n");
  9298. + rc = -ENXIO;
  9299. + goto err_prop;
  9300. + }
  9301. +
  9302. + interface_count = be32_to_cpup(prop);
  9303. + if (interface_count <= 0) {
  9304. + pr_err("No ethernet interface count : %d\n",
  9305. + interface_count);
  9306. + rc = -ENXIO;
  9307. + goto err_prop;
  9308. + }
  9309. +
  9310. + pfe_platform_data.ls1012a_mdio_pdata[0].phy_mask = 0xffffffff;
  9311. +
  9312. + for (ii = 0; ii < interface_count; ii++) {
  9313. + pfe_get_gemac_if_proprties(np, ii, interface_count,
  9314. + &pfe_platform_data);
  9315. + }
  9316. +
  9317. + pfe->dev = &pdev->dev;
  9318. +
  9319. + pfe->dev->platform_data = &pfe_platform_data;
  9320. +
  9321. + /* declare WoL capabilities */
  9322. + device_init_wakeup(&pdev->dev, true);
  9323. +
  9324. + /* find the clocks */
  9325. + pfe_clk = devm_clk_get(pfe->dev, "pfe");
  9326. + if (IS_ERR(pfe_clk))
  9327. + return PTR_ERR(pfe_clk);
  9328. +
  9329. + /* PFE clock is (platform clock / 2) */
  9330. + /* save sys_clk value as KHz */
  9331. + pfe->ctrl.sys_clk = clk_get_rate(pfe_clk) / (2 * 1000);
  9332. +
  9333. + rc = pfe_probe(pfe);
  9334. + if (rc < 0)
  9335. + goto err_probe;
  9336. +
  9337. + return 0;
  9338. +
  9339. +err_probe:
  9340. +err_prop:
  9341. +err_hif_irq:
  9342. + iounmap(pfe->cbus_baseaddr);
  9343. +
  9344. +err_axi:
  9345. + iounmap(pfe->ddr_baseaddr);
  9346. +
  9347. +err_ddr:
  9348. + platform_set_drvdata(pdev, NULL);
  9349. +
  9350. + kfree(pfe);
  9351. +
  9352. +err_alloc:
  9353. + return rc;
  9354. +}
  9355. +
  9356. +/*
  9357. + * pfe_platform_remove -
  9358. + */
  9359. +static int pfe_platform_remove(struct platform_device *pdev)
  9360. +{
  9361. + struct pfe *pfe = platform_get_drvdata(pdev);
  9362. + int rc;
  9363. +
  9364. + pr_info("%s\n", __func__);
  9365. +
  9366. + rc = pfe_remove(pfe);
  9367. +
  9368. + iounmap(pfe->cbus_baseaddr);
  9369. + iounmap(pfe->ddr_baseaddr);
  9370. +
  9371. + platform_set_drvdata(pdev, NULL);
  9372. +
  9373. + kfree(pfe);
  9374. +
  9375. + return rc;
  9376. +}
  9377. +
  9378. +#ifdef CONFIG_PM
  9379. +#ifdef CONFIG_PM_SLEEP
  9380. +int pfe_platform_suspend(struct device *dev)
  9381. +{
  9382. + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
  9383. + struct net_device *netdev;
  9384. + int i;
  9385. +
  9386. + pfe->wake = 0;
  9387. +
  9388. + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
  9389. + netdev = pfe->eth.eth_priv[i]->ndev;
  9390. +
  9391. + netif_device_detach(netdev);
  9392. +
  9393. + if (netif_running(netdev))
  9394. + if (pfe_eth_suspend(netdev))
  9395. + pfe->wake = 1;
  9396. + }
  9397. +
  9398. + /* Shutdown PFE only if we're not waking up the system */
  9399. + if (!pfe->wake) {
  9400. +#if defined(LS1012A_PFE_RESET_WA)
  9401. + pfe_hif_rx_idle(&pfe->hif);
  9402. +#endif
  9403. + pfe_ctrl_suspend(&pfe->ctrl);
  9404. + pfe_firmware_exit(pfe);
  9405. +
  9406. + pfe_hif_exit(pfe);
  9407. + pfe_hif_lib_exit(pfe);
  9408. +
  9409. + pfe_hw_exit(pfe);
  9410. + }
  9411. +
  9412. + return 0;
  9413. +}
  9414. +
  9415. +static int pfe_platform_resume(struct device *dev)
  9416. +{
  9417. + struct pfe *pfe = platform_get_drvdata(to_platform_device(dev));
  9418. + struct net_device *netdev;
  9419. + int i;
  9420. +
  9421. + if (!pfe->wake) {
  9422. + pfe_hw_init(pfe, 1);
  9423. + pfe_hif_lib_init(pfe);
  9424. + pfe_hif_init(pfe);
  9425. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  9426. + util_enable();
  9427. +#endif
  9428. + tmu_enable(0xf);
  9429. + class_enable();
  9430. + pfe_ctrl_resume(&pfe->ctrl);
  9431. + }
  9432. +
  9433. + for (i = 0; i < (NUM_GEMAC_SUPPORT); i++) {
  9434. + netdev = pfe->eth.eth_priv[i]->ndev;
  9435. +
  9436. + if (pfe->eth.eth_priv[i]->mii_bus)
  9437. + pfe_eth_mdio_reset(pfe->eth.eth_priv[i]->mii_bus);
  9438. +
  9439. + if (netif_running(netdev))
  9440. + pfe_eth_resume(netdev);
  9441. +
  9442. + netif_device_attach(netdev);
  9443. + }
  9444. + return 0;
  9445. +}
  9446. +#else
  9447. +#define pfe_platform_suspend NULL
  9448. +#define pfe_platform_resume NULL
  9449. +#endif
  9450. +
  9451. +static const struct dev_pm_ops pfe_platform_pm_ops = {
  9452. + SET_SYSTEM_SLEEP_PM_OPS(pfe_platform_suspend, pfe_platform_resume)
  9453. +};
  9454. +#endif
  9455. +
  9456. +static const struct of_device_id pfe_match[] = {
  9457. + {
  9458. + .compatible = "fsl,pfe",
  9459. + },
  9460. + {},
  9461. +};
  9462. +MODULE_DEVICE_TABLE(of, pfe_match);
  9463. +
  9464. +static struct platform_driver pfe_platform_driver = {
  9465. + .probe = pfe_platform_probe,
  9466. + .remove = pfe_platform_remove,
  9467. + .driver = {
  9468. + .name = "pfe",
  9469. + .of_match_table = pfe_match,
  9470. +#ifdef CONFIG_PM
  9471. + .pm = &pfe_platform_pm_ops,
  9472. +#endif
  9473. + },
  9474. +};
  9475. +
  9476. +module_platform_driver(pfe_platform_driver);
  9477. +MODULE_LICENSE("GPL");
  9478. +MODULE_DESCRIPTION("PFE Ethernet driver");
  9479. +MODULE_AUTHOR("NXP DNCPE");
  9480. diff --git a/drivers/staging/fsl_ppfe/pfe_mod.c b/drivers/staging/fsl_ppfe/pfe_mod.c
  9481. new file mode 100644
  9482. index 00000000..d5ba56a3
  9483. --- /dev/null
  9484. +++ b/drivers/staging/fsl_ppfe/pfe_mod.c
  9485. @@ -0,0 +1,141 @@
  9486. +/*
  9487. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9488. + * Copyright 2017 NXP
  9489. + *
  9490. + * This program is free software; you can redistribute it and/or modify
  9491. + * it under the terms of the GNU General Public License as published by
  9492. + * the Free Software Foundation; either version 2 of the License, or
  9493. + * (at your option) any later version.
  9494. + *
  9495. + * This program is distributed in the hope that it will be useful,
  9496. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9497. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9498. + * GNU General Public License for more details.
  9499. + *
  9500. + * You should have received a copy of the GNU General Public License
  9501. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9502. + */
  9503. +
  9504. +#include <linux/dma-mapping.h>
  9505. +#include "pfe_mod.h"
  9506. +
  9507. +struct pfe *pfe;
  9508. +
  9509. +/*
  9510. + * pfe_probe -
  9511. + */
  9512. +int pfe_probe(struct pfe *pfe)
  9513. +{
  9514. + int rc;
  9515. +
  9516. + if (pfe->ddr_size < DDR_MAX_SIZE) {
  9517. + pr_err("%s: required DDR memory (%x) above platform ddr memory (%x)\n",
  9518. + __func__, (unsigned int)DDR_MAX_SIZE, pfe->ddr_size);
  9519. + rc = -ENOMEM;
  9520. + goto err_hw;
  9521. + }
  9522. +
  9523. + if (((int)(pfe->ddr_phys_baseaddr + BMU2_DDR_BASEADDR) &
  9524. + (8 * SZ_1M - 1)) != 0) {
  9525. + pr_err("%s: BMU2 base address (0x%x) must be aligned on 8MB boundary\n",
  9526. + __func__, (int)pfe->ddr_phys_baseaddr +
  9527. + BMU2_DDR_BASEADDR);
  9528. + rc = -ENOMEM;
  9529. + goto err_hw;
  9530. + }
  9531. +
  9532. + pr_info("cbus_baseaddr: %lx, ddr_baseaddr: %lx, ddr_phys_baseaddr: %lx, ddr_size: %x\n",
  9533. + (unsigned long)pfe->cbus_baseaddr,
  9534. + (unsigned long)pfe->ddr_baseaddr,
  9535. + pfe->ddr_phys_baseaddr, pfe->ddr_size);
  9536. +
  9537. + pfe_lib_init(pfe->cbus_baseaddr, pfe->ddr_baseaddr,
  9538. + pfe->ddr_phys_baseaddr, pfe->ddr_size);
  9539. +
  9540. + rc = pfe_hw_init(pfe, 0);
  9541. + if (rc < 0)
  9542. + goto err_hw;
  9543. +
  9544. + rc = pfe_hif_lib_init(pfe);
  9545. + if (rc < 0)
  9546. + goto err_hif_lib;
  9547. +
  9548. + rc = pfe_hif_init(pfe);
  9549. + if (rc < 0)
  9550. + goto err_hif;
  9551. +
  9552. + rc = pfe_firmware_init(pfe);
  9553. + if (rc < 0)
  9554. + goto err_firmware;
  9555. +
  9556. + rc = pfe_ctrl_init(pfe);
  9557. + if (rc < 0)
  9558. + goto err_ctrl;
  9559. +
  9560. + rc = pfe_eth_init(pfe);
  9561. + if (rc < 0)
  9562. + goto err_eth;
  9563. +
  9564. + rc = pfe_sysfs_init(pfe);
  9565. + if (rc < 0)
  9566. + goto err_sysfs;
  9567. +
  9568. + rc = pfe_debugfs_init(pfe);
  9569. + if (rc < 0)
  9570. + goto err_debugfs;
  9571. +
  9572. + return 0;
  9573. +
  9574. +err_debugfs:
  9575. + pfe_sysfs_exit(pfe);
  9576. +
  9577. +err_sysfs:
  9578. + pfe_eth_exit(pfe);
  9579. +
  9580. +err_eth:
  9581. + pfe_ctrl_exit(pfe);
  9582. +
  9583. +err_ctrl:
  9584. + pfe_firmware_exit(pfe);
  9585. +
  9586. +err_firmware:
  9587. + pfe_hif_exit(pfe);
  9588. +
  9589. +err_hif:
  9590. + pfe_hif_lib_exit(pfe);
  9591. +
  9592. +err_hif_lib:
  9593. + pfe_hw_exit(pfe);
  9594. +
  9595. +err_hw:
  9596. + return rc;
  9597. +}
  9598. +
  9599. +/*
  9600. + * pfe_remove -
  9601. + */
  9602. +int pfe_remove(struct pfe *pfe)
  9603. +{
  9604. + pr_info("%s\n", __func__);
  9605. +
  9606. + pfe_debugfs_exit(pfe);
  9607. +
  9608. + pfe_sysfs_exit(pfe);
  9609. +
  9610. + pfe_eth_exit(pfe);
  9611. +
  9612. + pfe_ctrl_exit(pfe);
  9613. +
  9614. +#if defined(LS1012A_PFE_RESET_WA)
  9615. + pfe_hif_rx_idle(&pfe->hif);
  9616. +#endif
  9617. + pfe_firmware_exit(pfe);
  9618. +
  9619. + pfe_hif_exit(pfe);
  9620. +
  9621. + pfe_hif_lib_exit(pfe);
  9622. +
  9623. + pfe_hw_exit(pfe);
  9624. +
  9625. + return 0;
  9626. +}
  9627. diff --git a/drivers/staging/fsl_ppfe/pfe_mod.h b/drivers/staging/fsl_ppfe/pfe_mod.h
  9628. new file mode 100644
  9629. index 00000000..3012f17f
  9630. --- /dev/null
  9631. +++ b/drivers/staging/fsl_ppfe/pfe_mod.h
  9632. @@ -0,0 +1,112 @@
  9633. +/*
  9634. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9635. + * Copyright 2017 NXP
  9636. + *
  9637. + * This program is free software; you can redistribute it and/or modify
  9638. + * it under the terms of the GNU General Public License as published by
  9639. + * the Free Software Foundation; either version 2 of the License, or
  9640. + * (at your option) any later version.
  9641. + *
  9642. + * This program is distributed in the hope that it will be useful,
  9643. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9644. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9645. + * GNU General Public License for more details.
  9646. + *
  9647. + * You should have received a copy of the GNU General Public License
  9648. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9649. + */
  9650. +
  9651. +#ifndef _PFE_MOD_H_
  9652. +#define _PFE_MOD_H_
  9653. +
  9654. +#include <linux/device.h>
  9655. +#include <linux/elf.h>
  9656. +
  9657. +struct pfe;
  9658. +
  9659. +#include "pfe_hw.h"
  9660. +#include "pfe_firmware.h"
  9661. +#include "pfe_ctrl.h"
  9662. +#include "pfe_hif.h"
  9663. +#include "pfe_hif_lib.h"
  9664. +#include "pfe_eth.h"
  9665. +#include "pfe_sysfs.h"
  9666. +#include "pfe_perfmon.h"
  9667. +#include "pfe_debugfs.h"
  9668. +
  9669. +#define PHYID_MAX_VAL 32
  9670. +
  9671. +struct pfe_tmu_credit {
  9672. + /* Number of allowed TX packet in-flight, matches TMU queue size */
  9673. + unsigned int tx_credit[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
  9674. + unsigned int tx_credit_max[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
  9675. + unsigned int tx_packets[NUM_GEMAC_SUPPORT][EMAC_TXQ_CNT];
  9676. +};
  9677. +
  9678. +struct pfe {
  9679. + struct regmap *scfg;
  9680. + unsigned long ddr_phys_baseaddr;
  9681. + void *ddr_baseaddr;
  9682. + unsigned int ddr_size;
  9683. + void *cbus_baseaddr;
  9684. + void *apb_baseaddr;
  9685. + unsigned long iram_phys_baseaddr;
  9686. + void *iram_baseaddr;
  9687. + unsigned long ipsec_phys_baseaddr;
  9688. + void *ipsec_baseaddr;
  9689. + int hif_irq;
  9690. + int wol_irq;
  9691. + int hif_client_irq;
  9692. + struct device *dev;
  9693. + struct dentry *dentry;
  9694. + struct pfe_ctrl ctrl;
  9695. + struct pfe_hif hif;
  9696. + struct pfe_eth eth;
  9697. + struct hif_client_s *hif_client[HIF_CLIENTS_MAX];
  9698. +#if defined(CFG_DIAGS)
  9699. + struct pfe_diags diags;
  9700. +#endif
  9701. + struct pfe_tmu_credit tmu_credit;
  9702. + struct pfe_cpumon cpumon;
  9703. + struct pfe_memmon memmon;
  9704. + int wake;
  9705. + int mdio_muxval[PHYID_MAX_VAL];
  9706. + struct clk *hfe_clock;
  9707. +};
  9708. +
  9709. +extern struct pfe *pfe;
  9710. +
  9711. +int pfe_probe(struct pfe *pfe);
  9712. +int pfe_remove(struct pfe *pfe);
  9713. +
  9714. +/* DDR Mapping in reserved memory*/
  9715. +#define ROUTE_TABLE_BASEADDR 0
  9716. +#define ROUTE_TABLE_HASH_BITS 15 /* 32K entries */
  9717. +#define ROUTE_TABLE_SIZE ((1 << ROUTE_TABLE_HASH_BITS) \
  9718. + * CLASS_ROUTE_SIZE)
  9719. +#define BMU2_DDR_BASEADDR (ROUTE_TABLE_BASEADDR + ROUTE_TABLE_SIZE)
  9720. +#define BMU2_BUF_COUNT (4096 - 256)
  9721. +/* This is to get a total DDR size of 12MiB */
  9722. +#define BMU2_DDR_SIZE (DDR_BUF_SIZE * BMU2_BUF_COUNT)
  9723. +#define UTIL_CODE_BASEADDR (BMU2_DDR_BASEADDR + BMU2_DDR_SIZE)
  9724. +#define UTIL_CODE_SIZE (128 * SZ_1K)
  9725. +#define UTIL_DDR_DATA_BASEADDR (UTIL_CODE_BASEADDR + UTIL_CODE_SIZE)
  9726. +#define UTIL_DDR_DATA_SIZE (64 * SZ_1K)
  9727. +#define CLASS_DDR_DATA_BASEADDR (UTIL_DDR_DATA_BASEADDR + UTIL_DDR_DATA_SIZE)
  9728. +#define CLASS_DDR_DATA_SIZE (32 * SZ_1K)
  9729. +#define TMU_DDR_DATA_BASEADDR (CLASS_DDR_DATA_BASEADDR + CLASS_DDR_DATA_SIZE)
  9730. +#define TMU_DDR_DATA_SIZE (32 * SZ_1K)
  9731. +#define TMU_LLM_BASEADDR (TMU_DDR_DATA_BASEADDR + TMU_DDR_DATA_SIZE)
  9732. +#define TMU_LLM_QUEUE_LEN (8 * 512)
  9733. +/* Must be power of two and at least 16 * 8 = 128 bytes */
  9734. +#define TMU_LLM_SIZE (4 * 16 * TMU_LLM_QUEUE_LEN)
  9735. +/* (4 TMU's x 16 queues x queue_len) */
  9736. +
  9737. +#define DDR_MAX_SIZE (TMU_LLM_BASEADDR + TMU_LLM_SIZE)
  9738. +
  9739. +/* LMEM Mapping */
  9740. +#define BMU1_LMEM_BASEADDR 0
  9741. +#define BMU1_BUF_COUNT 256
  9742. +#define BMU1_LMEM_SIZE (LMEM_BUF_SIZE * BMU1_BUF_COUNT)
  9743. +
  9744. +#endif /* _PFE_MOD_H */
  9745. diff --git a/drivers/staging/fsl_ppfe/pfe_perfmon.h b/drivers/staging/fsl_ppfe/pfe_perfmon.h
  9746. new file mode 100644
  9747. index 00000000..84908121
  9748. --- /dev/null
  9749. +++ b/drivers/staging/fsl_ppfe/pfe_perfmon.h
  9750. @@ -0,0 +1,38 @@
  9751. +/*
  9752. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9753. + * Copyright 2017 NXP
  9754. + *
  9755. + * This program is free software; you can redistribute it and/or modify
  9756. + * it under the terms of the GNU General Public License as published by
  9757. + * the Free Software Foundation; either version 2 of the License, or
  9758. + * (at your option) any later version.
  9759. + *
  9760. + * This program is distributed in the hope that it will be useful,
  9761. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9762. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9763. + * GNU General Public License for more details.
  9764. + *
  9765. + * You should have received a copy of the GNU General Public License
  9766. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9767. + */
  9768. +
  9769. +#ifndef _PFE_PERFMON_H_
  9770. +#define _PFE_PERFMON_H_
  9771. +
  9772. +#include "pfe/pfe.h"
  9773. +
  9774. +#define CT_CPUMON_INTERVAL (1 * TIMER_TICKS_PER_SEC)
  9775. +
  9776. +struct pfe_cpumon {
  9777. + u32 cpu_usage_pct[MAX_PE];
  9778. + u32 class_usage_pct;
  9779. +};
  9780. +
  9781. +struct pfe_memmon {
  9782. + u32 kernel_memory_allocated;
  9783. +};
  9784. +
  9785. +int pfe_perfmon_init(struct pfe *pfe);
  9786. +void pfe_perfmon_exit(struct pfe *pfe);
  9787. +
  9788. +#endif /* _PFE_PERFMON_H_ */
  9789. diff --git a/drivers/staging/fsl_ppfe/pfe_sysfs.c b/drivers/staging/fsl_ppfe/pfe_sysfs.c
  9790. new file mode 100644
  9791. index 00000000..2a763844
  9792. --- /dev/null
  9793. +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.c
  9794. @@ -0,0 +1,818 @@
  9795. +/*
  9796. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  9797. + * Copyright 2017 NXP
  9798. + *
  9799. + * This program is free software; you can redistribute it and/or modify
  9800. + * it under the terms of the GNU General Public License as published by
  9801. + * the Free Software Foundation; either version 2 of the License, or
  9802. + * (at your option) any later version.
  9803. + *
  9804. + * This program is distributed in the hope that it will be useful,
  9805. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9806. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9807. + * GNU General Public License for more details.
  9808. + *
  9809. + * You should have received a copy of the GNU General Public License
  9810. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  9811. + */
  9812. +
  9813. +#include <linux/module.h>
  9814. +#include <linux/platform_device.h>
  9815. +
  9816. +#include "pfe_mod.h"
  9817. +
  9818. +#define PE_EXCEPTION_DUMP_ADDRESS 0x1fa8
  9819. +#define NUM_QUEUES 16
  9820. +
  9821. +static char register_name[20][5] = {
  9822. + "EPC", "ECAS", "EID", "ED",
  9823. + "r0", "r1", "r2", "r3",
  9824. + "r4", "r5", "r6", "r7",
  9825. + "r8", "r9", "r10", "r11",
  9826. + "r12", "r13", "r14", "r15",
  9827. +};
  9828. +
  9829. +static char exception_name[14][20] = {
  9830. + "Reset",
  9831. + "HardwareFailure",
  9832. + "NMI",
  9833. + "InstBreakpoint",
  9834. + "DataBreakpoint",
  9835. + "Unsupported",
  9836. + "PrivilegeViolation",
  9837. + "InstBusError",
  9838. + "DataBusError",
  9839. + "AlignmentError",
  9840. + "ArithmeticError",
  9841. + "SystemCall",
  9842. + "MemoryManagement",
  9843. + "Interrupt",
  9844. +};
  9845. +
  9846. +static unsigned long class_do_clear;
  9847. +static unsigned long tmu_do_clear;
  9848. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  9849. +static unsigned long util_do_clear;
  9850. +#endif
  9851. +
  9852. +static ssize_t display_pe_status(char *buf, int id, u32 dmem_addr, unsigned long
  9853. + do_clear)
  9854. +{
  9855. + ssize_t len = 0;
  9856. + u32 val;
  9857. + char statebuf[5];
  9858. + struct pfe_cpumon *cpumon = &pfe->cpumon;
  9859. + u32 debug_indicator;
  9860. + u32 debug[20];
  9861. +
  9862. + *(u32 *)statebuf = pe_dmem_read(id, dmem_addr, 4);
  9863. + dmem_addr += 4;
  9864. +
  9865. + statebuf[4] = '\0';
  9866. + len += sprintf(buf + len, "state=%4s ", statebuf);
  9867. +
  9868. + val = pe_dmem_read(id, dmem_addr, 4);
  9869. + dmem_addr += 4;
  9870. + len += sprintf(buf + len, "ctr=%08x ", cpu_to_be32(val));
  9871. +
  9872. + val = pe_dmem_read(id, dmem_addr, 4);
  9873. + if (do_clear && val)
  9874. + pe_dmem_write(id, 0, dmem_addr, 4);
  9875. + dmem_addr += 4;
  9876. + len += sprintf(buf + len, "rx=%u ", cpu_to_be32(val));
  9877. +
  9878. + val = pe_dmem_read(id, dmem_addr, 4);
  9879. + if (do_clear && val)
  9880. + pe_dmem_write(id, 0, dmem_addr, 4);
  9881. + dmem_addr += 4;
  9882. + if (id >= TMU0_ID && id <= TMU_MAX_ID)
  9883. + len += sprintf(buf + len, "qstatus=%x", cpu_to_be32(val));
  9884. + else
  9885. + len += sprintf(buf + len, "tx=%u", cpu_to_be32(val));
  9886. +
  9887. + val = pe_dmem_read(id, dmem_addr, 4);
  9888. + if (do_clear && val)
  9889. + pe_dmem_write(id, 0, dmem_addr, 4);
  9890. + dmem_addr += 4;
  9891. + if (val)
  9892. + len += sprintf(buf + len, " drop=%u", cpu_to_be32(val));
  9893. +
  9894. + len += sprintf(buf + len, " load=%d%%", cpumon->cpu_usage_pct[id]);
  9895. +
  9896. + len += sprintf(buf + len, "\n");
  9897. +
  9898. + debug_indicator = pe_dmem_read(id, dmem_addr, 4);
  9899. + dmem_addr += 4;
  9900. + if (!strncmp((char *)&debug_indicator, "DBUG", 4)) {
  9901. + int j, last = 0;
  9902. +
  9903. + for (j = 0; j < 16; j++) {
  9904. + debug[j] = pe_dmem_read(id, dmem_addr, 4);
  9905. + if (debug[j]) {
  9906. + if (do_clear)
  9907. + pe_dmem_write(id, 0, dmem_addr, 4);
  9908. + last = j + 1;
  9909. + }
  9910. + dmem_addr += 4;
  9911. + }
  9912. + for (j = 0; j < last; j++) {
  9913. + len += sprintf(buf + len, "%08x%s",
  9914. + cpu_to_be32(debug[j]),
  9915. + (j & 0x7) == 0x7 || j == last - 1 ? "\n" : " ");
  9916. + }
  9917. + }
  9918. +
  9919. + if (!strncmp(statebuf, "DEAD", 4)) {
  9920. + u32 i, dump = PE_EXCEPTION_DUMP_ADDRESS;
  9921. +
  9922. + len += sprintf(buf + len, "Exception details:\n");
  9923. + for (i = 0; i < 20; i++) {
  9924. + debug[i] = pe_dmem_read(id, dump, 4);
  9925. + dump += 4;
  9926. + if (i == 2)
  9927. + len += sprintf(buf + len, "%4s = %08x (=%s) ",
  9928. + register_name[i], cpu_to_be32(debug[i]),
  9929. + exception_name[min((u32)
  9930. + cpu_to_be32(debug[i]), (u32)13)]);
  9931. + else
  9932. + len += sprintf(buf + len, "%4s = %08x%s",
  9933. + register_name[i], cpu_to_be32(debug[i]),
  9934. + (i & 0x3) == 0x3 || i == 19 ? "\n" : " ");
  9935. + }
  9936. + }
  9937. +
  9938. + return len;
  9939. +}
  9940. +
  9941. +static ssize_t class_phy_stats(char *buf, int phy)
  9942. +{
  9943. + ssize_t len = 0;
  9944. + int off1 = phy * 0x28;
  9945. + int off2 = phy * 0x10;
  9946. +
  9947. + if (phy == 3)
  9948. + off1 = CLASS_PHY4_RX_PKTS - CLASS_PHY1_RX_PKTS;
  9949. +
  9950. + len += sprintf(buf + len, "phy: %d\n", phy);
  9951. + len += sprintf(buf + len,
  9952. + " rx: %10u, tx: %10u, intf: %10u, ipv4: %10u, ipv6: %10u\n",
  9953. + readl(CLASS_PHY1_RX_PKTS + off1),
  9954. + readl(CLASS_PHY1_TX_PKTS + off1),
  9955. + readl(CLASS_PHY1_INTF_MATCH_PKTS + off1),
  9956. + readl(CLASS_PHY1_V4_PKTS + off1),
  9957. + readl(CLASS_PHY1_V6_PKTS + off1));
  9958. +
  9959. + len += sprintf(buf + len,
  9960. + " icmp: %10u, igmp: %10u, tcp: %10u, udp: %10u\n",
  9961. + readl(CLASS_PHY1_ICMP_PKTS + off2),
  9962. + readl(CLASS_PHY1_IGMP_PKTS + off2),
  9963. + readl(CLASS_PHY1_TCP_PKTS + off2),
  9964. + readl(CLASS_PHY1_UDP_PKTS + off2));
  9965. +
  9966. + len += sprintf(buf + len, " err\n");
  9967. + len += sprintf(buf + len,
  9968. + " lp: %10u, intf: %10u, l3: %10u, chcksum: %10u, ttl: %10u\n",
  9969. + readl(CLASS_PHY1_LP_FAIL_PKTS + off1),
  9970. + readl(CLASS_PHY1_INTF_FAIL_PKTS + off1),
  9971. + readl(CLASS_PHY1_L3_FAIL_PKTS + off1),
  9972. + readl(CLASS_PHY1_CHKSUM_ERR_PKTS + off1),
  9973. + readl(CLASS_PHY1_TTL_ERR_PKTS + off1));
  9974. +
  9975. + return len;
  9976. +}
  9977. +
  9978. +/* qm_read_drop_stat
  9979. + * This function is used to read the drop statistics from the TMU
  9980. + * hw drop counter. Since the hw counter is always cleared afer
  9981. + * reading, this function maintains the previous drop count, and
  9982. + * adds the new value to it. That value can be retrieved by
  9983. + * passing a pointer to it with the total_drops arg.
  9984. + *
  9985. + * @param tmu TMU number (0 - 3)
  9986. + * @param queue queue number (0 - 15)
  9987. + * @param total_drops pointer to location to store total drops (or NULL)
  9988. + * @param do_reset if TRUE, clear total drops after updating
  9989. + */
  9990. +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset)
  9991. +{
  9992. + static u32 qtotal[TMU_MAX_ID + 1][NUM_QUEUES];
  9993. + u32 val;
  9994. +
  9995. + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
  9996. + writel((tmu << 8) | queue, TMU_LLM_CTRL);
  9997. + val = readl(TMU_TEQ_DROP_STAT);
  9998. + qtotal[tmu][queue] += val;
  9999. + if (total_drops)
  10000. + *total_drops = qtotal[tmu][queue];
  10001. + if (do_reset)
  10002. + qtotal[tmu][queue] = 0;
  10003. + return val;
  10004. +}
  10005. +
  10006. +static ssize_t tmu_queue_stats(char *buf, int tmu, int queue)
  10007. +{
  10008. + ssize_t len = 0;
  10009. + u32 drops;
  10010. +
  10011. + len += sprintf(buf + len, "%d-%02d, ", tmu, queue);
  10012. +
  10013. + drops = qm_read_drop_stat(tmu, queue, NULL, 0);
  10014. +
  10015. + /* Select queue */
  10016. + writel((tmu << 8) | queue, TMU_TEQ_CTRL);
  10017. + writel((tmu << 8) | queue, TMU_LLM_CTRL);
  10018. +
  10019. + len += sprintf(buf + len,
  10020. + "(teq) drop: %10u, tx: %10u (llm) head: %08x, tail: %08x, drop: %10u\n",
  10021. + drops, readl(TMU_TEQ_TRANS_STAT),
  10022. + readl(TMU_LLM_QUE_HEADPTR), readl(TMU_LLM_QUE_TAILPTR),
  10023. + readl(TMU_LLM_QUE_DROPCNT));
  10024. +
  10025. + return len;
  10026. +}
  10027. +
  10028. +static ssize_t tmu_queues(char *buf, int tmu)
  10029. +{
  10030. + ssize_t len = 0;
  10031. + int queue;
  10032. +
  10033. + for (queue = 0; queue < 16; queue++)
  10034. + len += tmu_queue_stats(buf + len, tmu, queue);
  10035. +
  10036. + return len;
  10037. +}
  10038. +
  10039. +static ssize_t block_version(char *buf, void *addr)
  10040. +{
  10041. + ssize_t len = 0;
  10042. + u32 val;
  10043. +
  10044. + val = readl(addr);
  10045. + len += sprintf(buf + len, "revision: %x, version: %x, id: %x\n",
  10046. + (val >> 24) & 0xff, (val >> 16) & 0xff, val & 0xffff);
  10047. +
  10048. + return len;
  10049. +}
  10050. +
  10051. +static ssize_t bmu(char *buf, int id, void *base)
  10052. +{
  10053. + ssize_t len = 0;
  10054. +
  10055. + len += sprintf(buf + len, "%s: %d\n ", __func__, id);
  10056. +
  10057. + len += block_version(buf + len, base + BMU_VERSION);
  10058. +
  10059. + len += sprintf(buf + len, " buf size: %x\n", (1 << readl(base +
  10060. + BMU_BUF_SIZE)));
  10061. + len += sprintf(buf + len, " buf count: %x\n", readl(base +
  10062. + BMU_BUF_CNT));
  10063. + len += sprintf(buf + len, " buf rem: %x\n", readl(base +
  10064. + BMU_REM_BUF_CNT));
  10065. + len += sprintf(buf + len, " buf curr: %x\n", readl(base +
  10066. + BMU_CURR_BUF_CNT));
  10067. + len += sprintf(buf + len, " free err: %x\n", readl(base +
  10068. + BMU_FREE_ERR_ADDR));
  10069. +
  10070. + return len;
  10071. +}
  10072. +
  10073. +static ssize_t gpi(char *buf, int id, void *base)
  10074. +{
  10075. + ssize_t len = 0;
  10076. + u32 val;
  10077. +
  10078. + len += sprintf(buf + len, "%s%d:\n ", __func__, id);
  10079. + len += block_version(buf + len, base + GPI_VERSION);
  10080. +
  10081. + len += sprintf(buf + len, " tx under stick: %x\n", readl(base +
  10082. + GPI_FIFO_STATUS));
  10083. + val = readl(base + GPI_FIFO_DEBUG);
  10084. + len += sprintf(buf + len, " tx pkts: %x\n", (val >> 23) &
  10085. + 0x3f);
  10086. + len += sprintf(buf + len, " rx pkts: %x\n", (val >> 18) &
  10087. + 0x3f);
  10088. + len += sprintf(buf + len, " tx bytes: %x\n", (val >> 9) &
  10089. + 0x1ff);
  10090. + len += sprintf(buf + len, " rx bytes: %x\n", (val >> 0) &
  10091. + 0x1ff);
  10092. + len += sprintf(buf + len, " overrun: %x\n", readl(base +
  10093. + GPI_OVERRUN_DROPCNT));
  10094. +
  10095. + return len;
  10096. +}
  10097. +
  10098. +static ssize_t pfe_set_class(struct device *dev, struct device_attribute *attr,
  10099. + const char *buf, size_t count)
  10100. +{
  10101. + class_do_clear = kstrtoul(buf, 0, 0);
  10102. + return count;
  10103. +}
  10104. +
  10105. +static ssize_t pfe_show_class(struct device *dev, struct device_attribute *attr,
  10106. + char *buf)
  10107. +{
  10108. + ssize_t len = 0;
  10109. + int id;
  10110. + u32 val;
  10111. + struct pfe_cpumon *cpumon = &pfe->cpumon;
  10112. +
  10113. + len += block_version(buf + len, CLASS_VERSION);
  10114. +
  10115. + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
  10116. + len += sprintf(buf + len, "%d: ", id - CLASS0_ID);
  10117. +
  10118. + val = readl(CLASS_PE0_DEBUG + id * 4);
  10119. + len += sprintf(buf + len, "pc=1%04x ", val & 0xffff);
  10120. +
  10121. + len += display_pe_status(buf + len, id, CLASS_DM_PESTATUS,
  10122. + class_do_clear);
  10123. + }
  10124. + len += sprintf(buf + len, "aggregate load=%d%%\n\n",
  10125. + cpumon->class_usage_pct);
  10126. +
  10127. + len += sprintf(buf + len, "pe status: 0x%x\n",
  10128. + readl(CLASS_PE_STATUS));
  10129. + len += sprintf(buf + len, "max buf cnt: 0x%x afull thres: 0x%x\n",
  10130. + readl(CLASS_MAX_BUF_CNT), readl(CLASS_AFULL_THRES));
  10131. + len += sprintf(buf + len, "tsq max cnt: 0x%x tsq fifo thres: 0x%x\n",
  10132. + readl(CLASS_TSQ_MAX_CNT), readl(CLASS_TSQ_FIFO_THRES));
  10133. + len += sprintf(buf + len, "state: 0x%x\n", readl(CLASS_STATE));
  10134. +
  10135. + len += class_phy_stats(buf + len, 0);
  10136. + len += class_phy_stats(buf + len, 1);
  10137. + len += class_phy_stats(buf + len, 2);
  10138. + len += class_phy_stats(buf + len, 3);
  10139. +
  10140. + return len;
  10141. +}
  10142. +
  10143. +static ssize_t pfe_set_tmu(struct device *dev, struct device_attribute *attr,
  10144. + const char *buf, size_t count)
  10145. +{
  10146. + tmu_do_clear = kstrtoul(buf, 0, 0);
  10147. + return count;
  10148. +}
  10149. +
  10150. +static ssize_t pfe_show_tmu(struct device *dev, struct device_attribute *attr,
  10151. + char *buf)
  10152. +{
  10153. + ssize_t len = 0;
  10154. + int id;
  10155. + u32 val;
  10156. +
  10157. + len += block_version(buf + len, TMU_VERSION);
  10158. +
  10159. + for (id = TMU0_ID; id <= TMU_MAX_ID; id++) {
  10160. + if (id == TMU2_ID)
  10161. + continue;
  10162. + len += sprintf(buf + len, "%d: ", id - TMU0_ID);
  10163. +
  10164. + len += display_pe_status(buf + len, id, TMU_DM_PESTATUS,
  10165. + tmu_do_clear);
  10166. + }
  10167. +
  10168. + len += sprintf(buf + len, "pe status: %x\n", readl(TMU_PE_STATUS));
  10169. + len += sprintf(buf + len, "inq fifo cnt: %x\n",
  10170. + readl(TMU_PHY_INQ_FIFO_CNT));
  10171. + val = readl(TMU_INQ_STAT);
  10172. + len += sprintf(buf + len, "inq wr ptr: %x\n", val & 0x3ff);
  10173. + len += sprintf(buf + len, "inq rd ptr: %x\n", val >> 10);
  10174. +
  10175. + return len;
  10176. +}
  10177. +
  10178. +static unsigned long drops_do_clear;
  10179. +static u32 class_drop_counter[CLASS_NUM_DROP_COUNTERS];
  10180. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10181. +static u32 util_drop_counter[UTIL_NUM_DROP_COUNTERS];
  10182. +#endif
  10183. +
  10184. +char *class_drop_description[CLASS_NUM_DROP_COUNTERS] = {
  10185. + "ICC",
  10186. + "Host Pkt Error",
  10187. + "Rx Error",
  10188. + "IPsec Outbound",
  10189. + "IPsec Inbound",
  10190. + "EXPT IPsec Error",
  10191. + "Reassembly",
  10192. + "Fragmenter",
  10193. + "NAT-T",
  10194. + "Socket",
  10195. + "Multicast",
  10196. + "NAT-PT",
  10197. + "Tx Disabled",
  10198. +};
  10199. +
  10200. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10201. +char *util_drop_description[UTIL_NUM_DROP_COUNTERS] = {
  10202. + "IPsec Outbound",
  10203. + "IPsec Inbound",
  10204. + "IPsec Rate Limiter",
  10205. + "Fragmenter",
  10206. + "Socket",
  10207. + "Tx Disabled",
  10208. + "Rx Error",
  10209. +};
  10210. +#endif
  10211. +
  10212. +static ssize_t pfe_set_drops(struct device *dev, struct device_attribute *attr,
  10213. + const char *buf, size_t count)
  10214. +{
  10215. + drops_do_clear = kstrtoul(buf, 0, 0);
  10216. + return count;
  10217. +}
  10218. +
  10219. +static u32 tmu_drops[4][16];
  10220. +static ssize_t pfe_show_drops(struct device *dev, struct device_attribute *attr,
  10221. + char *buf)
  10222. +{
  10223. + ssize_t len = 0;
  10224. + int id, dropnum;
  10225. + int tmu, queue;
  10226. + u32 val;
  10227. + u32 dmem_addr;
  10228. + int num_class_drops = 0, num_tmu_drops = 0, num_util_drops = 0;
  10229. + struct pfe_ctrl *ctrl = &pfe->ctrl;
  10230. +
  10231. + memset(class_drop_counter, 0, sizeof(class_drop_counter));
  10232. + for (id = CLASS0_ID; id <= CLASS_MAX_ID; id++) {
  10233. + if (drops_do_clear)
  10234. + pe_sync_stop(ctrl, (1 << id));
  10235. + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
  10236. + dropnum++) {
  10237. + dmem_addr = CLASS_DM_DROP_CNTR;
  10238. + val = be32_to_cpu(pe_dmem_read(id, dmem_addr, 4));
  10239. + class_drop_counter[dropnum] += val;
  10240. + num_class_drops += val;
  10241. + if (drops_do_clear)
  10242. + pe_dmem_write(id, 0, dmem_addr, 4);
  10243. + }
  10244. + if (drops_do_clear)
  10245. + pe_start(ctrl, (1 << id));
  10246. + }
  10247. +
  10248. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10249. + if (drops_do_clear)
  10250. + pe_sync_stop(ctrl, (1 << UTIL_ID));
  10251. + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
  10252. + dmem_addr = UTIL_DM_DROP_CNTR;
  10253. + val = be32_to_cpu(pe_dmem_read(UTIL_ID, dmem_addr, 4));
  10254. + util_drop_counter[dropnum] = val;
  10255. + num_util_drops += val;
  10256. + if (drops_do_clear)
  10257. + pe_dmem_write(UTIL_ID, 0, dmem_addr, 4);
  10258. + }
  10259. + if (drops_do_clear)
  10260. + pe_start(ctrl, (1 << UTIL_ID));
  10261. +#endif
  10262. + for (tmu = 0; tmu < 4; tmu++) {
  10263. + for (queue = 0; queue < 16; queue++) {
  10264. + qm_read_drop_stat(tmu, queue, &tmu_drops[tmu][queue],
  10265. + drops_do_clear);
  10266. + num_tmu_drops += tmu_drops[tmu][queue];
  10267. + }
  10268. + }
  10269. +
  10270. + if (num_class_drops == 0 && num_util_drops == 0 && num_tmu_drops == 0)
  10271. + len += sprintf(buf + len, "No PE drops\n\n");
  10272. +
  10273. + if (num_class_drops > 0) {
  10274. + len += sprintf(buf + len, "Class PE drops --\n");
  10275. + for (dropnum = 0; dropnum < CLASS_NUM_DROP_COUNTERS;
  10276. + dropnum++) {
  10277. + if (class_drop_counter[dropnum] > 0)
  10278. + len += sprintf(buf + len, " %s: %d\n",
  10279. + class_drop_description[dropnum],
  10280. + class_drop_counter[dropnum]);
  10281. + }
  10282. + len += sprintf(buf + len, "\n");
  10283. + }
  10284. +
  10285. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10286. + if (num_util_drops > 0) {
  10287. + len += sprintf(buf + len, "Util PE drops --\n");
  10288. + for (dropnum = 0; dropnum < UTIL_NUM_DROP_COUNTERS; dropnum++) {
  10289. + if (util_drop_counter[dropnum] > 0)
  10290. + len += sprintf(buf + len, " %s: %d\n",
  10291. + util_drop_description[dropnum],
  10292. + util_drop_counter[dropnum]);
  10293. + }
  10294. + len += sprintf(buf + len, "\n");
  10295. + }
  10296. +#endif
  10297. + if (num_tmu_drops > 0) {
  10298. + len += sprintf(buf + len, "TMU drops --\n");
  10299. + for (tmu = 0; tmu < 4; tmu++) {
  10300. + for (queue = 0; queue < 16; queue++) {
  10301. + if (tmu_drops[tmu][queue] > 0)
  10302. + len += sprintf(buf + len,
  10303. + " TMU%d-Q%d: %d\n"
  10304. + , tmu, queue, tmu_drops[tmu][queue]);
  10305. + }
  10306. + }
  10307. + len += sprintf(buf + len, "\n");
  10308. + }
  10309. +
  10310. + return len;
  10311. +}
  10312. +
  10313. +static ssize_t pfe_show_tmu0_queues(struct device *dev, struct device_attribute
  10314. + *attr, char *buf)
  10315. +{
  10316. + return tmu_queues(buf, 0);
  10317. +}
  10318. +
  10319. +static ssize_t pfe_show_tmu1_queues(struct device *dev, struct device_attribute
  10320. + *attr, char *buf)
  10321. +{
  10322. + return tmu_queues(buf, 1);
  10323. +}
  10324. +
  10325. +static ssize_t pfe_show_tmu2_queues(struct device *dev, struct device_attribute
  10326. + *attr, char *buf)
  10327. +{
  10328. + return tmu_queues(buf, 2);
  10329. +}
  10330. +
  10331. +static ssize_t pfe_show_tmu3_queues(struct device *dev, struct device_attribute
  10332. + *attr, char *buf)
  10333. +{
  10334. + return tmu_queues(buf, 3);
  10335. +}
  10336. +
  10337. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10338. +static ssize_t pfe_set_util(struct device *dev, struct device_attribute *attr,
  10339. + const char *buf, size_t count)
  10340. +{
  10341. + util_do_clear = kstrtoul(buf, NULL, 0);
  10342. + return count;
  10343. +}
  10344. +
  10345. +static ssize_t pfe_show_util(struct device *dev, struct device_attribute *attr,
  10346. + char *buf)
  10347. +{
  10348. + ssize_t len = 0;
  10349. + struct pfe_ctrl *ctrl = &pfe->ctrl;
  10350. +
  10351. + len += block_version(buf + len, UTIL_VERSION);
  10352. +
  10353. + pe_sync_stop(ctrl, (1 << UTIL_ID));
  10354. + len += display_pe_status(buf + len, UTIL_ID, UTIL_DM_PESTATUS,
  10355. + util_do_clear);
  10356. + pe_start(ctrl, (1 << UTIL_ID));
  10357. +
  10358. + len += sprintf(buf + len, "pe status: %x\n", readl(UTIL_PE_STATUS));
  10359. + len += sprintf(buf + len, "max buf cnt: %x\n",
  10360. + readl(UTIL_MAX_BUF_CNT));
  10361. + len += sprintf(buf + len, "tsq max cnt: %x\n",
  10362. + readl(UTIL_TSQ_MAX_CNT));
  10363. +
  10364. + return len;
  10365. +}
  10366. +#endif
  10367. +
  10368. +static ssize_t pfe_show_bmu(struct device *dev, struct device_attribute *attr,
  10369. + char *buf)
  10370. +{
  10371. + ssize_t len = 0;
  10372. +
  10373. + len += bmu(buf + len, 1, BMU1_BASE_ADDR);
  10374. + len += bmu(buf + len, 2, BMU2_BASE_ADDR);
  10375. +
  10376. + return len;
  10377. +}
  10378. +
  10379. +static ssize_t pfe_show_hif(struct device *dev, struct device_attribute *attr,
  10380. + char *buf)
  10381. +{
  10382. + ssize_t len = 0;
  10383. +
  10384. + len += sprintf(buf + len, "hif:\n ");
  10385. + len += block_version(buf + len, HIF_VERSION);
  10386. +
  10387. + len += sprintf(buf + len, " tx curr bd: %x\n",
  10388. + readl(HIF_TX_CURR_BD_ADDR));
  10389. + len += sprintf(buf + len, " tx status: %x\n",
  10390. + readl(HIF_TX_STATUS));
  10391. + len += sprintf(buf + len, " tx dma status: %x\n",
  10392. + readl(HIF_TX_DMA_STATUS));
  10393. +
  10394. + len += sprintf(buf + len, " rx curr bd: %x\n",
  10395. + readl(HIF_RX_CURR_BD_ADDR));
  10396. + len += sprintf(buf + len, " rx status: %x\n",
  10397. + readl(HIF_RX_STATUS));
  10398. + len += sprintf(buf + len, " rx dma status: %x\n",
  10399. + readl(HIF_RX_DMA_STATUS));
  10400. +
  10401. + len += sprintf(buf + len, "hif nocopy:\n ");
  10402. + len += block_version(buf + len, HIF_NOCPY_VERSION);
  10403. +
  10404. + len += sprintf(buf + len, " tx curr bd: %x\n",
  10405. + readl(HIF_NOCPY_TX_CURR_BD_ADDR));
  10406. + len += sprintf(buf + len, " tx status: %x\n",
  10407. + readl(HIF_NOCPY_TX_STATUS));
  10408. + len += sprintf(buf + len, " tx dma status: %x\n",
  10409. + readl(HIF_NOCPY_TX_DMA_STATUS));
  10410. +
  10411. + len += sprintf(buf + len, " rx curr bd: %x\n",
  10412. + readl(HIF_NOCPY_RX_CURR_BD_ADDR));
  10413. + len += sprintf(buf + len, " rx status: %x\n",
  10414. + readl(HIF_NOCPY_RX_STATUS));
  10415. + len += sprintf(buf + len, " rx dma status: %x\n",
  10416. + readl(HIF_NOCPY_RX_DMA_STATUS));
  10417. +
  10418. + return len;
  10419. +}
  10420. +
  10421. +static ssize_t pfe_show_gpi(struct device *dev, struct device_attribute *attr,
  10422. + char *buf)
  10423. +{
  10424. + ssize_t len = 0;
  10425. +
  10426. + len += gpi(buf + len, 0, EGPI1_BASE_ADDR);
  10427. + len += gpi(buf + len, 1, EGPI2_BASE_ADDR);
  10428. + len += gpi(buf + len, 3, HGPI_BASE_ADDR);
  10429. +
  10430. + return len;
  10431. +}
  10432. +
  10433. +static ssize_t pfe_show_pfemem(struct device *dev, struct device_attribute
  10434. + *attr, char *buf)
  10435. +{
  10436. + ssize_t len = 0;
  10437. + struct pfe_memmon *memmon = &pfe->memmon;
  10438. +
  10439. + len += sprintf(buf + len, "Kernel Memory: %d Bytes (%d KB)\n",
  10440. + memmon->kernel_memory_allocated,
  10441. + (memmon->kernel_memory_allocated + 1023) / 1024);
  10442. +
  10443. + return len;
  10444. +}
  10445. +
  10446. +#ifdef HIF_NAPI_STATS
  10447. +static ssize_t pfe_show_hif_napi_stats(struct device *dev,
  10448. + struct device_attribute *attr,
  10449. + char *buf)
  10450. +{
  10451. + struct platform_device *pdev = to_platform_device(dev);
  10452. + struct pfe *pfe = platform_get_drvdata(pdev);
  10453. + ssize_t len = 0;
  10454. +
  10455. + len += sprintf(buf + len, "sched: %u\n",
  10456. + pfe->hif.napi_counters[NAPI_SCHED_COUNT]);
  10457. + len += sprintf(buf + len, "poll: %u\n",
  10458. + pfe->hif.napi_counters[NAPI_POLL_COUNT]);
  10459. + len += sprintf(buf + len, "packet: %u\n",
  10460. + pfe->hif.napi_counters[NAPI_PACKET_COUNT]);
  10461. + len += sprintf(buf + len, "budget: %u\n",
  10462. + pfe->hif.napi_counters[NAPI_FULL_BUDGET_COUNT]);
  10463. + len += sprintf(buf + len, "desc: %u\n",
  10464. + pfe->hif.napi_counters[NAPI_DESC_COUNT]);
  10465. + len += sprintf(buf + len, "full: %u\n",
  10466. + pfe->hif.napi_counters[NAPI_CLIENT_FULL_COUNT]);
  10467. +
  10468. + return len;
  10469. +}
  10470. +
  10471. +static ssize_t pfe_set_hif_napi_stats(struct device *dev,
  10472. + struct device_attribute *attr,
  10473. + const char *buf, size_t count)
  10474. +{
  10475. + struct platform_device *pdev = to_platform_device(dev);
  10476. + struct pfe *pfe = platform_get_drvdata(pdev);
  10477. +
  10478. + memset(pfe->hif.napi_counters, 0, sizeof(pfe->hif.napi_counters));
  10479. +
  10480. + return count;
  10481. +}
  10482. +
  10483. +static DEVICE_ATTR(hif_napi_stats, 0644, pfe_show_hif_napi_stats,
  10484. + pfe_set_hif_napi_stats);
  10485. +#endif
  10486. +
  10487. +static DEVICE_ATTR(class, 0644, pfe_show_class, pfe_set_class);
  10488. +static DEVICE_ATTR(tmu, 0644, pfe_show_tmu, pfe_set_tmu);
  10489. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10490. +static DEVICE_ATTR(util, 0644, pfe_show_util, pfe_set_util);
  10491. +#endif
  10492. +static DEVICE_ATTR(bmu, 0444, pfe_show_bmu, NULL);
  10493. +static DEVICE_ATTR(hif, 0444, pfe_show_hif, NULL);
  10494. +static DEVICE_ATTR(gpi, 0444, pfe_show_gpi, NULL);
  10495. +static DEVICE_ATTR(drops, 0644, pfe_show_drops, pfe_set_drops);
  10496. +static DEVICE_ATTR(tmu0_queues, 0444, pfe_show_tmu0_queues, NULL);
  10497. +static DEVICE_ATTR(tmu1_queues, 0444, pfe_show_tmu1_queues, NULL);
  10498. +static DEVICE_ATTR(tmu2_queues, 0444, pfe_show_tmu2_queues, NULL);
  10499. +static DEVICE_ATTR(tmu3_queues, 0444, pfe_show_tmu3_queues, NULL);
  10500. +static DEVICE_ATTR(pfemem, 0444, pfe_show_pfemem, NULL);
  10501. +
  10502. +int pfe_sysfs_init(struct pfe *pfe)
  10503. +{
  10504. + if (device_create_file(pfe->dev, &dev_attr_class))
  10505. + goto err_class;
  10506. +
  10507. + if (device_create_file(pfe->dev, &dev_attr_tmu))
  10508. + goto err_tmu;
  10509. +
  10510. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10511. + if (device_create_file(pfe->dev, &dev_attr_util))
  10512. + goto err_util;
  10513. +#endif
  10514. +
  10515. + if (device_create_file(pfe->dev, &dev_attr_bmu))
  10516. + goto err_bmu;
  10517. +
  10518. + if (device_create_file(pfe->dev, &dev_attr_hif))
  10519. + goto err_hif;
  10520. +
  10521. + if (device_create_file(pfe->dev, &dev_attr_gpi))
  10522. + goto err_gpi;
  10523. +
  10524. + if (device_create_file(pfe->dev, &dev_attr_drops))
  10525. + goto err_drops;
  10526. +
  10527. + if (device_create_file(pfe->dev, &dev_attr_tmu0_queues))
  10528. + goto err_tmu0_queues;
  10529. +
  10530. + if (device_create_file(pfe->dev, &dev_attr_tmu1_queues))
  10531. + goto err_tmu1_queues;
  10532. +
  10533. + if (device_create_file(pfe->dev, &dev_attr_tmu2_queues))
  10534. + goto err_tmu2_queues;
  10535. +
  10536. + if (device_create_file(pfe->dev, &dev_attr_tmu3_queues))
  10537. + goto err_tmu3_queues;
  10538. +
  10539. + if (device_create_file(pfe->dev, &dev_attr_pfemem))
  10540. + goto err_pfemem;
  10541. +
  10542. +#ifdef HIF_NAPI_STATS
  10543. + if (device_create_file(pfe->dev, &dev_attr_hif_napi_stats))
  10544. + goto err_hif_napi_stats;
  10545. +#endif
  10546. +
  10547. + return 0;
  10548. +
  10549. +#ifdef HIF_NAPI_STATS
  10550. +err_hif_napi_stats:
  10551. + device_remove_file(pfe->dev, &dev_attr_pfemem);
  10552. +#endif
  10553. +
  10554. +err_pfemem:
  10555. + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
  10556. +
  10557. +err_tmu3_queues:
  10558. + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
  10559. +
  10560. +err_tmu2_queues:
  10561. + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
  10562. +
  10563. +err_tmu1_queues:
  10564. + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
  10565. +
  10566. +err_tmu0_queues:
  10567. + device_remove_file(pfe->dev, &dev_attr_drops);
  10568. +
  10569. +err_drops:
  10570. + device_remove_file(pfe->dev, &dev_attr_gpi);
  10571. +
  10572. +err_gpi:
  10573. + device_remove_file(pfe->dev, &dev_attr_hif);
  10574. +
  10575. +err_hif:
  10576. + device_remove_file(pfe->dev, &dev_attr_bmu);
  10577. +
  10578. +err_bmu:
  10579. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10580. + device_remove_file(pfe->dev, &dev_attr_util);
  10581. +
  10582. +err_util:
  10583. +#endif
  10584. + device_remove_file(pfe->dev, &dev_attr_tmu);
  10585. +
  10586. +err_tmu:
  10587. + device_remove_file(pfe->dev, &dev_attr_class);
  10588. +
  10589. +err_class:
  10590. + return -1;
  10591. +}
  10592. +
  10593. +void pfe_sysfs_exit(struct pfe *pfe)
  10594. +{
  10595. +#ifdef HIF_NAPI_STATS
  10596. + device_remove_file(pfe->dev, &dev_attr_hif_napi_stats);
  10597. +#endif
  10598. + device_remove_file(pfe->dev, &dev_attr_pfemem);
  10599. + device_remove_file(pfe->dev, &dev_attr_tmu3_queues);
  10600. + device_remove_file(pfe->dev, &dev_attr_tmu2_queues);
  10601. + device_remove_file(pfe->dev, &dev_attr_tmu1_queues);
  10602. + device_remove_file(pfe->dev, &dev_attr_tmu0_queues);
  10603. + device_remove_file(pfe->dev, &dev_attr_drops);
  10604. + device_remove_file(pfe->dev, &dev_attr_gpi);
  10605. + device_remove_file(pfe->dev, &dev_attr_hif);
  10606. + device_remove_file(pfe->dev, &dev_attr_bmu);
  10607. +#if !defined(CONFIG_FSL_PPFE_UTIL_DISABLED)
  10608. + device_remove_file(pfe->dev, &dev_attr_util);
  10609. +#endif
  10610. + device_remove_file(pfe->dev, &dev_attr_tmu);
  10611. + device_remove_file(pfe->dev, &dev_attr_class);
  10612. +}
  10613. diff --git a/drivers/staging/fsl_ppfe/pfe_sysfs.h b/drivers/staging/fsl_ppfe/pfe_sysfs.h
  10614. new file mode 100644
  10615. index 00000000..4fb39c93
  10616. --- /dev/null
  10617. +++ b/drivers/staging/fsl_ppfe/pfe_sysfs.h
  10618. @@ -0,0 +1,29 @@
  10619. +/*
  10620. + * Copyright 2015-2016 Freescale Semiconductor, Inc.
  10621. + * Copyright 2017 NXP
  10622. + *
  10623. + * This program is free software; you can redistribute it and/or modify
  10624. + * it under the terms of the GNU General Public License as published by
  10625. + * the Free Software Foundation; either version 2 of the License, or
  10626. + * (at your option) any later version.
  10627. + *
  10628. + * This program is distributed in the hope that it will be useful,
  10629. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10630. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10631. + * GNU General Public License for more details.
  10632. + *
  10633. + * You should have received a copy of the GNU General Public License
  10634. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  10635. + */
  10636. +
  10637. +#ifndef _PFE_SYSFS_H_
  10638. +#define _PFE_SYSFS_H_
  10639. +
  10640. +#include <linux/proc_fs.h>
  10641. +
  10642. +u32 qm_read_drop_stat(u32 tmu, u32 queue, u32 *total_drops, int do_reset);
  10643. +
  10644. +int pfe_sysfs_init(struct pfe *pfe);
  10645. +void pfe_sysfs_exit(struct pfe *pfe);
  10646. +
  10647. +#endif /* _PFE_SYSFS_H_ */
  10648. --
  10649. 2.14.1