001-git_sync.patch 151 KB

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