001-git_sync.patch 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941
  1. --- a/arch/arm/boot/compressed/head.S
  2. +++ b/arch/arm/boot/compressed/head.S
  3. @@ -9,6 +9,7 @@
  4. * published by the Free Software Foundation.
  5. */
  6. #include <linux/linkage.h>
  7. +#include <asm/cache.h>
  8. /*
  9. * Debugging stuff
  10. @@ -355,7 +356,7 @@ params: ldr r0, =0x10000100 @ params_p
  11. * This routine must preserve:
  12. * r4, r5, r6, r7, r8
  13. */
  14. - .align 5
  15. + .align L1_CACHE_SHIFT
  16. cache_on: mov r3, #8 @ cache_on function
  17. b call_cache_fn
  18. @@ -544,7 +545,7 @@ __common_mmu_cache_on:
  19. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  20. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  21. b 1f
  22. - .align 5 @ cache line aligned
  23. + .align L1_CACHE_SHIFT @ cache line aligned
  24. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  25. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  26. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  27. @@ -563,7 +564,7 @@ __common_mmu_cache_on:
  28. * r8 = atags pointer
  29. * r9-r12,r14 = corrupted
  30. */
  31. - .align 5
  32. + .align L1_CACHE_SHIFT
  33. reloc_start: add r9, r5, r0
  34. sub r9, r9, #128 @ do not copy the stack
  35. debug_reloc_start
  36. @@ -793,7 +794,7 @@ proc_types:
  37. * This routine must preserve:
  38. * r4, r6, r7
  39. */
  40. - .align 5
  41. + .align L1_CACHE_SHIFT
  42. cache_off: mov r3, #12 @ cache_off function
  43. b call_cache_fn
  44. @@ -868,7 +869,7 @@ __armv3_mmu_cache_off:
  45. * This routine must preserve:
  46. * r0, r4, r5, r6, r7
  47. */
  48. - .align 5
  49. + .align L1_CACHE_SHIFT
  50. cache_clean_flush:
  51. mov r3, #16
  52. b call_cache_fn
  53. --- a/arch/arm/Kconfig
  54. +++ b/arch/arm/Kconfig
  55. @@ -307,6 +307,7 @@ config ARCH_GEMINI
  56. select CPU_FA526
  57. select ARCH_REQUIRE_GPIOLIB
  58. select ARCH_USES_GETTIMEOFFSET
  59. + select PCI
  60. help
  61. Support for the Cortina Systems Gemini family SoCs
  62. @@ -1164,7 +1165,7 @@ config ISA_DMA_API
  63. bool
  64. config PCI
  65. - bool "PCI support" if ARCH_INTEGRATOR_AP || ARCH_VERSATILE_PB || ARCH_IXP4XX || ARCH_KS8695 || MACH_ARMCORE || ARCH_CNS3XXX
  66. + bool "PCI support" if ARCH_INTEGRATOR_AP || ARCH_VERSATILE_PB || ARCH_IXP4XX || ARCH_KS8695 || MACH_ARMCORE || ARCH_CNS3XXX || ARCH_GEMINI
  67. help
  68. Find out whether you have a PCI motherboard. PCI is the name of a
  69. bus system, i.e. the way the CPU talks to the other stuff inside
  70. --- a/arch/arm/kernel/entry-armv.S
  71. +++ b/arch/arm/kernel/entry-armv.S
  72. @@ -23,6 +23,7 @@
  73. #include <asm/unwind.h>
  74. #include <asm/unistd.h>
  75. #include <asm/tls.h>
  76. +#include <asm/cache.h>
  77. #include "entry-header.S"
  78. @@ -167,7 +168,7 @@ ENDPROC(__und_invalid)
  79. stmia r5, {r0 - r4}
  80. .endm
  81. - .align 5
  82. + .align L1_CACHE_SHIFT
  83. __dabt_svc:
  84. svc_entry
  85. @@ -215,7 +216,7 @@ __dabt_svc:
  86. UNWIND(.fnend )
  87. ENDPROC(__dabt_svc)
  88. - .align 5
  89. + .align L1_CACHE_SHIFT
  90. __irq_svc:
  91. svc_entry
  92. @@ -259,7 +260,7 @@ svc_preempt:
  93. b 1b
  94. #endif
  95. - .align 5
  96. + .align L1_CACHE_SHIFT
  97. __und_svc:
  98. #ifdef CONFIG_KPROBES
  99. @ If a kprobe is about to simulate a "stmdb sp..." instruction,
  100. @@ -305,7 +306,7 @@ __und_svc:
  101. UNWIND(.fnend )
  102. ENDPROC(__und_svc)
  103. - .align 5
  104. + .align L1_CACHE_SHIFT
  105. __pabt_svc:
  106. svc_entry
  107. @@ -341,7 +342,7 @@ __pabt_svc:
  108. UNWIND(.fnend )
  109. ENDPROC(__pabt_svc)
  110. - .align 5
  111. + .align L1_CACHE_SHIFT
  112. .LCcralign:
  113. .word cr_alignment
  114. #ifdef MULTI_DABORT
  115. @@ -414,7 +415,7 @@ ENDPROC(__pabt_svc)
  116. #endif
  117. .endm
  118. - .align 5
  119. + .align L1_CACHE_SHIFT
  120. __dabt_usr:
  121. usr_entry
  122. kuser_cmpxchg_check
  123. @@ -446,7 +447,7 @@ __dabt_usr:
  124. UNWIND(.fnend )
  125. ENDPROC(__dabt_usr)
  126. - .align 5
  127. + .align L1_CACHE_SHIFT
  128. __irq_usr:
  129. usr_entry
  130. kuser_cmpxchg_check
  131. @@ -475,7 +476,7 @@ ENDPROC(__irq_usr)
  132. .ltorg
  133. - .align 5
  134. + .align L1_CACHE_SHIFT
  135. __und_usr:
  136. usr_entry
  137. @@ -691,7 +692,7 @@ __und_usr_unknown:
  138. b do_undefinstr
  139. ENDPROC(__und_usr_unknown)
  140. - .align 5
  141. + .align L1_CACHE_SHIFT
  142. __pabt_usr:
  143. usr_entry
  144. @@ -805,7 +806,7 @@ ENDPROC(__switch_to)
  145. #endif
  146. .endm
  147. - .align 5
  148. + .align L1_CACHE_SHIFT
  149. .globl __kuser_helper_start
  150. __kuser_helper_start:
  151. @@ -845,7 +846,7 @@ __kuser_memory_barrier: @ 0xffff0fa0
  152. smp_dmb
  153. usr_ret lr
  154. - .align 5
  155. + .align L1_CACHE_SHIFT
  156. /*
  157. * Reference prototype:
  158. @@ -972,7 +973,7 @@ kuser_cmpxchg_fixup:
  159. #endif
  160. - .align 5
  161. + .align L1_CACHE_SHIFT
  162. /*
  163. * Reference prototype:
  164. @@ -1050,7 +1051,7 @@ __kuser_helper_end:
  165. * of which is copied into r0 for the mode specific abort handler.
  166. */
  167. .macro vector_stub, name, mode, correction=0
  168. - .align 5
  169. + .align L1_CACHE_SHIFT
  170. vector_\name:
  171. .if \correction
  172. @@ -1181,7 +1182,7 @@ __stubs_start:
  173. .long __und_invalid @ e
  174. .long __und_invalid @ f
  175. - .align 5
  176. + .align L1_CACHE_SHIFT
  177. /*=============================================================================
  178. * Undefined FIQs
  179. @@ -1211,7 +1212,7 @@ vector_addrexcptn:
  180. * We group all the following data together to optimise
  181. * for CPUs with separate I & D caches.
  182. */
  183. - .align 5
  184. + .align L1_CACHE_SHIFT
  185. .LCvswi:
  186. .word vector_swi
  187. --- a/arch/arm/kernel/entry-common.S
  188. +++ b/arch/arm/kernel/entry-common.S
  189. @@ -10,13 +10,14 @@
  190. #include <asm/unistd.h>
  191. #include <asm/ftrace.h>
  192. +#include <asm/cache.h>
  193. #include <mach/entry-macro.S>
  194. #include <asm/unwind.h>
  195. #include "entry-header.S"
  196. - .align 5
  197. + .align L1_CACHE_SHIFT
  198. /*
  199. * This is the fast syscall return path. We do as little as
  200. * possible here, and this includes saving r0 back into the SVC
  201. @@ -266,7 +267,7 @@ ENDPROC(ftrace_stub)
  202. #define A710(code...)
  203. #endif
  204. - .align 5
  205. + .align L1_CACHE_SHIFT
  206. ENTRY(vector_swi)
  207. sub sp, sp, #S_FRAME_SIZE
  208. stmia sp, {r0 - r12} @ Calling r0 - r12
  209. @@ -410,7 +411,7 @@ __sys_trace_return:
  210. bl syscall_trace
  211. b ret_slow_syscall
  212. - .align 5
  213. + .align L1_CACHE_SHIFT
  214. #ifdef CONFIG_ALIGNMENT_TRAP
  215. .type __cr_alignment, #object
  216. __cr_alignment:
  217. --- a/arch/arm/kernel/head.S
  218. +++ b/arch/arm/kernel/head.S
  219. @@ -21,6 +21,7 @@
  220. #include <asm/memory.h>
  221. #include <asm/thread_info.h>
  222. #include <asm/system.h>
  223. +#include <asm/cache.h>
  224. #ifdef CONFIG_DEBUG_LL
  225. #include <mach/debug-macro.S>
  226. @@ -378,7 +379,7 @@ ENDPROC(__enable_mmu)
  227. *
  228. * other registers depend on the function called upon completion
  229. */
  230. - .align 5
  231. + .align L1_CACHE_SHIFT
  232. __turn_mmu_on:
  233. mov r0, r0
  234. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  235. --- a/arch/arm/lib/memchr.S
  236. +++ b/arch/arm/lib/memchr.S
  237. @@ -11,9 +11,10 @@
  238. */
  239. #include <linux/linkage.h>
  240. #include <asm/assembler.h>
  241. +#include <asm/cache.h>
  242. .text
  243. - .align 5
  244. + .align L1_CACHE_SHIFT
  245. ENTRY(memchr)
  246. 1: subs r2, r2, #1
  247. bmi 2f
  248. --- a/arch/arm/lib/memset.S
  249. +++ b/arch/arm/lib/memset.S
  250. @@ -11,9 +11,10 @@
  251. */
  252. #include <linux/linkage.h>
  253. #include <asm/assembler.h>
  254. +#include <asm/cache.h>
  255. .text
  256. - .align 5
  257. + .align L1_CACHE_SHIFT
  258. .word 0
  259. 1: subs r2, r2, #4 @ 1 do we have enough
  260. --- a/arch/arm/lib/memzero.S
  261. +++ b/arch/arm/lib/memzero.S
  262. @@ -9,9 +9,10 @@
  263. */
  264. #include <linux/linkage.h>
  265. #include <asm/assembler.h>
  266. +#include <asm/cache.h>
  267. .text
  268. - .align 5
  269. + .align L1_CACHE_SHIFT
  270. .word 0
  271. /*
  272. * Align the pointer in r0. r3 contains the number of bytes that we are
  273. --- a/arch/arm/lib/strchr.S
  274. +++ b/arch/arm/lib/strchr.S
  275. @@ -11,9 +11,10 @@
  276. */
  277. #include <linux/linkage.h>
  278. #include <asm/assembler.h>
  279. +#include <asm/cache.h>
  280. .text
  281. - .align 5
  282. + .align L1_CACHE_SHIFT
  283. ENTRY(strchr)
  284. and r1, r1, #0xff
  285. 1: ldrb r2, [r0], #1
  286. --- a/arch/arm/lib/strncpy_from_user.S
  287. +++ b/arch/arm/lib/strncpy_from_user.S
  288. @@ -10,9 +10,10 @@
  289. #include <linux/linkage.h>
  290. #include <asm/assembler.h>
  291. #include <asm/errno.h>
  292. +#include <asm/cache.h>
  293. .text
  294. - .align 5
  295. + .align L1_CACHE_SHIFT
  296. /*
  297. * Copy a string from user space to kernel space.
  298. --- a/arch/arm/lib/strnlen_user.S
  299. +++ b/arch/arm/lib/strnlen_user.S
  300. @@ -10,9 +10,10 @@
  301. #include <linux/linkage.h>
  302. #include <asm/assembler.h>
  303. #include <asm/errno.h>
  304. +#include <asm/cache.h>
  305. .text
  306. - .align 5
  307. + .align L1_CACHE_SHIFT
  308. /* Prototype: unsigned long __strnlen_user(const char *str, long n)
  309. * Purpose : get length of a string in user memory
  310. --- a/arch/arm/lib/strrchr.S
  311. +++ b/arch/arm/lib/strrchr.S
  312. @@ -11,9 +11,10 @@
  313. */
  314. #include <linux/linkage.h>
  315. #include <asm/assembler.h>
  316. +#include <asm/cache.h>
  317. .text
  318. - .align 5
  319. + .align L1_CACHE_SHIFT
  320. ENTRY(strrchr)
  321. mov r3, #0
  322. 1: ldrb r2, [r0], #1
  323. --- a/arch/arm/mach-gemini/board-rut1xx.c
  324. +++ b/arch/arm/mach-gemini/board-rut1xx.c
  325. @@ -14,13 +14,35 @@
  326. #include <linux/leds.h>
  327. #include <linux/input.h>
  328. #include <linux/gpio_keys.h>
  329. +#include <linux/mdio-gpio.h>
  330. #include <asm/mach-types.h>
  331. #include <asm/mach/arch.h>
  332. #include <asm/mach/time.h>
  333. +#include <mach/gmac.h>
  334. +
  335. #include "common.h"
  336. +static struct mdio_gpio_platform_data rut1xx_mdio = {
  337. + .mdc = 22,
  338. + .mdio = 21,
  339. + .phy_mask = ~(1 << 1),
  340. +};
  341. +
  342. +static struct platform_device rut1xx_phy_device = {
  343. + .name = "mdio-gpio",
  344. + .id = 0,
  345. + .dev = {
  346. + .platform_data = &rut1xx_mdio,
  347. + },
  348. +};
  349. +
  350. +static struct gemini_gmac_platform_data gmac_data = {
  351. + .bus_id[0] = "0:01",
  352. + .interface[0] = PHY_INTERFACE_MODE_MII,
  353. +};
  354. +
  355. static struct gpio_keys_button rut1xx_keys[] = {
  356. {
  357. .code = KEY_SETUP,
  358. @@ -79,9 +101,13 @@ static void __init rut1xx_init(void)
  359. {
  360. gemini_gpio_init();
  361. platform_register_uart();
  362. + platform_register_watchdog();
  363. + platform_register_usb(0);
  364. platform_register_pflash(SZ_8M, NULL, 0);
  365. platform_device_register(&rut1xx_leds);
  366. platform_device_register(&rut1xx_keys_device);
  367. + platform_device_register(&rut1xx_phy_device);
  368. + platform_register_ethernet(&gmac_data);
  369. }
  370. MACHINE_START(RUT100, "Teltonika RUT100")
  371. --- a/arch/arm/mach-gemini/common.h
  372. +++ b/arch/arm/mach-gemini/common.h
  373. @@ -13,6 +13,7 @@
  374. #define __GEMINI_COMMON_H__
  375. struct mtd_partition;
  376. +struct gemini_gmac_platform_data;
  377. extern void gemini_map_io(void);
  378. extern void gemini_init_irq(void);
  379. @@ -21,8 +22,11 @@ extern void gemini_gpio_init(void);
  380. /* Common platform devices registration functions */
  381. extern int platform_register_uart(void);
  382. +extern int platform_register_ethernet(struct gemini_gmac_platform_data *pdata);
  383. extern int platform_register_pflash(unsigned int size,
  384. struct mtd_partition *parts,
  385. unsigned int nr_parts);
  386. +extern int platform_register_usb(unsigned int i);
  387. +extern int platform_register_watchdog(void);
  388. #endif /* __GEMINI_COMMON_H__ */
  389. --- a/arch/arm/mach-gemini/devices.c
  390. +++ b/arch/arm/mach-gemini/devices.c
  391. @@ -17,6 +17,7 @@
  392. #include <mach/irqs.h>
  393. #include <mach/hardware.h>
  394. #include <mach/global_reg.h>
  395. +#include <mach/gmac.h>
  396. static struct plat_serial8250_port serial_platform_data[] = {
  397. {
  398. @@ -45,6 +46,116 @@ int platform_register_uart(void)
  399. return platform_device_register(&serial_device);
  400. }
  401. +static struct resource usb0_resources[] = {
  402. + {
  403. + .start = 0x68000000,
  404. + .end = 0x68000fff,
  405. + .flags = IORESOURCE_MEM,
  406. + },
  407. + {
  408. + .start = IRQ_USB0,
  409. + .end = IRQ_USB0,
  410. + .flags = IORESOURCE_IRQ,
  411. + },
  412. +};
  413. +
  414. +static struct resource usb1_resources[] = {
  415. + {
  416. + .start = 0x69000000,
  417. + .end = 0x69000fff,
  418. + .flags = IORESOURCE_MEM,
  419. + },
  420. + {
  421. + .start = IRQ_USB1,
  422. + .end = IRQ_USB1,
  423. + .flags = IORESOURCE_IRQ,
  424. + },
  425. +};
  426. +
  427. +static u64 usb0_dmamask = 0xffffffffUL;
  428. +
  429. +static u64 usb1_dmamask = 0xffffffffUL;
  430. +
  431. +static struct platform_device usb_device[] = {
  432. + {
  433. + .name = "ehci-fotg2xx",
  434. + .id = 0,
  435. + .dev = {
  436. + .dma_mask = &usb0_dmamask,
  437. + .coherent_dma_mask = 0xffffffff,
  438. + },
  439. + .num_resources = ARRAY_SIZE(usb0_resources),
  440. + .resource = usb0_resources,
  441. + },
  442. + {
  443. + .name = "ehci-fotg2xx",
  444. + .id = 1,
  445. + .dev = {
  446. + .dma_mask = &usb1_dmamask,
  447. + .coherent_dma_mask = 0xffffffff,
  448. + },
  449. + .num_resources = ARRAY_SIZE(usb1_resources),
  450. + .resource = usb1_resources,
  451. + },
  452. +};
  453. +
  454. +int platform_register_usb(unsigned int i)
  455. +{
  456. + if (i > 1)
  457. + return -EINVAL;
  458. +
  459. + return platform_device_register(&usb_device[i]);
  460. +}
  461. +
  462. +static struct resource gmac_resources[] = {
  463. + {
  464. + .start = 0x60000000,
  465. + .end = 0x6000ffff,
  466. + .flags = IORESOURCE_MEM,
  467. + },
  468. + {
  469. + .start = IRQ_GMAC0,
  470. + .end = IRQ_GMAC0,
  471. + .flags = IORESOURCE_IRQ,
  472. + },
  473. + {
  474. + .start = IRQ_GMAC1,
  475. + .end = IRQ_GMAC1,
  476. + .flags = IORESOURCE_IRQ,
  477. + },
  478. +};
  479. +
  480. +static u64 gmac_dmamask = 0xffffffffUL;
  481. +
  482. +static struct platform_device ethernet_device = {
  483. + .name = "gemini-gmac",
  484. + .id = 0,
  485. + .dev = {
  486. + .dma_mask = &gmac_dmamask,
  487. + .coherent_dma_mask = 0xffffffff,
  488. + },
  489. + .num_resources = ARRAY_SIZE(gmac_resources),
  490. + .resource = gmac_resources,
  491. +};
  492. +
  493. +int platform_register_ethernet(struct gemini_gmac_platform_data *pdata)
  494. +{
  495. + unsigned int reg = __raw_readl(IO_ADDRESS(GEMINI_GLOBAL_BASE) + GLOBAL_MISC_CTRL);
  496. +
  497. + reg &= ~(GMAC_GMII | GMAC_1_ENABLE);
  498. +
  499. + if (pdata->bus_id[1])
  500. + reg |= GMAC_1_ENABLE;
  501. + else if (pdata->interface[0] == PHY_INTERFACE_MODE_GMII)
  502. + reg |= GMAC_GMII;
  503. +
  504. + __raw_writel(reg, IO_ADDRESS(GEMINI_GLOBAL_BASE) + GLOBAL_MISC_CTRL);
  505. +
  506. + ethernet_device.dev.platform_data = pdata;
  507. +
  508. + return platform_device_register(&ethernet_device);
  509. +}
  510. +
  511. static struct resource flash_resource = {
  512. .start = GEMINI_FLASH_BASE,
  513. .flags = IORESOURCE_MEM,
  514. @@ -90,3 +201,21 @@ int platform_register_pflash(unsigned in
  515. return platform_device_register(&pflash_device);
  516. }
  517. +
  518. +static struct resource wdt_resource = {
  519. + .start = GEMINI_WAQTCHDOG_BASE,
  520. + .end = GEMINI_WAQTCHDOG_BASE + 0x18,
  521. + .flags = IORESOURCE_MEM,
  522. +};
  523. +
  524. +static struct platform_device wdt_device = {
  525. + .name = "gemini-wdt",
  526. + .id = 0,
  527. + .resource = &wdt_resource,
  528. + .num_resources = 1,
  529. +};
  530. +
  531. +int platform_register_watchdog(void)
  532. +{
  533. + return platform_device_register(&wdt_device);
  534. +}
  535. --- /dev/null
  536. +++ b/arch/arm/mach-gemini/include/mach/gmac.h
  537. @@ -0,0 +1,21 @@
  538. +/*
  539. + * Gemini GMAC specific defines
  540. + *
  541. + * Copyright (C) 2008, Paulius Zaleckas <[email protected]>
  542. + *
  543. + * This program is free software; you can redistribute it and/or modify
  544. + * it under the terms of the GNU General Public License as published by
  545. + * the Free Software Foundation; either version 2 of the License, or
  546. + * (at your option) any later version.
  547. + */
  548. +#ifndef __MACH_GMAC_H__
  549. +#define __MACH_GMAC_H__
  550. +
  551. +#include <linux/phy.h>
  552. +
  553. +struct gemini_gmac_platform_data {
  554. + char *bus_id[2]; /* NULL means that this port is not used */
  555. + phy_interface_t interface[2];
  556. +};
  557. +
  558. +#endif /* __MACH_GMAC_H__ */
  559. --- a/arch/arm/mach-gemini/include/mach/hardware.h
  560. +++ b/arch/arm/mach-gemini/include/mach/hardware.h
  561. @@ -71,4 +71,12 @@
  562. */
  563. #define IO_ADDRESS(x) ((((x) & 0xFFF00000) >> 4) | ((x) & 0x000FFFFF) | 0xF0000000)
  564. +/*
  565. + * PCI subsystem macros
  566. + */
  567. +#define PCIBIOS_MIN_IO 0x00000100
  568. +#define PCIBIOS_MIN_MEM 0x00000000
  569. +
  570. +#define pcibios_assign_all_busses() 1
  571. +
  572. #endif
  573. --- a/arch/arm/mach-gemini/include/mach/irqs.h
  574. +++ b/arch/arm/mach-gemini/include/mach/irqs.h
  575. @@ -43,11 +43,14 @@
  576. #define NORMAL_IRQ_NUM 32
  577. -#define GPIO_IRQ_BASE NORMAL_IRQ_NUM
  578. +#define PCI_IRQ_BASE NORMAL_IRQ_NUM
  579. +#define PCI_IRQ_NUM 4
  580. +
  581. +#define GPIO_IRQ_BASE (NORMAL_IRQ_NUM + PCI_IRQ_NUM)
  582. #define GPIO_IRQ_NUM (3 * 32)
  583. #define ARCH_TIMER_IRQ IRQ_TIMER2
  584. -#define NR_IRQS (NORMAL_IRQ_NUM + GPIO_IRQ_NUM)
  585. +#define NR_IRQS (NORMAL_IRQ_NUM + PCI_IRQ_NUM + GPIO_IRQ_NUM)
  586. #endif /* __MACH_IRQS_H__ */
  587. --- a/arch/arm/mach-gemini/Makefile
  588. +++ b/arch/arm/mach-gemini/Makefile
  589. @@ -6,6 +6,8 @@
  590. obj-y := irq.o mm.o time.o devices.o gpio.o
  591. +obj-$(CONFIG_PCI) += pci.o
  592. +
  593. # Board-specific support
  594. obj-$(CONFIG_MACH_NAS4220B) += board-nas4220b.o
  595. obj-$(CONFIG_MACH_RUT100) += board-rut1xx.o
  596. --- a/arch/arm/mach-gemini/mm.c
  597. +++ b/arch/arm/mach-gemini/mm.c
  598. @@ -59,6 +59,11 @@ static struct map_desc gemini_io_desc[]
  599. .length = SZ_512K,
  600. .type = MT_DEVICE,
  601. }, {
  602. + .virtual = IO_ADDRESS(GEMINI_PCI_IO_BASE),
  603. + .pfn = __phys_to_pfn(GEMINI_PCI_IO_BASE),
  604. + .length = SZ_512K,
  605. + .type = MT_DEVICE,
  606. + }, {
  607. .virtual = IO_ADDRESS(GEMINI_FLASH_CTRL_BASE),
  608. .pfn = __phys_to_pfn(GEMINI_FLASH_CTRL_BASE),
  609. .length = SZ_512K,
  610. --- /dev/null
  611. +++ b/arch/arm/mach-gemini/pci.c
  612. @@ -0,0 +1,315 @@
  613. +/*
  614. + * Support for Gemini PCI Controller
  615. + *
  616. + * Copyright (C) 2009 Janos Laube <[email protected]>
  617. + * Copyright (C) 2009 Paulius Zaleckas <[email protected]>
  618. + *
  619. + * based on SL2312 PCI controller code
  620. + * Storlink (C) 2003
  621. + *
  622. + * This program is free software; you can redistribute it and/or modify
  623. + * it under the terms of the GNU General Public License as published by
  624. + * the Free Software Foundation; either version 2 of the License, or
  625. + * (at your option) any later version.
  626. + */
  627. +
  628. +#include <linux/kernel.h>
  629. +#include <linux/pci.h>
  630. +#include <linux/irq.h>
  631. +
  632. +#include <asm/mach/pci.h>
  633. +#include <asm/gpio.h>
  634. +
  635. +#include <mach/irqs.h>
  636. +
  637. +#define GEMINI_PCI_IOSIZE_1M 0x0000
  638. +
  639. +#define GEMINI_PCI_PMC 0x40
  640. +#define GEMINI_PCI_PMCSR 0x44
  641. +#define GEMINI_PCI_CTRL1 0x48
  642. +#define GEMINI_PCI_CTRL2 0x4C
  643. +#define GEMINI_PCI_MEM1_BASE_SIZE 0x50
  644. +#define GEMINI_PCI_MEM2_BASE_SIZE 0x54
  645. +#define GEMINI_PCI_MEM3_BASE_SIZE 0x58
  646. +
  647. +#define PCI_CTRL2_INTSTS_OFFSET 28
  648. +#define PCI_CTRL2_INTMASK_OFFSET 22
  649. +
  650. +#define GEMINI_PCI_DMA_MASK 0xFFF00000
  651. +#define GEMINI_PCI_DMA_MEM1_BASE 0x00000000
  652. +#define GEMINI_PCI_DMA_MEM2_BASE 0x00000000
  653. +#define GEMINI_PCI_DMA_MEM3_BASE 0x00000000
  654. +#define GEMINI_PCI_DMA_MEM1_SIZE 7
  655. +#define GEMINI_PCI_DMA_MEM2_SIZE 6
  656. +#define GEMINI_PCI_DMA_MEM3_SIZE 6
  657. +
  658. +#define PCI_CONF_ENABLE (1 << 31)
  659. +#define PCI_CONF_WHERE(r) ((r) & 0xFC)
  660. +#define PCI_CONF_BUS(b) (((b) & 0xFF) << 16)
  661. +#define PCI_CONF_DEVICE(d) (((d) & 0x1F) << 11)
  662. +#define PCI_CONF_FUNCTION(f) (((f) & 0x07) << 8)
  663. +
  664. +#define PCI_IOSIZE_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE))
  665. +#define PCI_PROT_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE) + 0x04)
  666. +#define PCI_CTRL_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE) + 0x08)
  667. +#define PCI_SOFTRST_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE) + 0x10)
  668. +#define PCI_CONFIG_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE) + 0x28)
  669. +#define PCI_DATA_REG (IO_ADDRESS(GEMINI_PCI_IO_BASE) + 0x2C)
  670. +
  671. +
  672. +static DEFINE_SPINLOCK(gemini_pci_lock);
  673. +
  674. +static struct resource gemini_pci_resource_io = {
  675. + .name = "PCI I/O Space",
  676. + .start = IO_ADDRESS(GEMINI_PCI_IO_BASE),
  677. + .end = IO_ADDRESS(GEMINI_PCI_IO_BASE) + SZ_1M - 1,
  678. + .flags = IORESOURCE_IO,
  679. +};
  680. +
  681. +static struct resource gemini_pci_resource_mem = {
  682. + .name = "PCI Memory Space",
  683. + .start = GEMINI_PCI_MEM_BASE,
  684. + .end = GEMINI_PCI_MEM_BASE + SZ_128M - 1,
  685. + .flags = IORESOURCE_MEM,
  686. +};
  687. +
  688. +static int gemini_pci_read_config(struct pci_bus* bus, unsigned int fn,
  689. + int config, int size, u32* value)
  690. +{
  691. + unsigned long irq_flags;
  692. +
  693. + spin_lock_irqsave(&gemini_pci_lock, irq_flags);
  694. +
  695. + __raw_writel(PCI_CONF_BUS(bus->number) |
  696. + PCI_CONF_DEVICE(PCI_SLOT(fn)) |
  697. + PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
  698. + PCI_CONF_WHERE(config) |
  699. + PCI_CONF_ENABLE,
  700. + PCI_CONFIG_REG);
  701. +
  702. + *value = __raw_readl(PCI_DATA_REG);
  703. +
  704. + if (size == 1)
  705. + *value = (*value >> (8 * (config & 3))) & 0xFF;
  706. + else if (size == 2)
  707. + *value = (*value >> (8 * (config & 3))) & 0xFFFF;
  708. +
  709. + spin_unlock_irqrestore(&gemini_pci_lock, irq_flags);
  710. +
  711. + dev_dbg(&bus->dev,
  712. + "[read] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n",
  713. + PCI_SLOT(fn), PCI_FUNC(fn), config, size, *value);
  714. +
  715. + return PCIBIOS_SUCCESSFUL;
  716. +}
  717. +
  718. +static int gemini_pci_write_config(struct pci_bus* bus, unsigned int fn,
  719. + int config, int size, u32 value)
  720. +{
  721. + unsigned long irq_flags = 0;
  722. + int ret = PCIBIOS_SUCCESSFUL;
  723. +
  724. + dev_dbg(&bus->dev,
  725. + "[write] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n",
  726. + PCI_SLOT(fn), PCI_FUNC(fn), config, size, value);
  727. +
  728. + spin_lock_irqsave(&gemini_pci_lock, irq_flags);
  729. +
  730. + __raw_writel(PCI_CONF_BUS(bus->number) |
  731. + PCI_CONF_DEVICE(PCI_SLOT(fn)) |
  732. + PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
  733. + PCI_CONF_WHERE(config) |
  734. + PCI_CONF_ENABLE,
  735. + PCI_CONFIG_REG);
  736. +
  737. + switch(size) {
  738. + case 4:
  739. + __raw_writel(value, PCI_DATA_REG);
  740. + break;
  741. + case 2:
  742. + __raw_writew(value, PCI_DATA_REG + (config & 3));
  743. + break;
  744. + case 1:
  745. + __raw_writeb(value, PCI_DATA_REG + (config & 3));
  746. + break;
  747. + default:
  748. + ret = PCIBIOS_BAD_REGISTER_NUMBER;
  749. + }
  750. +
  751. + spin_unlock_irqrestore(&gemini_pci_lock, irq_flags);
  752. +
  753. + return ret;
  754. +}
  755. +
  756. +static struct pci_ops gemini_pci_ops = {
  757. + .read = gemini_pci_read_config,
  758. + .write = gemini_pci_write_config,
  759. +};
  760. +
  761. +static int __init gemini_pci_request_resources(struct pci_sys_data *sys)
  762. +{
  763. + if (request_resource(&ioport_resource, &gemini_pci_resource_io))
  764. + goto bad_resources;
  765. + if (request_resource(&iomem_resource, &gemini_pci_resource_mem))
  766. + goto bad_resources;
  767. +
  768. + sys->resource[0] = &gemini_pci_resource_io;
  769. + sys->resource[1] = &gemini_pci_resource_mem;
  770. + sys->resource[2] = 0;
  771. +
  772. + return 0;
  773. +
  774. +bad_resources:
  775. + pr_err("Gemini PCI: request_resource() failed. "
  776. + "Abort PCI bus enumeration.\n");
  777. + return -1;
  778. +}
  779. +
  780. +static int __init gemini_pci_setup(int nr, struct pci_sys_data *sys)
  781. +{
  782. + unsigned int cmd;
  783. +
  784. + if ((nr > 0) || gemini_pci_request_resources(sys))
  785. + return 0;
  786. +
  787. + /* setup I/O space to 1MB size */
  788. + __raw_writel(GEMINI_PCI_IOSIZE_1M, PCI_IOSIZE_REG);
  789. +
  790. + /* setup hostbridge */
  791. + cmd = __raw_readl(PCI_CTRL_REG);
  792. + cmd |= PCI_COMMAND_IO;
  793. + cmd |= PCI_COMMAND_MEMORY;
  794. + cmd |= PCI_COMMAND_MASTER;
  795. + __raw_writel(cmd, PCI_CTRL_REG);
  796. +
  797. + return 1;
  798. +}
  799. +
  800. +static struct pci_bus* __init gemini_pci_scan_bus(int nr, struct pci_sys_data* sys)
  801. +{
  802. + unsigned int reg = 0;
  803. + struct pci_bus* bus = 0;
  804. +
  805. + bus = pci_scan_bus(nr, &gemini_pci_ops, sys);
  806. + if (bus) {
  807. + dev_dbg(&bus->dev, "setting up PCI DMA\n");
  808. + reg = (GEMINI_PCI_DMA_MEM1_BASE & GEMINI_PCI_DMA_MASK)
  809. + | (GEMINI_PCI_DMA_MEM1_SIZE << 16);
  810. + gemini_pci_write_config(bus, 0, GEMINI_PCI_MEM1_BASE_SIZE, 4, reg);
  811. + reg = (GEMINI_PCI_DMA_MEM2_BASE & GEMINI_PCI_DMA_MASK)
  812. + | (GEMINI_PCI_DMA_MEM2_SIZE << 16);
  813. + gemini_pci_write_config(bus, 0, GEMINI_PCI_MEM2_BASE_SIZE, 4, reg);
  814. + reg = (GEMINI_PCI_DMA_MEM3_BASE & GEMINI_PCI_DMA_MASK)
  815. + | (GEMINI_PCI_DMA_MEM3_SIZE << 16);
  816. + gemini_pci_write_config(bus, 0, GEMINI_PCI_MEM3_BASE_SIZE, 4, reg);
  817. + }
  818. +
  819. + return bus;
  820. +}
  821. +
  822. +/* Should work with all boards based on original Storlink EVB */
  823. +static int __init gemini_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  824. +{
  825. + if (slot < 9 || slot > 12)
  826. + return -1;
  827. +
  828. + return PCI_IRQ_BASE + (((slot - 9) + (pin - 1)) & 0x3);
  829. +}
  830. +
  831. +static struct hw_pci gemini_hw_pci __initdata = {
  832. + .nr_controllers = 1,
  833. + .setup = gemini_pci_setup,
  834. + .scan = gemini_pci_scan_bus,
  835. + .swizzle = pci_std_swizzle,
  836. + .map_irq = gemini_pci_map_irq,
  837. +};
  838. +
  839. +/* we need this for muxed PCI interrupts handling */
  840. +static struct pci_bus bogus_pci_bus;
  841. +
  842. +static void gemini_pci_ack_irq(unsigned int irq)
  843. +{
  844. + unsigned int reg;
  845. +
  846. + gemini_pci_read_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, &reg);
  847. + reg &= ~(0xF << PCI_CTRL2_INTSTS_OFFSET);
  848. + reg |= 1 << (irq - PCI_IRQ_BASE + PCI_CTRL2_INTSTS_OFFSET);
  849. + gemini_pci_write_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, reg);
  850. +}
  851. +
  852. +static void gemini_pci_mask_irq(unsigned int irq)
  853. +{
  854. + unsigned int reg;
  855. +
  856. + gemini_pci_read_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, &reg);
  857. + reg &= ~((0xF << PCI_CTRL2_INTSTS_OFFSET)
  858. + | (1 << (irq - PCI_IRQ_BASE + PCI_CTRL2_INTMASK_OFFSET)));
  859. + gemini_pci_write_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, reg);
  860. +}
  861. +
  862. +static void gemini_pci_unmask_irq(unsigned int irq)
  863. +{
  864. + unsigned int reg;
  865. +
  866. + gemini_pci_read_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, &reg);
  867. + reg &= ~(0xF << PCI_CTRL2_INTSTS_OFFSET);
  868. + reg |= 1 << (irq - PCI_IRQ_BASE + PCI_CTRL2_INTMASK_OFFSET);
  869. + gemini_pci_write_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, reg);
  870. +}
  871. +
  872. +static void gemini_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
  873. +{
  874. + unsigned int pci_irq_no, irq_stat, reg, i;
  875. +
  876. + gemini_pci_read_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2, 4, &reg);
  877. + irq_stat = reg >> PCI_CTRL2_INTSTS_OFFSET;
  878. +
  879. + for (i = 0; i < 4; i++) {
  880. +
  881. + if ((irq_stat & (1 << i)) == 0)
  882. + continue;
  883. +
  884. + pci_irq_no = PCI_IRQ_BASE + i;
  885. +
  886. + BUG_ON(!(irq_desc[pci_irq_no].handle_irq));
  887. + irq_desc[pci_irq_no].handle_irq(pci_irq_no,
  888. + &irq_desc[pci_irq_no]);
  889. + }
  890. +}
  891. +
  892. +static struct irq_chip gemini_pci_irq_chip = {
  893. + .name = "PCI",
  894. + .ack = gemini_pci_ack_irq,
  895. + .mask = gemini_pci_mask_irq,
  896. + .unmask = gemini_pci_unmask_irq,
  897. +};
  898. +
  899. +static int __init gemini_pci_init(void)
  900. +{
  901. + int i;
  902. +
  903. + for (i = 72; i <= 95; i++)
  904. + gpio_request(i, "PCI");
  905. +
  906. + /* initialize our bogus bus */
  907. + dev_set_name(&bogus_pci_bus.dev, "PCI IRQ handler");
  908. + bogus_pci_bus.number = 0;
  909. +
  910. + /* mask and clear all interrupts */
  911. + gemini_pci_write_config(&bogus_pci_bus, 0, GEMINI_PCI_CTRL2 + 2, 2,
  912. + 0xF000);
  913. +
  914. + for (i = PCI_IRQ_BASE; i < PCI_IRQ_BASE + 4; i++) {
  915. + set_irq_chip(i, &gemini_pci_irq_chip);
  916. + set_irq_handler(i, handle_level_irq);
  917. + set_irq_flags(i, IRQF_VALID);
  918. + }
  919. +
  920. + set_irq_chained_handler(IRQ_PCI, gemini_pci_irq_handler);
  921. +
  922. + pci_common_init(&gemini_hw_pci);
  923. +
  924. + return 0;
  925. +}
  926. +
  927. +subsys_initcall(gemini_pci_init);
  928. --- a/arch/arm/mm/abort-ev4.S
  929. +++ b/arch/arm/mm/abort-ev4.S
  930. @@ -1,5 +1,6 @@
  931. #include <linux/linkage.h>
  932. #include <asm/assembler.h>
  933. +#include <asm/cache.h>
  934. /*
  935. * Function: v4_early_abort
  936. *
  937. @@ -17,7 +18,7 @@
  938. * abort here if the I-TLB and D-TLB aren't seeing the same
  939. * picture. Unfortunately, this does happen. We live with it.
  940. */
  941. - .align 5
  942. + .align L1_CACHE_SHIFT
  943. ENTRY(v4_early_abort)
  944. mrc p15, 0, r1, c5, c0, 0 @ get FSR
  945. mrc p15, 0, r0, c6, c0, 0 @ get FAR
  946. --- a/arch/arm/mm/abort-nommu.S
  947. +++ b/arch/arm/mm/abort-nommu.S
  948. @@ -1,5 +1,6 @@
  949. #include <linux/linkage.h>
  950. #include <asm/assembler.h>
  951. +#include <asm/cache.h>
  952. /*
  953. * Function: nommu_early_abort
  954. *
  955. @@ -12,7 +13,7 @@
  956. * Note: There is no FSR/FAR on !CPU_CP15_MMU cores.
  957. * Just fill zero into the registers.
  958. */
  959. - .align 5
  960. + .align L1_CACHE_SHIFT
  961. ENTRY(nommu_early_abort)
  962. mov r0, #0 @ clear r0, r1 (no FSR/FAR)
  963. mov r1, #0
  964. --- /dev/null
  965. +++ b/drivers/net/gemini_negmac/gm_gmac.c
  966. @@ -0,0 +1,1350 @@
  967. +/*
  968. + * Ethernet device driver for Gemini SoC.
  969. + *
  970. + * Copyright (C) 2006, Storlink, Corp.
  971. + * Copyright (C) 2008-2009, Paulius Zaleckas <[email protected]>
  972. + *
  973. + * This program is free software; you can redistribute it and/or modify
  974. + * it under the terms of the GNU General Public License as published by
  975. + * the Free Software Foundation; either version 2 of the License, or
  976. + * (at your option) any later version.
  977. + */
  978. +#include <linux/module.h>
  979. +#include <linux/kernel.h>
  980. +#include <linux/platform_device.h>
  981. +#include <linux/slab.h>
  982. +#include <linux/mm.h>
  983. +#include <linux/compiler.h>
  984. +#include <linux/dma-mapping.h>
  985. +#include <linux/init.h>
  986. +#include <linux/ioport.h>
  987. +#include <linux/netdevice.h>
  988. +#include <linux/etherdevice.h>
  989. +#include <linux/rtnetlink.h>
  990. +#include <linux/delay.h>
  991. +#include <linux/ethtool.h>
  992. +#include <linux/mii.h>
  993. +#include <linux/phy.h>
  994. +#include <linux/completion.h>
  995. +#include <linux/kthread.h>
  996. +#include <linux/io.h>
  997. +#include <mach/hardware.h>
  998. +#include <asm/irq.h>
  999. +#include <linux/semaphore.h>
  1000. +#include <mach/irqs.h>
  1001. +#include <linux/skbuff.h>
  1002. +#include <linux/in.h>
  1003. +#include <linux/ip.h>
  1004. +#include <linux/tcp.h>
  1005. +#include <linux/udp.h>
  1006. +#include <mach/gmac.h>
  1007. +
  1008. +#include "gm_gmac.h"
  1009. +
  1010. +/* #define GMAX_TX_INTR_DISABLED */
  1011. +#define DO_HW_CHKSUM
  1012. +/* #define ENABLE_TSO */
  1013. +#define GMAC_USE_TXQ0
  1014. +/* #define GMAC_LEN_1_2_ISSUE */
  1015. +
  1016. +#define DEFAULT_RXQ_MAX_CNT 256
  1017. +
  1018. +/* define chip information */
  1019. +#define DRV_VERSION "0.2"
  1020. +#define SL351x_DRIVER_NAME "Gemini Ethernet driver " DRV_VERSION
  1021. +
  1022. +#ifdef GMAC_LEN_1_2_ISSUE
  1023. + #define _DEBUG_PREFETCH_NUM 256
  1024. +static int _debug_prefetch_cnt;
  1025. +static char _debug_prefetch_buf[_DEBUG_PREFETCH_NUM][4] __attribute__((aligned(4)));
  1026. +#endif
  1027. +
  1028. +static inline void gmac_write_reg(unsigned int base, unsigned int offset, unsigned int data, unsigned int bit_mask)
  1029. +{
  1030. + unsigned int reg_val;
  1031. +
  1032. + reg_val = (__raw_readl(base + offset) & (~bit_mask)) | (data & bit_mask);
  1033. + __raw_writel(reg_val, base + offset);
  1034. +}
  1035. +
  1036. +/*----------------------------------------------------------------------
  1037. +* toe_init_free_queue
  1038. +* (1) Initialize the Free Queue Descriptor Base Address & size
  1039. +* Register: TOE_GLOBAL_BASE + 0x0004
  1040. +* (2) Initialize DMA Read/Write pointer for
  1041. +* SW Free Queue and HW Free Queue
  1042. +* (3) Initialize DMA Descriptors for
  1043. +* SW Free Queue and HW Free Queue,
  1044. +*----------------------------------------------------------------------*/
  1045. +static void toe_init_free_queue(struct toe_private *toe)
  1046. +{
  1047. + int i;
  1048. + DMA_RWPTR_T rwptr_reg;
  1049. + void *desc_buf;
  1050. + GMAC_RXDESC_T *sw_desc_ptr;
  1051. + struct sk_buff *skb;
  1052. +
  1053. + desc_buf = dma_alloc_coherent(toe->dev, TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T),
  1054. + &toe->sw_freeq_desc_base_dma, GFP_KERNEL);
  1055. + sw_desc_ptr = (GMAC_RXDESC_T *)desc_buf;
  1056. + if (!desc_buf) {
  1057. + dev_err(toe->dev, "%s::DMA ALLOC fail\n", __func__);
  1058. + return;
  1059. + }
  1060. + memset(desc_buf, 0, TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T));
  1061. +
  1062. + /* DMA Queue Base & Size */
  1063. + __raw_writel((toe->sw_freeq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_SW_FREEQ_DESC_POWER,
  1064. + toe->global_base + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
  1065. +
  1066. + /* init descriptor base */
  1067. + toe->swfq_desc_base = (unsigned int)desc_buf;
  1068. +
  1069. + /* SW Free Queue Descriptors */
  1070. + for (i = 0; i < TOE_SW_FREEQ_DESC_NUM; i++) {
  1071. + sw_desc_ptr->word0.bits.buffer_size = SW_RX_BUF_SIZE;
  1072. + skb = dev_alloc_skb(SW_RX_BUF_SIZE); /* allocate socket buffer */
  1073. + if (!skb) {
  1074. + dev_err(toe->dev, "%s::skb buffer allocation fail\n", __func__);
  1075. + return;
  1076. + }
  1077. + REG32(skb->data) = (unsigned int)skb;
  1078. + skb_reserve(skb, SKB_RESERVE_BYTES);
  1079. + sw_desc_ptr->word2.buf_adr = dma_map_single(toe->dev, skb->data,
  1080. + SW_RX_BUF_SIZE - SKB_RESERVE_BYTES,
  1081. + DMA_FROM_DEVICE);
  1082. + sw_desc_ptr++;
  1083. + }
  1084. +
  1085. + dma_sync_single_for_device(toe->dev, toe->sw_freeq_desc_base_dma,
  1086. + TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T),
  1087. + DMA_TO_DEVICE);
  1088. +
  1089. + /* SW Free Queue Read/Write Pointer */
  1090. + rwptr_reg.bits.wptr = TOE_SW_FREEQ_DESC_NUM - 1;
  1091. + rwptr_reg.bits.rptr = 0;
  1092. + __raw_writel(rwptr_reg.bits32, toe->global_base + GLOBAL_SWFQ_RWPTR_REG);
  1093. +
  1094. + /* DMA Queue Base & Size */
  1095. + __raw_writel(TOE_HW_FREEQ_DESC_POWER,
  1096. + toe->global_base + GLOBAL_HW_FREEQ_BASE_SIZE_REG);
  1097. + rwptr_reg.bits.wptr = TOE_HW_FREEQ_DESC_NUM - 1;
  1098. + rwptr_reg.bits.rptr = 0;
  1099. + __raw_writel(rwptr_reg.bits32, toe->global_base + GLOBAL_HWFQ_RWPTR_REG);
  1100. +}
  1101. +
  1102. +/*----------------------------------------------------------------------
  1103. +* toe_init_swtx_queue
  1104. +* (2) Initialize the GMAC 0/1 SW TXQ Queue Descriptor Base Address & sizeup
  1105. +* GMAC_SW_TX_QUEUE_BASE_REG(0x0050)
  1106. +* (2) Initialize DMA Read/Write pointer for
  1107. +* GMAC 0/1 SW TX Q0-5
  1108. +*----------------------------------------------------------------------*/
  1109. +static void toe_init_swtx_queue(struct net_device *dev)
  1110. +{
  1111. + int i;
  1112. + struct gmac_private *gmac = netdev_priv(dev);
  1113. + struct toe_private *toe = dev->ml_priv;
  1114. + DMA_RWPTR_T rwptr_reg;
  1115. + unsigned int rwptr_addr;
  1116. + void *desc_buf;
  1117. + unsigned int offset;
  1118. +
  1119. + desc_buf = dma_alloc_coherent(toe->dev, TOE_GMAC_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T),
  1120. + &gmac->swtxq_desc_base_dma, GFP_KERNEL);
  1121. + gmac->swtxq_desc_base = (unsigned int)desc_buf;
  1122. + if (!desc_buf) {
  1123. + dev_err(toe->dev, "%s::DMA ALLOC fail\n", __func__);
  1124. + return;
  1125. + }
  1126. + memset(desc_buf, 0, TOE_GMAC_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T));
  1127. + dma_sync_single_for_device(toe->dev, gmac->swtxq_desc_base_dma,
  1128. + TOE_GMAC_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T),
  1129. + DMA_TO_DEVICE);
  1130. + __raw_writel((gmac->swtxq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_GMAC_SWTXQ_DESC_POWER,
  1131. + gmac->dma_base_addr + GMAC_SW_TX_QUEUE_BASE_REG);
  1132. +
  1133. + /* GMAC0 SW TX Q0-Q5 */
  1134. + offset = 0;
  1135. + rwptr_reg.bits.wptr = 0;
  1136. + rwptr_reg.bits.rptr = 0;
  1137. + rwptr_addr = gmac->dma_base_addr + GMAC_SW_TX_QUEUE0_PTR_REG;
  1138. + for (i = 0; i < TOE_SW_TXQ_NUM; i++) {
  1139. + gmac->swtxq[i].rwptr_reg = rwptr_addr;
  1140. + gmac->swtxq[i].desc_base_dma = (unsigned int)gmac->swtxq_desc_base_dma + offset;
  1141. + gmac->swtxq[i].desc_base = (unsigned int)desc_buf + offset;
  1142. + offset += TOE_GMAC_SWTXQ_DESC_NUM * sizeof(GMAC_TXDESC_T);
  1143. + __raw_writel(rwptr_reg.bits32, rwptr_addr);
  1144. + rwptr_addr += 4;
  1145. + }
  1146. +}
  1147. +
  1148. +/*----------------------------------------------------------------------
  1149. +* toe_init_default_queue
  1150. +* (1) Initialize the default 0/1 Queue Header
  1151. +* Register: TOE_DEFAULT_Q0_HDR_BASE (0x60002000)
  1152. +* TOE_DEFAULT_Q1_HDR_BASE (0x60002008)
  1153. +* (2) Initialize Descriptors of Default Queue 0/1
  1154. +*----------------------------------------------------------------------*/
  1155. +static void toe_init_default_queue(struct net_device *dev)
  1156. +{
  1157. + struct gmac_private *gmac = netdev_priv(dev);
  1158. + struct toe_private *toe = dev->ml_priv;
  1159. + volatile NONTOE_QHDR_T *qhdr;
  1160. + GMAC_RXDESC_T *desc_ptr;
  1161. +
  1162. + desc_ptr = dma_alloc_coherent(toe->dev, TOE_DEFAULT_Q_DESC_NUM * sizeof(GMAC_RXDESC_T),
  1163. + &gmac->default_desc_base_dma, GFP_KERNEL);
  1164. + if (!desc_ptr) {
  1165. + dev_err(toe->dev, "%s::DMA ALLOC fail\n", __func__);
  1166. + return;
  1167. + }
  1168. + memset(desc_ptr, 0, TOE_DEFAULT_Q_DESC_NUM * sizeof(GMAC_RXDESC_T));
  1169. + dma_sync_single_for_device(toe->dev, gmac->default_desc_base_dma,
  1170. + TOE_DEFAULT_Q_DESC_NUM * sizeof(GMAC_RXDESC_T),
  1171. + DMA_TO_DEVICE);
  1172. + gmac->default_desc_base = (unsigned int)desc_ptr;
  1173. + qhdr = (volatile NONTOE_QHDR_T *)(toe->global_base + TOE_DEFAULT_Q_HDR_BASE(gmac->port_id));
  1174. + qhdr->word0.base_size = ((unsigned int)gmac->default_desc_base_dma & NONTOE_QHDR0_BASE_MASK) | TOE_DEFAULT_Q_DESC_POWER;
  1175. + qhdr->word1.bits32 = 0;
  1176. + gmac->default_qhdr = (NONTOE_QHDR_T *)qhdr;
  1177. +}
  1178. +
  1179. +/*----------------------------------------------------------------------
  1180. +* toe_init_interrupt_config
  1181. +* Interrupt Select Registers are used to map interrupt to int0 or int1
  1182. +* Int0 and int1 are wired to CPU 0/1 GMAC 0/1
  1183. +* Interrupt Device Inteface data are used to pass device info to
  1184. +* upper device driver or store status/statistics
  1185. +* ISR handler
  1186. +* (1) If status bit ON but masked, the prinf error message (bug issue)
  1187. +* (2) If select bits are for me, handle it, else skip to let
  1188. +* the other ISR handles it.
  1189. +* Notes:
  1190. +* GMACx init routine (for eCOS) or open routine (for Linux)
  1191. +* enable the interrupt bits only which are selected for it.
  1192. +*
  1193. +* Default Setting:
  1194. +* GMAC0 intr bits ------> int0 ----> eth0
  1195. +* GMAC1 intr bits ------> int1 ----> eth1
  1196. +* TOE intr -------------> int0 ----> eth0
  1197. +* Classification Intr --> int0 ----> eth0
  1198. +* Default Q0 -----------> int0 ----> eth0
  1199. +* Default Q1 -----------> int1 ----> eth1
  1200. +*----------------------------------------------------------------------*/
  1201. +static void toe_init_interrupt_config(struct toe_private *toe)
  1202. +{
  1203. + /* clear all status bits */
  1204. + __raw_writel(0xffffffff, toe->global_base + GLOBAL_INTERRUPT_STATUS_0_REG);
  1205. + __raw_writel(0xffffffff, toe->global_base + GLOBAL_INTERRUPT_STATUS_1_REG);
  1206. + __raw_writel(0xffffffff, toe->global_base + GLOBAL_INTERRUPT_STATUS_2_REG);
  1207. + __raw_writel(0xffffffff, toe->global_base + GLOBAL_INTERRUPT_STATUS_3_REG);
  1208. + __raw_writel(0xffffffff, toe->global_base + GLOBAL_INTERRUPT_STATUS_4_REG);
  1209. +
  1210. + /* Init select registers */
  1211. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_SELECT_0_REG);
  1212. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_SELECT_1_REG);
  1213. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_SELECT_2_REG);
  1214. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_SELECT_3_REG);
  1215. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_SELECT_4_REG);
  1216. +
  1217. + /* disable all interrupt */
  1218. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1219. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1220. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_ENABLE_2_REG);
  1221. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_ENABLE_3_REG);
  1222. + __raw_writel(0, toe->global_base + GLOBAL_INTERRUPT_ENABLE_4_REG);
  1223. +}
  1224. +
  1225. +static void toe_gmac_hw_start(struct gmac_private *gmac)
  1226. +{
  1227. + GMAC_DMA_CTRL_T dma_ctrl;
  1228. +
  1229. + /* program dma control register */
  1230. + dma_ctrl.bits32 = __raw_readl(gmac->dma_base_addr + GMAC_DMA_CTRL_REG);
  1231. + dma_ctrl.bits.rd_enable = 1;
  1232. + dma_ctrl.bits.td_enable = 1;
  1233. + dma_ctrl.bits.loopback = 0;
  1234. + dma_ctrl.bits.drop_small_ack = 0;
  1235. + dma_ctrl.bits.rd_prot = 0;
  1236. + dma_ctrl.bits.rd_burst_size = 3;
  1237. + dma_ctrl.bits.rd_insert_bytes = RX_INSERT_BYTES;
  1238. + dma_ctrl.bits.rd_bus = 3;
  1239. + dma_ctrl.bits.td_prot = 0;
  1240. + dma_ctrl.bits.td_burst_size = 3;
  1241. + dma_ctrl.bits.td_bus = 3;
  1242. +
  1243. + __raw_writel(dma_ctrl.bits32, gmac->dma_base_addr + GMAC_DMA_CTRL_REG);
  1244. +}
  1245. +
  1246. +static void toe_gmac_hw_stop(struct gmac_private *gmac)
  1247. +{
  1248. + GMAC_DMA_CTRL_T dma_ctrl;
  1249. +
  1250. + /* program dma control register */
  1251. + dma_ctrl.bits32 = __raw_readl(gmac->dma_base_addr + GMAC_DMA_CTRL_REG);
  1252. + dma_ctrl.bits.rd_enable = 0;
  1253. + dma_ctrl.bits.td_enable = 0;
  1254. + __raw_writel(dma_ctrl.bits32, gmac->dma_base_addr + GMAC_DMA_CTRL_REG);
  1255. +}
  1256. +
  1257. +static void toe_gmac_init_chip(struct net_device *dev)
  1258. +{
  1259. + struct gmac_private *gmac = netdev_priv(dev);
  1260. + GMAC_CONFIG2_T config2_val;
  1261. + GMAC_CONFIG0_T config0;
  1262. + GMAC_CONFIG1_T config1;
  1263. + GMAC_STATUS_T status;
  1264. + GMAC_TX_WCR0_T hw_weigh;
  1265. + GMAC_TX_WCR1_T sw_weigh;
  1266. + GMAC_RX_FLTR_T rx_filter;
  1267. +
  1268. + /* set RX_FLTR register to receive all multicast packet */
  1269. + rx_filter.bits32 = __raw_readl(dev->base_addr + GMAC_RX_FLTR);
  1270. + rx_filter.bits.unicast = 1;
  1271. + rx_filter.bits.multicast = 1;
  1272. + rx_filter.bits.broadcast = 1;
  1273. + __raw_writel(rx_filter.bits32, dev->base_addr + GMAC_RX_FLTR);
  1274. +
  1275. + /* set flow control threshold */
  1276. + config1.bits32 = 0;
  1277. + config1.bits.set_threshold = 32 / 2;
  1278. + config1.bits.rel_threshold = 32 / 4 * 3;
  1279. + __raw_writel(config1.bits32, dev->base_addr + GMAC_CONFIG1);
  1280. +
  1281. + /* set flow control threshold */
  1282. + config2_val.bits32 = 0;
  1283. + config2_val.bits.set_threshold = TOE_SW_FREEQ_DESC_NUM / 4;
  1284. + config2_val.bits.rel_threshold = TOE_SW_FREEQ_DESC_NUM / 2;
  1285. + __raw_writel(config2_val.bits32, dev->base_addr + GMAC_CONFIG2);
  1286. +
  1287. + /* disable TX/RX and disable internal loop back */
  1288. + config0.bits32 = __raw_readl(dev->base_addr + GMAC_CONFIG0);
  1289. +
  1290. + config0.bits.max_len = 2;
  1291. +
  1292. + gmac->flow_control_enable = 0;
  1293. +
  1294. + config0.bits.tx_fc_en = 0; /* disable tx flow control */
  1295. + config0.bits.rx_fc_en = 0; /* disable rx flow control */
  1296. + config0.bits.dis_rx = 1; /* disable rx */
  1297. + config0.bits.dis_tx = 1; /* disable tx */
  1298. + config0.bits.loop_back = 0; /* enable/disable GMAC loopback */
  1299. + config0.bits.rx_err_detect = 1;
  1300. + config0.bits.rgmii_en = 0;
  1301. + config0.bits.rgmm_edge = 1;
  1302. + config0.bits.rxc_inv = 0;
  1303. + config0.bits.ipv4_rx_chksum = 1; /* enable H/W to check ip checksum */
  1304. + config0.bits.ipv6_rx_chksum = 1; /* enable H/W to check ip checksum */
  1305. + config0.bits.port0_chk_hwq = 1;
  1306. + config0.bits.port1_chk_hwq = 1;
  1307. + config0.bits.port0_chk_toeq = 1;
  1308. + config0.bits.port1_chk_toeq = 1;
  1309. + config0.bits.port0_chk_classq = 1;
  1310. + config0.bits.port1_chk_classq = 1;
  1311. +
  1312. + __raw_writel(config0.bits32, dev->base_addr + GMAC_CONFIG0);
  1313. +
  1314. + hw_weigh.bits32 = 0;
  1315. + hw_weigh.bits.hw_tq3 = 1;
  1316. + hw_weigh.bits.hw_tq2 = 1;
  1317. + hw_weigh.bits.hw_tq1 = 1;
  1318. + hw_weigh.bits.hw_tq0 = 1;
  1319. + __raw_writel(hw_weigh.bits32, gmac->dma_base_addr + GMAC_TX_WEIGHTING_CTRL_0_REG);
  1320. +
  1321. + sw_weigh.bits32 = 0;
  1322. + sw_weigh.bits.sw_tq5 = 1;
  1323. + sw_weigh.bits.sw_tq4 = 1;
  1324. + sw_weigh.bits.sw_tq3 = 1;
  1325. + sw_weigh.bits.sw_tq2 = 1;
  1326. + sw_weigh.bits.sw_tq1 = 1;
  1327. + sw_weigh.bits.sw_tq0 = 1;
  1328. + __raw_writel(sw_weigh.bits32, gmac->dma_base_addr + GMAC_TX_WEIGHTING_CTRL_1_REG);
  1329. +
  1330. + /* set interface type */
  1331. + status.bits32 = __raw_readl(dev->base_addr + GMAC_STATUS);
  1332. +
  1333. + switch (gmac->phydev->interface) {
  1334. + case PHY_INTERFACE_MODE_MII:
  1335. + status.bits.mii_rmii = GMAC_PHY_MII;
  1336. + break;
  1337. + case PHY_INTERFACE_MODE_GMII:
  1338. + status.bits.mii_rmii = GMAC_PHY_GMII;
  1339. + break;
  1340. + case PHY_INTERFACE_MODE_RGMII:
  1341. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  1342. + break;
  1343. + default:
  1344. + dev_err(&dev->dev, "Unsupported MII interface\n");
  1345. + return;
  1346. + }
  1347. +
  1348. + __raw_writel(status.bits32, dev->base_addr + GMAC_STATUS);
  1349. +}
  1350. +
  1351. +static void toe_init_gmac(struct net_device *dev)
  1352. +{
  1353. + struct gmac_private *gmac = netdev_priv(dev);
  1354. + struct toe_private *toe = dev->ml_priv;
  1355. + u32 data;
  1356. +
  1357. + /* GMAC initialization */
  1358. + toe_gmac_init_chip(dev);
  1359. +
  1360. + /* -----------------------------------------------------------
  1361. + Enable GMAC interrupt & disable loopback
  1362. + Notes:
  1363. + GMACx init routine (for eCOS) or open routine (for Linux)
  1364. + enable the interrupt bits only which are selected for him.
  1365. + --------------------------------------------------------------*/
  1366. +
  1367. + /* Enable Interrupt Bits */
  1368. + if (gmac->port_id == 0) {
  1369. + gmac->intr0_selected = GMAC0_TXDERR_INT_BIT | GMAC0_TXPERR_INT_BIT |
  1370. + GMAC0_RXDERR_INT_BIT | GMAC0_RXPERR_INT_BIT |
  1371. + GMAC0_SWTQ05_FIN_INT_BIT | GMAC0_SWTQ05_EOF_INT_BIT |
  1372. + GMAC0_SWTQ04_FIN_INT_BIT | GMAC0_SWTQ04_EOF_INT_BIT |
  1373. + GMAC0_SWTQ03_FIN_INT_BIT | GMAC0_SWTQ03_EOF_INT_BIT |
  1374. + GMAC0_SWTQ02_FIN_INT_BIT | GMAC0_SWTQ02_EOF_INT_BIT |
  1375. + GMAC0_SWTQ01_FIN_INT_BIT | GMAC0_SWTQ01_EOF_INT_BIT |
  1376. + GMAC0_SWTQ00_FIN_INT_BIT | GMAC0_SWTQ00_EOF_INT_BIT;
  1377. +
  1378. +#ifdef GMAX_TX_INTR_DISABLED
  1379. + gmac->intr0_enabled = 0;
  1380. +#else
  1381. + gmac->intr0_enabled = GMAC0_SWTQ00_FIN_INT_BIT | GMAC0_SWTQ00_EOF_INT_BIT;
  1382. +#endif
  1383. +
  1384. + gmac->intr1_selected = TOE_IQ_ALL_BITS | TOE_CLASS_RX_INT_BITS |
  1385. + GMAC0_HWTQ03_EOF_INT_BIT | GMAC0_HWTQ02_EOF_INT_BIT |
  1386. + GMAC0_HWTQ01_EOF_INT_BIT | GMAC0_HWTQ00_EOF_INT_BIT |
  1387. + DEFAULT_Q0_INT_BIT;
  1388. + gmac->intr1_enabled = DEFAULT_Q0_INT_BIT | TOE_IQ_ALL_BITS;
  1389. + gmac->intr2_selected = 0xffffffff; /* TOE Queue 32-63 FUUL Intr */
  1390. + gmac->intr2_enabled = 0xffffffff;
  1391. + gmac->intr3_selected = 0xffffffff; /* TOE Queue 0-31 FUUL Intr */
  1392. + gmac->intr3_enabled = 0xffffffff;
  1393. + gmac->intr4_selected = GMAC0_INT_BITS | CLASS_RX_FULL_INT_BITS |
  1394. + HWFQ_EMPTY_INT_BIT | SWFQ_EMPTY_INT_BIT;
  1395. + gmac->intr4_enabled = GMAC0_INT_BITS | SWFQ_EMPTY_INT_BIT;
  1396. +
  1397. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_0_REG) & ~gmac->intr0_selected;
  1398. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_0_REG);
  1399. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_1_REG) & ~gmac->intr1_selected;
  1400. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_1_REG);
  1401. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_2_REG) & ~gmac->intr2_selected;
  1402. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_2_REG);
  1403. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_3_REG) & ~gmac->intr3_selected;
  1404. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_3_REG);
  1405. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_4_REG) & ~gmac->intr4_selected;
  1406. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_4_REG);
  1407. + } else {
  1408. + gmac->intr0_selected = GMAC1_TXDERR_INT_BIT | GMAC1_TXPERR_INT_BIT |
  1409. + GMAC1_RXDERR_INT_BIT | GMAC1_RXPERR_INT_BIT |
  1410. + GMAC1_SWTQ15_FIN_INT_BIT | GMAC1_SWTQ15_EOF_INT_BIT |
  1411. + GMAC1_SWTQ14_FIN_INT_BIT | GMAC1_SWTQ14_EOF_INT_BIT |
  1412. + GMAC1_SWTQ13_FIN_INT_BIT | GMAC1_SWTQ13_EOF_INT_BIT |
  1413. + GMAC1_SWTQ12_FIN_INT_BIT | GMAC1_SWTQ12_EOF_INT_BIT |
  1414. + GMAC1_SWTQ11_FIN_INT_BIT | GMAC1_SWTQ11_EOF_INT_BIT |
  1415. + GMAC1_SWTQ10_FIN_INT_BIT | GMAC1_SWTQ10_EOF_INT_BIT;
  1416. +#ifdef GMAX_TX_INTR_DISABLED
  1417. + gmac->intr0_enabled = 0;
  1418. +#else
  1419. + gmac->intr0_enabled = GMAC1_SWTQ10_FIN_INT_BIT | GMAC1_SWTQ10_EOF_INT_BIT;
  1420. +#endif
  1421. +
  1422. + gmac->intr1_selected = DEFAULT_Q1_INT_BIT;
  1423. + gmac->intr1_enabled = DEFAULT_Q1_INT_BIT | TOE_IQ_ALL_BITS;
  1424. + gmac->intr2_selected = 0; /* TOE Queue 32-63 FUUL Intr */
  1425. + gmac->intr2_enabled = 0;
  1426. + gmac->intr3_selected = 0; /* TOE Queue 0-31 FUUL Intr */
  1427. + gmac->intr3_enabled = 0;
  1428. + gmac->intr4_selected = GMAC1_INT_BITS;
  1429. + gmac->intr4_enabled = GMAC1_INT_BITS;
  1430. +
  1431. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_0_REG) | gmac->intr0_selected;
  1432. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_0_REG);
  1433. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_1_REG) | gmac->intr1_selected;
  1434. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_1_REG);
  1435. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_2_REG) | gmac->intr2_selected;
  1436. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_2_REG);
  1437. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_3_REG) | gmac->intr3_selected;
  1438. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_3_REG);
  1439. + data = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_SELECT_4_REG) | gmac->intr4_selected;
  1440. + __raw_writel(data, toe->global_base + GLOBAL_INTERRUPT_SELECT_4_REG);
  1441. + }
  1442. +
  1443. + /* enable only selected bits */
  1444. + gmac_write_reg(toe->global_base, GLOBAL_INTERRUPT_ENABLE_0_REG,
  1445. + gmac->intr0_enabled, gmac->intr0_selected);
  1446. + gmac_write_reg(toe->global_base, GLOBAL_INTERRUPT_ENABLE_1_REG,
  1447. + gmac->intr1_enabled, gmac->intr1_selected);
  1448. + gmac_write_reg(toe->global_base, GLOBAL_INTERRUPT_ENABLE_2_REG,
  1449. + gmac->intr2_enabled, gmac->intr2_selected);
  1450. + gmac_write_reg(toe->global_base, GLOBAL_INTERRUPT_ENABLE_3_REG,
  1451. + gmac->intr3_enabled, gmac->intr3_selected);
  1452. + gmac_write_reg(toe->global_base, GLOBAL_INTERRUPT_ENABLE_4_REG,
  1453. + gmac->intr4_enabled, gmac->intr4_selected);
  1454. +
  1455. + /* start DMA process */
  1456. + toe_gmac_hw_start(gmac);
  1457. +}
  1458. +
  1459. +static void toe_gmac_enable_tx_rx(struct net_device *dev)
  1460. +{
  1461. + GMAC_CONFIG0_T config0;
  1462. +
  1463. + /* enable TX/RX */
  1464. + config0.bits32 = __raw_readl(dev->base_addr + GMAC_CONFIG0);
  1465. + config0.bits.dis_rx = 0; /* enable rx */
  1466. + config0.bits.dis_tx = 0; /* enable tx */
  1467. + __raw_writel(config0.bits32, dev->base_addr + GMAC_CONFIG0);
  1468. +}
  1469. +
  1470. +static void toe_gmac_disable_tx_rx(struct net_device *dev)
  1471. +{
  1472. + GMAC_CONFIG0_T config0;
  1473. +
  1474. + /* enable TX/RX */
  1475. + config0.bits32 = __raw_readl(dev->base_addr + GMAC_CONFIG0);
  1476. + config0.bits.dis_rx = 1; /* disable rx */
  1477. + config0.bits.dis_tx = 1; /* disable tx */
  1478. + __raw_writel(config0.bits32, dev->base_addr + GMAC_CONFIG0);
  1479. +}
  1480. +
  1481. +static void toe_gmac_tx_complete(struct net_device *dev, unsigned int tx_qid)
  1482. +{
  1483. + struct gmac_private *gmac = netdev_priv(dev);
  1484. + struct toe_private *toe = dev->ml_priv;
  1485. + GMAC_TXDESC_T *curr_desc;
  1486. + GMAC_TXDESC_0_T word0;
  1487. + GMAC_TXDESC_1_T word1;
  1488. + unsigned int desc_count;
  1489. + GMAC_SWTXQ_T *swtxq;
  1490. + DMA_RWPTR_T rwptr;
  1491. +
  1492. + /* get tx H/W completed descriptor virtual address */
  1493. + /* check tx status and accumulate tx statistics */
  1494. + swtxq = &gmac->swtxq[tx_qid];
  1495. + for (;;) {
  1496. + rwptr.bits32 = __raw_readl(swtxq->rwptr_reg);
  1497. + if (rwptr.bits.rptr == swtxq->finished_idx)
  1498. + break;
  1499. + curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
  1500. + dma_sync_single_range_for_device(toe->dev, swtxq->desc_base_dma,
  1501. + swtxq->finished_idx * sizeof(GMAC_TXDESC_T),
  1502. + sizeof(GMAC_TXDESC_T),
  1503. + DMA_FROM_DEVICE);
  1504. + word0.bits32 = curr_desc->word0.bits32;
  1505. + word1.bits32 = curr_desc->word1.bits32;
  1506. +
  1507. + if (word0.bits.status_tx_ok) {
  1508. + dev->stats.tx_bytes += word1.bits.byte_count;
  1509. + desc_count = word0.bits.desc_count;
  1510. + if (desc_count == 0) {
  1511. + dev_err(&dev->dev, "%s::Desc 0x%x = 0x%x, desc_count=%d\n", __func__, (u32)curr_desc, word0.bits32, desc_count);
  1512. + BUG();
  1513. + }
  1514. + while (--desc_count) {
  1515. + word0.bits.status_tx_ok = 0;
  1516. + curr_desc->word0.bits32 = word0.bits32;
  1517. + dma_sync_single_range_for_device(toe->dev, swtxq->desc_base_dma,
  1518. + swtxq->finished_idx * sizeof(GMAC_TXDESC_T),
  1519. + sizeof(GMAC_TXDESC_T),
  1520. + DMA_TO_DEVICE);
  1521. + swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, TOE_GMAC_SWTXQ_DESC_NUM);
  1522. + curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
  1523. + dma_sync_single_range_for_device(toe->dev, swtxq->desc_base_dma,
  1524. + swtxq->finished_idx * sizeof(GMAC_TXDESC_T),
  1525. + sizeof(GMAC_TXDESC_T),
  1526. + DMA_FROM_DEVICE);
  1527. + word0.bits32 = curr_desc->word0.bits32;
  1528. + }
  1529. +
  1530. + word0.bits.status_tx_ok = 0;
  1531. + dev_kfree_skb_any(swtxq->tx_skb[swtxq->finished_idx]);
  1532. + swtxq->tx_skb[swtxq->finished_idx] = NULL;
  1533. +
  1534. + curr_desc->word0.bits32 = word0.bits32;
  1535. + dma_sync_single_range_for_device(toe->dev, swtxq->desc_base_dma,
  1536. + swtxq->finished_idx * sizeof(GMAC_TXDESC_T),
  1537. + sizeof(GMAC_TXDESC_T),
  1538. + DMA_TO_DEVICE);
  1539. + dev->stats.tx_packets++;
  1540. + swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, TOE_GMAC_SWTXQ_DESC_NUM);
  1541. + } else {
  1542. + break;
  1543. + }
  1544. + }
  1545. +
  1546. + if (netif_queue_stopped(dev))
  1547. + netif_wake_queue(dev);
  1548. +}
  1549. +
  1550. +static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1551. +{
  1552. + struct gmac_private *gmac = netdev_priv(dev);
  1553. + struct toe_private *toe = dev->ml_priv;
  1554. + DMA_RWPTR_T rwptr;
  1555. + GMAC_TXDESC_T *curr_desc;
  1556. + int snd_pages = skb_shinfo(skb)->nr_frags + 1; /* get number of descriptor */
  1557. + int frag_id = 0;
  1558. + int len, total_len = skb->len;
  1559. + struct net_device_stats *isPtr = &dev->stats;
  1560. + unsigned int free_desc;
  1561. + GMAC_SWTXQ_T *swtxq;
  1562. + register unsigned long word0, word1, word2, word3;
  1563. + unsigned short wptr, rptr;
  1564. +
  1565. +#ifdef GMAC_LEN_1_2_ISSUE
  1566. + int total_pages;
  1567. + total_pages = snd_pages;
  1568. +#endif
  1569. +
  1570. + if (skb->len >= 0x10000) {
  1571. + isPtr->tx_dropped++;
  1572. + dev_err(&dev->dev, "%s::skb->len %d >= 64K\n", __func__, skb->len);
  1573. + netif_stop_queue(dev);
  1574. + return 1;
  1575. + }
  1576. +
  1577. +#ifdef GMAC_USE_TXQ0
  1578. + #define tx_qid 0
  1579. +#endif
  1580. +
  1581. + swtxq = &gmac->swtxq[tx_qid];
  1582. +
  1583. + rwptr.bits32 = __raw_readl(swtxq->rwptr_reg);
  1584. + wptr = rwptr.bits.wptr;
  1585. + rptr = rwptr.bits.rptr;
  1586. +
  1587. + /*
  1588. + * check finished desc or empty BD
  1589. + * cannot check by read ptr of RW PTR register,
  1590. + * because the HW complete to send but the SW may NOT handle it
  1591. + */
  1592. +#ifdef GMAX_TX_INTR_DISABLED
  1593. + toe_gmac_tx_complete(dev, tx_qid);
  1594. +#endif
  1595. + if (wptr >= swtxq->finished_idx)
  1596. + free_desc = TOE_GMAC_SWTXQ_DESC_NUM - wptr + swtxq->finished_idx;
  1597. + else
  1598. + free_desc = swtxq->finished_idx - wptr;
  1599. +
  1600. + if (free_desc < snd_pages) {
  1601. + isPtr->tx_dropped++;
  1602. + netif_stop_queue(dev);
  1603. + return 1;
  1604. + }
  1605. +
  1606. + while (snd_pages) {
  1607. + char *pkt_datap;
  1608. +
  1609. + curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + wptr;
  1610. + if (frag_id == 0) {
  1611. + len = skb_headlen(skb);
  1612. + pkt_datap = dma_map_single(toe->dev, skb->data, len, DMA_TO_DEVICE);
  1613. + } else {
  1614. + skb_frag_t *frag = &skb_shinfo(skb)->frags[frag_id - 1];
  1615. + len = frag->size;
  1616. + pkt_datap = dma_map_page(toe->dev, frag->page, frag->page_offset, len, DMA_TO_DEVICE);
  1617. + }
  1618. +
  1619. + /* set TX descriptor */
  1620. + word0 = len;
  1621. + word3 = (dev->mtu + 14) | EOFIE_BIT;
  1622. +
  1623. +#ifdef DO_HW_CHKSUM
  1624. + if (total_len <= 1514 && ip_hdr(skb) && (ip_hdr(skb)->frag_off & __constant_htons(0x3fff)))
  1625. + word1 = total_len |
  1626. + TSS_IP_CHKSUM_BIT |
  1627. + TSS_IPV6_ENABLE_BIT |
  1628. + TSS_MTU_ENABLE_BIT;
  1629. + else
  1630. + word1 = total_len |
  1631. + TSS_UDP_CHKSUM_BIT |
  1632. + TSS_TCP_CHKSUM_BIT |
  1633. + TSS_IP_CHKSUM_BIT |
  1634. + TSS_IPV6_ENABLE_BIT |
  1635. + TSS_MTU_ENABLE_BIT;
  1636. +#else
  1637. + word1 = total_len | TSS_MTU_ENABLE_BIT;
  1638. +#endif
  1639. + word2 = pkt_datap;
  1640. +
  1641. + if (frag_id == 0)
  1642. + word3 |= SOF_BIT;
  1643. +
  1644. + if (snd_pages == 1) {
  1645. + word3 |= EOF_BIT;
  1646. + swtxq->tx_skb[wptr] = skb;
  1647. + } else
  1648. + swtxq->tx_skb[wptr] = NULL;
  1649. +
  1650. +#ifdef GMAC_LEN_1_2_ISSUE
  1651. + if ((total_pages != snd_pages) && (len == 1 || len == 2) && ((u32)pkt_datap & 0x03)) {
  1652. + memcpy((void *)&_debug_prefetch_buf[_debug_prefetch_cnt][0], pkt_datap, len);
  1653. + pkt_datap = (char *)&_debug_prefetch_buf[_debug_prefetch_cnt][0];
  1654. + word2 = (unsigned long)__pa(pkt_datap);
  1655. + _debug_prefetch_cnt++;
  1656. + if (_debug_prefetch_cnt >= _DEBUG_PREFETCH_NUM)
  1657. + _debug_prefetch_cnt = 0;
  1658. + }
  1659. +#endif
  1660. + curr_desc->word0.bits32 = word0;
  1661. + curr_desc->word1.bits32 = word1;
  1662. + curr_desc->word2.bits32 = word2;
  1663. + curr_desc->word3.bits32 = word3;
  1664. + free_desc--;
  1665. + dma_sync_single_range_for_device(toe->dev, swtxq->desc_base_dma,
  1666. + wptr * sizeof(GMAC_TXDESC_T),
  1667. + sizeof(GMAC_TXDESC_T),
  1668. + DMA_TO_DEVICE);
  1669. + wptr = RWPTR_ADVANCE_ONE(wptr, TOE_GMAC_SWTXQ_DESC_NUM);
  1670. + frag_id++;
  1671. + snd_pages--;
  1672. + }
  1673. +
  1674. + SET_WPTR(swtxq->rwptr_reg, wptr);
  1675. + dev->trans_start = jiffies;
  1676. +
  1677. + return 0;
  1678. +}
  1679. +
  1680. +static void __gmac_set_mac_address(struct net_device *dev)
  1681. +{
  1682. + unsigned int reg_val;
  1683. +
  1684. + reg_val = dev->dev_addr[0] + (dev->dev_addr[1] << 8) +
  1685. + (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
  1686. + __raw_writel(reg_val, dev->base_addr + GMAC_STA_ADD0);
  1687. + reg_val = (__raw_readl(dev->base_addr + GMAC_STA_ADD1) & 0xFFFF0000) +
  1688. + dev->dev_addr[4] + (dev->dev_addr[5] << 8);
  1689. + __raw_writel(reg_val, dev->base_addr + GMAC_STA_ADD1);
  1690. +}
  1691. +
  1692. +static int gmac_set_mac_address(struct net_device *dev, void *addr)
  1693. +{
  1694. + struct sockaddr *sa = addr;
  1695. +
  1696. + memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
  1697. +
  1698. + __gmac_set_mac_address(dev);
  1699. +
  1700. + return 0;
  1701. +}
  1702. +
  1703. +static void gmac_get_mac_address(struct net_device *dev)
  1704. +{
  1705. + unsigned int reg_val;
  1706. +
  1707. + reg_val = __raw_readl(dev->base_addr + GMAC_STA_ADD0);
  1708. + dev->dev_addr[0] = reg_val & 0xFF;
  1709. + dev->dev_addr[1] = (reg_val >> 8) & 0xFF;
  1710. + dev->dev_addr[2] = (reg_val >> 16) & 0xFF;
  1711. + dev->dev_addr[3] = (reg_val >> 24) & 0xFF;
  1712. + reg_val = __raw_readl(dev->base_addr + GMAC_STA_ADD1);
  1713. + dev->dev_addr[4] = reg_val & 0xFF;
  1714. + dev->dev_addr[5] = (reg_val >> 8) & 0xFF;
  1715. +
  1716. + if (!is_valid_ether_addr(dev->dev_addr)) {
  1717. + random_ether_addr(dev->dev_addr);
  1718. + __gmac_set_mac_address(dev);
  1719. + }
  1720. +}
  1721. +
  1722. +struct net_device_stats *gmac_get_stats(struct net_device *dev)
  1723. +{
  1724. + if (netif_running(dev)) {
  1725. + unsigned short multicast;
  1726. +
  1727. + multicast = __raw_readw(dev->base_addr + GMAC_IN_MCAST) +
  1728. + __raw_readw(dev->base_addr + GMAC_IN_BCAST);
  1729. +
  1730. + dev->stats.rx_dropped += __raw_readw(dev->base_addr + GMAC_IN_DISCARDS);
  1731. + dev->stats.rx_errors += __raw_readw(dev->base_addr + GMAC_IN_ERRORS);
  1732. + dev->stats.rx_packets += __raw_readl(dev->base_addr + GMAC_IN_MAC1) + multicast;
  1733. + dev->stats.multicast += multicast;
  1734. + }
  1735. +
  1736. + return &dev->stats;
  1737. +}
  1738. +
  1739. +/* TODO: If possible use crc32 from kernel lib */
  1740. +static unsigned const ethernet_polynomial = 0x04c11db7U;
  1741. +static unsigned int ether_crc(int length, unsigned char *data)
  1742. +{
  1743. + int crc = -1;
  1744. + unsigned int i;
  1745. + unsigned int crc_val = 0;
  1746. +
  1747. + while (--length >= 0) {
  1748. + unsigned char current_octet = *data++;
  1749. + int bit;
  1750. + for (bit = 0; bit < 8; bit++, current_octet >>= 1)
  1751. + crc = (crc << 1) ^ ((crc < 0) ^ (current_octet & 1) ?
  1752. + ethernet_polynomial : 0);
  1753. + }
  1754. + crc = ~crc;
  1755. + for (i = 0; i < 32; i++)
  1756. + crc_val = crc_val + (((crc << i) & 0x80000000) >> (31 - i));
  1757. +
  1758. + return crc_val;
  1759. +}
  1760. +
  1761. +/*----------------------------------------------------------------------
  1762. +* toe_gmac_fill_free_q
  1763. +* allocate buffers for free queue.
  1764. +*----------------------------------------------------------------------*/
  1765. +static void toe_gmac_fill_free_q(struct toe_private *toe)
  1766. +{
  1767. + struct sk_buff *skb;
  1768. + DMA_RWPTR_T fq_rwptr;
  1769. + GMAC_RXDESC_T *fq_desc;
  1770. + unsigned long flags;
  1771. +
  1772. + spin_lock_irqsave(&toe->freeq_lock, flags);
  1773. + fq_rwptr.bits32 = __raw_readl(toe->global_base + GLOBAL_SWFQ_RWPTR_REG);
  1774. + while ((unsigned short)RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr,
  1775. + TOE_SW_FREEQ_DESC_NUM) != fq_rwptr.bits.rptr) {
  1776. + skb = dev_alloc_skb(SW_RX_BUF_SIZE);
  1777. + if (skb == NULL) {
  1778. + dev_err(toe->dev, "%s::skb allocation fail\n", __func__);
  1779. + break;
  1780. + }
  1781. + REG32(skb->data) = (unsigned int)skb;
  1782. + skb_reserve(skb, SKB_RESERVE_BYTES);
  1783. + fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr,
  1784. + TOE_SW_FREEQ_DESC_NUM);
  1785. + fq_desc = (GMAC_RXDESC_T *)toe->swfq_desc_base + fq_rwptr.bits.wptr;
  1786. + fq_desc->word2.buf_adr = dma_map_single(toe->dev, skb->data,
  1787. + SW_RX_BUF_SIZE - SKB_RESERVE_BYTES,
  1788. + DMA_FROM_DEVICE);
  1789. + dma_sync_single_range_for_device(toe->dev,
  1790. + toe->sw_freeq_desc_base_dma,
  1791. + fq_rwptr.bits.wptr * sizeof(GMAC_RXDESC_T),
  1792. + sizeof(GMAC_RXDESC_T),
  1793. + DMA_TO_DEVICE);
  1794. + SET_WPTR(toe->global_base + GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
  1795. + }
  1796. + spin_unlock_irqrestore(&toe->freeq_lock, flags);
  1797. +}
  1798. +
  1799. +static void fill_free_q_worker(struct work_struct *work)
  1800. +{
  1801. + struct toe_private *toe = container_of(work, struct toe_private, freq_work);
  1802. +
  1803. + toe_gmac_fill_free_q(toe);
  1804. +}
  1805. +
  1806. +/*----------------------------------------------------------------------
  1807. +* toe_gmac_handle_default_rxq
  1808. +* (1) Get rx Buffer for default Rx queue
  1809. +* (2) notify or call upper-routine to handle it
  1810. +* (3) get a new buffer and insert it into SW free queue
  1811. +* (4) Note: The SW free queue Read-Write Pointer should be locked when accessing
  1812. +*----------------------------------------------------------------------*/
  1813. +static void toe_gmac_handle_default_rxq(struct net_device *dev)
  1814. +{
  1815. + struct gmac_private *gmac = netdev_priv(dev);
  1816. + struct toe_private *toe = dev->ml_priv;
  1817. + GMAC_RXDESC_T *curr_desc;
  1818. + struct sk_buff *skb;
  1819. + DMA_RWPTR_T rwptr;
  1820. + unsigned int pkt_size;
  1821. + int max_cnt;
  1822. + unsigned int desc_count;
  1823. + unsigned int chksum_status, rx_status;
  1824. + struct net_device_stats *isPtr = &dev->stats;
  1825. +
  1826. + rwptr.bits32 = __raw_readl(&gmac->default_qhdr->word1);
  1827. + max_cnt = DEFAULT_RXQ_MAX_CNT;
  1828. + while ((--max_cnt) && rwptr.bits.rptr != rwptr.bits.wptr) {
  1829. + curr_desc = (GMAC_RXDESC_T *)gmac->default_desc_base + rwptr.bits.rptr;
  1830. + dma_sync_single_range_for_device(toe->dev,
  1831. + gmac->default_desc_base_dma,
  1832. + rwptr.bits.rptr * sizeof(GMAC_RXDESC_T),
  1833. + sizeof(GMAC_RXDESC_T),
  1834. + DMA_FROM_DEVICE);
  1835. + rx_status = curr_desc->word0.bits.status;
  1836. + chksum_status = curr_desc->word0.bits.chksum_status;
  1837. + pkt_size = curr_desc->word1.bits.byte_count; /* total byte count in a frame */
  1838. + desc_count = curr_desc->word0.bits.desc_count; /* get descriptor count per frame */
  1839. + skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
  1840. +
  1841. + if ((curr_desc->word0.bits32 & (GMAC_RXDESC_0_T_derr | GMAC_RXDESC_0_T_perr))
  1842. + || (pkt_size < 60) || (chksum_status & 0x4) || rx_status) {
  1843. + if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_derr)
  1844. + dev_err(&dev->dev, "%s::derr\n", __func__);
  1845. + if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_perr)
  1846. + dev_err(&dev->dev, "%s::perr\n", __func__);
  1847. + if (rx_status && (rx_status == 4 || rx_status == 7))
  1848. + isPtr->rx_crc_errors++;
  1849. +
  1850. + dev_kfree_skb_irq(skb);
  1851. + goto bad_frame;
  1852. + }
  1853. +
  1854. + if (curr_desc->word0.bits.drop)
  1855. + dev_warn(&dev->dev, "%s::Drop\n", __func__);
  1856. +
  1857. + /* get frame information from the first descriptor of the frame */
  1858. + skb_reserve(skb, RX_INSERT_BYTES); /* 16 byte align the IP fields. */
  1859. + skb_put(skb, pkt_size);
  1860. + skb->dev = dev;
  1861. + skb->protocol = eth_type_trans(skb, dev);
  1862. + if (chksum_status == RX_CHKSUM_IP_UDP_TCP_OK || chksum_status == RX_CHKSUM_IP_OK_ONLY)
  1863. + skb->ip_summed = CHECKSUM_UNNECESSARY;
  1864. +
  1865. + netif_rx(skb); /* socket rx */
  1866. + dev->last_rx = jiffies;
  1867. +
  1868. + isPtr->rx_bytes += pkt_size;
  1869. +
  1870. +bad_frame:
  1871. + /* advance one for Rx default Q 0/1 */
  1872. + rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, TOE_DEFAULT_Q_DESC_NUM);
  1873. + SET_RPTR(&gmac->default_qhdr->word1, rwptr.bits.rptr);
  1874. + }
  1875. +
  1876. + schedule_work(&toe->freq_work);
  1877. +}
  1878. +
  1879. +static irqreturn_t toe_gmac_interrupt(int irq, void *dev_instance)
  1880. +{
  1881. + struct net_device *dev = dev_instance;
  1882. + struct gmac_private *gmac = netdev_priv(dev);
  1883. + struct toe_private *toe = dev->ml_priv;
  1884. + unsigned int status0;
  1885. + unsigned int status1;
  1886. + unsigned int status2;
  1887. + unsigned int status3;
  1888. + unsigned int status4;
  1889. + int handled = 0;
  1890. +
  1891. + /* read Interrupt status */
  1892. + status0 = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_STATUS_0_REG);
  1893. + status1 = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_STATUS_1_REG);
  1894. + status2 = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_STATUS_2_REG);
  1895. + status3 = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_STATUS_3_REG);
  1896. + status4 = __raw_readl(toe->global_base + GLOBAL_INTERRUPT_STATUS_4_REG);
  1897. +
  1898. + /* clear interrupts */
  1899. + if (status0)
  1900. + __raw_writel(status0, toe->global_base + GLOBAL_INTERRUPT_STATUS_0_REG);
  1901. + if (status1)
  1902. + __raw_writel(status1, toe->global_base + GLOBAL_INTERRUPT_STATUS_1_REG);
  1903. + if (status2)
  1904. + __raw_writel(status2, toe->global_base + GLOBAL_INTERRUPT_STATUS_2_REG);
  1905. + if (status3)
  1906. + __raw_writel(status3, toe->global_base + GLOBAL_INTERRUPT_STATUS_3_REG);
  1907. + if (status4)
  1908. + __raw_writel(status4, toe->global_base + GLOBAL_INTERRUPT_STATUS_4_REG);
  1909. +
  1910. + /* handle freeq interrupt first */
  1911. + if (status4 & gmac->intr4_enabled) {
  1912. + if ((status4 & SWFQ_EMPTY_INT_BIT) && (gmac->intr4_enabled & SWFQ_EMPTY_INT_BIT)) {
  1913. + toe_gmac_fill_free_q(toe);
  1914. + handled = 1;
  1915. + }
  1916. + }
  1917. +
  1918. + /* Interrupt Status 1 */
  1919. + if (status1 & gmac->intr1_enabled) {
  1920. + /*
  1921. + * Handle GMAC 0/1 HW Tx queue 0-3 EOF events
  1922. + * Only count
  1923. + * TOE, Classification, and default queues interrupts are handled by ISR
  1924. + * because they should pass packets to upper layer
  1925. + */
  1926. + if (gmac->port_id == 0) {
  1927. + if (netif_running(dev) && (status1 & DEFAULT_Q0_INT_BIT) && (gmac->intr1_enabled & DEFAULT_Q0_INT_BIT)) {
  1928. + toe_gmac_handle_default_rxq(dev);
  1929. + handled = 1;
  1930. + }
  1931. + } else if (gmac->port_id == 1) {
  1932. + if (netif_running(dev) && (status1 & DEFAULT_Q1_INT_BIT) && (gmac->intr1_enabled & DEFAULT_Q1_INT_BIT)) {
  1933. + toe_gmac_handle_default_rxq(dev);
  1934. + handled = 1;
  1935. + }
  1936. + }
  1937. + }
  1938. +
  1939. + /* Interrupt Status 0 */
  1940. + if (status0 & gmac->intr0_enabled) {
  1941. +#ifndef GMAX_TX_INTR_DISABLED
  1942. + if (gmac->port_id == 1 && netif_running(dev) &&
  1943. + (((status0 & GMAC1_SWTQ10_FIN_INT_BIT) && (gmac->intr0_enabled & GMAC1_SWTQ10_FIN_INT_BIT))
  1944. + ||
  1945. + ((status0 & GMAC1_SWTQ10_EOF_INT_BIT) && (gmac->intr0_enabled & GMAC1_SWTQ10_EOF_INT_BIT)))) {
  1946. + toe_gmac_tx_complete(dev, 0);
  1947. + handled = 1;
  1948. + }
  1949. +
  1950. + if (gmac->port_id == 0 && netif_running(dev) &&
  1951. + (((status0 & GMAC0_SWTQ00_FIN_INT_BIT) && (gmac->intr0_enabled & GMAC0_SWTQ00_FIN_INT_BIT))
  1952. + ||
  1953. + ((status0 & GMAC0_SWTQ00_EOF_INT_BIT) && (gmac->intr0_enabled & GMAC0_SWTQ00_EOF_INT_BIT)))) {
  1954. + toe_gmac_tx_complete(dev, 0);
  1955. + handled = 1;
  1956. + }
  1957. +#endif
  1958. + }
  1959. +
  1960. + return IRQ_RETVAL(handled);
  1961. +}
  1962. +
  1963. +static int gmac_open(struct net_device *dev)
  1964. +{
  1965. + struct gmac_private *gmac = netdev_priv(dev);
  1966. + int retval;
  1967. +
  1968. + /* hook ISR */
  1969. + retval = request_irq(dev->irq, toe_gmac_interrupt, 0, dev->name, dev);
  1970. + if (retval)
  1971. + return retval;
  1972. +
  1973. + toe_init_gmac(dev);
  1974. +
  1975. + netif_carrier_off(dev);
  1976. + phy_start(gmac->phydev);
  1977. +
  1978. + netif_start_queue(dev);
  1979. +
  1980. + return 0;
  1981. +}
  1982. +
  1983. +static int gmac_close(struct net_device *dev)
  1984. +{
  1985. + struct gmac_private *gmac = netdev_priv(dev);
  1986. +
  1987. + netif_stop_queue(dev);
  1988. + mdelay(20);
  1989. +
  1990. + if (gmac->phydev)
  1991. + phy_stop(gmac->phydev);
  1992. +
  1993. + /* stop tx/rx packet */
  1994. + toe_gmac_disable_tx_rx(dev);
  1995. + mdelay(20);
  1996. +
  1997. + /* stop the chip's Tx and Rx DMA processes */
  1998. + toe_gmac_hw_stop(gmac);
  1999. +
  2000. + disable_irq(dev->irq);
  2001. + free_irq(dev->irq, dev);
  2002. +
  2003. + return 0;
  2004. +}
  2005. +
  2006. +static void gmac_get_phy_status(struct net_device *dev)
  2007. +{
  2008. + struct gmac_private *gmac = netdev_priv(dev);
  2009. + GMAC_CONFIG0_T config0;
  2010. + GMAC_STATUS_T status, old_status;
  2011. + struct phy_device *phydev = gmac->phydev;
  2012. +
  2013. + old_status.bits32 = status.bits32 = __raw_readl(dev->base_addr + GMAC_STATUS);
  2014. +
  2015. + status.bits.link = phydev->link;
  2016. + status.bits.duplex = phydev->duplex;
  2017. +
  2018. + switch (phydev->speed) {
  2019. + case 1000:
  2020. + status.bits.speed = GMAC_SPEED_1000;
  2021. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  2022. + status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
  2023. + break;
  2024. + case 100:
  2025. + status.bits.speed = GMAC_SPEED_100;
  2026. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  2027. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  2028. + break;
  2029. + case 10:
  2030. + status.bits.speed = GMAC_SPEED_10;
  2031. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  2032. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  2033. + break;
  2034. + default:
  2035. + dev_warn(&dev->dev, "Not supported PHY speed (%d)\n", phydev->speed);
  2036. + }
  2037. +
  2038. + if (phydev->pause) {
  2039. + if (gmac->flow_control_enable == 0) {
  2040. + config0.bits32 = __raw_readl(dev->base_addr + GMAC_CONFIG0);
  2041. + config0.bits.tx_fc_en = 1; /* enable tx flow control */
  2042. + config0.bits.rx_fc_en = 1; /* enable rx flow control */
  2043. + __raw_writel(config0.bits32, dev->base_addr + GMAC_CONFIG0);
  2044. + dev_info(&dev->dev, "MII flow control enabled\n");
  2045. + }
  2046. + gmac->flow_control_enable = 1;
  2047. + } else {
  2048. + if (gmac->flow_control_enable == 1) {
  2049. + config0.bits32 = __raw_readl(dev->base_addr + GMAC_CONFIG0);
  2050. + config0.bits.tx_fc_en = 0; /* disable tx flow control */
  2051. + config0.bits.rx_fc_en = 0; /* disable rx flow control */
  2052. + __raw_writel(config0.bits32, dev->base_addr + GMAC_CONFIG0);
  2053. + dev_info(&dev->dev, "MII flow control disabled\n");
  2054. + }
  2055. + gmac->flow_control_enable = 0;
  2056. + }
  2057. +
  2058. + if (old_status.bits32 != status.bits32) {
  2059. + toe_gmac_disable_tx_rx(dev);
  2060. + phy_print_status(phydev);
  2061. + mdelay(10); /* let GMAC consume packet */
  2062. + __raw_writel(status.bits32, dev->base_addr + GMAC_STATUS);
  2063. + if (status.bits.link)
  2064. + toe_gmac_enable_tx_rx(dev);
  2065. + }
  2066. +}
  2067. +
  2068. +static void gmac_set_rx_mode(struct net_device *dev)
  2069. +{
  2070. + GMAC_RX_FLTR_T filter;
  2071. + unsigned int mc_filter[2]; /* Multicast hash filter */
  2072. + int bit_nr;
  2073. + unsigned int i;
  2074. +
  2075. + filter.bits32 = 0;
  2076. + filter.bits.error = 0;
  2077. + if (dev->flags & IFF_PROMISC) {
  2078. + filter.bits.error = 1;
  2079. + filter.bits.promiscuous = 1;
  2080. + filter.bits.broadcast = 1;
  2081. + filter.bits.multicast = 1;
  2082. + filter.bits.unicast = 1;
  2083. + mc_filter[1] = mc_filter[0] = 0xffffffff;
  2084. + } else if (dev->flags & IFF_ALLMULTI) {
  2085. + filter.bits.broadcast = 1;
  2086. + filter.bits.multicast = 1;
  2087. + filter.bits.unicast = 1;
  2088. + mc_filter[1] = mc_filter[0] = 0xffffffff;
  2089. + } else {
  2090. + struct netdev_hw_addr *ha;
  2091. +
  2092. + filter.bits.broadcast = 1;
  2093. + filter.bits.multicast = 1;
  2094. + filter.bits.unicast = 1;
  2095. + mc_filter[1] = mc_filter[0] = 0;
  2096. + netdev_for_each_mc_addr(ha, dev) {
  2097. + bit_nr = ether_crc(ETH_ALEN, ha->addr) & 0x3f;
  2098. + if (bit_nr <= 32)
  2099. + mc_filter[0] = mc_filter[0] | (1 << bit_nr);
  2100. + else
  2101. + mc_filter[1] = mc_filter[1] | (1 << (bit_nr - 32));
  2102. + }
  2103. + }
  2104. + __raw_writel(filter.bits32, dev->base_addr + GMAC_RX_FLTR);
  2105. + __raw_writel(mc_filter[0], dev->base_addr + GMAC_MCAST_FIL0);
  2106. + __raw_writel(mc_filter[1], dev->base_addr + GMAC_MCAST_FIL1);
  2107. +}
  2108. +
  2109. +static void gmac_tx_timeout(struct net_device *dev)
  2110. +{
  2111. + if (!netif_queue_stopped(dev))
  2112. + netif_wake_queue(dev);
  2113. +
  2114. + dev_warn(&dev->dev, "TX timeout\n");
  2115. +}
  2116. +
  2117. +const static struct net_device_ops gemini_gmac_ops = {
  2118. + .ndo_open = gmac_open,
  2119. + .ndo_stop = gmac_close,
  2120. + .ndo_start_xmit = gmac_start_xmit,
  2121. + .ndo_get_stats = gmac_get_stats,
  2122. + .ndo_set_multicast_list = gmac_set_rx_mode,
  2123. + .ndo_set_mac_address = gmac_set_mac_address,
  2124. + .ndo_tx_timeout = gmac_tx_timeout,
  2125. +};
  2126. +
  2127. +static void __init mac_init_drv(struct toe_private *toe)
  2128. +{
  2129. + QUEUE_THRESHOLD_T threshold;
  2130. + DMA_SKB_SIZE_T skb_size;
  2131. +
  2132. + /* clear non TOE Queue Header Area */
  2133. + memset(toe->global_base + TOE_NONTOE_QUE_HDR_BASE, 0,
  2134. + NONTOE_Q_HDR_AREA_END - TOE_NONTOE_QUE_HDR_BASE);
  2135. +
  2136. + /* clear TOE Queue Header Area */
  2137. + memset(toe->global_base + TOE_TOE_QUE_HDR_BASE, 0,
  2138. + TOE_Q_HDR_AREA_END - TOE_TOE_QUE_HDR_BASE);
  2139. +
  2140. + /* Write GLOBAL_QUEUE_THRESHOLD_REG */
  2141. + threshold.bits32 = 0;
  2142. + threshold.bits.swfq_empty = (TOE_SW_FREEQ_DESC_NUM > 256) ? 255 :
  2143. + TOE_SW_FREEQ_DESC_NUM / 2;
  2144. + threshold.bits.hwfq_empty = (TOE_HW_FREEQ_DESC_NUM > 256) ? 256 / 4 :
  2145. + TOE_HW_FREEQ_DESC_NUM / 4;
  2146. + threshold.bits.toe_class = (TOE_TOE_DESC_NUM > 256) ? 256 / 4 :
  2147. + TOE_TOE_DESC_NUM / 4;
  2148. + threshold.bits.intrq = (TOE_INTR_DESC_NUM > 256) ? 256 / 4 :
  2149. + TOE_INTR_DESC_NUM / 4;
  2150. + __raw_writel(threshold.bits32, toe->global_base + GLOBAL_QUEUE_THRESHOLD_REG);
  2151. +
  2152. + /* Init skb size */
  2153. + skb_size.bits.hw_skb_size = HW_RX_BUF_SIZE;
  2154. + skb_size.bits.sw_skb_size = SW_RX_BUF_SIZE;
  2155. + __raw_writel(skb_size.bits32, toe->global_base + GLOBAL_DMA_SKB_SIZE_REG);
  2156. +
  2157. + toe_init_free_queue(toe);
  2158. + toe_init_interrupt_config(toe);
  2159. +}
  2160. +
  2161. +static int __init gmac_init_eth(struct platform_device *pdev, unsigned int num)
  2162. +{
  2163. + struct gmac_private *gmac;
  2164. + struct net_device *dev;
  2165. + struct toe_private *toe = platform_get_drvdata(pdev);
  2166. + struct gemini_gmac_platform_data *pdata = pdev->dev.platform_data;
  2167. +
  2168. + if (!pdata->bus_id[num])
  2169. + return 0;
  2170. +
  2171. + dev = alloc_etherdev(sizeof(*gmac));
  2172. + if (dev == NULL) {
  2173. + dev_err(&pdev->dev, "Can't allocate ethernet device #%d\n", num);
  2174. + return -ENOMEM;
  2175. + }
  2176. +
  2177. + gmac = netdev_priv(dev);
  2178. + dev->ml_priv = toe;
  2179. + toe->net_dev[num] = dev;
  2180. +
  2181. + gmac->dma_base_addr = toe->global_base + TOE_GMAC_DMA_BASE(num);
  2182. + gmac->port_id = num;
  2183. +
  2184. + dev->base_addr = toe->global_base + TOE_GMAC_BASE(num);
  2185. + dev->irq = platform_get_irq(pdev, num);
  2186. + dev->netdev_ops = &gemini_gmac_ops;
  2187. + dev->watchdog_timeo = GMAC_DEV_TX_TIMEOUT;
  2188. + dev->tx_queue_len = TOE_GMAC_SWTXQ_DESC_NUM;
  2189. +
  2190. +#ifdef DO_HW_CHKSUM
  2191. + dev->features = NETIF_F_SG | NETIF_F_HW_CSUM;
  2192. +#ifdef ENABLE_TSO
  2193. + dev->features |= NETIF_F_TSO;
  2194. +#endif
  2195. +#endif
  2196. +
  2197. + toe_init_swtx_queue(dev);
  2198. + toe_init_default_queue(dev);
  2199. +
  2200. + gmac_get_mac_address(dev);
  2201. +
  2202. + /* TODO: Do we need this? */
  2203. + __raw_writel(0x55aa55aa, dev->base_addr + GMAC_STA_ADD2);
  2204. +
  2205. + if (register_netdev(dev))
  2206. + return -1;
  2207. +
  2208. + gmac->phydev = phy_connect(dev, pdata->bus_id[num], &gmac_get_phy_status, 0,
  2209. + pdata->interface[num]);
  2210. + if (IS_ERR(gmac->phydev))
  2211. + return PTR_ERR(gmac->phydev);
  2212. +
  2213. + gmac->phydev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause;
  2214. + gmac->phydev->advertising = gmac->phydev->supported;
  2215. +
  2216. + return 0;
  2217. +}
  2218. +
  2219. +static int __init gmac_probe(struct platform_device *pdev)
  2220. +{
  2221. + struct resource *res;
  2222. + struct toe_private *toe;
  2223. + int retval;
  2224. +
  2225. + if (!pdev->dev.platform_data)
  2226. + return -EINVAL;
  2227. +
  2228. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2229. + if (!res) {
  2230. + dev_err(&pdev->dev, "can't get device resources\n");
  2231. + return -ENODEV;
  2232. + }
  2233. +
  2234. + toe = kzalloc(sizeof(struct toe_private), GFP_KERNEL);
  2235. + if (!toe)
  2236. + return -ENOMEM;
  2237. +
  2238. + toe->dev = &pdev->dev;
  2239. +
  2240. + toe->global_base = ioremap(res->start, resource_size(res));
  2241. + if (!toe->global_base) {
  2242. + dev_err(toe->dev, "ioremap failed\n");
  2243. + retval = -EIO;
  2244. + goto err_data;
  2245. + }
  2246. +
  2247. + platform_set_drvdata(pdev, toe);
  2248. +
  2249. + mac_init_drv(toe);
  2250. +
  2251. + INIT_WORK(&toe->freq_work, fill_free_q_worker);
  2252. + spin_lock_init(&toe->freeq_lock);
  2253. +
  2254. + retval = gmac_init_eth(pdev, GMAC_PORT0);
  2255. + if (retval)
  2256. + goto err_unmap;
  2257. + retval = gmac_init_eth(pdev, GMAC_PORT1);
  2258. + if (retval)
  2259. + goto err_unmap;
  2260. +
  2261. + dev_info(&pdev->dev, SL351x_DRIVER_NAME "\n");
  2262. +
  2263. + return 0;
  2264. +
  2265. +err_unmap:
  2266. + iounmap(toe->global_base);
  2267. +err_data:
  2268. + kfree(toe);
  2269. + return retval;
  2270. +}
  2271. +
  2272. +static int __exit gmac_remove(struct platform_device *pdev)
  2273. +{
  2274. + struct toe_private *toe = platform_get_drvdata(pdev);
  2275. + int i;
  2276. +
  2277. + for (i = 0; i < 2; i++)
  2278. + if (toe->net_dev[i]) {
  2279. + unregister_netdev(toe->net_dev[i]);
  2280. + kfree(toe->net_dev[i]);
  2281. + }
  2282. +
  2283. + iounmap(toe->global_base);
  2284. +
  2285. + kfree(toe);
  2286. +
  2287. + return 0;
  2288. +}
  2289. +
  2290. +static struct platform_driver gemini_gmac_driver = {
  2291. + .probe = gmac_probe,
  2292. + .remove = __exit_p(gmac_remove),
  2293. +
  2294. + .driver = {
  2295. + .name = "gemini-gmac",
  2296. + .owner = THIS_MODULE,
  2297. + },
  2298. +};
  2299. +
  2300. +static int __init gemini_gmac_init(void)
  2301. +{
  2302. + return platform_driver_register(&gemini_gmac_driver);
  2303. +}
  2304. +
  2305. +static void __exit gemini_gmac_exit(void)
  2306. +{
  2307. + platform_driver_unregister(&gemini_gmac_driver);
  2308. +}
  2309. +
  2310. +module_init(gemini_gmac_init);
  2311. +module_exit(gemini_gmac_exit);
  2312. +
  2313. +MODULE_AUTHOR("Paulius Zaleckas");
  2314. +MODULE_DESCRIPTION("Ethernet device driver for Gemini SoC");
  2315. +MODULE_LICENSE("GPL");
  2316. +MODULE_ALIAS("platform:gemini-gmac");
  2317. --- /dev/null
  2318. +++ b/drivers/net/gemini_negmac/gm_gmac.h
  2319. @@ -0,0 +1,1488 @@
  2320. +/*
  2321. + * Register definitions for Gemini Ethernet device driver.
  2322. + *
  2323. + * Copyright (C) 2006, Storlink, Corp.
  2324. + * Copyright (C) 2008-2009, Paulius Zaleckas <[email protected]>
  2325. + *
  2326. + * This program is free software; you can redistribute it and/or modify
  2327. + * it under the terms of the GNU General Public License as published by
  2328. + * the Free Software Foundation; either version 2 of the License, or
  2329. + * (at your option) any later version.
  2330. + */
  2331. +#ifndef _GMAC_SL351x_H
  2332. +#define _GMAC_SL351x_H
  2333. +#include <linux/skbuff.h>
  2334. +
  2335. +#define _PACKED_ __attribute__ ((aligned(1), packed))
  2336. +
  2337. +#ifndef BIT
  2338. +#define BIT(x) (1 << (x))
  2339. +#endif
  2340. +
  2341. +#define REG32(addr) (*(volatile unsigned long * const)(addr))
  2342. +
  2343. +/* Define frame size */
  2344. +#define GMAC_MAX_ETH_FRAME_SIZE 1514
  2345. +#define GMAC_TX_BUF_SIZE ((GMAC_MAX_ETH_FRAME_SIZE + 31) & (~31))
  2346. +
  2347. +#define SW_RX_BUF_SIZE 1536
  2348. +#define HW_RX_BUF_SIZE 1536
  2349. +
  2350. +#define GMAC_DEV_TX_TIMEOUT (10*HZ)
  2351. +#define SKB_RESERVE_BYTES 16
  2352. +
  2353. +/*
  2354. + * Base Registers
  2355. + */
  2356. +#define TOE_NONTOE_QUE_HDR_BASE 0x2000
  2357. +#define TOE_TOE_QUE_HDR_BASE 0x3000
  2358. +#define TOE_V_BIT_BASE 0x4000
  2359. +#define TOE_A_BIT_BASE 0x6000
  2360. +#define TOE_GMAC_DMA_BASE(x) (0x8000 + 0x4000 * (x))
  2361. +#define TOE_GMAC_BASE(x) (0xA000 + 0x4000 * (x))
  2362. +
  2363. +/*
  2364. + * Queue ID
  2365. + */
  2366. +#define TOE_SW_FREE_QID 0x00
  2367. +#define TOE_HW_FREE_QID 0x01
  2368. +#define TOE_GMAC0_SW_TXQ0_QID 0x02
  2369. +#define TOE_GMAC0_SW_TXQ1_QID 0x03
  2370. +#define TOE_GMAC0_SW_TXQ2_QID 0x04
  2371. +#define TOE_GMAC0_SW_TXQ3_QID 0x05
  2372. +#define TOE_GMAC0_SW_TXQ4_QID 0x06
  2373. +#define TOE_GMAC0_SW_TXQ5_QID 0x07
  2374. +#define TOE_GMAC0_HW_TXQ0_QID 0x08
  2375. +#define TOE_GMAC0_HW_TXQ1_QID 0x09
  2376. +#define TOE_GMAC0_HW_TXQ2_QID 0x0A
  2377. +#define TOE_GMAC0_HW_TXQ3_QID 0x0B
  2378. +#define TOE_GMAC1_SW_TXQ0_QID 0x12
  2379. +#define TOE_GMAC1_SW_TXQ1_QID 0x13
  2380. +#define TOE_GMAC1_SW_TXQ2_QID 0x14
  2381. +#define TOE_GMAC1_SW_TXQ3_QID 0x15
  2382. +#define TOE_GMAC1_SW_TXQ4_QID 0x16
  2383. +#define TOE_GMAC1_SW_TXQ5_QID 0x17
  2384. +#define TOE_GMAC1_HW_TXQ0_QID 0x18
  2385. +#define TOE_GMAC1_HW_TXQ1_QID 0x19
  2386. +#define TOE_GMAC1_HW_TXQ2_QID 0x1A
  2387. +#define TOE_GMAC1_HW_TXQ3_QID 0x1B
  2388. +#define TOE_GMAC0_DEFAULT_QID 0x20
  2389. +#define TOE_GMAC1_DEFAULT_QID 0x21
  2390. +#define TOE_CLASSIFICATION_QID(x) (0x22 + x) // 0x22 ~ 0x2F
  2391. +#define TOE_TOE_QID(x) (0x40 + x) // 0x40 ~ 0x7F
  2392. +
  2393. +/*
  2394. + * TOE DMA Queue Number should be 2^n, n = 6...12
  2395. + * TOE DMA Queues are the following queue types:
  2396. + * SW Free Queue, HW Free Queue,
  2397. + * GMAC 0/1 SW TX Q0-5, and GMAC 0/1 HW TX Q0-5
  2398. + * They have same descriptor numbers.
  2399. + * The base address and descriptor number are configured at
  2400. + * DMA Queues Descriptor Ring Base Address/Size Register (offset 0x0004)
  2401. + */
  2402. +#define TOE_SW_FREEQ_DESC_POWER 8
  2403. +#define TOE_SW_FREEQ_DESC_NUM (1<<TOE_SW_FREEQ_DESC_POWER)
  2404. +#define TOE_HW_FREEQ_DESC_POWER 8
  2405. +#define TOE_HW_FREEQ_DESC_NUM (1<<TOE_HW_FREEQ_DESC_POWER)
  2406. +#define TOE_GMAC_SWTXQ_DESC_POWER 8
  2407. +#define TOE_GMAC_SWTXQ_DESC_NUM (1<<TOE_GMAC_SWTXQ_DESC_POWER)
  2408. +#define TOE_GMAC_HWTXQ_DESC_POWER 8
  2409. +#define TOE_GMAC_HWTXQ_DESC_NUM (1<<TOE_GMAC_HWTXQ_DESC_POWER)
  2410. +#define TOE_DEFAULT_Q_DESC_POWER 8
  2411. +#define TOE_DEFAULT_Q_DESC_NUM (1<<TOE_DEFAULT_Q_DESC_POWER)
  2412. +#define TOE_TOE_DESC_POWER 8
  2413. +#define TOE_TOE_DESC_NUM (1<<TOE_TOE_DESC_POWER)
  2414. +#define TOE_CLASS_DESC_POWER 8
  2415. +#define TOE_CLASS_DESC_NUM (1<<TOE_CLASS_DESC_POWER)
  2416. +#define TOE_INTR_DESC_POWER 8
  2417. +#define TOE_INTR_DESC_NUM (1<<TOE_INTR_DESC_POWER)
  2418. +
  2419. +#define TOE_TOE_QUEUE_MAX 64
  2420. +#define TOE_TOE_QUEUE_NUM 64
  2421. +#define TOE_CLASS_QUEUE_MAX 14
  2422. +#define TOE_CLASS_QUEUE_NUM 14
  2423. +#define TOE_INTR_QUEUE_MAX 4
  2424. +#define TOE_INTR_QUEUE_NUM 4
  2425. +#define TOE_SW_TXQ_MAX 6
  2426. +#define TOE_SW_TXQ_NUM 1
  2427. +#define TOE_HW_TXQ_MAX 4
  2428. +#define TOE_HW_TXQ_NUM 4
  2429. +
  2430. +#define RWPTR_ADVANCE_ONE(x, max) ((x == (max -1)) ? 0 : x+1)
  2431. +#define RWPTR_RECEDE_ONE(x, max) ((x == 0) ? (max -1) : x-1)
  2432. +#define SET_WPTR(addr, data) (*(volatile u16 * const)((u32)(addr) + 2) = (u16)data)
  2433. +#define SET_RPTR(addr, data) (*(volatile u16 * const)((u32)(addr)) = (u16)data)
  2434. +
  2435. +/*
  2436. + * Global registers
  2437. + * #define TOE_GLOBAL_BASE (TOE_BASE + 0x0000)
  2438. + * Base 0x60000000
  2439. + */
  2440. +#define GLOBAL_TOE_VERSION_REG 0x0000
  2441. +#define GLOBAL_SW_FREEQ_BASE_SIZE_REG 0x0004
  2442. +#define GLOBAL_HW_FREEQ_BASE_SIZE_REG 0x0008
  2443. +#define GLOBAL_DMA_SKB_SIZE_REG 0x0010
  2444. +#define GLOBAL_SWFQ_RWPTR_REG 0x0014
  2445. +#define GLOBAL_HWFQ_RWPTR_REG 0x0018
  2446. +#define GLOBAL_INTERRUPT_STATUS_0_REG 0x0020
  2447. +#define GLOBAL_INTERRUPT_ENABLE_0_REG 0x0024
  2448. +#define GLOBAL_INTERRUPT_SELECT_0_REG 0x0028
  2449. +#define GLOBAL_INTERRUPT_STATUS_1_REG 0x0030
  2450. +#define GLOBAL_INTERRUPT_ENABLE_1_REG 0x0034
  2451. +#define GLOBAL_INTERRUPT_SELECT_1_REG 0x0038
  2452. +#define GLOBAL_INTERRUPT_STATUS_2_REG 0x0040
  2453. +#define GLOBAL_INTERRUPT_ENABLE_2_REG 0x0044
  2454. +#define GLOBAL_INTERRUPT_SELECT_2_REG 0x0048
  2455. +#define GLOBAL_INTERRUPT_STATUS_3_REG 0x0050
  2456. +#define GLOBAL_INTERRUPT_ENABLE_3_REG 0x0054
  2457. +#define GLOBAL_INTERRUPT_SELECT_3_REG 0x0058
  2458. +#define GLOBAL_INTERRUPT_STATUS_4_REG 0x0060
  2459. +#define GLOBAL_INTERRUPT_ENABLE_4_REG 0x0064
  2460. +#define GLOBAL_INTERRUPT_SELECT_4_REG 0x0068
  2461. +#define GLOBAL_HASH_TABLE_BASE_REG 0x006C
  2462. +#define GLOBAL_QUEUE_THRESHOLD_REG 0x0070
  2463. +
  2464. +/*
  2465. + * GMAC 0/1 DMA/TOE register
  2466. + * #define TOE_GMAC0_DMA_BASE (TOE_BASE + 0x8000)
  2467. + * #define TOE_GMAC1_DMA_BASE (TOE_BASE + 0xC000)
  2468. + * Base 0x60008000 or 0x6000C000
  2469. + */
  2470. +#define GMAC_DMA_CTRL_REG 0x0000
  2471. +#define GMAC_TX_WEIGHTING_CTRL_0_REG 0x0004
  2472. +#define GMAC_TX_WEIGHTING_CTRL_1_REG 0x0008
  2473. +#define GMAC_SW_TX_QUEUE0_PTR_REG 0x000C
  2474. +#define GMAC_SW_TX_QUEUE1_PTR_REG 0x0010
  2475. +#define GMAC_SW_TX_QUEUE2_PTR_REG 0x0014
  2476. +#define GMAC_SW_TX_QUEUE3_PTR_REG 0x0018
  2477. +#define GMAC_SW_TX_QUEUE4_PTR_REG 0x001C
  2478. +#define GMAC_SW_TX_QUEUE5_PTR_REG 0x0020
  2479. +#define GMAC_HW_TX_QUEUE0_PTR_REG 0x0024
  2480. +#define GMAC_HW_TX_QUEUE1_PTR_REG 0x0028
  2481. +#define GMAC_HW_TX_QUEUE2_PTR_REG 0x002C
  2482. +#define GMAC_HW_TX_QUEUE3_PTR_REG 0x0030
  2483. +#define GMAC_DMA_TX_FIRST_DESC_REG 0x0038
  2484. +#define GMAC_DMA_TX_CURR_DESC_REG 0x003C
  2485. +#define GMAC_DMA_TX_DESC_WORD0_REG 0x0040
  2486. +#define GMAC_DMA_TX_DESC_WORD1_REG 0x0044
  2487. +#define GMAC_DMA_TX_DESC_WORD2_REG 0x0048
  2488. +#define GMAC_DMA_TX_DESC_WORD3_REG 0x004C
  2489. +#define GMAC_SW_TX_QUEUE_BASE_REG 0x0050
  2490. +#define GMAC_HW_TX_QUEUE_BASE_REG 0x0054
  2491. +#define GMAC_DMA_RX_FIRST_DESC_REG 0x0058
  2492. +#define GMAC_DMA_RX_CURR_DESC_REG 0x005C
  2493. +#define GMAC_DMA_RX_DESC_WORD0_REG 0x0060
  2494. +#define GMAC_DMA_RX_DESC_WORD1_REG 0x0064
  2495. +#define GMAC_DMA_RX_DESC_WORD2_REG 0x0068
  2496. +#define GMAC_DMA_RX_DESC_WORD3_REG 0x006C
  2497. +#define GMAC_HASH_ENGINE_REG0 0x0070
  2498. +#define GMAC_HASH_ENGINE_REG1 0x0074
  2499. +/* matching rule 0 Control register 0 */
  2500. +#define GMAC_MR0CR0 0x0078
  2501. +#define GMAC_MR0CR1 0x007C
  2502. +#define GMAC_MR0CR2 0x0080
  2503. +#define GMAC_MR1CR0 0x0084
  2504. +#define GMAC_MR1CR1 0x0088
  2505. +#define GMAC_MR1CR2 0x008C
  2506. +#define GMAC_MR2CR0 0x0090
  2507. +#define GMAC_MR2CR1 0x0094
  2508. +#define GMAC_MR2CR2 0x0098
  2509. +#define GMAC_MR3CR0 0x009C
  2510. +#define GMAC_MR3CR1 0x00A0
  2511. +#define GMAC_MR3CR2 0x00A4
  2512. +/* Support Protocol Regsister 0 */
  2513. +#define GMAC_SPR0 0x00A8
  2514. +#define GMAC_SPR1 0x00AC
  2515. +#define GMAC_SPR2 0x00B0
  2516. +#define GMAC_SPR3 0x00B4
  2517. +#define GMAC_SPR4 0x00B8
  2518. +#define GMAC_SPR5 0x00BC
  2519. +#define GMAC_SPR6 0x00C0
  2520. +#define GMAC_SPR7 0x00C4
  2521. +/* GMAC Hash/Rx/Tx AHB Weighting register */
  2522. +#define GMAC_AHB_WEIGHT_REG 0x00C8
  2523. +
  2524. +/*
  2525. + * TOE GMAC 0/1 register
  2526. + * #define TOE_GMAC0_BASE (TOE_BASE + 0xA000)
  2527. + * #define TOE_GMAC1_BASE (TOE_BASE + 0xE000)
  2528. + * Base 0x6000A000 or 0x6000E000
  2529. + */
  2530. +enum GMAC_REGISTER {
  2531. + GMAC_STA_ADD0 = 0x0000,
  2532. + GMAC_STA_ADD1 = 0x0004,
  2533. + GMAC_STA_ADD2 = 0x0008,
  2534. + GMAC_RX_FLTR = 0x000c,
  2535. + GMAC_MCAST_FIL0 = 0x0010,
  2536. + GMAC_MCAST_FIL1 = 0x0014,
  2537. + GMAC_CONFIG0 = 0x0018,
  2538. + GMAC_CONFIG1 = 0x001c,
  2539. + GMAC_CONFIG2 = 0x0020,
  2540. + GMAC_CONFIG3 = 0x0024,
  2541. + GMAC_RESERVED = 0x0028,
  2542. + GMAC_STATUS = 0x002c,
  2543. + GMAC_IN_DISCARDS= 0x0030,
  2544. + GMAC_IN_ERRORS = 0x0034,
  2545. + GMAC_IN_MCAST = 0x0038,
  2546. + GMAC_IN_BCAST = 0x003c,
  2547. + GMAC_IN_MAC1 = 0x0040, /* for STA 1 MAC Address */
  2548. + GMAC_IN_MAC2 = 0x0044 /* for STA 2 MAC Address */
  2549. +};
  2550. +
  2551. +/*
  2552. + * DMA Queues description Ring Base Address/Size Register (offset 0x0004)
  2553. + */
  2554. +typedef union {
  2555. + unsigned int bits32;
  2556. + unsigned int base_size;
  2557. +} DMA_Q_BASE_SIZE_T;
  2558. +#define DMA_Q_BASE_MASK (~0x0f)
  2559. +
  2560. +/*
  2561. + * DMA SKB Buffer register (offset 0x0008)
  2562. + */
  2563. +typedef union {
  2564. + unsigned int bits32;
  2565. + struct bit_0008 {
  2566. + unsigned int sw_skb_size : 16; /* SW Free poll SKB Size */
  2567. + unsigned int hw_skb_size : 16; /* HW Free poll SKB Size */
  2568. + } bits;
  2569. +} DMA_SKB_SIZE_T;
  2570. +
  2571. +/*
  2572. + * DMA SW Free Queue Read/Write Pointer Register (offset 0x000C)
  2573. + */
  2574. +typedef union {
  2575. + unsigned int bits32;
  2576. + struct bit_000c {
  2577. + unsigned int rptr : 16; /* Read Ptr, RO */
  2578. + unsigned int wptr : 16; /* Write Ptr, RW */
  2579. + } bits;
  2580. +} DMA_RWPTR_T;
  2581. +
  2582. +/*
  2583. + * DMA HW Free Queue Read/Write Pointer Register (offset 0x0010)
  2584. + * see DMA_RWPTR_T structure
  2585. + */
  2586. +
  2587. +/*
  2588. + * Interrupt Status Register 0 (offset 0x0020)
  2589. + * Interrupt Mask Register 0 (offset 0x0024)
  2590. + * Interrupt Select Register 0 (offset 0x0028)
  2591. + */
  2592. +typedef union {
  2593. + unsigned int bits32;
  2594. + struct bit_0020 {
  2595. + /* GMAC0 SW Tx Queue 0 EOF Interrupt */
  2596. + unsigned int swtq00_eof : 1;
  2597. + unsigned int swtq01_eof : 1;
  2598. + unsigned int swtq02_eof : 1;
  2599. + unsigned int swtq03_eof : 1;
  2600. + unsigned int swtq04_eof : 1;
  2601. + unsigned int swtq05_eof : 1;
  2602. + /* GMAC1 SW Tx Queue 0 EOF Interrupt */
  2603. + unsigned int swtq10_eof : 1;
  2604. + unsigned int swtq11_eof : 1;
  2605. + unsigned int swtq12_eof : 1;
  2606. + unsigned int swtq13_eof : 1;
  2607. + unsigned int swtq14_eof : 1;
  2608. + unsigned int swtq15_eof : 1;
  2609. + /* GMAC0 SW Tx Queue 0 Finish Interrupt */
  2610. + unsigned int swtq00_fin : 1;
  2611. + unsigned int swtq01_fin : 1;
  2612. + unsigned int swtq02_fin : 1;
  2613. + unsigned int swtq03_fin : 1;
  2614. + unsigned int swtq04_fin : 1;
  2615. + unsigned int swtq05_fin : 1;
  2616. + /* GMAC1 SW Tx Queue 0 Finish Interrupt */
  2617. + unsigned int swtq10_fin : 1;
  2618. + unsigned int swtq11_fin : 1;
  2619. + unsigned int swtq12_fin : 1;
  2620. + unsigned int swtq13_fin : 1;
  2621. + unsigned int swtq14_fin : 1;
  2622. + unsigned int swtq15_fin : 1;
  2623. + /* GMAC0 Rx Descriptor Protocol Error */
  2624. + unsigned int rxPerr0 : 1;
  2625. + /* GMAC0 AHB Bus Error while Rx */
  2626. + unsigned int rxDerr0 : 1;
  2627. + /* GMAC1 Rx Descriptor Protocol Error */
  2628. + unsigned int rxPerr1 : 1;
  2629. + /* GMAC1 AHB Bus Error while Rx */
  2630. + unsigned int rxDerr1 : 1;
  2631. + /* GMAC0 Tx Descriptor Protocol Error */
  2632. + unsigned int txPerr0 : 1;
  2633. + /* GMAC0 AHB Bus Error while Tx */
  2634. + unsigned int txDerr0 : 1;
  2635. + /* GMAC1 Tx Descriptor Protocol Error */
  2636. + unsigned int txPerr1 : 1;
  2637. + /* GMAC1 AHB Bus Error while Tx */
  2638. + unsigned int txDerr1 : 1;
  2639. + } bits;
  2640. +} INTR_REG0_T;
  2641. +
  2642. +#define GMAC1_TXDERR_INT_BIT BIT(31)
  2643. +#define GMAC1_TXPERR_INT_BIT BIT(30)
  2644. +#define GMAC0_TXDERR_INT_BIT BIT(29)
  2645. +#define GMAC0_TXPERR_INT_BIT BIT(28)
  2646. +#define GMAC1_RXDERR_INT_BIT BIT(27)
  2647. +#define GMAC1_RXPERR_INT_BIT BIT(26)
  2648. +#define GMAC0_RXDERR_INT_BIT BIT(25)
  2649. +#define GMAC0_RXPERR_INT_BIT BIT(24)
  2650. +#define GMAC1_SWTQ15_FIN_INT_BIT BIT(23)
  2651. +#define GMAC1_SWTQ14_FIN_INT_BIT BIT(22)
  2652. +#define GMAC1_SWTQ13_FIN_INT_BIT BIT(21)
  2653. +#define GMAC1_SWTQ12_FIN_INT_BIT BIT(20)
  2654. +#define GMAC1_SWTQ11_FIN_INT_BIT BIT(19)
  2655. +#define GMAC1_SWTQ10_FIN_INT_BIT BIT(18)
  2656. +#define GMAC0_SWTQ05_FIN_INT_BIT BIT(17)
  2657. +#define GMAC0_SWTQ04_FIN_INT_BIT BIT(16)
  2658. +#define GMAC0_SWTQ03_FIN_INT_BIT BIT(15)
  2659. +#define GMAC0_SWTQ02_FIN_INT_BIT BIT(14)
  2660. +#define GMAC0_SWTQ01_FIN_INT_BIT BIT(13)
  2661. +#define GMAC0_SWTQ00_FIN_INT_BIT BIT(12)
  2662. +#define GMAC1_SWTQ15_EOF_INT_BIT BIT(11)
  2663. +#define GMAC1_SWTQ14_EOF_INT_BIT BIT(10)
  2664. +#define GMAC1_SWTQ13_EOF_INT_BIT BIT(9)
  2665. +#define GMAC1_SWTQ12_EOF_INT_BIT BIT(8)
  2666. +#define GMAC1_SWTQ11_EOF_INT_BIT BIT(7)
  2667. +#define GMAC1_SWTQ10_EOF_INT_BIT BIT(6)
  2668. +#define GMAC0_SWTQ05_EOF_INT_BIT BIT(5)
  2669. +#define GMAC0_SWTQ04_EOF_INT_BIT BIT(4)
  2670. +#define GMAC0_SWTQ03_EOF_INT_BIT BIT(3)
  2671. +#define GMAC0_SWTQ02_EOF_INT_BIT BIT(2)
  2672. +#define GMAC0_SWTQ01_EOF_INT_BIT BIT(1)
  2673. +#define GMAC0_SWTQ00_EOF_INT_BIT BIT(0)
  2674. +
  2675. +/*
  2676. + * Interrupt Status Register 1 (offset 0x0030)
  2677. + * Interrupt Mask Register 1 (offset 0x0034)
  2678. + * Interrupt Select Register 1 (offset 0x0038)
  2679. + */
  2680. +typedef union {
  2681. + unsigned int bits32;
  2682. + struct bit_0030 {
  2683. + unsigned int default_q0_eof : 1; /* Default Queue 0 EOF Interrupt */
  2684. + unsigned int default_q1_eof : 1; /* Default Queue 1 EOF Interrupt */
  2685. + unsigned int class_rx : 14; /* Classification Queue Rx Interrupt */
  2686. + unsigned int hwtq00_eof : 1; /* GMAC0 HW Tx Queue0 EOF Interrupt */
  2687. + unsigned int hwtq01_eof : 1; /* GMAC0 HW Tx Queue1 EOF Interrupt */
  2688. + unsigned int hwtq02_eof : 1; /* GMAC0 HW Tx Queue2 EOF Interrupt */
  2689. + unsigned int hwtq03_eof : 1; /* GMAC0 HW Tx Queue3 EOF Interrupt */
  2690. + unsigned int hwtq10_eof : 1; /* GMAC1 HW Tx Queue0 EOF Interrupt */
  2691. + unsigned int hwtq11_eof : 1; /* GMAC1 HW Tx Queue1 EOF Interrupt */
  2692. + unsigned int hwtq12_eof : 1; /* GMAC1 HW Tx Queue2 EOF Interrupt */
  2693. + unsigned int hwtq13_eof : 1; /* GMAC1 HW Tx Queue3 EOF Interrupt */
  2694. + unsigned int toe_iq0_intr : 1; /* TOE Interrupt Queue 0 with Interrupts */
  2695. + unsigned int toe_iq1_intr : 1; /* TOE Interrupt Queue 1 with Interrupts */
  2696. + unsigned int toe_iq2_intr : 1; /* TOE Interrupt Queue 2 with Interrupts */
  2697. + unsigned int toe_iq3_intr : 1; /* TOE Interrupt Queue 3 with Interrupts */
  2698. + unsigned int toe_iq0_full : 1; /* TOE Interrupt Queue 0 Full Interrupt */
  2699. + unsigned int toe_iq1_full : 1; /* TOE Interrupt Queue 1 Full Interrupt */
  2700. + unsigned int toe_iq2_full : 1; /* TOE Interrupt Queue 2 Full Interrupt */
  2701. + unsigned int toe_iq3_full : 1; /* TOE Interrupt Queue 3 Full Interrupt */
  2702. + } bits;
  2703. +} INTR_REG1_T;
  2704. +
  2705. +#define TOE_IQ3_FULL_INT_BIT BIT(31)
  2706. +#define TOE_IQ2_FULL_INT_BIT BIT(30)
  2707. +#define TOE_IQ1_FULL_INT_BIT BIT(29)
  2708. +#define TOE_IQ0_FULL_INT_BIT BIT(28)
  2709. +#define TOE_IQ3_INT_BIT BIT(27)
  2710. +#define TOE_IQ2_INT_BIT BIT(26)
  2711. +#define TOE_IQ1_INT_BIT BIT(25)
  2712. +#define TOE_IQ0_INT_BIT BIT(24)
  2713. +#define GMAC1_HWTQ13_EOF_INT_BIT BIT(23)
  2714. +#define GMAC1_HWTQ12_EOF_INT_BIT BIT(22)
  2715. +#define GMAC1_HWTQ11_EOF_INT_BIT BIT(21)
  2716. +#define GMAC1_HWTQ10_EOF_INT_BIT BIT(20)
  2717. +#define GMAC0_HWTQ03_EOF_INT_BIT BIT(19)
  2718. +#define GMAC0_HWTQ02_EOF_INT_BIT BIT(18)
  2719. +#define GMAC0_HWTQ01_EOF_INT_BIT BIT(17)
  2720. +#define GMAC0_HWTQ00_EOF_INT_BIT BIT(16)
  2721. +#define CLASS_RX_INT_BIT(x) BIT((x + 2))
  2722. +#define DEFAULT_Q1_INT_BIT BIT(1)
  2723. +#define DEFAULT_Q0_INT_BIT BIT(0)
  2724. +
  2725. +#define TOE_IQ_INT_BITS (TOE_IQ0_INT_BIT | TOE_IQ1_INT_BIT | \
  2726. + TOE_IQ2_INT_BIT | TOE_IQ3_INT_BIT)
  2727. +#define TOE_IQ_FULL_BITS (TOE_IQ0_FULL_INT_BIT | TOE_IQ1_FULL_INT_BIT | \
  2728. + TOE_IQ2_FULL_INT_BIT | TOE_IQ3_FULL_INT_BIT)
  2729. +#define TOE_IQ_ALL_BITS (TOE_IQ_INT_BITS | TOE_IQ_FULL_BITS)
  2730. +#define TOE_CLASS_RX_INT_BITS 0xfffc
  2731. +
  2732. +/*
  2733. + * Interrupt Status Register 2 (offset 0x0040)
  2734. + * Interrupt Mask Register 2 (offset 0x0044)
  2735. + * Interrupt Select Register 2 (offset 0x0048)
  2736. + */
  2737. +typedef union {
  2738. + unsigned int bits32;
  2739. + struct bit_0040 {
  2740. + unsigned int toe_q0_full : 1; // bit 0 TOE Queue 0 Full Interrupt
  2741. + unsigned int toe_q1_full : 1; // bit 1 TOE Queue 1 Full Interrupt
  2742. + unsigned int toe_q2_full : 1; // bit 2 TOE Queue 2 Full Interrupt
  2743. + unsigned int toe_q3_full : 1; // bit 3 TOE Queue 3 Full Interrupt
  2744. + unsigned int toe_q4_full : 1; // bit 4 TOE Queue 4 Full Interrupt
  2745. + unsigned int toe_q5_full : 1; // bit 5 TOE Queue 5 Full Interrupt
  2746. + unsigned int toe_q6_full : 1; // bit 6 TOE Queue 6 Full Interrupt
  2747. + unsigned int toe_q7_full : 1; // bit 7 TOE Queue 7 Full Interrupt
  2748. + unsigned int toe_q8_full : 1; // bit 8 TOE Queue 8 Full Interrupt
  2749. + unsigned int toe_q9_full : 1; // bit 9 TOE Queue 9 Full Interrupt
  2750. + unsigned int toe_q10_full : 1; // bit 10 TOE Queue 10 Full Interrupt
  2751. + unsigned int toe_q11_full : 1; // bit 11 TOE Queue 11 Full Interrupt
  2752. + unsigned int toe_q12_full : 1; // bit 12 TOE Queue 12 Full Interrupt
  2753. + unsigned int toe_q13_full : 1; // bit 13 TOE Queue 13 Full Interrupt
  2754. + unsigned int toe_q14_full : 1; // bit 14 TOE Queue 14 Full Interrupt
  2755. + unsigned int toe_q15_full : 1; // bit 15 TOE Queue 15 Full Interrupt
  2756. + unsigned int toe_q16_full : 1; // bit 16 TOE Queue 16 Full Interrupt
  2757. + unsigned int toe_q17_full : 1; // bit 17 TOE Queue 17 Full Interrupt
  2758. + unsigned int toe_q18_full : 1; // bit 18 TOE Queue 18 Full Interrupt
  2759. + unsigned int toe_q19_full : 1; // bit 19 TOE Queue 19 Full Interrupt
  2760. + unsigned int toe_q20_full : 1; // bit 20 TOE Queue 20 Full Interrupt
  2761. + unsigned int toe_q21_full : 1; // bit 21 TOE Queue 21 Full Interrupt
  2762. + unsigned int toe_q22_full : 1; // bit 22 TOE Queue 22 Full Interrupt
  2763. + unsigned int toe_q23_full : 1; // bit 23 TOE Queue 23 Full Interrupt
  2764. + unsigned int toe_q24_full : 1; // bit 24 TOE Queue 24 Full Interrupt
  2765. + unsigned int toe_q25_full : 1; // bit 25 TOE Queue 25 Full Interrupt
  2766. + unsigned int toe_q26_full : 1; // bit 26 TOE Queue 26 Full Interrupt
  2767. + unsigned int toe_q27_full : 1; // bit 27 TOE Queue 27 Full Interrupt
  2768. + unsigned int toe_q28_full : 1; // bit 28 TOE Queue 28 Full Interrupt
  2769. + unsigned int toe_q29_full : 1; // bit 29 TOE Queue 29 Full Interrupt
  2770. + unsigned int toe_q30_full : 1; // bit 30 TOE Queue 30 Full Interrupt
  2771. + unsigned int toe_q31_full : 1; // bit 31 TOE Queue 31 Full Interrupt
  2772. + } bits;
  2773. +} INTR_REG2_T;
  2774. +
  2775. +#define TOE_QL_FULL_INT_BIT(x) BIT(x)
  2776. +
  2777. +/*
  2778. + * Interrupt Status Register 3 (offset 0x0050)
  2779. + * Interrupt Mask Register 3 (offset 0x0054)
  2780. + * Interrupt Select Register 3 (offset 0x0058)
  2781. + */
  2782. +typedef union {
  2783. + unsigned int bits32;
  2784. + struct bit_0050 {
  2785. + unsigned int toe_q32_full : 1; // bit 32 TOE Queue 32 Full Interrupt
  2786. + unsigned int toe_q33_full : 1; // bit 33 TOE Queue 33 Full Interrupt
  2787. + unsigned int toe_q34_full : 1; // bit 34 TOE Queue 34 Full Interrupt
  2788. + unsigned int toe_q35_full : 1; // bit 35 TOE Queue 35 Full Interrupt
  2789. + unsigned int toe_q36_full : 1; // bit 36 TOE Queue 36 Full Interrupt
  2790. + unsigned int toe_q37_full : 1; // bit 37 TOE Queue 37 Full Interrupt
  2791. + unsigned int toe_q38_full : 1; // bit 38 TOE Queue 38 Full Interrupt
  2792. + unsigned int toe_q39_full : 1; // bit 39 TOE Queue 39 Full Interrupt
  2793. + unsigned int toe_q40_full : 1; // bit 40 TOE Queue 40 Full Interrupt
  2794. + unsigned int toe_q41_full : 1; // bit 41 TOE Queue 41 Full Interrupt
  2795. + unsigned int toe_q42_full : 1; // bit 42 TOE Queue 42 Full Interrupt
  2796. + unsigned int toe_q43_full : 1; // bit 43 TOE Queue 43 Full Interrupt
  2797. + unsigned int toe_q44_full : 1; // bit 44 TOE Queue 44 Full Interrupt
  2798. + unsigned int toe_q45_full : 1; // bit 45 TOE Queue 45 Full Interrupt
  2799. + unsigned int toe_q46_full : 1; // bit 46 TOE Queue 46 Full Interrupt
  2800. + unsigned int toe_q47_full : 1; // bit 47 TOE Queue 47 Full Interrupt
  2801. + unsigned int toe_q48_full : 1; // bit 48 TOE Queue 48 Full Interrupt
  2802. + unsigned int toe_q49_full : 1; // bit 49 TOE Queue 49 Full Interrupt
  2803. + unsigned int toe_q50_full : 1; // bit 50 TOE Queue 50 Full Interrupt
  2804. + unsigned int toe_q51_full : 1; // bit 51 TOE Queue 51 Full Interrupt
  2805. + unsigned int toe_q52_full : 1; // bit 52 TOE Queue 52 Full Interrupt
  2806. + unsigned int toe_q53_full : 1; // bit 53 TOE Queue 53 Full Interrupt
  2807. + unsigned int toe_q54_full : 1; // bit 54 TOE Queue 54 Full Interrupt
  2808. + unsigned int toe_q55_full : 1; // bit 55 TOE Queue 55 Full Interrupt
  2809. + unsigned int toe_q56_full : 1; // bit 56 TOE Queue 56 Full Interrupt
  2810. + unsigned int toe_q57_full : 1; // bit 57 TOE Queue 57 Full Interrupt
  2811. + unsigned int toe_q58_full : 1; // bit 58 TOE Queue 58 Full Interrupt
  2812. + unsigned int toe_q59_full : 1; // bit 59 TOE Queue 59 Full Interrupt
  2813. + unsigned int toe_q60_full : 1; // bit 60 TOE Queue 60 Full Interrupt
  2814. + unsigned int toe_q61_full : 1; // bit 61 TOE Queue 61 Full Interrupt
  2815. + unsigned int toe_q62_full : 1; // bit 62 TOE Queue 62 Full Interrupt
  2816. + unsigned int toe_q63_full : 1; // bit 63 TOE Queue 63 Full Interrupt
  2817. + } bits;
  2818. +} INTR_REG3_T;
  2819. +
  2820. +#define TOE_QH_FULL_INT_BIT(x) BIT(x-32)
  2821. +
  2822. +/*
  2823. + * Interrupt Status Register 4 (offset 0x0060)
  2824. + * Interrupt Mask Register 4 (offset 0x0064)
  2825. + * Interrupt Select Register 4 (offset 0x0068)
  2826. + */
  2827. +typedef union {
  2828. + unsigned char byte;
  2829. + struct bit_0060 {
  2830. + unsigned char status_changed : 1; // Status Changed Intr for RGMII Mode
  2831. + unsigned char rx_overrun : 1; // GMAC Rx FIFO overrun interrupt
  2832. + unsigned char tx_pause_off : 1; // received pause off frame interrupt
  2833. + unsigned char rx_pause_off : 1; // received pause off frame interrupt
  2834. + unsigned char tx_pause_on : 1; // transmit pause on frame interrupt
  2835. + unsigned char rx_pause_on : 1; // received pause on frame interrupt
  2836. + unsigned char cnt_full : 1; // MIB counters half full interrupt
  2837. + unsigned char reserved : 1; //
  2838. + } _PACKED_ bits;
  2839. +} _PACKED_ GMAC_INTR_T;
  2840. +
  2841. +typedef union {
  2842. + unsigned int bits32;
  2843. + struct bit_0060_2 {
  2844. + unsigned int swfq_empty : 1; // bit 0 Software Free Queue Empty Intr.
  2845. + unsigned int hwfq_empty : 1; // bit 1 Hardware Free Queue Empty Intr.
  2846. + unsigned int class_qf_int : 14; // bit 15:2 Classification Rx Queue13-0 Full Intr.
  2847. + GMAC_INTR_T gmac0;
  2848. + GMAC_INTR_T gmac1;
  2849. + } bits;
  2850. +} INTR_REG4_T;
  2851. +
  2852. +#define GMAC1_RESERVED_INT_BIT BIT(31)
  2853. +#define GMAC1_MIB_INT_BIT BIT(30)
  2854. +#define GMAC1_RX_PAUSE_ON_INT_BIT BIT(29)
  2855. +#define GMAC1_TX_PAUSE_ON_INT_BIT BIT(28)
  2856. +#define GMAC1_RX_PAUSE_OFF_INT_BIT BIT(27)
  2857. +#define GMAC1_TX_PAUSE_OFF_INT_BIT BIT(26)
  2858. +#define GMAC1_RX_OVERRUN_INT_BIT BIT(25)
  2859. +#define GMAC1_STATUS_CHANGE_INT_BIT BIT(24)
  2860. +#define GMAC0_RESERVED_INT_BIT BIT(23)
  2861. +#define GMAC0_MIB_INT_BIT BIT(22)
  2862. +#define GMAC0_RX_PAUSE_ON_INT_BIT BIT(21)
  2863. +#define GMAC0_TX_PAUSE_ON_INT_BIT BIT(20)
  2864. +#define GMAC0_RX_PAUSE_OFF_INT_BIT BIT(19)
  2865. +#define GMAC0_TX_PAUSE_OFF_INT_BIT BIT(18)
  2866. +#define GMAC0_RX_OVERRUN_INT_BIT BIT(17)
  2867. +#define GMAC0_STATUS_CHANGE_INT_BIT BIT(16)
  2868. +#define CLASS_RX_FULL_INT_BIT(x) BIT((x+2))
  2869. +#define HWFQ_EMPTY_INT_BIT BIT(1)
  2870. +#define SWFQ_EMPTY_INT_BIT BIT(0)
  2871. +
  2872. +#if 1
  2873. +#define GMAC0_INT_BITS (GMAC0_MIB_INT_BIT)
  2874. +#define GMAC1_INT_BITS (GMAC1_MIB_INT_BIT)
  2875. +#else
  2876. +#define GMAC0_INT_BITS (GMAC0_RESERVED_INT_BIT | GMAC0_MIB_INT_BIT | \
  2877. + GMAC0_RX_PAUSE_ON_INT_BIT | GMAC0_TX_PAUSE_ON_INT_BIT | \
  2878. + GMAC0_RX_PAUSE_OFF_INT_BIT | GMAC0_TX_PAUSE_OFF_INT_BIT | \
  2879. + GMAC0_RX_OVERRUN_INT_BIT | GMAC0_STATUS_CHANGE_INT_BIT)
  2880. +#define GMAC1_INT_BITS (GMAC1_RESERVED_INT_BIT | GMAC1_MIB_INT_BIT | \
  2881. + GMAC1_RX_PAUSE_ON_INT_BIT | GMAC1_TX_PAUSE_ON_INT_BIT | \
  2882. + GMAC1_RX_PAUSE_OFF_INT_BIT | GMAC1_TX_PAUSE_OFF_INT_BIT | \
  2883. + GMAC1_RX_OVERRUN_INT_BIT | GMAC1_STATUS_CHANGE_INT_BIT)
  2884. +#endif
  2885. +
  2886. +#define CLASS_RX_FULL_INT_BITS 0xfffc
  2887. +
  2888. +/*
  2889. + * GLOBAL_QUEUE_THRESHOLD_REG (offset 0x0070)
  2890. + */
  2891. +typedef union {
  2892. + unsigned int bits32;
  2893. + struct bit_0070_2 {
  2894. + unsigned int swfq_empty : 8; // 7:0 Software Free Queue Empty Threshold
  2895. + unsigned int hwfq_empty : 8; // 15:8 Hardware Free Queue Empty Threshold
  2896. + unsigned int intrq : 8; // 23:16
  2897. + unsigned int toe_class : 8; // 31:24
  2898. + } bits;
  2899. +} QUEUE_THRESHOLD_T;
  2900. +
  2901. +
  2902. +/*
  2903. + * GMAC DMA Control Register
  2904. + * GMAC0 offset 0x8000
  2905. + * GMAC1 offset 0xC000
  2906. + */
  2907. +typedef union {
  2908. + unsigned int bits32;
  2909. + struct bit_8000 {
  2910. + unsigned int td_bus : 2; // bit 1:0 Peripheral Bus Width
  2911. + unsigned int td_burst_size : 2; // bit 3:2 TxDMA max burst size for every AHB request
  2912. + unsigned int td_prot : 4; // bit 7:4 TxDMA protection control
  2913. + unsigned int rd_bus : 2; // bit 9:8 Peripheral Bus Width
  2914. + unsigned int rd_burst_size : 2; // bit 11:10 DMA max burst size for every AHB request
  2915. + unsigned int rd_prot : 4; // bit 15:12 DMA Protection Control
  2916. + unsigned int rd_insert_bytes : 2; // bit 17:16
  2917. + unsigned int reserved : 10; // bit 27:18
  2918. + unsigned int drop_small_ack : 1; // bit 28 1: Drop, 0: Accept
  2919. + unsigned int loopback : 1; // bit 29 Loopback TxDMA to RxDMA
  2920. + unsigned int td_enable : 1; // bit 30 Tx DMA Enable
  2921. + unsigned int rd_enable : 1; // bit 31 Rx DMA Enable
  2922. + } bits;
  2923. +} GMAC_DMA_CTRL_T;
  2924. +
  2925. +/*
  2926. + * GMAC Tx Weighting Control Register 0
  2927. + * GMAC0 offset 0x8004
  2928. + * GMAC1 offset 0xC004
  2929. + */
  2930. +typedef union {
  2931. + unsigned int bits32;
  2932. + struct bit_8004 {
  2933. + unsigned int hw_tq0 : 6; // bit 5:0 HW TX Queue 3
  2934. + unsigned int hw_tq1 : 6; // bit 11:6 HW TX Queue 2
  2935. + unsigned int hw_tq2 : 6; // bit 17:12 HW TX Queue 1
  2936. + unsigned int hw_tq3 : 6; // bit 23:18 HW TX Queue 0
  2937. + unsigned int reserved : 8; // bit 31:24
  2938. + } bits;
  2939. +} GMAC_TX_WCR0_T; /* Weighting Control Register 0 */
  2940. +
  2941. +/*
  2942. + * GMAC Tx Weighting Control Register 1
  2943. + * GMAC0 offset 0x8008
  2944. + * GMAC1 offset 0xC008
  2945. + */
  2946. +typedef union {
  2947. + unsigned int bits32;
  2948. + struct bit_8008 {
  2949. + unsigned int sw_tq0 : 5; // bit 4:0 SW TX Queue 0
  2950. + unsigned int sw_tq1 : 5; // bit 9:5 SW TX Queue 1
  2951. + unsigned int sw_tq2 : 5; // bit 14:10 SW TX Queue 2
  2952. + unsigned int sw_tq3 : 5; // bit 19:15 SW TX Queue 3
  2953. + unsigned int sw_tq4 : 5; // bit 24:20 SW TX Queue 4
  2954. + unsigned int sw_tq5 : 5; // bit 29:25 SW TX Queue 5
  2955. + unsigned int reserved : 2; // bit 31:30
  2956. + } bits;
  2957. +} GMAC_TX_WCR1_T; /* Weighting Control Register 1 */
  2958. +
  2959. +/*
  2960. + * Queue Read/Write Pointer
  2961. + * GMAC SW TX Queue 0~5 Read/Write Pointer register
  2962. + * GMAC0 offset 0x800C ~ 0x8020
  2963. + * GMAC1 offset 0xC00C ~ 0xC020
  2964. + * GMAC HW TX Queue 0~3 Read/Write Pointer register
  2965. + * GMAC0 offset 0x8024 ~ 0x8030
  2966. + * GMAC1 offset 0xC024 ~ 0xC030
  2967. + *
  2968. + * see DMA_RWPTR_T structure
  2969. + */
  2970. +
  2971. +/*
  2972. + * GMAC DMA Tx First Description Address Register
  2973. + * GMAC0 offset 0x8038
  2974. + * GMAC1 offset 0xC038
  2975. + */
  2976. +typedef union {
  2977. + unsigned int bits32;
  2978. + struct bit_8038 {
  2979. + unsigned int reserved : 3;
  2980. + unsigned int td_busy : 1; // bit 3 1: TxDMA busy; 0: TxDMA idle
  2981. + unsigned int td_first_des_ptr : 28; // bit 31:4 first descriptor address
  2982. + } bits;
  2983. +} GMAC_TXDMA_FIRST_DESC_T;
  2984. +
  2985. +/*
  2986. + * GMAC DMA Tx Current Description Address Register
  2987. + * GMAC0 offset 0x803C
  2988. + * GMAC1 offset 0xC03C
  2989. + */
  2990. +typedef union {
  2991. + unsigned int bits32;
  2992. + struct bit_803C {
  2993. + unsigned int reserved : 4;
  2994. + unsigned int td_curr_desc_ptr : 28; // bit 31:4 current descriptor address
  2995. + } bits;
  2996. +} GMAC_TXDMA_CURR_DESC_T;
  2997. +
  2998. +/*
  2999. + * GMAC DMA Tx Description Word 0 Register
  3000. + * GMAC0 offset 0x8040
  3001. + * GMAC1 offset 0xC040
  3002. + */
  3003. +typedef union {
  3004. + unsigned int bits32;
  3005. + struct bit_8040 {
  3006. + unsigned int buffer_size : 16; // bit 15:0 Transfer size
  3007. + unsigned int desc_count : 6; // bit 21:16 number of descriptors used for the current frame
  3008. + unsigned int status_tx_ok : 1; // bit 22 Tx Status, 1: Successful 0: Failed
  3009. + unsigned int status_rvd : 6; // bit 28:23 Tx Status, Reserved bits
  3010. + unsigned int perr : 1; // bit 29 protocol error during processing this descriptor
  3011. + unsigned int derr : 1; // bit 30 data error during processing this descriptor
  3012. + unsigned int reserved : 1; // bit 31
  3013. + } bits;
  3014. +} GMAC_TXDESC_0_T;
  3015. +
  3016. +/*
  3017. + * GMAC DMA Tx Description Word 1 Register
  3018. + * GMAC0 offset 0x8044
  3019. + * GMAC1 offset 0xC044
  3020. + */
  3021. +typedef union {
  3022. + unsigned int bits32;
  3023. + struct txdesc_word1 {
  3024. + unsigned int byte_count : 16; // bit 15: 0 Tx Frame Byte Count
  3025. + unsigned int mtu_enable : 1; // bit 16 TSS segmentation use MTU setting
  3026. + unsigned int ip_chksum : 1; // bit 17 IPV4 Header Checksum Enable
  3027. + unsigned int ipv6_enable : 1; // bit 18 IPV6 Tx Enable
  3028. + unsigned int tcp_chksum : 1; // bit 19 TCP Checksum Enable
  3029. + unsigned int udp_chksum : 1; // bit 20 UDP Checksum Enable
  3030. + unsigned int bypass_tss : 1; // bit 21
  3031. + unsigned int ip_fixed_len : 1; // bit 22
  3032. + unsigned int reserved : 9; // bit 31:23 Tx Flag, Reserved
  3033. + } bits;
  3034. +} GMAC_TXDESC_1_T;
  3035. +
  3036. +#define TSS_IP_FIXED_LEN_BIT BIT(22)
  3037. +#define TSS_UDP_CHKSUM_BIT BIT(20)
  3038. +#define TSS_TCP_CHKSUM_BIT BIT(19)
  3039. +#define TSS_IPV6_ENABLE_BIT BIT(18)
  3040. +#define TSS_IP_CHKSUM_BIT BIT(17)
  3041. +#define TSS_MTU_ENABLE_BIT BIT(16)
  3042. +
  3043. +/*
  3044. + * GMAC DMA Tx Description Word 2 Register
  3045. + * GMAC0 offset 0x8048
  3046. + * GMAC1 offset 0xC048
  3047. + */
  3048. +typedef union {
  3049. + unsigned int bits32;
  3050. + unsigned int buf_adr;
  3051. +} GMAC_TXDESC_2_T;
  3052. +
  3053. +/*
  3054. + * GMAC DMA Tx Description Word 3 Register
  3055. + * GMAC0 offset 0x804C
  3056. + * GMAC1 offset 0xC04C
  3057. + */
  3058. +typedef union {
  3059. + unsigned int bits32;
  3060. + struct txdesc_word3 {
  3061. + unsigned int mtu_size : 11; // bit 10: 0 Tx Frame Byte Count
  3062. + unsigned int reserved : 18; // bit 28:11
  3063. + unsigned int eofie : 1; // bit 29 End of frame interrupt enable
  3064. + unsigned int sof_eof : 2; // bit 31:30 11: only one, 10: first, 01: last, 00: linking
  3065. + } bits;
  3066. +} GMAC_TXDESC_3_T;
  3067. +#define SOF_EOF_BIT_MASK 0x3fffffff
  3068. +#define SOF_BIT 0x80000000
  3069. +#define EOF_BIT 0x40000000
  3070. +#define EOFIE_BIT BIT(29)
  3071. +#define MTU_SIZE_BIT_MASK 0x7ff
  3072. +
  3073. +/*
  3074. + * GMAC Tx Descriptor
  3075. + */
  3076. +typedef struct {
  3077. + GMAC_TXDESC_0_T word0;
  3078. + GMAC_TXDESC_1_T word1;
  3079. + GMAC_TXDESC_2_T word2;
  3080. + GMAC_TXDESC_3_T word3;
  3081. +} GMAC_TXDESC_T;
  3082. +
  3083. +/*
  3084. + * GMAC DMA Rx First Description Address Register
  3085. + * GMAC0 offset 0x8058
  3086. + * GMAC1 offset 0xC058
  3087. + */
  3088. +typedef union {
  3089. + unsigned int bits32;
  3090. + struct bit_8058 {
  3091. + unsigned int reserved : 3; // bit 2:0
  3092. + unsigned int rd_busy : 1; // bit 3 1-RxDMA busy; 0-RxDMA idle
  3093. + unsigned int rd_first_des_ptr : 28; // bit 31:4 first descriptor address
  3094. + } bits;
  3095. +} GMAC_RXDMA_FIRST_DESC_T;
  3096. +
  3097. +/*
  3098. + * GMAC DMA Rx Current Description Address Register
  3099. + * GMAC0 offset 0x805C
  3100. + * GMAC1 offset 0xC05C
  3101. + */
  3102. +typedef union {
  3103. + unsigned int bits32;
  3104. + struct bit_805C {
  3105. + unsigned int reserved : 4; // bit 3:0
  3106. + unsigned int rd_curr_des_ptr : 28; // bit 31:4 current descriptor address
  3107. + } bits;
  3108. +} GMAC_RXDMA_CURR_DESC_T;
  3109. +
  3110. +/*
  3111. + * GMAC DMA Rx Description Word 0 Register
  3112. + * GMAC0 offset 0x8060
  3113. + * GMAC1 offset 0xC060
  3114. + */
  3115. +typedef union {
  3116. + unsigned int bits32;
  3117. + struct bit_8060 {
  3118. + unsigned int buffer_size : 16; // bit 15:0 number of descriptors used for the current frame
  3119. + unsigned int desc_count : 6; // bit 21:16 number of descriptors used for the current frame
  3120. + unsigned int status : 4; // bit 24:22 Status of rx frame
  3121. + unsigned int chksum_status : 3; // bit 28:26 Check Sum Status
  3122. + unsigned int perr : 1; // bit 29 protocol error during processing this descriptor
  3123. + unsigned int derr : 1; // bit 30 data error during processing this descriptor
  3124. + unsigned int drop : 1; // bit 31 TOE/CIS Queue Full dropped packet to default queue
  3125. + } bits;
  3126. +} GMAC_RXDESC_0_T;
  3127. +
  3128. +#define GMAC_RXDESC_0_T_derr BIT(30)
  3129. +#define GMAC_RXDESC_0_T_perr BIT(29)
  3130. +#define GMAC_RXDESC_0_T_chksum_status(x) BIT((x+26))
  3131. +#define GMAC_RXDESC_0_T_status(x) BIT((x+22))
  3132. +#define GMAC_RXDESC_0_T_desc_count(x) BIT((x+16))
  3133. +
  3134. +#define RX_CHKSUM_IP_UDP_TCP_OK 0
  3135. +#define RX_CHKSUM_IP_OK_ONLY 1
  3136. +#define RX_CHKSUM_NONE 2
  3137. +#define RX_CHKSUM_IP_ERR_UNKNOWN 4
  3138. +#define RX_CHKSUM_IP_ERR 5
  3139. +#define RX_CHKSUM_TCP_UDP_ERR 6
  3140. +#define RX_CHKSUM_NUM 8
  3141. +
  3142. +#define RX_STATUS_GOOD_FRAME 0
  3143. +#define RX_STATUS_TOO_LONG_GOOD_CRC 1
  3144. +#define RX_STATUS_RUNT_FRAME 2
  3145. +#define RX_STATUS_SFD_NOT_FOUND 3
  3146. +#define RX_STATUS_CRC_ERROR 4
  3147. +#define RX_STATUS_TOO_LONG_BAD_CRC 5
  3148. +#define RX_STATUS_ALIGNMENT_ERROR 6
  3149. +#define RX_STATUS_TOO_LONG_BAD_ALIGN 7
  3150. +#define RX_STATUS_RX_ERR 8
  3151. +#define RX_STATUS_DA_FILTERED 9
  3152. +#define RX_STATUS_BUFFER_FULL 10
  3153. +#define RX_STATUS_NUM 16
  3154. +
  3155. +
  3156. +/*
  3157. + * GMAC DMA Rx Description Word 1 Register
  3158. + * GMAC0 offset 0x8064
  3159. + * GMAC1 offset 0xC064
  3160. + */
  3161. +typedef union {
  3162. + unsigned int bits32;
  3163. + struct rxdesc_word1 {
  3164. + unsigned int byte_count : 16; // bit 15: 0 Rx Frame Byte Count
  3165. + unsigned int sw_id : 16; // bit 31:16 Software ID
  3166. + } bits;
  3167. +} GMAC_RXDESC_1_T;
  3168. +
  3169. +/*
  3170. + * GMAC DMA Rx Description Word 2 Register
  3171. + * GMAC0 offset 0x8068
  3172. + * GMAC1 offset 0xC068
  3173. + */
  3174. +typedef union {
  3175. + unsigned int bits32;
  3176. + unsigned int buf_adr;
  3177. +} GMAC_RXDESC_2_T;
  3178. +
  3179. +#define RX_INSERT_NONE 0
  3180. +#define RX_INSERT_1_BYTE 1
  3181. +#define RX_INSERT_2_BYTE 2
  3182. +#define RX_INSERT_3_BYTE 3
  3183. +
  3184. +#define RX_INSERT_BYTES RX_INSERT_2_BYTE
  3185. +/*
  3186. + * GMAC DMA Rx Description Word 3 Register
  3187. + * GMAC0 offset 0x806C
  3188. + * GMAC1 offset 0xC06C
  3189. + */
  3190. +typedef union {
  3191. + unsigned int bits32;
  3192. + struct rxdesc_word3 {
  3193. + unsigned int l3_offset : 8; // bit 7: 0 L3 data offset
  3194. + unsigned int l4_offset : 8; // bit 15: 8 L4 data offset
  3195. + unsigned int l7_offset : 8; // bit 23: 16 L7 data offset
  3196. + unsigned int dup_ack : 1; // bit 24 Duplicated ACK detected
  3197. + unsigned int abnormal : 1; // bit 25 abnormal case found
  3198. + unsigned int option : 1; // bit 26 IPV4 option or IPV6 extension header
  3199. + unsigned int out_of_seq : 1; // bit 27 Out of Sequence packet
  3200. + unsigned int ctrl_flag : 1; // bit 28 Control Flag is present
  3201. + unsigned int eofie : 1; // bit 29 End of frame interrupt enable
  3202. + unsigned int sof_eof : 2; // bit 31:30 11: only one, 10: first, 01: last, 00: linking
  3203. + } bits;
  3204. +} GMAC_RXDESC_3_T;
  3205. +
  3206. +/*
  3207. + * GMAC Rx Descriptor
  3208. + */
  3209. +typedef struct {
  3210. + GMAC_RXDESC_0_T word0;
  3211. + GMAC_RXDESC_1_T word1;
  3212. + GMAC_RXDESC_2_T word2;
  3213. + GMAC_RXDESC_3_T word3;
  3214. +} GMAC_RXDESC_T;
  3215. +
  3216. +/*
  3217. + * GMAC Hash Engine Enable/Action Register 0 Offset Register
  3218. + * GMAC0 offset 0x8070
  3219. + * GMAC1 offset 0xC070
  3220. + */
  3221. +typedef union {
  3222. + unsigned int bits32;
  3223. + struct bit_8070 {
  3224. + unsigned int mr0hel : 6; // bit 5:0 match rule 0 hash entry size
  3225. + unsigned int mr0_action : 5; // bit 10:6 Matching Rule 0 action offset
  3226. + unsigned int reserved0 : 4; // bit 14:11
  3227. + unsigned int mr0en : 1; // bit 15 Enable Matching Rule 0
  3228. + unsigned int mr1hel : 6; // bit 21:16 match rule 1 hash entry size
  3229. + unsigned int mr1_action : 5; // bit 26:22 Matching Rule 1 action offset
  3230. + unsigned int timing : 3; // bit 29:27
  3231. + unsigned int reserved1 : 1; // bit 30
  3232. + unsigned int mr1en : 1; // bit 31 Enable Matching Rule 1
  3233. + } bits;
  3234. +} GMAC_HASH_ENABLE_REG0_T;
  3235. +
  3236. +/*
  3237. + * GMAC Hash Engine Enable/Action Register 1 Offset Register
  3238. + * GMAC0 offset 0x8074
  3239. + * GMAC1 offset 0xC074
  3240. + */
  3241. +typedef union {
  3242. + unsigned int bits32;
  3243. + struct bit_8074 {
  3244. + unsigned int mr2hel : 6; // bit 5:0 match rule 2 hash entry size
  3245. + unsigned int mr2_action : 5; // bit 10:6 Matching Rule 2 action offset
  3246. + unsigned int reserved2 : 4; // bit 14:11
  3247. + unsigned int mr2en : 1; // bit 15 Enable Matching Rule 2
  3248. + unsigned int mr3hel : 6; // bit 21:16 match rule 3 hash entry size
  3249. + unsigned int mr3_action : 5; // bit 26:22 Matching Rule 3 action offset
  3250. + unsigned int reserved1 : 4; // bit 30:27
  3251. + unsigned int mr3en : 1; // bit 31 Enable Matching Rule 3
  3252. + } bits;
  3253. +} GMAC_HASH_ENABLE_REG1_T;
  3254. +
  3255. +/*
  3256. + * GMAC Matching Rule Control Register 0
  3257. + * GMAC0 offset 0x8078
  3258. + * GMAC1 offset 0xC078
  3259. + */
  3260. +typedef union {
  3261. + unsigned int bits32;
  3262. + struct bit_8078 {
  3263. + unsigned int sprx : 8; // bit 7:0 Support Protocol Register 7:0
  3264. + unsigned int reserved2 : 4; // bit 11:8
  3265. + unsigned int tos_traffic : 1; // bit 12 IPV4 TOS or IPV6 Traffice Class
  3266. + unsigned int flow_lable : 1; // bit 13 IPV6 Flow label
  3267. + unsigned int ip_hdr_len : 1; // bit 14 IPV4 Header length
  3268. + unsigned int ip_version : 1; // bit 15 0: IPV4, 1: IPV6
  3269. + unsigned int reserved1 : 3; // bit 18:16
  3270. + unsigned int pppoe : 1; // bit 19 PPPoE Session ID enable
  3271. + unsigned int vlan : 1; // bit 20 VLAN ID enable
  3272. + unsigned int ether_type : 1; // bit 21 Ethernet type enable
  3273. + unsigned int sa : 1; // bit 22 MAC SA enable
  3274. + unsigned int da : 1; // bit 23 MAC DA enable
  3275. + unsigned int priority : 3; // bit 26:24 priority if multi-rules matched
  3276. + unsigned int port : 1; // bit 27 PORT ID matching enable
  3277. + unsigned int l7 : 1; // bit 28 L7 matching enable
  3278. + unsigned int l4 : 1; // bit 29 L4 matching enable
  3279. + unsigned int l3 : 1; // bit 30 L3 matching enable
  3280. + unsigned int l2 : 1; // bit 31 L2 matching enable
  3281. + } bits;
  3282. +} GMAC_MRxCR0_T;
  3283. +
  3284. +#define MR_L2_BIT BIT(31)
  3285. +#define MR_L3_BIT BIT(30)
  3286. +#define MR_L4_BIT BIT(29)
  3287. +#define MR_L7_BIT BIT(28)
  3288. +#define MR_PORT_BIT BIT(27)
  3289. +#define MR_PRIORITY_BIT BIT(26)
  3290. +#define MR_DA_BIT BIT(23)
  3291. +#define MR_SA_BIT BIT(22)
  3292. +#define MR_ETHER_TYPE_BIT BIT(21)
  3293. +#define MR_VLAN_BIT BIT(20)
  3294. +#define MR_PPPOE_BIT BIT(19)
  3295. +#define MR_IP_VER_BIT BIT(15)
  3296. +#define MR_IP_HDR_LEN_BIT BIT(14)
  3297. +#define MR_FLOW_LABLE_BIT BIT(13)
  3298. +#define MR_TOS_TRAFFIC_BIT BIT(12)
  3299. +#define MR_SPR_BIT(x) BIT(x)
  3300. +#define MR_SPR_BITS 0xff
  3301. +
  3302. +/*
  3303. + * GMAC Matching Rule Control Register 1
  3304. + * GMAC0 offset 0x807C
  3305. + * GMAC1 offset 0xC07C
  3306. + */
  3307. +typedef union {
  3308. + unsigned int bits32;
  3309. + struct bit_807C {
  3310. + unsigned int l4_byte0_15 : 16; // bit 15: 0
  3311. + unsigned int dip_netmask : 7; // bit 22:16 Dest IP net mask, number of mask bits
  3312. + unsigned int dip : 1; // bit 23 Dest IP
  3313. + unsigned int sip_netmask : 7; // bit 30:24 Srce IP net mask, number of mask bits
  3314. + unsigned int sip : 1; // bit 31 Srce IP
  3315. + } bits;
  3316. +} GMAC_MRxCR1_T;
  3317. +
  3318. +/*
  3319. + * GMAC Matching Rule Control Register 2
  3320. + * GMAC0 offset 0x8080
  3321. + * GMAC1 offset 0xC080
  3322. + */
  3323. +typedef union {
  3324. + unsigned int bits32;
  3325. + struct bit_8080 {
  3326. + unsigned int l7_byte0_23 : 24; // bit 23:0
  3327. + unsigned int l4_byte16_24 : 8; // bit 31: 24
  3328. + } bits;
  3329. +} GMAC_MRxCR2_T;
  3330. +
  3331. +/*
  3332. + * GMAC Support registers
  3333. + * GMAC0 offset 0x80A8
  3334. + * GMAC1 offset 0xC0A8
  3335. + */
  3336. +typedef union {
  3337. + unsigned int bits32;
  3338. + struct bit_80A8 {
  3339. + unsigned int protocol : 8; // bit 7:0 Supported protocol
  3340. + unsigned int swap : 3; // bit 10:8 Swap
  3341. + unsigned int reserved : 21; // bit 31:11
  3342. + } bits;
  3343. +} GMAC_SPR_T;
  3344. +
  3345. +/*
  3346. + * GMAC_AHB_WEIGHT registers
  3347. + * GMAC0 offset 0x80C8
  3348. + * GMAC1 offset 0xC0C8
  3349. + */
  3350. +typedef union {
  3351. + unsigned int bits32;
  3352. + struct bit_80C8 {
  3353. + unsigned int hash_weight : 5; // 4:0
  3354. + unsigned int rx_weight : 5; // 9:5
  3355. + unsigned int tx_weight : 5; // 14:10
  3356. + unsigned int pre_req : 5; // 19:15 Rx Data Pre Request FIFO Threshold
  3357. + unsigned int tqDV_threshold : 5; // 24:20 DMA TqCtrl to Start tqDV FIFO Threshold
  3358. + unsigned int reserved : 7; // 31:25
  3359. + } bits;
  3360. +} GMAC_AHB_WEIGHT_T;
  3361. +
  3362. +/*
  3363. + * the register structure of GMAC
  3364. + */
  3365. +
  3366. +/*
  3367. + * GMAC RX FLTR
  3368. + * GMAC0 Offset 0xA00C
  3369. + * GMAC1 Offset 0xE00C
  3370. + */
  3371. +typedef union {
  3372. + unsigned int bits32;
  3373. + struct bit1_000c {
  3374. + unsigned int unicast : 1; /* enable receive of unicast frames that are sent to STA address */
  3375. + unsigned int multicast : 1; /* enable receive of multicast frames that pass multicast filter */
  3376. + unsigned int broadcast : 1; /* enable receive of broadcast frames */
  3377. + unsigned int promiscuous : 1; /* enable receive of all frames */
  3378. + unsigned int error : 1; /* enable receive of all error frames */
  3379. + unsigned int : 27;
  3380. + } bits;
  3381. +} GMAC_RX_FLTR_T;
  3382. +
  3383. +/*
  3384. + * GMAC Configuration 0
  3385. + * GMAC0 Offset 0xA018
  3386. + * GMAC1 Offset 0xE018
  3387. + */
  3388. +typedef union {
  3389. + unsigned int bits32;
  3390. + struct bit1_0018 {
  3391. + unsigned int dis_tx : 1; /* 0: disable transmit */
  3392. + unsigned int dis_rx : 1; /* 1: disable receive */
  3393. + unsigned int loop_back : 1; /* 2: transmit data loopback enable */
  3394. + unsigned int flow_ctrl : 1; /* 3: flow control also trigged by Rx queues */
  3395. + unsigned int adj_ifg : 4; /* 4-7: adjust IFG from 96+/-56 */
  3396. + unsigned int max_len : 3; /* 8-10 maximum receive frame length allowed */
  3397. + unsigned int dis_bkoff : 1; /* 11: disable back-off function */
  3398. + unsigned int dis_col : 1; /* 12: disable 16 collisions abort function */
  3399. + unsigned int sim_test : 1; /* 13: speed up timers in simulation */
  3400. + unsigned int rx_fc_en : 1; /* 14: RX flow control enable */
  3401. + unsigned int tx_fc_en : 1; /* 15: TX flow control enable */
  3402. + unsigned int rgmii_en : 1; /* 16: RGMII in-band status enable */
  3403. + unsigned int ipv4_rx_chksum : 1; /* 17: IPv4 RX Checksum enable */
  3404. + unsigned int ipv6_rx_chksum : 1; /* 18: IPv6 RX Checksum enable */
  3405. + unsigned int rx_tag_remove : 1; /* 19: Remove Rx VLAN tag */
  3406. + unsigned int rgmm_edge : 1; // 20
  3407. + unsigned int rxc_inv : 1; // 21
  3408. + unsigned int ipv6_exthdr_order : 1; // 22
  3409. + unsigned int rx_err_detect : 1; // 23
  3410. + unsigned int port0_chk_hwq : 1; // 24
  3411. + unsigned int port1_chk_hwq : 1; // 25
  3412. + unsigned int port0_chk_toeq : 1; // 26
  3413. + unsigned int port1_chk_toeq : 1; // 27
  3414. + unsigned int port0_chk_classq : 1; // 28
  3415. + unsigned int port1_chk_classq : 1; // 29
  3416. + unsigned int reserved : 2; // 31
  3417. + } bits;
  3418. +} GMAC_CONFIG0_T;
  3419. +
  3420. +/*
  3421. + * GMAC Configuration 1
  3422. + * GMAC0 Offset 0xA01C
  3423. + * GMAC1 Offset 0xE01C
  3424. + */
  3425. +typedef union {
  3426. + unsigned int bits32;
  3427. + struct bit1_001c {
  3428. + unsigned int set_threshold : 8; /* flow control set threshold */
  3429. + unsigned int rel_threshold : 8; /* flow control release threshold */
  3430. + unsigned int reserved : 16;
  3431. + } bits;
  3432. +} GMAC_CONFIG1_T;
  3433. +
  3434. +#define GMAC_FLOWCTRL_SET_MAX 32
  3435. +#define GMAC_FLOWCTRL_SET_MIN 0
  3436. +#define GMAC_FLOWCTRL_RELEASE_MAX 32
  3437. +#define GMAC_FLOWCTRL_RELEASE_MIN 0
  3438. +
  3439. +/*
  3440. + * GMAC Configuration 2
  3441. + * GMAC0 Offset 0xA020
  3442. + * GMAC1 Offset 0xE020
  3443. + */
  3444. +typedef union {
  3445. + unsigned int bits32;
  3446. + struct bit1_0020 {
  3447. + unsigned int set_threshold : 16; /* flow control set threshold */
  3448. + unsigned int rel_threshold : 16; /* flow control release threshold */
  3449. + } bits;
  3450. +} GMAC_CONFIG2_T;
  3451. +
  3452. +/*
  3453. + * GMAC Configuration 3
  3454. + * GMAC0 Offset 0xA024
  3455. + * GMAC1 Offset 0xE024
  3456. + */
  3457. +typedef union {
  3458. + unsigned int bits32;
  3459. + struct bit1_0024 {
  3460. + unsigned int set_threshold : 16; /* flow control set threshold */
  3461. + unsigned int rel_threshold : 16; /* flow control release threshold */
  3462. + } bits;
  3463. +} GMAC_CONFIG3_T;
  3464. +
  3465. +
  3466. +/*
  3467. + * GMAC STATUS
  3468. + * GMAC0 Offset 0xA02C
  3469. + * GMAC1 Offset 0xE02C
  3470. + */
  3471. +typedef union {
  3472. + unsigned int bits32;
  3473. + struct bit1_002c {
  3474. + unsigned int link : 1; /* link status */
  3475. + unsigned int speed : 2; /* link speed(00->2.5M 01->25M 10->125M) */
  3476. + unsigned int duplex : 1; /* duplex mode */
  3477. + unsigned int reserved : 1;
  3478. + unsigned int mii_rmii : 2; /* PHY interface type */
  3479. + unsigned int : 25;
  3480. + } bits;
  3481. +} GMAC_STATUS_T;
  3482. +
  3483. +#define GMAC_SPEED_10 0
  3484. +#define GMAC_SPEED_100 1
  3485. +#define GMAC_SPEED_1000 2
  3486. +
  3487. +#define GMAC_PHY_MII 0
  3488. +#define GMAC_PHY_GMII 1
  3489. +#define GMAC_PHY_RGMII_100_10 2
  3490. +#define GMAC_PHY_RGMII_1000 3
  3491. +
  3492. +/*
  3493. + * Queue Header
  3494. + * (1) TOE Queue Header
  3495. + * (2) Non-TOE Queue Header
  3496. + * (3) Interrupt Queue Header
  3497. + *
  3498. + * memory Layout
  3499. + * TOE Queue Header
  3500. + * 0x60003000 +---------------------------+ 0x0000
  3501. + * | TOE Queue 0 Header |
  3502. + * | 8 * 4 Bytes |
  3503. + * +---------------------------+ 0x0020
  3504. + * | TOE Queue 1 Header |
  3505. + * | 8 * 4 Bytes |
  3506. + * +---------------------------+ 0x0040
  3507. + * | ...... |
  3508. + * | |
  3509. + * +---------------------------+
  3510. + *
  3511. + * Non TOE Queue Header
  3512. + * 0x60002000 +---------------------------+ 0x0000
  3513. + * | Default Queue 0 Header |
  3514. + * | 2 * 4 Bytes |
  3515. + * +---------------------------+ 0x0008
  3516. + * | Default Queue 1 Header |
  3517. + * | 2 * 4 Bytes |
  3518. + * +---------------------------+ 0x0010
  3519. + * | Classification Queue 0 |
  3520. + * | 2 * 4 Bytes |
  3521. + * +---------------------------+
  3522. + * | Classification Queue 1 |
  3523. + * | 2 * 4 Bytes |
  3524. + * +---------------------------+ (n * 8 + 0x10)
  3525. + * | ... |
  3526. + * | 2 * 4 Bytes |
  3527. + * +---------------------------+ (13 * 8 + 0x10)
  3528. + * | Classification Queue 13 |
  3529. + * | 2 * 4 Bytes |
  3530. + * +---------------------------+ 0x80
  3531. + * | Interrupt Queue 0 |
  3532. + * | 2 * 4 Bytes |
  3533. + * +---------------------------+
  3534. + * | Interrupt Queue 1 |
  3535. + * | 2 * 4 Bytes |
  3536. + * +---------------------------+
  3537. + * | Interrupt Queue 2 |
  3538. + * | 2 * 4 Bytes |
  3539. + * +---------------------------+
  3540. + * | Interrupt Queue 3 |
  3541. + * | 2 * 4 Bytes |
  3542. + * +---------------------------+
  3543. + *
  3544. + */
  3545. +#define TOE_QUEUE_HDR_ADDR(n) (TOE_TOE_QUE_HDR_BASE + n * 32)
  3546. +#define TOE_Q_HDR_AREA_END (TOE_QUEUE_HDR_ADDR(TOE_TOE_QUEUE_MAX + 1))
  3547. +#define TOE_DEFAULT_Q_HDR_BASE(x) (TOE_NONTOE_QUE_HDR_BASE + 0x08 * (x))
  3548. +#define TOE_CLASS_Q_HDR_BASE (TOE_NONTOE_QUE_HDR_BASE + 0x10)
  3549. +#define TOE_INTR_Q_HDR_BASE (TOE_NONTOE_QUE_HDR_BASE + 0x80)
  3550. +#define INTERRUPT_QUEUE_HDR_ADDR(n) (TOE_INTR_Q_HDR_BASE + n * 8)
  3551. +#define NONTOE_Q_HDR_AREA_END (INTERRUPT_QUEUE_HDR_ADDR(TOE_INTR_QUEUE_MAX + 1))
  3552. +/*
  3553. + * TOE Queue Header Word 0
  3554. + */
  3555. +typedef union {
  3556. + unsigned int bits32;
  3557. + unsigned int base_size;
  3558. +} TOE_QHDR0_T;
  3559. +
  3560. +#define TOE_QHDR0_BASE_MASK (~0x0f)
  3561. +
  3562. +/*
  3563. + * TOE Queue Header Word 1
  3564. + */
  3565. +typedef union {
  3566. + unsigned int bits32;
  3567. + struct bit_qhdr1 {
  3568. + unsigned int rptr : 16; // bit 15:0
  3569. + unsigned int wptr : 16; // bit 31:16
  3570. + } bits;
  3571. +} TOE_QHDR1_T;
  3572. +
  3573. +/*
  3574. + * TOE Queue Header Word 2
  3575. + */
  3576. +typedef union {
  3577. + unsigned int bits32;
  3578. + struct bit_qhdr2 {
  3579. + unsigned int TotalPktSize : 17; // bit 16: 0 Total packet size
  3580. + unsigned int reserved : 7; // bit 23:17
  3581. + unsigned int dack : 1; // bit 24 1: Duplicated ACK
  3582. + unsigned int abn : 1; // bit 25 1: Abnormal case Found
  3583. + unsigned int tcp_opt : 1; // bit 26 1: Have TCP option
  3584. + unsigned int ip_opt : 1; // bit 27 1: have IPV4 option or IPV6 Extension header
  3585. + unsigned int sat : 1; // bit 28 1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
  3586. + unsigned int osq : 1; // bit 29 1: out of sequence
  3587. + unsigned int ctl : 1; // bit 30 1: have control flag bits (except ack)
  3588. + unsigned int usd : 1; // bit 31 0: if no data assembled yet
  3589. + } bits;
  3590. +} TOE_QHDR2_T;
  3591. +
  3592. +/*
  3593. + * TOE Queue Header Word 3
  3594. + */
  3595. +typedef union {
  3596. + unsigned int bits32;
  3597. + unsigned int seq_num;
  3598. +} TOE_QHDR3_T;
  3599. +
  3600. +/*
  3601. + * TOE Queue Header Word 4
  3602. + */
  3603. +typedef union {
  3604. + unsigned int bits32;
  3605. + unsigned int ack_num;
  3606. +} TOE_QHDR4_T;
  3607. +
  3608. +/*
  3609. + * TOE Queue Header Word 5
  3610. + */
  3611. +typedef union {
  3612. + unsigned int bits32;
  3613. + struct bit_qhdr5 {
  3614. + unsigned int AckCnt : 16; // bit 15:0
  3615. + unsigned int SeqCnt : 16; // bit 31:16
  3616. + } bits;
  3617. +} TOE_QHDR5_T;
  3618. +
  3619. +/*
  3620. + * TOE Queue Header Word 6
  3621. + */
  3622. +typedef union {
  3623. + unsigned int bits32;
  3624. + struct bit_qhdr6 {
  3625. + unsigned int WinSize : 16; // bit 15:0
  3626. + unsigned int iq_num : 2; // bit 17:16
  3627. + unsigned int MaxPktSize : 14; // bit 31:18
  3628. + } bits;
  3629. +} TOE_QHDR6_T;
  3630. +
  3631. +/*
  3632. + * TOE Queue Header Word 7
  3633. + */
  3634. +typedef union {
  3635. + unsigned int bits32;
  3636. + struct bit_qhdr7 {
  3637. + unsigned int AckThreshold : 16; // bit 15:0
  3638. + unsigned int SeqThreshold : 16; // bit 31:16
  3639. + } bits;
  3640. +} TOE_QHDR7_T;
  3641. +
  3642. +/*
  3643. + * TOE Queue Header
  3644. + */
  3645. +typedef struct {
  3646. + TOE_QHDR0_T word0;
  3647. + TOE_QHDR1_T word1;
  3648. + TOE_QHDR2_T word2;
  3649. + TOE_QHDR3_T word3;
  3650. + TOE_QHDR4_T word4;
  3651. + TOE_QHDR5_T word5;
  3652. + TOE_QHDR6_T word6;
  3653. + TOE_QHDR7_T word7;
  3654. +} TOE_QHDR_T;
  3655. +
  3656. +/*
  3657. + * NONTOE Queue Header Word 0
  3658. + */
  3659. +typedef union {
  3660. + unsigned int bits32;
  3661. + unsigned int base_size;
  3662. +} NONTOE_QHDR0_T;
  3663. +
  3664. +#define NONTOE_QHDR0_BASE_MASK (~0x0f)
  3665. +
  3666. +/*
  3667. + * NONTOE Queue Header Word 1
  3668. + */
  3669. +typedef union {
  3670. + unsigned int bits32;
  3671. + struct bit_nonqhdr1 {
  3672. + unsigned int rptr : 16; // bit 15:0
  3673. + unsigned int wptr : 16; // bit 31:16
  3674. + } bits;
  3675. +} NONTOE_QHDR1_T;
  3676. +
  3677. +/*
  3678. + * Non-TOE Queue Header
  3679. + */
  3680. +typedef struct {
  3681. + NONTOE_QHDR0_T word0;
  3682. + NONTOE_QHDR1_T word1;
  3683. +} NONTOE_QHDR_T;
  3684. +
  3685. +/*
  3686. + * Interrupt Queue Header Word 0
  3687. + */
  3688. +typedef union {
  3689. + unsigned int bits32;
  3690. + struct bit_intrqhdr0 {
  3691. + unsigned int win_size : 16; // bit 15:0 Descriptor Ring Size
  3692. + unsigned int wptr : 16; // bit 31:16 Write Pointer where hw stopped
  3693. + } bits;
  3694. +} INTR_QHDR0_T;
  3695. +
  3696. +/*
  3697. + * Interrupt Queue Header Word 1
  3698. + */
  3699. +typedef union {
  3700. + unsigned int bits32;
  3701. + struct bit_intrqhdr1 {
  3702. + unsigned int TotalPktSize : 17; // bit 16: 0 Total packet size
  3703. + unsigned int tcp_qid : 8; // bit 24:17 TCP Queue ID
  3704. + unsigned int dack : 1; // bit 25 1: Duplicated ACK
  3705. + unsigned int abn : 1; // bit 26 1: Abnormal case Found
  3706. + unsigned int tcp_opt : 1; // bit 27 1: Have TCP option
  3707. + unsigned int ip_opt : 1; // bit 28 1: have IPV4 option or IPV6 Extension header
  3708. + unsigned int sat : 1; // bit 29 1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
  3709. + unsigned int osq : 1; // bit 30 1: out of sequence
  3710. + unsigned int ctl : 1; // bit 31 1: have control flag bits (except ack)
  3711. + } bits;
  3712. +} INTR_QHDR1_T;
  3713. +
  3714. +/*
  3715. + * Interrupt Queue Header Word 2
  3716. + */
  3717. +typedef union {
  3718. + unsigned int bits32;
  3719. + unsigned int seq_num;
  3720. +} INTR_QHDR2_T;
  3721. +
  3722. +/*
  3723. + * Interrupt Queue Header Word 3
  3724. + */
  3725. +typedef union {
  3726. + unsigned int bits32;
  3727. + unsigned int ack_num;
  3728. +} INTR_QHDR3_T;
  3729. +
  3730. +/*
  3731. + * Interrupt Queue Header Word 4
  3732. + */
  3733. +typedef union {
  3734. + unsigned int bits32;
  3735. + struct bit_intrqhdr4 {
  3736. + unsigned int AckCnt : 16; // bit 15:0 Ack# change since last ack# intr.
  3737. + unsigned int SeqCnt : 16; // bit 31:16 Seq# change since last seq# intr.
  3738. + } bits;
  3739. +} INTR_QHDR4_T;
  3740. +
  3741. +/*
  3742. + * Interrupt Queue Header
  3743. + */
  3744. +typedef struct {
  3745. + INTR_QHDR0_T word0;
  3746. + INTR_QHDR1_T word1;
  3747. + INTR_QHDR2_T word2;
  3748. + INTR_QHDR3_T word3;
  3749. + INTR_QHDR4_T word4;
  3750. + unsigned int word5;
  3751. + unsigned int word6;
  3752. + unsigned int word7;
  3753. +} INTR_QHDR_T;
  3754. +
  3755. +/*
  3756. + * GMAC private data
  3757. + */
  3758. +typedef struct {
  3759. + unsigned int rwptr_reg;
  3760. + unsigned int desc_base;
  3761. + unsigned int desc_base_dma;
  3762. + unsigned short finished_idx;
  3763. + struct sk_buff *tx_skb[TOE_GMAC_SWTXQ_DESC_NUM];
  3764. +} GMAC_SWTXQ_T;
  3765. +
  3766. +struct gmac_private {
  3767. + struct phy_device *phydev;
  3768. + unsigned int port_id;
  3769. + unsigned int dma_base_addr;
  3770. + unsigned int swtxq_desc_base;
  3771. + GMAC_SWTXQ_T swtxq[TOE_SW_TXQ_NUM];
  3772. + NONTOE_QHDR_T *default_qhdr;
  3773. + unsigned int default_desc_base;
  3774. + dma_addr_t default_desc_base_dma;
  3775. + dma_addr_t swtxq_desc_base_dma;
  3776. + unsigned int flow_control_enable;
  3777. + unsigned int intr0_enabled;
  3778. + unsigned int intr1_enabled;
  3779. + unsigned int intr2_enabled;
  3780. + unsigned int intr3_enabled;
  3781. + unsigned int intr4_enabled;
  3782. + unsigned int intr0_selected;
  3783. + unsigned int intr1_selected;
  3784. + unsigned int intr2_selected;
  3785. + unsigned int intr3_selected;
  3786. + unsigned int intr4_selected;
  3787. +};
  3788. +
  3789. +struct toe_private {
  3790. + void __iomem *global_base;
  3791. + struct net_device *net_dev[2];
  3792. + struct device *dev;
  3793. + struct work_struct freq_work;
  3794. + spinlock_t freeq_lock;
  3795. + unsigned int swfq_desc_base;
  3796. + unsigned int hwfq_desc_base;
  3797. + unsigned int hwfq_buf_base;
  3798. + dma_addr_t sw_freeq_desc_base_dma;
  3799. + dma_addr_t hw_freeq_desc_base_dma;
  3800. + dma_addr_t hwfq_buf_base_dma;
  3801. + dma_addr_t hwfq_buf_end_dma;
  3802. +};
  3803. +
  3804. +#define GMAC_PORT0 0
  3805. +#define GMAC_PORT1 1
  3806. +
  3807. +#endif /* _GMAC_SL351x_H */
  3808. --- /dev/null
  3809. +++ b/drivers/net/gemini_negmac/Makefile
  3810. @@ -0,0 +1,3 @@
  3811. +obj-$(CONFIG_GEMINI_NET_ENGINE_GMAC)+= gemini_negmac.o
  3812. +
  3813. +gemini_negmac-objs := gm_gmac.o
  3814. --- a/drivers/net/Kconfig
  3815. +++ b/drivers/net/Kconfig
  3816. @@ -2068,6 +2068,13 @@ config ACENIC_OMIT_TIGON_I
  3817. The safe and default value for this is N.
  3818. +config GEMINI_NET_ENGINE_GMAC
  3819. + tristate "Gemini Gigabit Ethernet support"
  3820. + depends on ARCH_GEMINI
  3821. + select PHYLIB
  3822. + help
  3823. + This driver supports Gemini TOE and NAT dual Gigabit Ethernet.
  3824. +
  3825. config DL2K
  3826. tristate "DL2000/TC902x-based Gigabit Ethernet support"
  3827. depends on PCI
  3828. --- a/drivers/net/Makefile
  3829. +++ b/drivers/net/Makefile
  3830. @@ -257,6 +257,7 @@ obj-$(CONFIG_MLX4_CORE) += mlx4/
  3831. obj-$(CONFIG_ENC28J60) += enc28j60.o
  3832. obj-$(CONFIG_ETHOC) += ethoc.o
  3833. obj-$(CONFIG_GRETH) += greth.o
  3834. +obj-$(CONFIG_GEMINI_NET_ENGINE_GMAC) += gemini_negmac/
  3835. obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o
  3836. --- /dev/null
  3837. +++ b/drivers/usb/host/ehci-fotg2xx.c
  3838. @@ -0,0 +1,459 @@
  3839. +/*
  3840. + * EHCI Host Controller driver
  3841. + *
  3842. + * Copyright (C) 2006 Sony Computer Entertainment Inc.
  3843. + * Copyright 2006 Sony Corp.
  3844. + *
  3845. + * This program is free software; you can redistribute it and/or modify
  3846. + * it under the terms of the GNU General Public License as published by
  3847. + * the Free Software Foundation; version 2 of the License.
  3848. + */
  3849. +
  3850. +#include <linux/platform_device.h>
  3851. +#include <mach/hardware.h>
  3852. +
  3853. +#define otg_set(port, bits) writel(readl(hcd->regs + port) | bits, hcd->regs + port)
  3854. +
  3855. +#define otg_clear(port, bits) writel(readl(hcd->regs + port) & ~bits, hcd->regs + port)
  3856. +
  3857. +#define GLOBAL_ISR 0xC0
  3858. +#define GLOBAL_ICR 0xC4
  3859. +
  3860. +#define HCD_MISC 0x40
  3861. +
  3862. +#define OTGC_SCR 0x80
  3863. +#define OTGC_INT_EN 0x88
  3864. +
  3865. +#define GLOBAL_INT_POLARITY (1 << 3)
  3866. +#define GLOBAL_INT_MASK_HC (1 << 2)
  3867. +#define GLOBAL_INT_MASK_OTG (1 << 1)
  3868. +#define GLOBAL_INT_MASK_DEV (1 << 0)
  3869. +
  3870. +#define OTGC_SCR_ID (1 << 21)
  3871. +#define OTGC_SCR_CROLE (1 << 20)
  3872. +#define OTGC_SCR_VBUS_VLD (1 << 19)
  3873. +#define OTGC_SCR_A_SRP_RESP_TYPE (1 << 8)
  3874. +#define OTGC_SCR_A_SRP_DET_EN (1 << 7)
  3875. +#define OTGC_SCR_A_SET_B_HNP_EN (1 << 6)
  3876. +#define OTGC_SCR_A_BUS_DROP (1 << 5)
  3877. +#define OTGC_SCR_A_BUS_REQ (1 << 4)
  3878. +
  3879. +#define OTGC_INT_APLGRMV (1 << 12)
  3880. +#define OTGC_INT_BPLGRMV (1 << 11)
  3881. +#define OTGC_INT_OVC (1 << 10)
  3882. +#define OTGC_INT_IDCHG (1 << 9)
  3883. +#define OTGC_INT_RLCHG (1 << 8)
  3884. +#define OTGC_INT_AVBUSERR (1 << 5)
  3885. +#define OTGC_INT_ASRPDET (1 << 4)
  3886. +#define OTGC_INT_BSRPDN (1 << 0)
  3887. +
  3888. +#define OTGC_INT_A_TYPE (OTGC_INT_ASRPDET|OTGC_INT_AVBUSERR|OTGC_INT_OVC|OTGC_INT_RLCHG|OTGC_INT_IDCHG|OTGC_INT_APLGRMV)
  3889. +#define OTGC_INT_B_TYPE (OTGC_INT_AVBUSERR|OTGC_INT_OVC|OTGC_INT_RLCHG|OTGC_INT_IDCHG)
  3890. +
  3891. +static void fotg2xx_otgc_role_change(struct usb_hcd *hcd);
  3892. +
  3893. +static void fotg2xx_otgc_init(struct usb_hcd *hcd)
  3894. +{
  3895. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  3896. + unsigned int reg;
  3897. +
  3898. + reg = __raw_readl(hcd->regs + OTGC_SCR);
  3899. + ehci_info(ehci, "role detected: %s, ",
  3900. + (reg & OTGC_SCR_CROLE) ? "Peripheral" : "Host");
  3901. +
  3902. + if (reg & OTGC_SCR_ID)
  3903. + ehci_info(ehci, "B-Device (may be unsupported!)\n");
  3904. + else
  3905. + ehci_info(ehci, "A-Device\n");
  3906. +
  3907. + /* Enable the SRP detect */
  3908. + reg &= ~OTGC_SCR_A_SRP_RESP_TYPE;
  3909. + __raw_writel(reg, hcd->regs + OTGC_SCR);
  3910. +
  3911. + reg = __raw_readl(hcd->regs + OTGC_INT_EN);
  3912. + /* clear INT B: bits AVBUSERR | OVC | RLCHG | IDCHG */
  3913. + reg &= ~OTGC_INT_B_TYPE;
  3914. + /* set INT A: bits ASRPDET | AVBUSERR | OVC | RLCHG | IDCHG | APLGRMV */
  3915. + reg |= OTGC_INT_A_TYPE;
  3916. + __raw_writel(reg, hcd->regs + OTGC_INT_EN);
  3917. +
  3918. + reg = __raw_readl(hcd->regs + GLOBAL_ICR);
  3919. + reg &= ~GLOBAL_INT_MASK_OTG;
  3920. + __raw_writel(reg, hcd->regs + GLOBAL_ICR);
  3921. +
  3922. + /* setup MISC register, fixes timing problems */
  3923. + reg = __raw_readl(hcd->regs + HCD_MISC);
  3924. + reg |= 0xD;
  3925. + __raw_writel(reg, hcd->regs + HCD_MISC);
  3926. +
  3927. + fotg2xx_otgc_role_change(hcd);
  3928. +}
  3929. +
  3930. +static void fotg2xx_otgh_close(struct usb_hcd *hcd)
  3931. +{
  3932. + unsigned int reg;
  3933. +
  3934. + /* <1>.Enable Interrupt Mask */
  3935. + reg = __raw_readl(hcd->regs + GLOBAL_ICR);
  3936. + reg |= GLOBAL_INT_MASK_HC;
  3937. + __raw_writel(reg, hcd->regs + GLOBAL_ICR);
  3938. +
  3939. + /* <2>.Clear the Interrupt status */
  3940. + reg = __raw_readl(hcd->regs + 0x18);
  3941. + reg &= 0x0000003F;
  3942. + __raw_writel(reg, hcd->regs + 0x14);
  3943. +}
  3944. +
  3945. +static void fotg2xx_otgh_open(struct usb_hcd *hcd)
  3946. +{
  3947. + unsigned int reg;
  3948. +
  3949. + reg = __raw_readl(hcd->regs + OTGC_SCR);
  3950. + reg &= ~OTGC_SCR_A_SRP_DET_EN;
  3951. + __raw_writel(reg, hcd->regs + OTGC_SCR);
  3952. +
  3953. + reg = __raw_readl(hcd->regs + GLOBAL_ICR);
  3954. + reg &= ~GLOBAL_INT_MASK_HC;
  3955. + __raw_writel(reg, hcd->regs + GLOBAL_ICR);
  3956. +}
  3957. +
  3958. +/* change to host role */
  3959. +static void fotg2xx_otgc_role_change(struct usb_hcd *hcd)
  3960. +{
  3961. +
  3962. + /* clear A_SET_B_HNP_EN */
  3963. + otg_clear(0x80, BIT(6));
  3964. +
  3965. + /*** Enable VBUS driving */
  3966. + if (readl(hcd->regs + 0x80) & BIT(19))
  3967. + printk(KERN_INFO "VBUS already enabled\n");
  3968. + else {
  3969. + int cnt = 0;
  3970. +
  3971. + /* clear A_BUS_DROP */
  3972. + otg_clear(0x80, BIT(5));
  3973. +
  3974. + /* set A_BUS_REQ */
  3975. + otg_set(0x80, BIT(4));
  3976. +
  3977. + /* set global bus reg to VBUS on */
  3978. + writel(readl(IO_ADDRESS(0x40000000) + 0x30) | ((BIT(21)|BIT(22))),
  3979. + IO_ADDRESS(0x40000000) + 0x30);
  3980. +
  3981. + if (readl(hcd->regs + 0x80) & (1<<19)) {
  3982. + printk(KERN_INFO "Waiting for VBus");
  3983. + while (!(readl(hcd->regs + 0x80) & (1<<19)) && (cnt < 80)) {
  3984. + printk(KERN_CONT ".");
  3985. + cnt++;
  3986. + }
  3987. + printk(KERN_CONT "\n");
  3988. + } else
  3989. + printk(KERN_INFO "VBUS enabled.\n");
  3990. +
  3991. + mdelay(1);
  3992. + }
  3993. + fotg2xx_otgh_open(hcd);
  3994. +}
  3995. +
  3996. +static int fotg2xx_ehci_hc_reset(struct usb_hcd *hcd)
  3997. +{
  3998. + int result;
  3999. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  4000. +
  4001. + ehci->caps = hcd->regs;
  4002. + ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  4003. +
  4004. + dbg_hcs_params(ehci, "reset");
  4005. + dbg_hcc_params(ehci, "reset");
  4006. +
  4007. + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  4008. + hcd->has_tt = 1;
  4009. +
  4010. + result = ehci_halt(ehci);
  4011. + if (result)
  4012. + return result;
  4013. +
  4014. + result = ehci_init(hcd);
  4015. + if (result)
  4016. + return result;
  4017. +
  4018. + ehci_port_power(ehci, 0);
  4019. +
  4020. + return result;
  4021. +}
  4022. +
  4023. +/*
  4024. + * Name: OTGC_INT_ISR
  4025. + * Description:This interrupt service routine belongs to the OTG-Controller
  4026. + * <1>.Check for ID_Change
  4027. + * <2>.Check for RL_Change
  4028. + * <3>.Error Detect
  4029. + * Input: wINTStatus
  4030. + * Output:void
  4031. + */
  4032. +void fotg2xx_int_isr(struct usb_hcd *hcd, u32 wINTStatus)
  4033. +{
  4034. + /* <1>.Check for ID_Change */
  4035. + if (wINTStatus&OTGC_INT_IDCHG) {
  4036. + if ((readl(hcd->regs + 0x80) & BIT(21)) != 0)
  4037. + fotg2xx_otgc_init(hcd); /* Change to B Type */
  4038. + else
  4039. + fotg2xx_otgc_init(hcd); /* Change to A Type */
  4040. +
  4041. + return;
  4042. + }
  4043. +
  4044. + /* <2>.Check for RL_Change */
  4045. + if (wINTStatus&OTGC_INT_RLCHG)
  4046. + fotg2xx_otgc_role_change(hcd);
  4047. +
  4048. + /* <3>.Error Detect */
  4049. + if (wINTStatus&OTGC_INT_AVBUSERR)
  4050. + printk(KERN_ERR "VBus error!\n");
  4051. +
  4052. + if (wINTStatus&OTGC_INT_OVC)
  4053. + printk(KERN_WARNING "Overcurrent detected!\n");
  4054. +
  4055. + /* <3>.Check for Type-A/Type-B Interrupt */
  4056. + if ((readl(hcd->regs + 0x80) & BIT(21)) == 0) { /*For Type-A Interrupt*/
  4057. + if (wINTStatus & (OTGC_INT_A_TYPE | OTGC_INT_ASRPDET)) {
  4058. + /* <1>.SRP detected => then set global variable */
  4059. + printk(KERN_WARNING "SRP detected, but not implemented!\n");
  4060. +
  4061. +#if 0
  4062. + u32 wTempCounter;
  4063. + /* <2>.Turn on the V Bus */
  4064. + pFTC_OTG->otg.state = OTG_STATE_A_WAIT_VRISE;
  4065. + OTGC_enable_vbus_draw_storlink(1);
  4066. + pFTC_OTG->otg.state = OTG_STATE_A_HOST;
  4067. + /* <3>.Should waiting for Device-Connect Wait 300ms */
  4068. + INFO(pFTC_OTG, ">>> OTG-A Waiting for OTG-B Connect,\n");
  4069. + wTempCounter = 0;
  4070. + while (mwHost20_PORTSC_ConnectStatus_Rd() == 0) {
  4071. + mdelay(1);
  4072. + wTempCounter++;
  4073. + /* Waiting for 300 ms */
  4074. + if (wTempCounter > 300) {
  4075. + mdwOTGC_Control_A_SRP_DET_EN_Clr();
  4076. + INFO(pFTC_OTG, ">>> OTG-B do not connect under 300 ms...\n");
  4077. + break;
  4078. + }
  4079. + }
  4080. + /* <4>.If Connect => issue quick Reset */
  4081. + if (mwHost20_PORTSC_ConnectStatus_Rd() > 0) {
  4082. + mdelay(300); /* For OPT-A Test */
  4083. + OTGH_host_quick_Reset();
  4084. + OTGH_Open();
  4085. + pFTC_OTG->otg.host->A_Disable_Set_Feature_HNP = 0;
  4086. + }
  4087. +#endif
  4088. + }
  4089. + } else { /* For Type-B Interrupt */
  4090. + BUG();
  4091. + }
  4092. +}
  4093. +
  4094. +static irqreturn_t fotg2xx_ehci_irq(int irq, void *devid)
  4095. +{
  4096. + struct usb_hcd *hcd = devid;
  4097. + u32 val;
  4098. +
  4099. + /* OTG Interrupt Status Register */
  4100. + val = readl(hcd->regs + 0x84);
  4101. +
  4102. + /* OTG stuff */
  4103. + if (val) {
  4104. + /* supposed to do "INT STS Clr" - XXX */
  4105. + writel(readl(hcd->regs + 0x84) | val, hcd->regs + 0x84);
  4106. +
  4107. + fotg2xx_int_isr(hcd, val);
  4108. +
  4109. + /* supposed to do "INT STS Clr" - XXX */
  4110. + writel(readl(hcd->regs + 0x84) | val, hcd->regs + 0x84);
  4111. +
  4112. + return IRQ_HANDLED;
  4113. + }
  4114. +
  4115. + if ((readl(hcd->regs + 0x80) & BIT(20)) == 0) { /* Role is HOST */
  4116. + if (readl(hcd->regs + 0xC0) & BIT(2)) { /* INT STS HOST */
  4117. + /* leave this for ehci irq handler */
  4118. + return IRQ_NONE;
  4119. + }
  4120. + } else
  4121. + printk(KERN_WARNING
  4122. + "received irq for peripheral - don't know what to do!\n");
  4123. +
  4124. + /* do not call the ehci irq handler */
  4125. + return IRQ_HANDLED;
  4126. +}
  4127. +
  4128. +static int fotg2xx_ehci_run(struct usb_hcd *hcd)
  4129. +{
  4130. + int retval;
  4131. +
  4132. + retval = ehci_run(hcd);
  4133. +
  4134. + fotg2xx_otgh_close(hcd);
  4135. + fotg2xx_otgc_init(hcd);
  4136. +
  4137. + return retval;
  4138. +}
  4139. +
  4140. +static const struct hc_driver fotg2xx_ehci_hc_driver = {
  4141. + .description = hcd_name,
  4142. + .product_desc = "FOTG2XX EHCI Host Controller",
  4143. + .hcd_priv_size = sizeof(struct ehci_hcd),
  4144. + .irq = ehci_irq,
  4145. + .flags = HCD_MEMORY | HCD_USB2,
  4146. + .reset = fotg2xx_ehci_hc_reset,
  4147. + .start = fotg2xx_ehci_run,
  4148. + .stop = ehci_stop,
  4149. + .shutdown = ehci_shutdown,
  4150. + .urb_enqueue = ehci_urb_enqueue,
  4151. + .urb_dequeue = ehci_urb_dequeue,
  4152. + .endpoint_disable = ehci_endpoint_disable,
  4153. + .get_frame_number = ehci_get_frame,
  4154. + .hub_status_data = ehci_hub_status_data,
  4155. + .hub_control = ehci_hub_control,
  4156. +#if defined(CONFIG_PM)
  4157. + .bus_suspend = ehci_bus_suspend,
  4158. + .bus_resume = ehci_bus_resume,
  4159. +#endif
  4160. + .relinquish_port = ehci_relinquish_port,
  4161. + .port_handed_over = ehci_port_handed_over,
  4162. +};
  4163. +
  4164. +static int fotg2xx_ehci_probe(struct platform_device *pdev)
  4165. +{
  4166. + const struct hc_driver *driver = &fotg2xx_ehci_hc_driver;
  4167. + struct usb_hcd *hcd;
  4168. + struct resource *res;
  4169. + int irq;
  4170. + int retval;
  4171. +
  4172. + pr_debug("initializing FOTG2XX-SOC USB Controller\n");
  4173. +
  4174. + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  4175. + if (!res) {
  4176. + dev_err(&pdev->dev,
  4177. + "Found HC with no IRQ. Check %s setup!\n",
  4178. + dev_name(&pdev->dev));
  4179. + return -ENODEV;
  4180. + }
  4181. +
  4182. + irq = res->start;
  4183. +
  4184. + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  4185. + if (!hcd) {
  4186. + retval = -ENOMEM;
  4187. + goto err1;
  4188. + }
  4189. +
  4190. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4191. + if (!res) {
  4192. + dev_err(&pdev->dev,
  4193. + "Found HC with no register addr. Check %s setup!\n",
  4194. + dev_name(&pdev->dev));
  4195. + retval = -ENODEV;
  4196. + goto err2;
  4197. + }
  4198. +
  4199. + hcd->rsrc_start = res->start;
  4200. + hcd->rsrc_len = res->end - res->start + 1;
  4201. + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  4202. + driver->description)) {
  4203. + dev_dbg(&pdev->dev, "controller already in use\n");
  4204. + retval = -EBUSY;
  4205. + goto err2;
  4206. + }
  4207. +
  4208. + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  4209. + if (hcd->regs == NULL) {
  4210. + dev_dbg(&pdev->dev, "error mapping memory\n");
  4211. + retval = -EFAULT;
  4212. + goto err3;
  4213. + }
  4214. +
  4215. +
  4216. + /* set global reg to mini-A host */
  4217. + writel(readl(IO_ADDRESS(0x40000000) + 0x30) & ~(BIT(30)|BIT(29)),
  4218. + IO_ADDRESS(0x40000000) + 0x30);
  4219. +
  4220. + /* USB0&USB1 - VBUS off */
  4221. + writel(readl(IO_ADDRESS(0x40000000) + 0x30) & ~(BIT(21)|BIT(22)),
  4222. + IO_ADDRESS(0x40000000) + 0x30);
  4223. +
  4224. + if ((readl(hcd->regs) == 0x01000010) &&
  4225. + (readl(hcd->regs + 4) == 0x00000001) &&
  4226. + (readl(hcd->regs + 8) == 0x00000006)) {
  4227. + dev_info(&pdev->dev,
  4228. + "Found Faraday OTG 2XX controller (base = 0x%08lX)\n",
  4229. + (unsigned long) hcd->rsrc_start);
  4230. + } else {
  4231. + dev_err(&pdev->dev, "fotg2xx id mismatch: found %d.%d.%d\n",
  4232. + readl(hcd->regs + 0x00),
  4233. + readl(hcd->regs + 0x04),
  4234. + readl(hcd->regs + 0x08));
  4235. + retval = -ENODEV;
  4236. + goto err4;
  4237. + }
  4238. +
  4239. + platform_set_drvdata(pdev, hcd);
  4240. +
  4241. + /* mask interrupts - peripheral, otg, host, hi-active (bits 0,1,2,3) */
  4242. + otg_set(0xc4, BIT(3)); /* hi active */
  4243. +
  4244. + otg_set(0xc4, BIT(2)); /* host */
  4245. + otg_set(0xc4, BIT(1)); /* otg */
  4246. + otg_set(0xc4, BIT(0)); /* peripheral */
  4247. +
  4248. + /* register additional interrupt - here we check otg status */
  4249. + if ((request_irq(irq, &fotg2xx_ehci_irq, IRQF_SHARED | IRQF_DISABLED,
  4250. + hcd->irq_descr, hcd)) != 0) {
  4251. + dev_dbg(&pdev->dev, "error requesting irq %d\n", irq);
  4252. + retval = -EFAULT;
  4253. + goto err4;
  4254. + }
  4255. +
  4256. + retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  4257. + if (retval != 0)
  4258. + goto err4;
  4259. + return retval;
  4260. +
  4261. +err4:
  4262. + iounmap(hcd->regs);
  4263. +err3:
  4264. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  4265. +err2:
  4266. + usb_put_hcd(hcd);
  4267. +err1:
  4268. + dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
  4269. + return retval;
  4270. +}
  4271. +
  4272. +/* may be called without controller electrically present */
  4273. +/* may be called with controller, bus, and devices active */
  4274. +
  4275. +int fotg2xx_ehci_remove(struct platform_device *pdev)
  4276. +{
  4277. + struct usb_hcd *hcd =
  4278. + (struct usb_hcd *)platform_get_drvdata(pdev);
  4279. +
  4280. + usb_remove_hcd(hcd);
  4281. + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  4282. + iounmap(hcd->regs);
  4283. + usb_put_hcd(hcd);
  4284. + platform_set_drvdata(pdev, NULL);
  4285. +
  4286. + return 0;
  4287. +}
  4288. +
  4289. +MODULE_ALIAS("platform:ehci-fotg2xx");
  4290. +
  4291. +static struct platform_driver fotg2xx_ehci_driver = {
  4292. + .probe = fotg2xx_ehci_probe,
  4293. + .remove = fotg2xx_ehci_remove,
  4294. + .driver = {
  4295. + .name = "ehci-fotg2xx",
  4296. + },
  4297. +};
  4298. --- a/drivers/usb/host/ehci.h
  4299. +++ b/drivers/usb/host/ehci.h
  4300. @@ -561,7 +561,12 @@ static inline unsigned int
  4301. ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
  4302. {
  4303. if (ehci_is_TDI(ehci)) {
  4304. +#ifdef CONFIG_ARCH_GEMINI
  4305. + portsc = readl(ehci_to_hcd(ehci)->regs + 0x80);
  4306. + switch ((portsc>>22)&3) {
  4307. +#else
  4308. switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
  4309. +#endif
  4310. case 0:
  4311. return 0;
  4312. case 1:
  4313. --- a/drivers/usb/host/ehci-hcd.c
  4314. +++ b/drivers/usb/host/ehci-hcd.c
  4315. @@ -223,9 +223,11 @@ static int ehci_halt (struct ehci_hcd *e
  4316. if ((temp & STS_HALT) != 0)
  4317. return 0;
  4318. +#ifndef CONFIG_ARCH_GEMINI
  4319. temp = ehci_readl(ehci, &ehci->regs->command);
  4320. temp &= ~CMD_RUN;
  4321. ehci_writel(ehci, temp, &ehci->regs->command);
  4322. +#endif
  4323. return handshake (ehci, &ehci->regs->status,
  4324. STS_HALT, STS_HALT, 16 * 125);
  4325. }
  4326. @@ -292,8 +294,8 @@ static int ehci_reset (struct ehci_hcd *
  4327. if (retval)
  4328. return retval;
  4329. - if (ehci_is_TDI(ehci))
  4330. - tdi_reset (ehci);
  4331. +// if (ehci_is_TDI(ehci))
  4332. +// tdi_reset (ehci);
  4333. if (ehci->debug)
  4334. dbgp_external_startup();
  4335. @@ -427,12 +429,13 @@ static void ehci_silence_controller(stru
  4336. {
  4337. ehci_halt(ehci);
  4338. ehci_turn_off_all_ports(ehci);
  4339. -
  4340. +#ifndef CONFIG_ARCH_GEMINI
  4341. /* make BIOS/etc use companion controller during reboot */
  4342. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  4343. /* unblock posted writes */
  4344. ehci_readl(ehci, &ehci->regs->configured_flag);
  4345. +#endif
  4346. }
  4347. /* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
  4348. @@ -712,7 +715,9 @@ static int ehci_run (struct usb_hcd *hcd
  4349. // Philips, Intel, and maybe others need CMD_RUN before the
  4350. // root hub will detect new devices (why?); NEC doesn't
  4351. ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
  4352. +#ifndef CONFIG_ARCH_GEMINI
  4353. ehci->command |= CMD_RUN;
  4354. +#endif
  4355. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  4356. dbg_cmd (ehci, "init", ehci->command);
  4357. @@ -732,9 +737,11 @@ static int ehci_run (struct usb_hcd *hcd
  4358. */
  4359. down_write(&ehci_cf_port_reset_rwsem);
  4360. hcd->state = HC_STATE_RUNNING;
  4361. +#ifndef CONFIG_ARCH_GEMINI
  4362. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  4363. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  4364. msleep(5);
  4365. +#endif
  4366. up_write(&ehci_cf_port_reset_rwsem);
  4367. ehci->last_periodic_enable = ktime_get_real();
  4368. @@ -827,9 +834,10 @@ static irqreturn_t ehci_irq (struct usb_
  4369. pcd_status = status;
  4370. /* resume root hub? */
  4371. +#ifndef CONFIG_ARCH_GEMINI
  4372. if (!(cmd & CMD_RUN))
  4373. usb_hcd_resume_root_hub(hcd);
  4374. -
  4375. +#endif
  4376. /* get per-port change detect bits */
  4377. if (ehci->has_ppcd)
  4378. ppcd = status >> 16;
  4379. @@ -871,7 +879,9 @@ static irqreturn_t ehci_irq (struct usb_
  4380. ehci_halt(ehci);
  4381. dead:
  4382. ehci_reset(ehci);
  4383. +#ifndef CONFIG_ARCH_GEMINI
  4384. ehci_writel(ehci, 0, &ehci->regs->configured_flag);
  4385. +#endif
  4386. /* generic layer kills/unlinks all urbs, then
  4387. * uses ehci_stop to clean up the rest
  4388. */
  4389. @@ -1169,6 +1179,11 @@ MODULE_LICENSE ("GPL");
  4390. #define PCI_DRIVER ehci_pci_driver
  4391. #endif
  4392. +#ifdef CONFIG_ARCH_GEMINI
  4393. +#include "ehci-fotg2xx.c"
  4394. +#define PLATFORM_DRIVER fotg2xx_ehci_driver
  4395. +#endif
  4396. +
  4397. #ifdef CONFIG_USB_EHCI_FSL
  4398. #include "ehci-fsl.c"
  4399. #define PLATFORM_DRIVER ehci_fsl_driver
  4400. --- a/drivers/usb/host/ehci-hub.c
  4401. +++ b/drivers/usb/host/ehci-hub.c
  4402. @@ -929,6 +929,12 @@ static int ehci_hub_control (
  4403. /* see what we found out */
  4404. temp = check_reset_complete (ehci, wIndex, status_reg,
  4405. ehci_readl(ehci, status_reg));
  4406. +#ifdef CONFIG_ARCH_GEMINI
  4407. + /* restart schedule */
  4408. + ehci_writel(ehci, ehci_readl(ehci, &ehci->regs->command) | CMD_RUN, &ehci->regs->command);
  4409. +
  4410. +// hcd->state = HC_STATE_RUNNING;
  4411. +#endif
  4412. }
  4413. if (!(temp & (PORT_RESUME|PORT_RESET)))
  4414. --- a/drivers/usb/Kconfig
  4415. +++ b/drivers/usb/Kconfig
  4416. @@ -66,6 +66,7 @@ config USB_ARCH_HAS_EHCI
  4417. default y if ARCH_AT91SAM9G45
  4418. default y if ARCH_MXC
  4419. default y if ARCH_OMAP3
  4420. + default y if ARCH_GEMINI
  4421. default PCI
  4422. # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
  4423. --- /dev/null
  4424. +++ b/drivers/watchdog/gemini_wdt.c
  4425. @@ -0,0 +1,368 @@
  4426. +/*
  4427. + * Watchdog driver for Cortina Systems Gemini SoC
  4428. + *
  4429. + * Copyright (C) 2009 Paulius Zaleckas <[email protected]>
  4430. + *
  4431. + * This program is free software; you can redistribute it and/or modify
  4432. + * it under the terms of the GNU General Public License version 2 as
  4433. + * published by the Free Software Foundation.
  4434. + */
  4435. +
  4436. +#include <linux/kernel.h>
  4437. +#include <linux/init.h>
  4438. +#include <linux/io.h>
  4439. +#include <linux/fs.h>
  4440. +#include <linux/uaccess.h>
  4441. +#include <linux/miscdevice.h>
  4442. +#include <linux/platform_device.h>
  4443. +#include <linux/watchdog.h>
  4444. +#include <linux/slab.h>
  4445. +
  4446. +#define GEMINI_WDCOUNTER 0x0
  4447. +#define GEMINI_WDLOAD 0x4
  4448. +#define GEMINI_WDRESTART 0x8
  4449. +
  4450. +#define WDRESTART_MAGIC 0x5AB9
  4451. +
  4452. +#define GEMINI_WDCR 0xC
  4453. +
  4454. +#define WDCR_CLOCK_5MHZ (1 << 4)
  4455. +#define WDCR_SYS_RST (1 << 1)
  4456. +#define WDCR_ENABLE (1 << 0)
  4457. +
  4458. +#define WDT_CLOCK 5000000 /* 5 MHz */
  4459. +#define WDT_DEFAULT_TIMEOUT 13
  4460. +#define WDT_MAX_TIMEOUT (0xFFFFFFFF / WDT_CLOCK)
  4461. +
  4462. +/* status bits */
  4463. +#define WDT_ACTIVE 0
  4464. +#define WDT_OK_TO_CLOSE 1
  4465. +
  4466. +static unsigned int timeout = WDT_DEFAULT_TIMEOUT;
  4467. +static int nowayout = WATCHDOG_NOWAYOUT;
  4468. +
  4469. +static DEFINE_SPINLOCK(gemini_wdt_lock);
  4470. +
  4471. +static struct platform_device *gemini_wdt_dev;
  4472. +
  4473. +struct gemini_wdt_struct {
  4474. + struct resource *res;
  4475. + struct device *dev;
  4476. + void __iomem *base;
  4477. + unsigned long status;
  4478. +};
  4479. +
  4480. +static struct watchdog_info gemini_wdt_info = {
  4481. + .identity = "Gemini watchdog",
  4482. + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING |
  4483. + WDIOF_SETTIMEOUT,
  4484. +};
  4485. +
  4486. +/* Disable the watchdog. */
  4487. +static void gemini_wdt_stop(struct gemini_wdt_struct *gemini_wdt)
  4488. +{
  4489. + spin_lock(&gemini_wdt_lock);
  4490. +
  4491. + __raw_writel(0, gemini_wdt->base + GEMINI_WDCR);
  4492. +
  4493. + clear_bit(WDT_ACTIVE, &gemini_wdt->status);
  4494. +
  4495. + spin_unlock(&gemini_wdt_lock);
  4496. +}
  4497. +
  4498. +/* Service the watchdog */
  4499. +static void gemini_wdt_service(struct gemini_wdt_struct *gemini_wdt)
  4500. +{
  4501. + __raw_writel(WDRESTART_MAGIC, gemini_wdt->base + GEMINI_WDRESTART);
  4502. +}
  4503. +
  4504. +/* Enable and reset the watchdog. */
  4505. +static void gemini_wdt_start(struct gemini_wdt_struct *gemini_wdt)
  4506. +{
  4507. + spin_lock(&gemini_wdt_lock);
  4508. +
  4509. + __raw_writel(timeout * WDT_CLOCK, gemini_wdt->base + GEMINI_WDLOAD);
  4510. +
  4511. + gemini_wdt_service(gemini_wdt);
  4512. +
  4513. + /* set clock before enabling */
  4514. + __raw_writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST,
  4515. + gemini_wdt->base + GEMINI_WDCR);
  4516. +
  4517. + __raw_writel(WDCR_CLOCK_5MHZ | WDCR_SYS_RST | WDCR_ENABLE,
  4518. + gemini_wdt->base + GEMINI_WDCR);
  4519. +
  4520. + set_bit(WDT_ACTIVE, &gemini_wdt->status);
  4521. +
  4522. + spin_unlock(&gemini_wdt_lock);
  4523. +}
  4524. +
  4525. +/* Watchdog device is opened, and watchdog starts running. */
  4526. +static int gemini_wdt_open(struct inode *inode, struct file *file)
  4527. +{
  4528. + struct gemini_wdt_struct *gemini_wdt = platform_get_drvdata(gemini_wdt_dev);
  4529. +
  4530. + if (test_bit(WDT_ACTIVE, &gemini_wdt->status))
  4531. + return -EBUSY;
  4532. +
  4533. + file->private_data = gemini_wdt;
  4534. +
  4535. + gemini_wdt_start(gemini_wdt);
  4536. +
  4537. + return nonseekable_open(inode, file);
  4538. +}
  4539. +
  4540. +/* Close the watchdog device. */
  4541. +static int gemini_wdt_close(struct inode *inode, struct file *file)
  4542. +{
  4543. + struct gemini_wdt_struct *gemini_wdt = file->private_data;
  4544. +
  4545. + /* Disable the watchdog if possible */
  4546. + if (test_bit(WDT_OK_TO_CLOSE, &gemini_wdt->status))
  4547. + gemini_wdt_stop(gemini_wdt);
  4548. + else
  4549. + dev_warn(gemini_wdt->dev, "Device closed unexpectedly - timer will not stop\n");
  4550. +
  4551. + return 0;
  4552. +}
  4553. +
  4554. +/* Handle commands from user-space. */
  4555. +static int gemini_wdt_ioctl(struct inode *inode, struct file *file,
  4556. + unsigned int cmd, unsigned long arg)
  4557. +{
  4558. + struct gemini_wdt_struct *gemini_wdt = file->private_data;
  4559. +
  4560. + int value;
  4561. +
  4562. + switch (cmd) {
  4563. + case WDIOC_KEEPALIVE:
  4564. + gemini_wdt_service(gemini_wdt);
  4565. + return 0;
  4566. +
  4567. + case WDIOC_GETSUPPORT:
  4568. + return copy_to_user((struct watchdog_info *)arg, &gemini_wdt_info,
  4569. + sizeof(gemini_wdt_info)) ? -EFAULT : 0;
  4570. +
  4571. + case WDIOC_SETTIMEOUT:
  4572. + if (get_user(value, (int *)arg))
  4573. + return -EFAULT;
  4574. +
  4575. + if ((value < 1) || (value > WDT_MAX_TIMEOUT))
  4576. + return -EINVAL;
  4577. +
  4578. + timeout = value;
  4579. +
  4580. + /* restart wdt to use new timeout */
  4581. + gemini_wdt_stop(gemini_wdt);
  4582. + gemini_wdt_start(gemini_wdt);
  4583. +
  4584. + /* Fall through */
  4585. + case WDIOC_GETTIMEOUT:
  4586. + return put_user(timeout, (int *)arg);
  4587. +
  4588. + case WDIOC_GETTIMELEFT:
  4589. + value = __raw_readl(gemini_wdt->base + GEMINI_WDCOUNTER);
  4590. + return put_user(value / WDT_CLOCK, (int *)arg);
  4591. +
  4592. + default:
  4593. + return -ENOTTY;
  4594. + }
  4595. +}
  4596. +
  4597. +/* Refresh the watchdog whenever device is written to. */
  4598. +static ssize_t gemini_wdt_write(struct file *file, const char *data,
  4599. + size_t len, loff_t *ppos)
  4600. +{
  4601. + struct gemini_wdt_struct *gemini_wdt = file->private_data;
  4602. +
  4603. + if (len) {
  4604. + if (!nowayout) {
  4605. + size_t i;
  4606. +
  4607. + clear_bit(WDT_OK_TO_CLOSE, &gemini_wdt->status);
  4608. + for (i = 0; i != len; i++) {
  4609. + char c;
  4610. +
  4611. + if (get_user(c, data + i))
  4612. + return -EFAULT;
  4613. + if (c == 'V')
  4614. + set_bit(WDT_OK_TO_CLOSE,
  4615. + &gemini_wdt->status);
  4616. + }
  4617. + }
  4618. + gemini_wdt_service(gemini_wdt);
  4619. + }
  4620. +
  4621. + return len;
  4622. +}
  4623. +
  4624. +static const struct file_operations gemini_wdt_fops = {
  4625. + .owner = THIS_MODULE,
  4626. + .llseek = no_llseek,
  4627. + .open = gemini_wdt_open,
  4628. + .release = gemini_wdt_close,
  4629. + .write = gemini_wdt_write,
  4630. +};
  4631. +
  4632. +static struct miscdevice gemini_wdt_miscdev = {
  4633. + .minor = WATCHDOG_MINOR,
  4634. + .name = "watchdog",
  4635. + .fops = &gemini_wdt_fops,
  4636. +};
  4637. +
  4638. +static void gemini_wdt_shutdown(struct platform_device *pdev)
  4639. +{
  4640. + struct gemini_wdt_struct *gemini_wdt = platform_get_drvdata(pdev);
  4641. +
  4642. + gemini_wdt_stop(gemini_wdt);
  4643. +}
  4644. +
  4645. +static int __init gemini_wdt_probe(struct platform_device *pdev)
  4646. +{
  4647. + int ret;
  4648. + int res_size;
  4649. + struct resource *res;
  4650. + void __iomem *base;
  4651. + struct gemini_wdt_struct *gemini_wdt;
  4652. +
  4653. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4654. + if (!res) {
  4655. + dev_err(&pdev->dev, "can't get device resources\n");
  4656. + return -ENODEV;
  4657. + }
  4658. +
  4659. + res_size = resource_size(res);
  4660. + if (!request_mem_region(res->start, res_size, res->name)) {
  4661. + dev_err(&pdev->dev, "can't allocate %d bytes at %d address\n",
  4662. + res_size, res->start);
  4663. + return -ENOMEM;
  4664. + }
  4665. +
  4666. + base = ioremap(res->start, res_size);
  4667. + if (!base) {
  4668. + dev_err(&pdev->dev, "ioremap failed\n");
  4669. + ret = -EIO;
  4670. + goto fail0;
  4671. + }
  4672. +
  4673. + gemini_wdt = kzalloc(sizeof(struct gemini_wdt_struct), GFP_KERNEL);
  4674. + if (!gemini_wdt) {
  4675. + dev_err(&pdev->dev, "can't allocate interface\n");
  4676. + ret = -ENOMEM;
  4677. + goto fail1;
  4678. + }
  4679. +
  4680. + /* Setup gemini_wdt driver structure */
  4681. + gemini_wdt->base = base;
  4682. + gemini_wdt->res = res;
  4683. +
  4684. + /* Set up platform driver data */
  4685. + platform_set_drvdata(pdev, gemini_wdt);
  4686. + gemini_wdt_dev = pdev;
  4687. +
  4688. + if (gemini_wdt_miscdev.parent) {
  4689. + ret = -EBUSY;
  4690. + goto fail2;
  4691. + }
  4692. +
  4693. + gemini_wdt_miscdev.parent = &pdev->dev;
  4694. +
  4695. + ret = misc_register(&gemini_wdt_miscdev);
  4696. + if (ret)
  4697. + goto fail2;
  4698. +
  4699. + return 0;
  4700. +
  4701. +fail2:
  4702. + platform_set_drvdata(pdev, NULL);
  4703. + kfree(gemini_wdt);
  4704. +fail1:
  4705. + iounmap(base);
  4706. +fail0:
  4707. + release_mem_region(res->start, res_size);
  4708. +
  4709. + return ret;
  4710. +}
  4711. +
  4712. +static int __exit gemini_wdt_remove(struct platform_device *pdev)
  4713. +{
  4714. + struct gemini_wdt_struct *gemini_wdt = platform_get_drvdata(pdev);
  4715. +
  4716. + platform_set_drvdata(pdev, NULL);
  4717. + misc_deregister(&gemini_wdt_miscdev);
  4718. + gemini_wdt_dev = NULL;
  4719. + iounmap(gemini_wdt->base);
  4720. + release_mem_region(gemini_wdt->res->start, resource_size(gemini_wdt->res));
  4721. +
  4722. + kfree(gemini_wdt);
  4723. +
  4724. + return 0;
  4725. +}
  4726. +
  4727. +#ifdef CONFIG_PM
  4728. +static int gemini_wdt_suspend(struct platform_device *pdev, pm_message_t message)
  4729. +{
  4730. + struct gemini_wdt_struct *gemini_wdt = platform_get_drvdata(pdev);
  4731. + unsigned int reg;
  4732. +
  4733. + reg = __raw_readw(gemini_wdt->base + GEMINI_WDCR);
  4734. + reg &= ~(WDCR_WDENABLE);
  4735. + __raw_writel(reg, gemini_wdt->base + GEMINI_WDCR);
  4736. +
  4737. + return 0;
  4738. +}
  4739. +
  4740. +static int gemini_wdt_resume(struct platform_device *pdev)
  4741. +{
  4742. + struct gemini_wdt_struct *gemini_wdt = platform_get_drvdata(pdev);
  4743. + unsigned int reg;
  4744. +
  4745. + if (gemini_wdt->status) {
  4746. + reg = __raw_readw(gemini_wdt->base + GEMINI_WDCR);
  4747. + reg |= WDCR_WDENABLE;
  4748. + __raw_writel(reg, gemini_wdt->base + GEMINI_WDCR);
  4749. + }
  4750. +
  4751. + return 0;
  4752. +}
  4753. +#else
  4754. +#define gemini_wdt_suspend NULL
  4755. +#define gemini_wdt_resume NULL
  4756. +#endif
  4757. +
  4758. +static struct platform_driver gemini_wdt_driver = {
  4759. + .probe = gemini_wdt_probe,
  4760. + .remove = __exit_p(gemini_wdt_remove),
  4761. + .shutdown = gemini_wdt_shutdown,
  4762. + .suspend = gemini_wdt_suspend,
  4763. + .resume = gemini_wdt_resume,
  4764. + .driver = {
  4765. + .name = "gemini-wdt",
  4766. + .owner = THIS_MODULE,
  4767. + },
  4768. +};
  4769. +
  4770. +static int __init gemini_wdt_init(void)
  4771. +{
  4772. + return platform_driver_probe(&gemini_wdt_driver, gemini_wdt_probe);
  4773. +}
  4774. +
  4775. +static void __exit gemini_wdt_exit(void)
  4776. +{
  4777. + platform_driver_unregister(&gemini_wdt_driver);
  4778. +}
  4779. +
  4780. +module_init(gemini_wdt_init);
  4781. +module_exit(gemini_wdt_exit);
  4782. +
  4783. +module_param(timeout, uint, 0);
  4784. +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");
  4785. +
  4786. +module_param(nowayout, int, 0);
  4787. +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
  4788. +
  4789. +MODULE_AUTHOR("Paulius Zaleckas");
  4790. +MODULE_DESCRIPTION("Watchdog driver for Gemini");
  4791. +MODULE_LICENSE("GPL");
  4792. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  4793. +MODULE_ALIAS("platform:gemini-wdt");
  4794. --- a/drivers/watchdog/Kconfig
  4795. +++ b/drivers/watchdog/Kconfig
  4796. @@ -118,6 +118,16 @@ config 977_WATCHDOG
  4797. Not sure? It's safe to say N.
  4798. +config GEMINI_WATCHDOG
  4799. + tristate "Gemini watchdog"
  4800. + depends on ARCH_GEMINI
  4801. + help
  4802. + Say Y here if to include support for the watchdog timer
  4803. + embedded in the Cortina Systems Gemini family of devices.
  4804. +
  4805. + To compile this driver as a module, choose M here: the
  4806. + module will be called gemini_wdt.
  4807. +
  4808. config IXP2000_WATCHDOG
  4809. tristate "IXP2000 Watchdog"
  4810. depends on ARCH_IXP2000
  4811. --- a/drivers/watchdog/Makefile
  4812. +++ b/drivers/watchdog/Makefile
  4813. @@ -32,6 +32,7 @@ obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.
  4814. obj-$(CONFIG_TWL4030_WATCHDOG) += twl4030_wdt.o
  4815. obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
  4816. obj-$(CONFIG_977_WATCHDOG) += wdt977.o
  4817. +obj-$(CONFIG_GEMINI_WATCHDOG) += gemini_wdt.o
  4818. obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
  4819. obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o
  4820. obj-$(CONFIG_KS8695_WATCHDOG) += ks8695_wdt.o
  4821. --- a/include/linux/usb/ehci_def.h
  4822. +++ b/include/linux/usb/ehci_def.h
  4823. @@ -105,9 +105,9 @@ struct ehci_regs {
  4824. u32 frame_list; /* points to periodic list */
  4825. /* ASYNCLISTADDR: offset 0x18 */
  4826. u32 async_next; /* address of next async queue head */
  4827. -
  4828. +#ifndef CONFIG_ARCH_GEMINI
  4829. u32 reserved[9];
  4830. -
  4831. +#endif
  4832. /* CONFIGFLAG: offset 0x40 */
  4833. u32 configured_flag;
  4834. #define FLAG_CF (1<<0) /* true: we'll support "high speed" */
  4835. --- a/arch/arm/mm/Kconfig
  4836. +++ b/arch/arm/mm/Kconfig
  4837. @@ -806,6 +806,7 @@ config CACHE_XSC3L2
  4838. config ARM_L1_CACHE_SHIFT
  4839. int
  4840. + default 4 if CPU_FA526
  4841. default 6 if ARM_L1_CACHE_SHIFT_6
  4842. default 5
  4843. --- a/arch/arm/lib/copy_page.S
  4844. +++ b/arch/arm/lib/copy_page.S
  4845. @@ -17,7 +17,7 @@
  4846. #define COPY_COUNT (PAGE_SZ / (2 * L1_CACHE_BYTES) PLD( -1 ))
  4847. .text
  4848. - .align 5
  4849. + .align L1_CACHE_SHIFT
  4850. /*
  4851. * StrongARM optimised copy_page routine
  4852. * now 1.78bytes/cycle, was 1.60 bytes/cycle (50MHz bus -> 89MB/s)