ucc_geth.c 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317
  1. /*
  2. * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
  3. *
  4. * Author: Shlomi Gridish <gridish@freescale.com>
  5. * Li Yang <leoli@freescale.com>
  6. *
  7. * Description:
  8. * QE UCC Gigabit Ethernet Driver
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/slab.h>
  19. #include <linux/stddef.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/skbuff.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/mm.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/delay.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/fsl_devices.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/mii.h>
  32. #include <asm/of_device.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/irq.h>
  35. #include <asm/io.h>
  36. #include <asm/immap_qe.h>
  37. #include <asm/qe.h>
  38. #include <asm/ucc.h>
  39. #include <asm/ucc_fast.h>
  40. #include "ucc_geth.h"
  41. #include "ucc_geth_phy.h"
  42. #undef DEBUG
  43. #define DRV_DESC "QE UCC Gigabit Ethernet Controller version:Sept 11, 2006"
  44. #define DRV_NAME "ucc_geth"
  45. #define ugeth_printk(level, format, arg...) \
  46. printk(level format "\n", ## arg)
  47. #define ugeth_dbg(format, arg...) \
  48. ugeth_printk(KERN_DEBUG , format , ## arg)
  49. #define ugeth_err(format, arg...) \
  50. ugeth_printk(KERN_ERR , format , ## arg)
  51. #define ugeth_info(format, arg...) \
  52. ugeth_printk(KERN_INFO , format , ## arg)
  53. #define ugeth_warn(format, arg...) \
  54. ugeth_printk(KERN_WARNING , format , ## arg)
  55. #ifdef UGETH_VERBOSE_DEBUG
  56. #define ugeth_vdbg ugeth_dbg
  57. #else
  58. #define ugeth_vdbg(fmt, args...) do { } while (0)
  59. #endif /* UGETH_VERBOSE_DEBUG */
  60. static DEFINE_SPINLOCK(ugeth_lock);
  61. static struct ucc_geth_info ugeth_primary_info = {
  62. .uf_info = {
  63. .bd_mem_part = MEM_PART_SYSTEM,
  64. .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES,
  65. .max_rx_buf_length = 1536,
  66. /* FIXME: should be changed in run time for 1G and 100M */
  67. #ifdef CONFIG_UGETH_HAS_GIGA
  68. .urfs = UCC_GETH_URFS_GIGA_INIT,
  69. .urfet = UCC_GETH_URFET_GIGA_INIT,
  70. .urfset = UCC_GETH_URFSET_GIGA_INIT,
  71. .utfs = UCC_GETH_UTFS_GIGA_INIT,
  72. .utfet = UCC_GETH_UTFET_GIGA_INIT,
  73. .utftt = UCC_GETH_UTFTT_GIGA_INIT,
  74. #else
  75. .urfs = UCC_GETH_URFS_INIT,
  76. .urfet = UCC_GETH_URFET_INIT,
  77. .urfset = UCC_GETH_URFSET_INIT,
  78. .utfs = UCC_GETH_UTFS_INIT,
  79. .utfet = UCC_GETH_UTFET_INIT,
  80. .utftt = UCC_GETH_UTFTT_INIT,
  81. #endif
  82. .ufpt = 256,
  83. .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET,
  84. .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL,
  85. .tenc = UCC_FAST_TX_ENCODING_NRZ,
  86. .renc = UCC_FAST_RX_ENCODING_NRZ,
  87. .tcrc = UCC_FAST_16_BIT_CRC,
  88. .synl = UCC_FAST_SYNC_LEN_NOT_USED,
  89. },
  90. .numQueuesTx = 1,
  91. .numQueuesRx = 1,
  92. .extendedFilteringChainPointer = ((uint32_t) NULL),
  93. .typeorlen = 3072 /*1536 */ ,
  94. .nonBackToBackIfgPart1 = 0x40,
  95. .nonBackToBackIfgPart2 = 0x60,
  96. .miminumInterFrameGapEnforcement = 0x50,
  97. .backToBackInterFrameGap = 0x60,
  98. .mblinterval = 128,
  99. .nortsrbytetime = 5,
  100. .fracsiz = 1,
  101. .strictpriorityq = 0xff,
  102. .altBebTruncation = 0xa,
  103. .excessDefer = 1,
  104. .maxRetransmission = 0xf,
  105. .collisionWindow = 0x37,
  106. .receiveFlowControl = 1,
  107. .maxGroupAddrInHash = 4,
  108. .maxIndAddrInHash = 4,
  109. .prel = 7,
  110. .maxFrameLength = 1518,
  111. .minFrameLength = 64,
  112. .maxD1Length = 1520,
  113. .maxD2Length = 1520,
  114. .vlantype = 0x8100,
  115. .ecamptr = ((uint32_t) NULL),
  116. .eventRegMask = UCCE_OTHER,
  117. .pausePeriod = 0xf000,
  118. .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
  119. .bdRingLenTx = {
  120. TX_BD_RING_LEN,
  121. TX_BD_RING_LEN,
  122. TX_BD_RING_LEN,
  123. TX_BD_RING_LEN,
  124. TX_BD_RING_LEN,
  125. TX_BD_RING_LEN,
  126. TX_BD_RING_LEN,
  127. TX_BD_RING_LEN},
  128. .bdRingLenRx = {
  129. RX_BD_RING_LEN,
  130. RX_BD_RING_LEN,
  131. RX_BD_RING_LEN,
  132. RX_BD_RING_LEN,
  133. RX_BD_RING_LEN,
  134. RX_BD_RING_LEN,
  135. RX_BD_RING_LEN,
  136. RX_BD_RING_LEN},
  137. .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
  138. .largestexternallookupkeysize =
  139. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
  140. .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_NONE,
  141. .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
  142. .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
  143. .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
  144. .aufc = UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE,
  145. .padAndCrc = MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC,
  146. .numThreadsTx = UCC_GETH_NUM_OF_THREADS_4,
  147. .numThreadsRx = UCC_GETH_NUM_OF_THREADS_4,
  148. .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
  149. .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
  150. };
  151. static struct ucc_geth_info ugeth_info[8];
  152. #ifdef DEBUG
  153. static void mem_disp(u8 *addr, int size)
  154. {
  155. u8 *i;
  156. int size16Aling = (size >> 4) << 4;
  157. int size4Aling = (size >> 2) << 2;
  158. int notAlign = 0;
  159. if (size % 16)
  160. notAlign = 1;
  161. for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16)
  162. printk("0x%08x: %08x %08x %08x %08x\r\n",
  163. (u32) i,
  164. *((u32 *) (i)),
  165. *((u32 *) (i + 4)),
  166. *((u32 *) (i + 8)), *((u32 *) (i + 12)));
  167. if (notAlign == 1)
  168. printk("0x%08x: ", (u32) i);
  169. for (; (u32) i < (u32) addr + size4Aling; i += 4)
  170. printk("%08x ", *((u32 *) (i)));
  171. for (; (u32) i < (u32) addr + size; i++)
  172. printk("%02x", *((u8 *) (i)));
  173. if (notAlign == 1)
  174. printk("\r\n");
  175. }
  176. #endif /* DEBUG */
  177. #ifdef CONFIG_UGETH_FILTERING
  178. static void enqueue(struct list_head *node, struct list_head *lh)
  179. {
  180. unsigned long flags;
  181. spin_lock_irqsave(ugeth_lock, flags);
  182. list_add_tail(node, lh);
  183. spin_unlock_irqrestore(ugeth_lock, flags);
  184. }
  185. #endif /* CONFIG_UGETH_FILTERING */
  186. static struct list_head *dequeue(struct list_head *lh)
  187. {
  188. unsigned long flags;
  189. spin_lock_irqsave(ugeth_lock, flags);
  190. if (!list_empty(lh)) {
  191. struct list_head *node = lh->next;
  192. list_del(node);
  193. spin_unlock_irqrestore(ugeth_lock, flags);
  194. return node;
  195. } else {
  196. spin_unlock_irqrestore(ugeth_lock, flags);
  197. return NULL;
  198. }
  199. }
  200. static int get_interface_details(enum enet_interface enet_interface,
  201. enum enet_speed *speed,
  202. int *r10m,
  203. int *rmm,
  204. int *rpm,
  205. int *tbi, int *limited_to_full_duplex)
  206. {
  207. /* Analyze enet_interface according to Interface Mode
  208. Configuration table */
  209. switch (enet_interface) {
  210. case ENET_10_MII:
  211. *speed = ENET_SPEED_10BT;
  212. break;
  213. case ENET_10_RMII:
  214. *speed = ENET_SPEED_10BT;
  215. *r10m = 1;
  216. *rmm = 1;
  217. break;
  218. case ENET_10_RGMII:
  219. *speed = ENET_SPEED_10BT;
  220. *rpm = 1;
  221. *r10m = 1;
  222. *limited_to_full_duplex = 1;
  223. break;
  224. case ENET_100_MII:
  225. *speed = ENET_SPEED_100BT;
  226. break;
  227. case ENET_100_RMII:
  228. *speed = ENET_SPEED_100BT;
  229. *rmm = 1;
  230. break;
  231. case ENET_100_RGMII:
  232. *speed = ENET_SPEED_100BT;
  233. *rpm = 1;
  234. *limited_to_full_duplex = 1;
  235. break;
  236. case ENET_1000_GMII:
  237. *speed = ENET_SPEED_1000BT;
  238. *limited_to_full_duplex = 1;
  239. break;
  240. case ENET_1000_RGMII:
  241. *speed = ENET_SPEED_1000BT;
  242. *rpm = 1;
  243. *limited_to_full_duplex = 1;
  244. break;
  245. case ENET_1000_TBI:
  246. *speed = ENET_SPEED_1000BT;
  247. *tbi = 1;
  248. *limited_to_full_duplex = 1;
  249. break;
  250. case ENET_1000_RTBI:
  251. *speed = ENET_SPEED_1000BT;
  252. *rpm = 1;
  253. *tbi = 1;
  254. *limited_to_full_duplex = 1;
  255. break;
  256. default:
  257. return -EINVAL;
  258. break;
  259. }
  260. return 0;
  261. }
  262. static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth, u8 *bd)
  263. {
  264. struct sk_buff *skb = NULL;
  265. skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
  266. UCC_GETH_RX_DATA_BUF_ALIGNMENT);
  267. if (skb == NULL)
  268. return NULL;
  269. /* We need the data buffer to be aligned properly. We will reserve
  270. * as many bytes as needed to align the data properly
  271. */
  272. skb_reserve(skb,
  273. UCC_GETH_RX_DATA_BUF_ALIGNMENT -
  274. (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
  275. 1)));
  276. skb->dev = ugeth->dev;
  277. out_be32(&((struct qe_bd *)bd)->buf,
  278. dma_map_single(NULL,
  279. skb->data,
  280. ugeth->ug_info->uf_info.max_rx_buf_length +
  281. UCC_GETH_RX_DATA_BUF_ALIGNMENT,
  282. DMA_FROM_DEVICE));
  283. out_be32((u32 *)bd, (R_E | R_I | (in_be32((u32 *)bd) & R_W)));
  284. return skb;
  285. }
  286. static int rx_bd_buffer_set(struct ucc_geth_private *ugeth, u8 rxQ)
  287. {
  288. u8 *bd;
  289. u32 bd_status;
  290. struct sk_buff *skb;
  291. int i;
  292. bd = ugeth->p_rx_bd_ring[rxQ];
  293. i = 0;
  294. do {
  295. bd_status = in_be32((u32*)bd);
  296. skb = get_new_skb(ugeth, bd);
  297. if (!skb) /* If can not allocate data buffer,
  298. abort. Cleanup will be elsewhere */
  299. return -ENOMEM;
  300. ugeth->rx_skbuff[rxQ][i] = skb;
  301. /* advance the BD pointer */
  302. bd += sizeof(struct qe_bd);
  303. i++;
  304. } while (!(bd_status & R_W));
  305. return 0;
  306. }
  307. static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
  308. volatile u32 *p_start,
  309. u8 num_entries,
  310. u32 thread_size,
  311. u32 thread_alignment,
  312. enum qe_risc_allocation risc,
  313. int skip_page_for_first_entry)
  314. {
  315. u32 init_enet_offset;
  316. u8 i;
  317. int snum;
  318. for (i = 0; i < num_entries; i++) {
  319. if ((snum = qe_get_snum()) < 0) {
  320. ugeth_err("fill_init_enet_entries: Can not get SNUM.");
  321. return snum;
  322. }
  323. if ((i == 0) && skip_page_for_first_entry)
  324. /* First entry of Rx does not have page */
  325. init_enet_offset = 0;
  326. else {
  327. init_enet_offset =
  328. qe_muram_alloc(thread_size, thread_alignment);
  329. if (IS_MURAM_ERR(init_enet_offset)) {
  330. ugeth_err
  331. ("fill_init_enet_entries: Can not allocate DPRAM memory.");
  332. qe_put_snum((u8) snum);
  333. return -ENOMEM;
  334. }
  335. }
  336. *(p_start++) =
  337. ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
  338. | risc;
  339. }
  340. return 0;
  341. }
  342. static int return_init_enet_entries(struct ucc_geth_private *ugeth,
  343. volatile u32 *p_start,
  344. u8 num_entries,
  345. enum qe_risc_allocation risc,
  346. int skip_page_for_first_entry)
  347. {
  348. u32 init_enet_offset;
  349. u8 i;
  350. int snum;
  351. for (i = 0; i < num_entries; i++) {
  352. /* Check that this entry was actually valid --
  353. needed in case failed in allocations */
  354. if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
  355. snum =
  356. (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
  357. ENET_INIT_PARAM_SNUM_SHIFT;
  358. qe_put_snum((u8) snum);
  359. if (!((i == 0) && skip_page_for_first_entry)) {
  360. /* First entry of Rx does not have page */
  361. init_enet_offset =
  362. (in_be32(p_start) &
  363. ENET_INIT_PARAM_PTR_MASK);
  364. qe_muram_free(init_enet_offset);
  365. }
  366. *(p_start++) = 0; /* Just for cosmetics */
  367. }
  368. }
  369. return 0;
  370. }
  371. #ifdef DEBUG
  372. static int dump_init_enet_entries(struct ucc_geth_private *ugeth,
  373. volatile u32 *p_start,
  374. u8 num_entries,
  375. u32 thread_size,
  376. enum qe_risc_allocation risc,
  377. int skip_page_for_first_entry)
  378. {
  379. u32 init_enet_offset;
  380. u8 i;
  381. int snum;
  382. for (i = 0; i < num_entries; i++) {
  383. /* Check that this entry was actually valid --
  384. needed in case failed in allocations */
  385. if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
  386. snum =
  387. (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
  388. ENET_INIT_PARAM_SNUM_SHIFT;
  389. qe_put_snum((u8) snum);
  390. if (!((i == 0) && skip_page_for_first_entry)) {
  391. /* First entry of Rx does not have page */
  392. init_enet_offset =
  393. (in_be32(p_start) &
  394. ENET_INIT_PARAM_PTR_MASK);
  395. ugeth_info("Init enet entry %d:", i);
  396. ugeth_info("Base address: 0x%08x",
  397. (u32)
  398. qe_muram_addr(init_enet_offset));
  399. mem_disp(qe_muram_addr(init_enet_offset),
  400. thread_size);
  401. }
  402. p_start++;
  403. }
  404. }
  405. return 0;
  406. }
  407. #endif
  408. #ifdef CONFIG_UGETH_FILTERING
  409. static struct enet_addr_container *get_enet_addr_container(void)
  410. {
  411. struct enet_addr_container *enet_addr_cont;
  412. /* allocate memory */
  413. enet_addr_cont = kmalloc(sizeof(struct enet_addr_container), GFP_KERNEL);
  414. if (!enet_addr_cont) {
  415. ugeth_err("%s: No memory for enet_addr_container object.",
  416. __FUNCTION__);
  417. return NULL;
  418. }
  419. return enet_addr_cont;
  420. }
  421. #endif /* CONFIG_UGETH_FILTERING */
  422. static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
  423. {
  424. kfree(enet_addr_cont);
  425. }
  426. static int set_mac_addr(__be16 __iomem *reg, u8 *mac)
  427. {
  428. out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
  429. out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
  430. out_be16(&reg[2], ((u16)mac[1] << 8) | mac[0]);
  431. }
  432. #ifdef CONFIG_UGETH_FILTERING
  433. static int hw_add_addr_in_paddr(struct ucc_geth_private *ugeth,
  434. u8 *p_enet_addr, u8 paddr_num)
  435. {
  436. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  437. if (!(paddr_num < NUM_OF_PADDRS)) {
  438. ugeth_warn("%s: Illegal paddr_num.", __FUNCTION__);
  439. return -EINVAL;
  440. }
  441. p_82xx_addr_filt =
  442. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
  443. addressfiltering;
  444. /* Ethernet frames are defined in Little Endian mode, */
  445. /* therefore to insert the address we reverse the bytes. */
  446. set_mac_addr(&p_82xx_addr_filt->paddr[paddr_num].h, p_enet_addr);
  447. return 0;
  448. }
  449. #endif /* CONFIG_UGETH_FILTERING */
  450. static int hw_clear_addr_in_paddr(struct ucc_geth_private *ugeth, u8 paddr_num)
  451. {
  452. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  453. if (!(paddr_num < NUM_OF_PADDRS)) {
  454. ugeth_warn("%s: Illagel paddr_num.", __FUNCTION__);
  455. return -EINVAL;
  456. }
  457. p_82xx_addr_filt =
  458. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
  459. addressfiltering;
  460. /* Writing address ff.ff.ff.ff.ff.ff disables address
  461. recognition for this register */
  462. out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
  463. out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
  464. out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
  465. return 0;
  466. }
  467. static void hw_add_addr_in_hash(struct ucc_geth_private *ugeth,
  468. u8 *p_enet_addr)
  469. {
  470. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  471. u32 cecr_subblock;
  472. p_82xx_addr_filt =
  473. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
  474. addressfiltering;
  475. cecr_subblock =
  476. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  477. /* Ethernet frames are defined in Little Endian mode,
  478. therefor to insert */
  479. /* the address to the hash (Big Endian mode), we reverse the bytes.*/
  480. set_mac_addr(&p_82xx_addr_filt->taddr.h, p_enet_addr);
  481. qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
  482. QE_CR_PROTOCOL_ETHERNET, 0);
  483. }
  484. #ifdef CONFIG_UGETH_MAGIC_PACKET
  485. static void magic_packet_detection_enable(struct ucc_geth_private *ugeth)
  486. {
  487. struct ucc_fast_private *uccf;
  488. struct ucc_geth *ug_regs;
  489. u32 maccfg2, uccm;
  490. uccf = ugeth->uccf;
  491. ug_regs = ugeth->ug_regs;
  492. /* Enable interrupts for magic packet detection */
  493. uccm = in_be32(uccf->p_uccm);
  494. uccm |= UCCE_MPD;
  495. out_be32(uccf->p_uccm, uccm);
  496. /* Enable magic packet detection */
  497. maccfg2 = in_be32(&ug_regs->maccfg2);
  498. maccfg2 |= MACCFG2_MPE;
  499. out_be32(&ug_regs->maccfg2, maccfg2);
  500. }
  501. static void magic_packet_detection_disable(struct ucc_geth_private *ugeth)
  502. {
  503. struct ucc_fast_private *uccf;
  504. struct ucc_geth *ug_regs;
  505. u32 maccfg2, uccm;
  506. uccf = ugeth->uccf;
  507. ug_regs = ugeth->ug_regs;
  508. /* Disable interrupts for magic packet detection */
  509. uccm = in_be32(uccf->p_uccm);
  510. uccm &= ~UCCE_MPD;
  511. out_be32(uccf->p_uccm, uccm);
  512. /* Disable magic packet detection */
  513. maccfg2 = in_be32(&ug_regs->maccfg2);
  514. maccfg2 &= ~MACCFG2_MPE;
  515. out_be32(&ug_regs->maccfg2, maccfg2);
  516. }
  517. #endif /* MAGIC_PACKET */
  518. static inline int compare_addr(u8 **addr1, u8 **addr2)
  519. {
  520. return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
  521. }
  522. #ifdef DEBUG
  523. static void get_statistics(struct ucc_geth_private *ugeth,
  524. struct ucc_geth_tx_firmware_statistics *
  525. tx_firmware_statistics,
  526. struct ucc_geth_rx_firmware_statistics *
  527. rx_firmware_statistics,
  528. struct ucc_geth_hardware_statistics *hardware_statistics)
  529. {
  530. struct ucc_fast *uf_regs;
  531. struct ucc_geth *ug_regs;
  532. struct ucc_geth_tx_firmware_statistics_pram *p_tx_fw_statistics_pram;
  533. struct ucc_geth_rx_firmware_statistics_pram *p_rx_fw_statistics_pram;
  534. ug_regs = ugeth->ug_regs;
  535. uf_regs = (struct ucc_fast *) ug_regs;
  536. p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
  537. p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
  538. /* Tx firmware only if user handed pointer and driver actually
  539. gathers Tx firmware statistics */
  540. if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
  541. tx_firmware_statistics->sicoltx =
  542. in_be32(&p_tx_fw_statistics_pram->sicoltx);
  543. tx_firmware_statistics->mulcoltx =
  544. in_be32(&p_tx_fw_statistics_pram->mulcoltx);
  545. tx_firmware_statistics->latecoltxfr =
  546. in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
  547. tx_firmware_statistics->frabortduecol =
  548. in_be32(&p_tx_fw_statistics_pram->frabortduecol);
  549. tx_firmware_statistics->frlostinmactxer =
  550. in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
  551. tx_firmware_statistics->carriersenseertx =
  552. in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
  553. tx_firmware_statistics->frtxok =
  554. in_be32(&p_tx_fw_statistics_pram->frtxok);
  555. tx_firmware_statistics->txfrexcessivedefer =
  556. in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
  557. tx_firmware_statistics->txpkts256 =
  558. in_be32(&p_tx_fw_statistics_pram->txpkts256);
  559. tx_firmware_statistics->txpkts512 =
  560. in_be32(&p_tx_fw_statistics_pram->txpkts512);
  561. tx_firmware_statistics->txpkts1024 =
  562. in_be32(&p_tx_fw_statistics_pram->txpkts1024);
  563. tx_firmware_statistics->txpktsjumbo =
  564. in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
  565. }
  566. /* Rx firmware only if user handed pointer and driver actually
  567. * gathers Rx firmware statistics */
  568. if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
  569. int i;
  570. rx_firmware_statistics->frrxfcser =
  571. in_be32(&p_rx_fw_statistics_pram->frrxfcser);
  572. rx_firmware_statistics->fraligner =
  573. in_be32(&p_rx_fw_statistics_pram->fraligner);
  574. rx_firmware_statistics->inrangelenrxer =
  575. in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
  576. rx_firmware_statistics->outrangelenrxer =
  577. in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
  578. rx_firmware_statistics->frtoolong =
  579. in_be32(&p_rx_fw_statistics_pram->frtoolong);
  580. rx_firmware_statistics->runt =
  581. in_be32(&p_rx_fw_statistics_pram->runt);
  582. rx_firmware_statistics->verylongevent =
  583. in_be32(&p_rx_fw_statistics_pram->verylongevent);
  584. rx_firmware_statistics->symbolerror =
  585. in_be32(&p_rx_fw_statistics_pram->symbolerror);
  586. rx_firmware_statistics->dropbsy =
  587. in_be32(&p_rx_fw_statistics_pram->dropbsy);
  588. for (i = 0; i < 0x8; i++)
  589. rx_firmware_statistics->res0[i] =
  590. p_rx_fw_statistics_pram->res0[i];
  591. rx_firmware_statistics->mismatchdrop =
  592. in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
  593. rx_firmware_statistics->underpkts =
  594. in_be32(&p_rx_fw_statistics_pram->underpkts);
  595. rx_firmware_statistics->pkts256 =
  596. in_be32(&p_rx_fw_statistics_pram->pkts256);
  597. rx_firmware_statistics->pkts512 =
  598. in_be32(&p_rx_fw_statistics_pram->pkts512);
  599. rx_firmware_statistics->pkts1024 =
  600. in_be32(&p_rx_fw_statistics_pram->pkts1024);
  601. rx_firmware_statistics->pktsjumbo =
  602. in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
  603. rx_firmware_statistics->frlossinmacer =
  604. in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
  605. rx_firmware_statistics->pausefr =
  606. in_be32(&p_rx_fw_statistics_pram->pausefr);
  607. for (i = 0; i < 0x4; i++)
  608. rx_firmware_statistics->res1[i] =
  609. p_rx_fw_statistics_pram->res1[i];
  610. rx_firmware_statistics->removevlan =
  611. in_be32(&p_rx_fw_statistics_pram->removevlan);
  612. rx_firmware_statistics->replacevlan =
  613. in_be32(&p_rx_fw_statistics_pram->replacevlan);
  614. rx_firmware_statistics->insertvlan =
  615. in_be32(&p_rx_fw_statistics_pram->insertvlan);
  616. }
  617. /* Hardware only if user handed pointer and driver actually
  618. gathers hardware statistics */
  619. if (hardware_statistics && (in_be32(&uf_regs->upsmr) & UPSMR_HSE)) {
  620. hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
  621. hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
  622. hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
  623. hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
  624. hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
  625. hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
  626. hardware_statistics->txok = in_be32(&ug_regs->txok);
  627. hardware_statistics->txcf = in_be16(&ug_regs->txcf);
  628. hardware_statistics->tmca = in_be32(&ug_regs->tmca);
  629. hardware_statistics->tbca = in_be32(&ug_regs->tbca);
  630. hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
  631. hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
  632. hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
  633. hardware_statistics->rmca = in_be32(&ug_regs->rmca);
  634. hardware_statistics->rbca = in_be32(&ug_regs->rbca);
  635. }
  636. }
  637. static void dump_bds(struct ucc_geth_private *ugeth)
  638. {
  639. int i;
  640. int length;
  641. for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
  642. if (ugeth->p_tx_bd_ring[i]) {
  643. length =
  644. (ugeth->ug_info->bdRingLenTx[i] *
  645. sizeof(struct qe_bd));
  646. ugeth_info("TX BDs[%d]", i);
  647. mem_disp(ugeth->p_tx_bd_ring[i], length);
  648. }
  649. }
  650. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  651. if (ugeth->p_rx_bd_ring[i]) {
  652. length =
  653. (ugeth->ug_info->bdRingLenRx[i] *
  654. sizeof(struct qe_bd));
  655. ugeth_info("RX BDs[%d]", i);
  656. mem_disp(ugeth->p_rx_bd_ring[i], length);
  657. }
  658. }
  659. }
  660. static void dump_regs(struct ucc_geth_private *ugeth)
  661. {
  662. int i;
  663. ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
  664. ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
  665. ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
  666. (u32) & ugeth->ug_regs->maccfg1,
  667. in_be32(&ugeth->ug_regs->maccfg1));
  668. ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
  669. (u32) & ugeth->ug_regs->maccfg2,
  670. in_be32(&ugeth->ug_regs->maccfg2));
  671. ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
  672. (u32) & ugeth->ug_regs->ipgifg,
  673. in_be32(&ugeth->ug_regs->ipgifg));
  674. ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
  675. (u32) & ugeth->ug_regs->hafdup,
  676. in_be32(&ugeth->ug_regs->hafdup));
  677. ugeth_info("miimcfg : addr - 0x%08x, val - 0x%08x",
  678. (u32) & ugeth->ug_regs->miimng.miimcfg,
  679. in_be32(&ugeth->ug_regs->miimng.miimcfg));
  680. ugeth_info("miimcom : addr - 0x%08x, val - 0x%08x",
  681. (u32) & ugeth->ug_regs->miimng.miimcom,
  682. in_be32(&ugeth->ug_regs->miimng.miimcom));
  683. ugeth_info("miimadd : addr - 0x%08x, val - 0x%08x",
  684. (u32) & ugeth->ug_regs->miimng.miimadd,
  685. in_be32(&ugeth->ug_regs->miimng.miimadd));
  686. ugeth_info("miimcon : addr - 0x%08x, val - 0x%08x",
  687. (u32) & ugeth->ug_regs->miimng.miimcon,
  688. in_be32(&ugeth->ug_regs->miimng.miimcon));
  689. ugeth_info("miimstat : addr - 0x%08x, val - 0x%08x",
  690. (u32) & ugeth->ug_regs->miimng.miimstat,
  691. in_be32(&ugeth->ug_regs->miimng.miimstat));
  692. ugeth_info("miimmind : addr - 0x%08x, val - 0x%08x",
  693. (u32) & ugeth->ug_regs->miimng.miimind,
  694. in_be32(&ugeth->ug_regs->miimng.miimind));
  695. ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
  696. (u32) & ugeth->ug_regs->ifctl,
  697. in_be32(&ugeth->ug_regs->ifctl));
  698. ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
  699. (u32) & ugeth->ug_regs->ifstat,
  700. in_be32(&ugeth->ug_regs->ifstat));
  701. ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
  702. (u32) & ugeth->ug_regs->macstnaddr1,
  703. in_be32(&ugeth->ug_regs->macstnaddr1));
  704. ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
  705. (u32) & ugeth->ug_regs->macstnaddr2,
  706. in_be32(&ugeth->ug_regs->macstnaddr2));
  707. ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
  708. (u32) & ugeth->ug_regs->uempr,
  709. in_be32(&ugeth->ug_regs->uempr));
  710. ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
  711. (u32) & ugeth->ug_regs->utbipar,
  712. in_be32(&ugeth->ug_regs->utbipar));
  713. ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
  714. (u32) & ugeth->ug_regs->uescr,
  715. in_be16(&ugeth->ug_regs->uescr));
  716. ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
  717. (u32) & ugeth->ug_regs->tx64,
  718. in_be32(&ugeth->ug_regs->tx64));
  719. ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
  720. (u32) & ugeth->ug_regs->tx127,
  721. in_be32(&ugeth->ug_regs->tx127));
  722. ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
  723. (u32) & ugeth->ug_regs->tx255,
  724. in_be32(&ugeth->ug_regs->tx255));
  725. ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
  726. (u32) & ugeth->ug_regs->rx64,
  727. in_be32(&ugeth->ug_regs->rx64));
  728. ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
  729. (u32) & ugeth->ug_regs->rx127,
  730. in_be32(&ugeth->ug_regs->rx127));
  731. ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
  732. (u32) & ugeth->ug_regs->rx255,
  733. in_be32(&ugeth->ug_regs->rx255));
  734. ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
  735. (u32) & ugeth->ug_regs->txok,
  736. in_be32(&ugeth->ug_regs->txok));
  737. ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
  738. (u32) & ugeth->ug_regs->txcf,
  739. in_be16(&ugeth->ug_regs->txcf));
  740. ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
  741. (u32) & ugeth->ug_regs->tmca,
  742. in_be32(&ugeth->ug_regs->tmca));
  743. ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
  744. (u32) & ugeth->ug_regs->tbca,
  745. in_be32(&ugeth->ug_regs->tbca));
  746. ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
  747. (u32) & ugeth->ug_regs->rxfok,
  748. in_be32(&ugeth->ug_regs->rxfok));
  749. ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
  750. (u32) & ugeth->ug_regs->rxbok,
  751. in_be32(&ugeth->ug_regs->rxbok));
  752. ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
  753. (u32) & ugeth->ug_regs->rbyt,
  754. in_be32(&ugeth->ug_regs->rbyt));
  755. ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
  756. (u32) & ugeth->ug_regs->rmca,
  757. in_be32(&ugeth->ug_regs->rmca));
  758. ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
  759. (u32) & ugeth->ug_regs->rbca,
  760. in_be32(&ugeth->ug_regs->rbca));
  761. ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
  762. (u32) & ugeth->ug_regs->scar,
  763. in_be32(&ugeth->ug_regs->scar));
  764. ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
  765. (u32) & ugeth->ug_regs->scam,
  766. in_be32(&ugeth->ug_regs->scam));
  767. if (ugeth->p_thread_data_tx) {
  768. int numThreadsTxNumerical;
  769. switch (ugeth->ug_info->numThreadsTx) {
  770. case UCC_GETH_NUM_OF_THREADS_1:
  771. numThreadsTxNumerical = 1;
  772. break;
  773. case UCC_GETH_NUM_OF_THREADS_2:
  774. numThreadsTxNumerical = 2;
  775. break;
  776. case UCC_GETH_NUM_OF_THREADS_4:
  777. numThreadsTxNumerical = 4;
  778. break;
  779. case UCC_GETH_NUM_OF_THREADS_6:
  780. numThreadsTxNumerical = 6;
  781. break;
  782. case UCC_GETH_NUM_OF_THREADS_8:
  783. numThreadsTxNumerical = 8;
  784. break;
  785. default:
  786. numThreadsTxNumerical = 0;
  787. break;
  788. }
  789. ugeth_info("Thread data TXs:");
  790. ugeth_info("Base address: 0x%08x",
  791. (u32) ugeth->p_thread_data_tx);
  792. for (i = 0; i < numThreadsTxNumerical; i++) {
  793. ugeth_info("Thread data TX[%d]:", i);
  794. ugeth_info("Base address: 0x%08x",
  795. (u32) & ugeth->p_thread_data_tx[i]);
  796. mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
  797. sizeof(struct ucc_geth_thread_data_tx));
  798. }
  799. }
  800. if (ugeth->p_thread_data_rx) {
  801. int numThreadsRxNumerical;
  802. switch (ugeth->ug_info->numThreadsRx) {
  803. case UCC_GETH_NUM_OF_THREADS_1:
  804. numThreadsRxNumerical = 1;
  805. break;
  806. case UCC_GETH_NUM_OF_THREADS_2:
  807. numThreadsRxNumerical = 2;
  808. break;
  809. case UCC_GETH_NUM_OF_THREADS_4:
  810. numThreadsRxNumerical = 4;
  811. break;
  812. case UCC_GETH_NUM_OF_THREADS_6:
  813. numThreadsRxNumerical = 6;
  814. break;
  815. case UCC_GETH_NUM_OF_THREADS_8:
  816. numThreadsRxNumerical = 8;
  817. break;
  818. default:
  819. numThreadsRxNumerical = 0;
  820. break;
  821. }
  822. ugeth_info("Thread data RX:");
  823. ugeth_info("Base address: 0x%08x",
  824. (u32) ugeth->p_thread_data_rx);
  825. for (i = 0; i < numThreadsRxNumerical; i++) {
  826. ugeth_info("Thread data RX[%d]:", i);
  827. ugeth_info("Base address: 0x%08x",
  828. (u32) & ugeth->p_thread_data_rx[i]);
  829. mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
  830. sizeof(struct ucc_geth_thread_data_rx));
  831. }
  832. }
  833. if (ugeth->p_exf_glbl_param) {
  834. ugeth_info("EXF global param:");
  835. ugeth_info("Base address: 0x%08x",
  836. (u32) ugeth->p_exf_glbl_param);
  837. mem_disp((u8 *) ugeth->p_exf_glbl_param,
  838. sizeof(*ugeth->p_exf_glbl_param));
  839. }
  840. if (ugeth->p_tx_glbl_pram) {
  841. ugeth_info("TX global param:");
  842. ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
  843. ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
  844. (u32) & ugeth->p_tx_glbl_pram->temoder,
  845. in_be16(&ugeth->p_tx_glbl_pram->temoder));
  846. ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
  847. (u32) & ugeth->p_tx_glbl_pram->sqptr,
  848. in_be32(&ugeth->p_tx_glbl_pram->sqptr));
  849. ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
  850. (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
  851. in_be32(&ugeth->p_tx_glbl_pram->
  852. schedulerbasepointer));
  853. ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
  854. (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
  855. in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
  856. ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
  857. (u32) & ugeth->p_tx_glbl_pram->tstate,
  858. in_be32(&ugeth->p_tx_glbl_pram->tstate));
  859. ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
  860. (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
  861. ugeth->p_tx_glbl_pram->iphoffset[0]);
  862. ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
  863. (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
  864. ugeth->p_tx_glbl_pram->iphoffset[1]);
  865. ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
  866. (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
  867. ugeth->p_tx_glbl_pram->iphoffset[2]);
  868. ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
  869. (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
  870. ugeth->p_tx_glbl_pram->iphoffset[3]);
  871. ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
  872. (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
  873. ugeth->p_tx_glbl_pram->iphoffset[4]);
  874. ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
  875. (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
  876. ugeth->p_tx_glbl_pram->iphoffset[5]);
  877. ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
  878. (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
  879. ugeth->p_tx_glbl_pram->iphoffset[6]);
  880. ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
  881. (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
  882. ugeth->p_tx_glbl_pram->iphoffset[7]);
  883. ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
  884. (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
  885. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
  886. ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
  887. (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
  888. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
  889. ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
  890. (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
  891. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
  892. ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
  893. (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
  894. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
  895. ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
  896. (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
  897. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
  898. ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
  899. (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
  900. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
  901. ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
  902. (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
  903. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
  904. ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
  905. (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
  906. in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
  907. ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
  908. (u32) & ugeth->p_tx_glbl_pram->tqptr,
  909. in_be32(&ugeth->p_tx_glbl_pram->tqptr));
  910. }
  911. if (ugeth->p_rx_glbl_pram) {
  912. ugeth_info("RX global param:");
  913. ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
  914. ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
  915. (u32) & ugeth->p_rx_glbl_pram->remoder,
  916. in_be32(&ugeth->p_rx_glbl_pram->remoder));
  917. ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
  918. (u32) & ugeth->p_rx_glbl_pram->rqptr,
  919. in_be32(&ugeth->p_rx_glbl_pram->rqptr));
  920. ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
  921. (u32) & ugeth->p_rx_glbl_pram->typeorlen,
  922. in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
  923. ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
  924. (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
  925. ugeth->p_rx_glbl_pram->rxgstpack);
  926. ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
  927. (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
  928. in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
  929. ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
  930. (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
  931. in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
  932. ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
  933. (u32) & ugeth->p_rx_glbl_pram->rstate,
  934. ugeth->p_rx_glbl_pram->rstate);
  935. ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
  936. (u32) & ugeth->p_rx_glbl_pram->mrblr,
  937. in_be16(&ugeth->p_rx_glbl_pram->mrblr));
  938. ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
  939. (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
  940. in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
  941. ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
  942. (u32) & ugeth->p_rx_glbl_pram->mflr,
  943. in_be16(&ugeth->p_rx_glbl_pram->mflr));
  944. ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
  945. (u32) & ugeth->p_rx_glbl_pram->minflr,
  946. in_be16(&ugeth->p_rx_glbl_pram->minflr));
  947. ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
  948. (u32) & ugeth->p_rx_glbl_pram->maxd1,
  949. in_be16(&ugeth->p_rx_glbl_pram->maxd1));
  950. ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
  951. (u32) & ugeth->p_rx_glbl_pram->maxd2,
  952. in_be16(&ugeth->p_rx_glbl_pram->maxd2));
  953. ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
  954. (u32) & ugeth->p_rx_glbl_pram->ecamptr,
  955. in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
  956. ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
  957. (u32) & ugeth->p_rx_glbl_pram->l2qt,
  958. in_be32(&ugeth->p_rx_glbl_pram->l2qt));
  959. ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
  960. (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
  961. in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
  962. ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
  963. (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
  964. in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
  965. ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
  966. (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
  967. in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
  968. ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
  969. (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
  970. in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
  971. ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
  972. (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
  973. in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
  974. ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
  975. (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
  976. in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
  977. ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
  978. (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
  979. in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
  980. ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
  981. (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
  982. in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
  983. ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
  984. (u32) & ugeth->p_rx_glbl_pram->vlantype,
  985. in_be16(&ugeth->p_rx_glbl_pram->vlantype));
  986. ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
  987. (u32) & ugeth->p_rx_glbl_pram->vlantci,
  988. in_be16(&ugeth->p_rx_glbl_pram->vlantci));
  989. for (i = 0; i < 64; i++)
  990. ugeth_info
  991. ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
  992. i,
  993. (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
  994. ugeth->p_rx_glbl_pram->addressfiltering[i]);
  995. ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
  996. (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
  997. in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
  998. }
  999. if (ugeth->p_send_q_mem_reg) {
  1000. ugeth_info("Send Q memory registers:");
  1001. ugeth_info("Base address: 0x%08x",
  1002. (u32) ugeth->p_send_q_mem_reg);
  1003. for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
  1004. ugeth_info("SQQD[%d]:", i);
  1005. ugeth_info("Base address: 0x%08x",
  1006. (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
  1007. mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
  1008. sizeof(struct ucc_geth_send_queue_qd));
  1009. }
  1010. }
  1011. if (ugeth->p_scheduler) {
  1012. ugeth_info("Scheduler:");
  1013. ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
  1014. mem_disp((u8 *) ugeth->p_scheduler,
  1015. sizeof(*ugeth->p_scheduler));
  1016. }
  1017. if (ugeth->p_tx_fw_statistics_pram) {
  1018. ugeth_info("TX FW statistics pram:");
  1019. ugeth_info("Base address: 0x%08x",
  1020. (u32) ugeth->p_tx_fw_statistics_pram);
  1021. mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
  1022. sizeof(*ugeth->p_tx_fw_statistics_pram));
  1023. }
  1024. if (ugeth->p_rx_fw_statistics_pram) {
  1025. ugeth_info("RX FW statistics pram:");
  1026. ugeth_info("Base address: 0x%08x",
  1027. (u32) ugeth->p_rx_fw_statistics_pram);
  1028. mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
  1029. sizeof(*ugeth->p_rx_fw_statistics_pram));
  1030. }
  1031. if (ugeth->p_rx_irq_coalescing_tbl) {
  1032. ugeth_info("RX IRQ coalescing tables:");
  1033. ugeth_info("Base address: 0x%08x",
  1034. (u32) ugeth->p_rx_irq_coalescing_tbl);
  1035. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  1036. ugeth_info("RX IRQ coalescing table entry[%d]:", i);
  1037. ugeth_info("Base address: 0x%08x",
  1038. (u32) & ugeth->p_rx_irq_coalescing_tbl->
  1039. coalescingentry[i]);
  1040. ugeth_info
  1041. ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
  1042. (u32) & ugeth->p_rx_irq_coalescing_tbl->
  1043. coalescingentry[i].interruptcoalescingmaxvalue,
  1044. in_be32(&ugeth->p_rx_irq_coalescing_tbl->
  1045. coalescingentry[i].
  1046. interruptcoalescingmaxvalue));
  1047. ugeth_info
  1048. ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
  1049. (u32) & ugeth->p_rx_irq_coalescing_tbl->
  1050. coalescingentry[i].interruptcoalescingcounter,
  1051. in_be32(&ugeth->p_rx_irq_coalescing_tbl->
  1052. coalescingentry[i].
  1053. interruptcoalescingcounter));
  1054. }
  1055. }
  1056. if (ugeth->p_rx_bd_qs_tbl) {
  1057. ugeth_info("RX BD QS tables:");
  1058. ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
  1059. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  1060. ugeth_info("RX BD QS table[%d]:", i);
  1061. ugeth_info("Base address: 0x%08x",
  1062. (u32) & ugeth->p_rx_bd_qs_tbl[i]);
  1063. ugeth_info
  1064. ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
  1065. (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
  1066. in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
  1067. ugeth_info
  1068. ("bdptr : addr - 0x%08x, val - 0x%08x",
  1069. (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
  1070. in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
  1071. ugeth_info
  1072. ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
  1073. (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  1074. in_be32(&ugeth->p_rx_bd_qs_tbl[i].
  1075. externalbdbaseptr));
  1076. ugeth_info
  1077. ("externalbdptr : addr - 0x%08x, val - 0x%08x",
  1078. (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
  1079. in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
  1080. ugeth_info("ucode RX Prefetched BDs:");
  1081. ugeth_info("Base address: 0x%08x",
  1082. (u32)
  1083. qe_muram_addr(in_be32
  1084. (&ugeth->p_rx_bd_qs_tbl[i].
  1085. bdbaseptr)));
  1086. mem_disp((u8 *)
  1087. qe_muram_addr(in_be32
  1088. (&ugeth->p_rx_bd_qs_tbl[i].
  1089. bdbaseptr)),
  1090. sizeof(struct ucc_geth_rx_prefetched_bds));
  1091. }
  1092. }
  1093. if (ugeth->p_init_enet_param_shadow) {
  1094. int size;
  1095. ugeth_info("Init enet param shadow:");
  1096. ugeth_info("Base address: 0x%08x",
  1097. (u32) ugeth->p_init_enet_param_shadow);
  1098. mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
  1099. sizeof(*ugeth->p_init_enet_param_shadow));
  1100. size = sizeof(struct ucc_geth_thread_rx_pram);
  1101. if (ugeth->ug_info->rxExtendedFiltering) {
  1102. size +=
  1103. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
  1104. if (ugeth->ug_info->largestexternallookupkeysize ==
  1105. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
  1106. size +=
  1107. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
  1108. if (ugeth->ug_info->largestexternallookupkeysize ==
  1109. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
  1110. size +=
  1111. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
  1112. }
  1113. dump_init_enet_entries(ugeth,
  1114. &(ugeth->p_init_enet_param_shadow->
  1115. txthread[0]),
  1116. ENET_INIT_PARAM_MAX_ENTRIES_TX,
  1117. sizeof(struct ucc_geth_thread_tx_pram),
  1118. ugeth->ug_info->riscTx, 0);
  1119. dump_init_enet_entries(ugeth,
  1120. &(ugeth->p_init_enet_param_shadow->
  1121. rxthread[0]),
  1122. ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
  1123. ugeth->ug_info->riscRx, 1);
  1124. }
  1125. }
  1126. #endif /* DEBUG */
  1127. static void init_default_reg_vals(volatile u32 *upsmr_register,
  1128. volatile u32 *maccfg1_register,
  1129. volatile u32 *maccfg2_register)
  1130. {
  1131. out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
  1132. out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
  1133. out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
  1134. }
  1135. static int init_half_duplex_params(int alt_beb,
  1136. int back_pressure_no_backoff,
  1137. int no_backoff,
  1138. int excess_defer,
  1139. u8 alt_beb_truncation,
  1140. u8 max_retransmissions,
  1141. u8 collision_window,
  1142. volatile u32 *hafdup_register)
  1143. {
  1144. u32 value = 0;
  1145. if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
  1146. (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
  1147. (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
  1148. return -EINVAL;
  1149. value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
  1150. if (alt_beb)
  1151. value |= HALFDUP_ALT_BEB;
  1152. if (back_pressure_no_backoff)
  1153. value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
  1154. if (no_backoff)
  1155. value |= HALFDUP_NO_BACKOFF;
  1156. if (excess_defer)
  1157. value |= HALFDUP_EXCESSIVE_DEFER;
  1158. value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
  1159. value |= collision_window;
  1160. out_be32(hafdup_register, value);
  1161. return 0;
  1162. }
  1163. static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
  1164. u8 non_btb_ipg,
  1165. u8 min_ifg,
  1166. u8 btb_ipg,
  1167. volatile u32 *ipgifg_register)
  1168. {
  1169. u32 value = 0;
  1170. /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
  1171. IPG part 2 */
  1172. if (non_btb_cs_ipg > non_btb_ipg)
  1173. return -EINVAL;
  1174. if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
  1175. (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
  1176. /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
  1177. (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
  1178. return -EINVAL;
  1179. value |=
  1180. ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
  1181. IPGIFG_NBTB_CS_IPG_MASK);
  1182. value |=
  1183. ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
  1184. IPGIFG_NBTB_IPG_MASK);
  1185. value |=
  1186. ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
  1187. IPGIFG_MIN_IFG_MASK);
  1188. value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
  1189. out_be32(ipgifg_register, value);
  1190. return 0;
  1191. }
  1192. static int init_flow_control_params(u32 automatic_flow_control_mode,
  1193. int rx_flow_control_enable,
  1194. int tx_flow_control_enable,
  1195. u16 pause_period,
  1196. u16 extension_field,
  1197. volatile u32 *upsmr_register,
  1198. volatile u32 *uempr_register,
  1199. volatile u32 *maccfg1_register)
  1200. {
  1201. u32 value = 0;
  1202. /* Set UEMPR register */
  1203. value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
  1204. value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
  1205. out_be32(uempr_register, value);
  1206. /* Set UPSMR register */
  1207. value = in_be32(upsmr_register);
  1208. value |= automatic_flow_control_mode;
  1209. out_be32(upsmr_register, value);
  1210. value = in_be32(maccfg1_register);
  1211. if (rx_flow_control_enable)
  1212. value |= MACCFG1_FLOW_RX;
  1213. if (tx_flow_control_enable)
  1214. value |= MACCFG1_FLOW_TX;
  1215. out_be32(maccfg1_register, value);
  1216. return 0;
  1217. }
  1218. static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
  1219. int auto_zero_hardware_statistics,
  1220. volatile u32 *upsmr_register,
  1221. volatile u16 *uescr_register)
  1222. {
  1223. u32 upsmr_value = 0;
  1224. u16 uescr_value = 0;
  1225. /* Enable hardware statistics gathering if requested */
  1226. if (enable_hardware_statistics) {
  1227. upsmr_value = in_be32(upsmr_register);
  1228. upsmr_value |= UPSMR_HSE;
  1229. out_be32(upsmr_register, upsmr_value);
  1230. }
  1231. /* Clear hardware statistics counters */
  1232. uescr_value = in_be16(uescr_register);
  1233. uescr_value |= UESCR_CLRCNT;
  1234. /* Automatically zero hardware statistics counters on read,
  1235. if requested */
  1236. if (auto_zero_hardware_statistics)
  1237. uescr_value |= UESCR_AUTOZ;
  1238. out_be16(uescr_register, uescr_value);
  1239. return 0;
  1240. }
  1241. static int init_firmware_statistics_gathering_mode(int
  1242. enable_tx_firmware_statistics,
  1243. int enable_rx_firmware_statistics,
  1244. volatile u32 *tx_rmon_base_ptr,
  1245. u32 tx_firmware_statistics_structure_address,
  1246. volatile u32 *rx_rmon_base_ptr,
  1247. u32 rx_firmware_statistics_structure_address,
  1248. volatile u16 *temoder_register,
  1249. volatile u32 *remoder_register)
  1250. {
  1251. /* Note: this function does not check if */
  1252. /* the parameters it receives are NULL */
  1253. u16 temoder_value;
  1254. u32 remoder_value;
  1255. if (enable_tx_firmware_statistics) {
  1256. out_be32(tx_rmon_base_ptr,
  1257. tx_firmware_statistics_structure_address);
  1258. temoder_value = in_be16(temoder_register);
  1259. temoder_value |= TEMODER_TX_RMON_STATISTICS_ENABLE;
  1260. out_be16(temoder_register, temoder_value);
  1261. }
  1262. if (enable_rx_firmware_statistics) {
  1263. out_be32(rx_rmon_base_ptr,
  1264. rx_firmware_statistics_structure_address);
  1265. remoder_value = in_be32(remoder_register);
  1266. remoder_value |= REMODER_RX_RMON_STATISTICS_ENABLE;
  1267. out_be32(remoder_register, remoder_value);
  1268. }
  1269. return 0;
  1270. }
  1271. static int init_mac_station_addr_regs(u8 address_byte_0,
  1272. u8 address_byte_1,
  1273. u8 address_byte_2,
  1274. u8 address_byte_3,
  1275. u8 address_byte_4,
  1276. u8 address_byte_5,
  1277. volatile u32 *macstnaddr1_register,
  1278. volatile u32 *macstnaddr2_register)
  1279. {
  1280. u32 value = 0;
  1281. /* Example: for a station address of 0x12345678ABCD, */
  1282. /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
  1283. /* MACSTNADDR1 Register: */
  1284. /* 0 7 8 15 */
  1285. /* station address byte 5 station address byte 4 */
  1286. /* 16 23 24 31 */
  1287. /* station address byte 3 station address byte 2 */
  1288. value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
  1289. value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
  1290. value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
  1291. value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
  1292. out_be32(macstnaddr1_register, value);
  1293. /* MACSTNADDR2 Register: */
  1294. /* 0 7 8 15 */
  1295. /* station address byte 1 station address byte 0 */
  1296. /* 16 23 24 31 */
  1297. /* reserved reserved */
  1298. value = 0;
  1299. value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
  1300. value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
  1301. out_be32(macstnaddr2_register, value);
  1302. return 0;
  1303. }
  1304. static int init_mac_duplex_mode(int full_duplex,
  1305. int limited_to_full_duplex,
  1306. volatile u32 *maccfg2_register)
  1307. {
  1308. u32 value = 0;
  1309. /* some interfaces must work in full duplex mode */
  1310. if ((full_duplex == 0) && (limited_to_full_duplex == 1))
  1311. return -EINVAL;
  1312. value = in_be32(maccfg2_register);
  1313. if (full_duplex)
  1314. value |= MACCFG2_FDX;
  1315. else
  1316. value &= ~MACCFG2_FDX;
  1317. out_be32(maccfg2_register, value);
  1318. return 0;
  1319. }
  1320. static int init_check_frame_length_mode(int length_check,
  1321. volatile u32 *maccfg2_register)
  1322. {
  1323. u32 value = 0;
  1324. value = in_be32(maccfg2_register);
  1325. if (length_check)
  1326. value |= MACCFG2_LC;
  1327. else
  1328. value &= ~MACCFG2_LC;
  1329. out_be32(maccfg2_register, value);
  1330. return 0;
  1331. }
  1332. static int init_preamble_length(u8 preamble_length,
  1333. volatile u32 *maccfg2_register)
  1334. {
  1335. u32 value = 0;
  1336. if ((preamble_length < 3) || (preamble_length > 7))
  1337. return -EINVAL;
  1338. value = in_be32(maccfg2_register);
  1339. value &= ~MACCFG2_PREL_MASK;
  1340. value |= (preamble_length << MACCFG2_PREL_SHIFT);
  1341. out_be32(maccfg2_register, value);
  1342. return 0;
  1343. }
  1344. static int init_mii_management_configuration(int reset_mgmt,
  1345. int preamble_supress,
  1346. volatile u32 *miimcfg_register,
  1347. volatile u32 *miimind_register)
  1348. {
  1349. unsigned int timeout = PHY_INIT_TIMEOUT;
  1350. u32 value = 0;
  1351. value = in_be32(miimcfg_register);
  1352. if (reset_mgmt) {
  1353. value |= MIIMCFG_RESET_MANAGEMENT;
  1354. out_be32(miimcfg_register, value);
  1355. }
  1356. value = 0;
  1357. if (preamble_supress)
  1358. value |= MIIMCFG_NO_PREAMBLE;
  1359. value |= UCC_GETH_MIIMCFG_MNGMNT_CLC_DIV_INIT;
  1360. out_be32(miimcfg_register, value);
  1361. /* Wait until the bus is free */
  1362. while ((in_be32(miimind_register) & MIIMIND_BUSY) && timeout--)
  1363. cpu_relax();
  1364. if (timeout <= 0) {
  1365. ugeth_err("%s: The MII Bus is stuck!", __FUNCTION__);
  1366. return -ETIMEDOUT;
  1367. }
  1368. return 0;
  1369. }
  1370. static int init_rx_parameters(int reject_broadcast,
  1371. int receive_short_frames,
  1372. int promiscuous, volatile u32 *upsmr_register)
  1373. {
  1374. u32 value = 0;
  1375. value = in_be32(upsmr_register);
  1376. if (reject_broadcast)
  1377. value |= UPSMR_BRO;
  1378. else
  1379. value &= ~UPSMR_BRO;
  1380. if (receive_short_frames)
  1381. value |= UPSMR_RSH;
  1382. else
  1383. value &= ~UPSMR_RSH;
  1384. if (promiscuous)
  1385. value |= UPSMR_PRO;
  1386. else
  1387. value &= ~UPSMR_PRO;
  1388. out_be32(upsmr_register, value);
  1389. return 0;
  1390. }
  1391. static int init_max_rx_buff_len(u16 max_rx_buf_len,
  1392. volatile u16 *mrblr_register)
  1393. {
  1394. /* max_rx_buf_len value must be a multiple of 128 */
  1395. if ((max_rx_buf_len == 0)
  1396. || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
  1397. return -EINVAL;
  1398. out_be16(mrblr_register, max_rx_buf_len);
  1399. return 0;
  1400. }
  1401. static int init_min_frame_len(u16 min_frame_length,
  1402. volatile u16 *minflr_register,
  1403. volatile u16 *mrblr_register)
  1404. {
  1405. u16 mrblr_value = 0;
  1406. mrblr_value = in_be16(mrblr_register);
  1407. if (min_frame_length >= (mrblr_value - 4))
  1408. return -EINVAL;
  1409. out_be16(minflr_register, min_frame_length);
  1410. return 0;
  1411. }
  1412. static int adjust_enet_interface(struct ucc_geth_private *ugeth)
  1413. {
  1414. struct ucc_geth_info *ug_info;
  1415. struct ucc_geth *ug_regs;
  1416. struct ucc_fast *uf_regs;
  1417. enum enet_speed speed;
  1418. int ret_val, rpm = 0, tbi = 0, r10m = 0, rmm =
  1419. 0, limited_to_full_duplex = 0;
  1420. u32 upsmr, maccfg2, utbipar, tbiBaseAddress;
  1421. u16 value;
  1422. ugeth_vdbg("%s: IN", __FUNCTION__);
  1423. ug_info = ugeth->ug_info;
  1424. ug_regs = ugeth->ug_regs;
  1425. uf_regs = ugeth->uccf->uf_regs;
  1426. /* Analyze enet_interface according to Interface Mode Configuration
  1427. table */
  1428. ret_val =
  1429. get_interface_details(ug_info->enet_interface, &speed, &r10m, &rmm,
  1430. &rpm, &tbi, &limited_to_full_duplex);
  1431. if (ret_val != 0) {
  1432. ugeth_err
  1433. ("%s: half duplex not supported in requested configuration.",
  1434. __FUNCTION__);
  1435. return ret_val;
  1436. }
  1437. /* Set MACCFG2 */
  1438. maccfg2 = in_be32(&ug_regs->maccfg2);
  1439. maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
  1440. if ((speed == ENET_SPEED_10BT) || (speed == ENET_SPEED_100BT))
  1441. maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
  1442. else if (speed == ENET_SPEED_1000BT)
  1443. maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
  1444. maccfg2 |= ug_info->padAndCrc;
  1445. out_be32(&ug_regs->maccfg2, maccfg2);
  1446. /* Set UPSMR */
  1447. upsmr = in_be32(&uf_regs->upsmr);
  1448. upsmr &= ~(UPSMR_RPM | UPSMR_R10M | UPSMR_TBIM | UPSMR_RMM);
  1449. if (rpm)
  1450. upsmr |= UPSMR_RPM;
  1451. if (r10m)
  1452. upsmr |= UPSMR_R10M;
  1453. if (tbi)
  1454. upsmr |= UPSMR_TBIM;
  1455. if (rmm)
  1456. upsmr |= UPSMR_RMM;
  1457. out_be32(&uf_regs->upsmr, upsmr);
  1458. /* Set UTBIPAR */
  1459. utbipar = in_be32(&ug_regs->utbipar);
  1460. utbipar &= ~UTBIPAR_PHY_ADDRESS_MASK;
  1461. if (tbi)
  1462. utbipar |=
  1463. (ug_info->phy_address +
  1464. ugeth->ug_info->uf_info.
  1465. ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
  1466. else
  1467. utbipar |=
  1468. (0x10 +
  1469. ugeth->ug_info->uf_info.
  1470. ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
  1471. out_be32(&ug_regs->utbipar, utbipar);
  1472. /* Disable autonegotiation in tbi mode, because by default it
  1473. comes up in autonegotiation mode. */
  1474. /* Note that this depends on proper setting in utbipar register. */
  1475. if (tbi) {
  1476. tbiBaseAddress = in_be32(&ug_regs->utbipar);
  1477. tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
  1478. tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
  1479. value =
  1480. ugeth->mii_info->mdio_read(ugeth->dev, (u8) tbiBaseAddress,
  1481. ENET_TBI_MII_CR);
  1482. value &= ~0x1000; /* Turn off autonegotiation */
  1483. ugeth->mii_info->mdio_write(ugeth->dev, (u8) tbiBaseAddress,
  1484. ENET_TBI_MII_CR, value);
  1485. }
  1486. ret_val = init_mac_duplex_mode(1,
  1487. limited_to_full_duplex,
  1488. &ug_regs->maccfg2);
  1489. if (ret_val != 0) {
  1490. ugeth_err
  1491. ("%s: half duplex not supported in requested configuration.",
  1492. __FUNCTION__);
  1493. return ret_val;
  1494. }
  1495. init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
  1496. ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
  1497. if (ret_val != 0) {
  1498. ugeth_err
  1499. ("%s: Preamble length must be between 3 and 7 inclusive.",
  1500. __FUNCTION__);
  1501. return ret_val;
  1502. }
  1503. return 0;
  1504. }
  1505. /* Called every time the controller might need to be made
  1506. * aware of new link state. The PHY code conveys this
  1507. * information through variables in the ugeth structure, and this
  1508. * function converts those variables into the appropriate
  1509. * register values, and can bring down the device if needed.
  1510. */
  1511. static void adjust_link(struct net_device *dev)
  1512. {
  1513. struct ucc_geth_private *ugeth = netdev_priv(dev);
  1514. struct ucc_geth *ug_regs;
  1515. u32 tempval;
  1516. struct ugeth_mii_info *mii_info = ugeth->mii_info;
  1517. ug_regs = ugeth->ug_regs;
  1518. if (mii_info->link) {
  1519. /* Now we make sure that we can be in full duplex mode.
  1520. * If not, we operate in half-duplex mode. */
  1521. if (mii_info->duplex != ugeth->oldduplex) {
  1522. if (!(mii_info->duplex)) {
  1523. tempval = in_be32(&ug_regs->maccfg2);
  1524. tempval &= ~(MACCFG2_FDX);
  1525. out_be32(&ug_regs->maccfg2, tempval);
  1526. ugeth_info("%s: Half Duplex", dev->name);
  1527. } else {
  1528. tempval = in_be32(&ug_regs->maccfg2);
  1529. tempval |= MACCFG2_FDX;
  1530. out_be32(&ug_regs->maccfg2, tempval);
  1531. ugeth_info("%s: Full Duplex", dev->name);
  1532. }
  1533. ugeth->oldduplex = mii_info->duplex;
  1534. }
  1535. if (mii_info->speed != ugeth->oldspeed) {
  1536. switch (mii_info->speed) {
  1537. case 1000:
  1538. #ifdef CONFIG_PPC_MPC836x
  1539. /* FIXME: This code is for 100Mbs BUG fixing,
  1540. remove this when it is fixed!!! */
  1541. if (ugeth->ug_info->enet_interface ==
  1542. ENET_1000_GMII)
  1543. /* Run the commands which initialize the PHY */
  1544. {
  1545. tempval =
  1546. (u32) mii_info->mdio_read(ugeth->
  1547. dev, mii_info->mii_id, 0x1b);
  1548. tempval |= 0x000f;
  1549. mii_info->mdio_write(ugeth->dev,
  1550. mii_info->mii_id, 0x1b,
  1551. (u16) tempval);
  1552. tempval =
  1553. (u32) mii_info->mdio_read(ugeth->
  1554. dev, mii_info->mii_id,
  1555. MII_BMCR);
  1556. mii_info->mdio_write(ugeth->dev,
  1557. mii_info->mii_id, MII_BMCR,
  1558. (u16) (tempval | BMCR_RESET));
  1559. } else if (ugeth->ug_info->enet_interface ==
  1560. ENET_1000_RGMII)
  1561. /* Run the commands which initialize the PHY */
  1562. {
  1563. tempval =
  1564. (u32) mii_info->mdio_read(ugeth->
  1565. dev, mii_info->mii_id, 0x1b);
  1566. tempval = (tempval & ~0x000f) | 0x000b;
  1567. mii_info->mdio_write(ugeth->dev,
  1568. mii_info->mii_id, 0x1b,
  1569. (u16) tempval);
  1570. tempval =
  1571. (u32) mii_info->mdio_read(ugeth->
  1572. dev, mii_info->mii_id,
  1573. MII_BMCR);
  1574. mii_info->mdio_write(ugeth->dev,
  1575. mii_info->mii_id, MII_BMCR,
  1576. (u16) (tempval | BMCR_RESET));
  1577. }
  1578. msleep(4000);
  1579. #endif /* CONFIG_MPC8360 */
  1580. adjust_enet_interface(ugeth);
  1581. break;
  1582. case 100:
  1583. case 10:
  1584. #ifdef CONFIG_PPC_MPC836x
  1585. /* FIXME: This code is for 100Mbs BUG fixing,
  1586. remove this lines when it will be fixed!!! */
  1587. ugeth->ug_info->enet_interface = ENET_100_RGMII;
  1588. tempval =
  1589. (u32) mii_info->mdio_read(ugeth->dev,
  1590. mii_info->mii_id,
  1591. 0x1b);
  1592. tempval = (tempval & ~0x000f) | 0x000b;
  1593. mii_info->mdio_write(ugeth->dev,
  1594. mii_info->mii_id, 0x1b,
  1595. (u16) tempval);
  1596. tempval =
  1597. (u32) mii_info->mdio_read(ugeth->dev,
  1598. mii_info->mii_id,
  1599. MII_BMCR);
  1600. mii_info->mdio_write(ugeth->dev,
  1601. mii_info->mii_id, MII_BMCR,
  1602. (u16) (tempval |
  1603. BMCR_RESET));
  1604. msleep(4000);
  1605. #endif /* CONFIG_MPC8360 */
  1606. adjust_enet_interface(ugeth);
  1607. break;
  1608. default:
  1609. ugeth_warn
  1610. ("%s: Ack! Speed (%d) is not 10/100/1000!",
  1611. dev->name, mii_info->speed);
  1612. break;
  1613. }
  1614. ugeth_info("%s: Speed %dBT", dev->name,
  1615. mii_info->speed);
  1616. ugeth->oldspeed = mii_info->speed;
  1617. }
  1618. if (!ugeth->oldlink) {
  1619. ugeth_info("%s: Link is up", dev->name);
  1620. ugeth->oldlink = 1;
  1621. netif_carrier_on(dev);
  1622. netif_schedule(dev);
  1623. }
  1624. } else {
  1625. if (ugeth->oldlink) {
  1626. ugeth_info("%s: Link is down", dev->name);
  1627. ugeth->oldlink = 0;
  1628. ugeth->oldspeed = 0;
  1629. ugeth->oldduplex = -1;
  1630. netif_carrier_off(dev);
  1631. }
  1632. }
  1633. }
  1634. /* Configure the PHY for dev.
  1635. * returns 0 if success. -1 if failure
  1636. */
  1637. static int init_phy(struct net_device *dev)
  1638. {
  1639. struct ucc_geth_private *ugeth = netdev_priv(dev);
  1640. struct phy_info *curphy;
  1641. struct ucc_mii_mng *mii_regs;
  1642. struct ugeth_mii_info *mii_info;
  1643. int err;
  1644. mii_regs = &ugeth->ug_regs->miimng;
  1645. ugeth->oldlink = 0;
  1646. ugeth->oldspeed = 0;
  1647. ugeth->oldduplex = -1;
  1648. mii_info = kmalloc(sizeof(struct ugeth_mii_info), GFP_KERNEL);
  1649. if (NULL == mii_info) {
  1650. ugeth_err("%s: Could not allocate mii_info", dev->name);
  1651. return -ENOMEM;
  1652. }
  1653. mii_info->mii_regs = mii_regs;
  1654. mii_info->speed = SPEED_1000;
  1655. mii_info->duplex = DUPLEX_FULL;
  1656. mii_info->pause = 0;
  1657. mii_info->link = 0;
  1658. mii_info->advertising = (ADVERTISED_10baseT_Half |
  1659. ADVERTISED_10baseT_Full |
  1660. ADVERTISED_100baseT_Half |
  1661. ADVERTISED_100baseT_Full |
  1662. ADVERTISED_1000baseT_Full);
  1663. mii_info->autoneg = 1;
  1664. mii_info->mii_id = ugeth->ug_info->phy_address;
  1665. mii_info->dev = dev;
  1666. mii_info->mdio_read = &read_phy_reg;
  1667. mii_info->mdio_write = &write_phy_reg;
  1668. ugeth->mii_info = mii_info;
  1669. spin_lock_irq(&ugeth->lock);
  1670. /* Set this UCC to be the master of the MII managment */
  1671. ucc_set_qe_mux_mii_mng(ugeth->ug_info->uf_info.ucc_num);
  1672. if (init_mii_management_configuration(1,
  1673. ugeth->ug_info->
  1674. miiPreambleSupress,
  1675. &mii_regs->miimcfg,
  1676. &mii_regs->miimind)) {
  1677. ugeth_err("%s: The MII Bus is stuck!", dev->name);
  1678. err = -1;
  1679. goto bus_fail;
  1680. }
  1681. spin_unlock_irq(&ugeth->lock);
  1682. /* get info for this PHY */
  1683. curphy = get_phy_info(ugeth->mii_info);
  1684. if (curphy == NULL) {
  1685. ugeth_err("%s: No PHY found", dev->name);
  1686. err = -1;
  1687. goto no_phy;
  1688. }
  1689. mii_info->phyinfo = curphy;
  1690. /* Run the commands which initialize the PHY */
  1691. if (curphy->init) {
  1692. err = curphy->init(ugeth->mii_info);
  1693. if (err)
  1694. goto phy_init_fail;
  1695. }
  1696. return 0;
  1697. phy_init_fail:
  1698. no_phy:
  1699. bus_fail:
  1700. kfree(mii_info);
  1701. return err;
  1702. }
  1703. #ifdef CONFIG_UGETH_TX_ON_DEMOND
  1704. static int ugeth_transmit_on_demand(struct ucc_geth_private *ugeth)
  1705. {
  1706. struct ucc_fastransmit_on_demand(ugeth->uccf);
  1707. return 0;
  1708. }
  1709. #endif
  1710. static int ugeth_graceful_stop_tx(struct ucc_geth_private *ugeth)
  1711. {
  1712. struct ucc_fast_private *uccf;
  1713. u32 cecr_subblock;
  1714. u32 temp;
  1715. uccf = ugeth->uccf;
  1716. /* Mask GRACEFUL STOP TX interrupt bit and clear it */
  1717. temp = in_be32(uccf->p_uccm);
  1718. temp &= ~UCCE_GRA;
  1719. out_be32(uccf->p_uccm, temp);
  1720. out_be32(uccf->p_ucce, UCCE_GRA); /* clear by writing 1 */
  1721. /* Issue host command */
  1722. cecr_subblock =
  1723. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  1724. qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
  1725. QE_CR_PROTOCOL_ETHERNET, 0);
  1726. /* Wait for command to complete */
  1727. do {
  1728. temp = in_be32(uccf->p_ucce);
  1729. } while (!(temp & UCCE_GRA));
  1730. uccf->stopped_tx = 1;
  1731. return 0;
  1732. }
  1733. static int ugeth_graceful_stop_rx(struct ucc_geth_private * ugeth)
  1734. {
  1735. struct ucc_fast_private *uccf;
  1736. u32 cecr_subblock;
  1737. u8 temp;
  1738. uccf = ugeth->uccf;
  1739. /* Clear acknowledge bit */
  1740. temp = ugeth->p_rx_glbl_pram->rxgstpack;
  1741. temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
  1742. ugeth->p_rx_glbl_pram->rxgstpack = temp;
  1743. /* Keep issuing command and checking acknowledge bit until
  1744. it is asserted, according to spec */
  1745. do {
  1746. /* Issue host command */
  1747. cecr_subblock =
  1748. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
  1749. ucc_num);
  1750. qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
  1751. QE_CR_PROTOCOL_ETHERNET, 0);
  1752. temp = ugeth->p_rx_glbl_pram->rxgstpack;
  1753. } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX));
  1754. uccf->stopped_rx = 1;
  1755. return 0;
  1756. }
  1757. static int ugeth_restart_tx(struct ucc_geth_private *ugeth)
  1758. {
  1759. struct ucc_fast_private *uccf;
  1760. u32 cecr_subblock;
  1761. uccf = ugeth->uccf;
  1762. cecr_subblock =
  1763. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  1764. qe_issue_cmd(QE_RESTART_TX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET, 0);
  1765. uccf->stopped_tx = 0;
  1766. return 0;
  1767. }
  1768. static int ugeth_restart_rx(struct ucc_geth_private *ugeth)
  1769. {
  1770. struct ucc_fast_private *uccf;
  1771. u32 cecr_subblock;
  1772. uccf = ugeth->uccf;
  1773. cecr_subblock =
  1774. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  1775. qe_issue_cmd(QE_RESTART_RX, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
  1776. 0);
  1777. uccf->stopped_rx = 0;
  1778. return 0;
  1779. }
  1780. static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
  1781. {
  1782. struct ucc_fast_private *uccf;
  1783. int enabled_tx, enabled_rx;
  1784. uccf = ugeth->uccf;
  1785. /* check if the UCC number is in range. */
  1786. if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
  1787. ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
  1788. return -EINVAL;
  1789. }
  1790. enabled_tx = uccf->enabled_tx;
  1791. enabled_rx = uccf->enabled_rx;
  1792. /* Get Tx and Rx going again, in case this channel was actively
  1793. disabled. */
  1794. if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
  1795. ugeth_restart_tx(ugeth);
  1796. if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
  1797. ugeth_restart_rx(ugeth);
  1798. ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
  1799. return 0;
  1800. }
  1801. static int ugeth_disable(struct ucc_geth_private * ugeth, enum comm_dir mode)
  1802. {
  1803. struct ucc_fast_private *uccf;
  1804. uccf = ugeth->uccf;
  1805. /* check if the UCC number is in range. */
  1806. if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
  1807. ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
  1808. return -EINVAL;
  1809. }
  1810. /* Stop any transmissions */
  1811. if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
  1812. ugeth_graceful_stop_tx(ugeth);
  1813. /* Stop any receptions */
  1814. if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
  1815. ugeth_graceful_stop_rx(ugeth);
  1816. ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
  1817. return 0;
  1818. }
  1819. static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
  1820. {
  1821. #ifdef DEBUG
  1822. ucc_fast_dump_regs(ugeth->uccf);
  1823. dump_regs(ugeth);
  1824. dump_bds(ugeth);
  1825. #endif
  1826. }
  1827. #ifdef CONFIG_UGETH_FILTERING
  1828. static int ugeth_ext_filtering_serialize_tad(struct ucc_geth_tad_params *
  1829. p_UccGethTadParams,
  1830. struct qe_fltr_tad *qe_fltr_tad)
  1831. {
  1832. u16 temp;
  1833. /* Zero serialized TAD */
  1834. memset(qe_fltr_tad, 0, QE_FLTR_TAD_SIZE);
  1835. qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_V; /* Must have this */
  1836. if (p_UccGethTadParams->rx_non_dynamic_extended_features_mode ||
  1837. (p_UccGethTadParams->vtag_op != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
  1838. || (p_UccGethTadParams->vnontag_op !=
  1839. UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP)
  1840. )
  1841. qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_EF;
  1842. if (p_UccGethTadParams->reject_frame)
  1843. qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_REJ;
  1844. temp =
  1845. (u16) (((u16) p_UccGethTadParams->
  1846. vtag_op) << UCC_GETH_TAD_VTAG_OP_SHIFT);
  1847. qe_fltr_tad->serialized[0] |= (u8) (temp >> 8); /* upper bits */
  1848. qe_fltr_tad->serialized[1] |= (u8) (temp & 0x00ff); /* lower bits */
  1849. if (p_UccGethTadParams->vnontag_op ==
  1850. UCC_GETH_VLAN_OPERATION_NON_TAGGED_Q_TAG_INSERT)
  1851. qe_fltr_tad->serialized[1] |= UCC_GETH_TAD_V_NON_VTAG_OP;
  1852. qe_fltr_tad->serialized[1] |=
  1853. p_UccGethTadParams->rqos << UCC_GETH_TAD_RQOS_SHIFT;
  1854. qe_fltr_tad->serialized[2] |=
  1855. p_UccGethTadParams->vpri << UCC_GETH_TAD_V_PRIORITY_SHIFT;
  1856. /* upper bits */
  1857. qe_fltr_tad->serialized[2] |= (u8) (p_UccGethTadParams->vid >> 8);
  1858. /* lower bits */
  1859. qe_fltr_tad->serialized[3] |= (u8) (p_UccGethTadParams->vid & 0x00ff);
  1860. return 0;
  1861. }
  1862. static struct enet_addr_container_t
  1863. *ugeth_82xx_filtering_get_match_addr_in_hash(struct ucc_geth_private *ugeth,
  1864. struct enet_addr *p_enet_addr)
  1865. {
  1866. struct enet_addr_container *enet_addr_cont;
  1867. struct list_head *p_lh;
  1868. u16 i, num;
  1869. int32_t j;
  1870. u8 *p_counter;
  1871. if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
  1872. p_lh = &ugeth->group_hash_q;
  1873. p_counter = &(ugeth->numGroupAddrInHash);
  1874. } else {
  1875. p_lh = &ugeth->ind_hash_q;
  1876. p_counter = &(ugeth->numIndAddrInHash);
  1877. }
  1878. if (!p_lh)
  1879. return NULL;
  1880. num = *p_counter;
  1881. for (i = 0; i < num; i++) {
  1882. enet_addr_cont =
  1883. (struct enet_addr_container *)
  1884. ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
  1885. for (j = ENET_NUM_OCTETS_PER_ADDRESS - 1; j >= 0; j--) {
  1886. if ((*p_enet_addr)[j] != (enet_addr_cont->address)[j])
  1887. break;
  1888. if (j == 0)
  1889. return enet_addr_cont; /* Found */
  1890. }
  1891. enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
  1892. }
  1893. return NULL;
  1894. }
  1895. static int ugeth_82xx_filtering_add_addr_in_hash(struct ucc_geth_private *ugeth,
  1896. struct enet_addr *p_enet_addr)
  1897. {
  1898. enum ucc_geth_enet_address_recognition_location location;
  1899. struct enet_addr_container *enet_addr_cont;
  1900. struct list_head *p_lh;
  1901. u8 i;
  1902. u32 limit;
  1903. u8 *p_counter;
  1904. if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
  1905. p_lh = &ugeth->group_hash_q;
  1906. limit = ugeth->ug_info->maxGroupAddrInHash;
  1907. location =
  1908. UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_GROUP_HASH;
  1909. p_counter = &(ugeth->numGroupAddrInHash);
  1910. } else {
  1911. p_lh = &ugeth->ind_hash_q;
  1912. limit = ugeth->ug_info->maxIndAddrInHash;
  1913. location =
  1914. UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_INDIVIDUAL_HASH;
  1915. p_counter = &(ugeth->numIndAddrInHash);
  1916. }
  1917. if ((enet_addr_cont =
  1918. ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr))) {
  1919. list_add(p_lh, &enet_addr_cont->node); /* Put it back */
  1920. return 0;
  1921. }
  1922. if ((!p_lh) || (!(*p_counter < limit)))
  1923. return -EBUSY;
  1924. if (!(enet_addr_cont = get_enet_addr_container()))
  1925. return -ENOMEM;
  1926. for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
  1927. (enet_addr_cont->address)[i] = (*p_enet_addr)[i];
  1928. enet_addr_cont->location = location;
  1929. enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
  1930. ++(*p_counter);
  1931. hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
  1932. return 0;
  1933. }
  1934. static int ugeth_82xx_filtering_clear_addr_in_hash(struct ucc_geth_private *ugeth,
  1935. struct enet_addr *p_enet_addr)
  1936. {
  1937. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  1938. struct enet_addr_container *enet_addr_cont;
  1939. struct ucc_fast_private *uccf;
  1940. enum comm_dir comm_dir;
  1941. u16 i, num;
  1942. struct list_head *p_lh;
  1943. u32 *addr_h, *addr_l;
  1944. u8 *p_counter;
  1945. uccf = ugeth->uccf;
  1946. p_82xx_addr_filt =
  1947. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
  1948. addressfiltering;
  1949. if (!
  1950. (enet_addr_cont =
  1951. ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr)))
  1952. return -ENOENT;
  1953. /* It's been found and removed from the CQ. */
  1954. /* Now destroy its container */
  1955. put_enet_addr_container(enet_addr_cont);
  1956. if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
  1957. addr_h = &(p_82xx_addr_filt->gaddr_h);
  1958. addr_l = &(p_82xx_addr_filt->gaddr_l);
  1959. p_lh = &ugeth->group_hash_q;
  1960. p_counter = &(ugeth->numGroupAddrInHash);
  1961. } else {
  1962. addr_h = &(p_82xx_addr_filt->iaddr_h);
  1963. addr_l = &(p_82xx_addr_filt->iaddr_l);
  1964. p_lh = &ugeth->ind_hash_q;
  1965. p_counter = &(ugeth->numIndAddrInHash);
  1966. }
  1967. comm_dir = 0;
  1968. if (uccf->enabled_tx)
  1969. comm_dir |= COMM_DIR_TX;
  1970. if (uccf->enabled_rx)
  1971. comm_dir |= COMM_DIR_RX;
  1972. if (comm_dir)
  1973. ugeth_disable(ugeth, comm_dir);
  1974. /* Clear the hash table. */
  1975. out_be32(addr_h, 0x00000000);
  1976. out_be32(addr_l, 0x00000000);
  1977. /* Add all remaining CQ elements back into hash */
  1978. num = --(*p_counter);
  1979. for (i = 0; i < num; i++) {
  1980. enet_addr_cont =
  1981. (struct enet_addr_container *)
  1982. ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
  1983. hw_add_addr_in_hash(ugeth, enet_addr_cont->address);
  1984. enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
  1985. }
  1986. if (comm_dir)
  1987. ugeth_enable(ugeth, comm_dir);
  1988. return 0;
  1989. }
  1990. #endif /* CONFIG_UGETH_FILTERING */
  1991. static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
  1992. ugeth,
  1993. enum enet_addr_type
  1994. enet_addr_type)
  1995. {
  1996. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  1997. struct ucc_fast_private *uccf;
  1998. enum comm_dir comm_dir;
  1999. struct list_head *p_lh;
  2000. u16 i, num;
  2001. u32 *addr_h, *addr_l;
  2002. u8 *p_counter;
  2003. uccf = ugeth->uccf;
  2004. p_82xx_addr_filt =
  2005. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->p_rx_glbl_pram->
  2006. addressfiltering;
  2007. if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
  2008. addr_h = &(p_82xx_addr_filt->gaddr_h);
  2009. addr_l = &(p_82xx_addr_filt->gaddr_l);
  2010. p_lh = &ugeth->group_hash_q;
  2011. p_counter = &(ugeth->numGroupAddrInHash);
  2012. } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
  2013. addr_h = &(p_82xx_addr_filt->iaddr_h);
  2014. addr_l = &(p_82xx_addr_filt->iaddr_l);
  2015. p_lh = &ugeth->ind_hash_q;
  2016. p_counter = &(ugeth->numIndAddrInHash);
  2017. } else
  2018. return -EINVAL;
  2019. comm_dir = 0;
  2020. if (uccf->enabled_tx)
  2021. comm_dir |= COMM_DIR_TX;
  2022. if (uccf->enabled_rx)
  2023. comm_dir |= COMM_DIR_RX;
  2024. if (comm_dir)
  2025. ugeth_disable(ugeth, comm_dir);
  2026. /* Clear the hash table. */
  2027. out_be32(addr_h, 0x00000000);
  2028. out_be32(addr_l, 0x00000000);
  2029. if (!p_lh)
  2030. return 0;
  2031. num = *p_counter;
  2032. /* Delete all remaining CQ elements */
  2033. for (i = 0; i < num; i++)
  2034. put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
  2035. *p_counter = 0;
  2036. if (comm_dir)
  2037. ugeth_enable(ugeth, comm_dir);
  2038. return 0;
  2039. }
  2040. #ifdef CONFIG_UGETH_FILTERING
  2041. static int ugeth_82xx_filtering_add_addr_in_paddr(struct ucc_geth_private *ugeth,
  2042. struct enet_addr *p_enet_addr,
  2043. u8 paddr_num)
  2044. {
  2045. int i;
  2046. if ((*p_enet_addr)[0] & ENET_GROUP_ADDR)
  2047. ugeth_warn
  2048. ("%s: multicast address added to paddr will have no "
  2049. "effect - is this what you wanted?",
  2050. __FUNCTION__);
  2051. ugeth->indAddrRegUsed[paddr_num] = 1; /* mark this paddr as used */
  2052. /* store address in our database */
  2053. for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
  2054. ugeth->paddr[paddr_num][i] = (*p_enet_addr)[i];
  2055. /* put in hardware */
  2056. return hw_add_addr_in_paddr(ugeth, p_enet_addr, paddr_num);
  2057. }
  2058. #endif /* CONFIG_UGETH_FILTERING */
  2059. static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
  2060. u8 paddr_num)
  2061. {
  2062. ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
  2063. return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
  2064. }
  2065. static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
  2066. {
  2067. u16 i, j;
  2068. u8 *bd;
  2069. if (!ugeth)
  2070. return;
  2071. if (ugeth->uccf)
  2072. ucc_fast_free(ugeth->uccf);
  2073. if (ugeth->p_thread_data_tx) {
  2074. qe_muram_free(ugeth->thread_dat_tx_offset);
  2075. ugeth->p_thread_data_tx = NULL;
  2076. }
  2077. if (ugeth->p_thread_data_rx) {
  2078. qe_muram_free(ugeth->thread_dat_rx_offset);
  2079. ugeth->p_thread_data_rx = NULL;
  2080. }
  2081. if (ugeth->p_exf_glbl_param) {
  2082. qe_muram_free(ugeth->exf_glbl_param_offset);
  2083. ugeth->p_exf_glbl_param = NULL;
  2084. }
  2085. if (ugeth->p_rx_glbl_pram) {
  2086. qe_muram_free(ugeth->rx_glbl_pram_offset);
  2087. ugeth->p_rx_glbl_pram = NULL;
  2088. }
  2089. if (ugeth->p_tx_glbl_pram) {
  2090. qe_muram_free(ugeth->tx_glbl_pram_offset);
  2091. ugeth->p_tx_glbl_pram = NULL;
  2092. }
  2093. if (ugeth->p_send_q_mem_reg) {
  2094. qe_muram_free(ugeth->send_q_mem_reg_offset);
  2095. ugeth->p_send_q_mem_reg = NULL;
  2096. }
  2097. if (ugeth->p_scheduler) {
  2098. qe_muram_free(ugeth->scheduler_offset);
  2099. ugeth->p_scheduler = NULL;
  2100. }
  2101. if (ugeth->p_tx_fw_statistics_pram) {
  2102. qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
  2103. ugeth->p_tx_fw_statistics_pram = NULL;
  2104. }
  2105. if (ugeth->p_rx_fw_statistics_pram) {
  2106. qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
  2107. ugeth->p_rx_fw_statistics_pram = NULL;
  2108. }
  2109. if (ugeth->p_rx_irq_coalescing_tbl) {
  2110. qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
  2111. ugeth->p_rx_irq_coalescing_tbl = NULL;
  2112. }
  2113. if (ugeth->p_rx_bd_qs_tbl) {
  2114. qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
  2115. ugeth->p_rx_bd_qs_tbl = NULL;
  2116. }
  2117. if (ugeth->p_init_enet_param_shadow) {
  2118. return_init_enet_entries(ugeth,
  2119. &(ugeth->p_init_enet_param_shadow->
  2120. rxthread[0]),
  2121. ENET_INIT_PARAM_MAX_ENTRIES_RX,
  2122. ugeth->ug_info->riscRx, 1);
  2123. return_init_enet_entries(ugeth,
  2124. &(ugeth->p_init_enet_param_shadow->
  2125. txthread[0]),
  2126. ENET_INIT_PARAM_MAX_ENTRIES_TX,
  2127. ugeth->ug_info->riscTx, 0);
  2128. kfree(ugeth->p_init_enet_param_shadow);
  2129. ugeth->p_init_enet_param_shadow = NULL;
  2130. }
  2131. for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
  2132. bd = ugeth->p_tx_bd_ring[i];
  2133. for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
  2134. if (ugeth->tx_skbuff[i][j]) {
  2135. dma_unmap_single(NULL,
  2136. ((qe_bd_t *)bd)->buf,
  2137. (in_be32((u32 *)bd) &
  2138. BD_LENGTH_MASK),
  2139. DMA_TO_DEVICE);
  2140. dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
  2141. ugeth->tx_skbuff[i][j] = NULL;
  2142. }
  2143. }
  2144. kfree(ugeth->tx_skbuff[i]);
  2145. if (ugeth->p_tx_bd_ring[i]) {
  2146. if (ugeth->ug_info->uf_info.bd_mem_part ==
  2147. MEM_PART_SYSTEM)
  2148. kfree((void *)ugeth->tx_bd_ring_offset[i]);
  2149. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2150. MEM_PART_MURAM)
  2151. qe_muram_free(ugeth->tx_bd_ring_offset[i]);
  2152. ugeth->p_tx_bd_ring[i] = NULL;
  2153. }
  2154. }
  2155. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  2156. if (ugeth->p_rx_bd_ring[i]) {
  2157. /* Return existing data buffers in ring */
  2158. bd = ugeth->p_rx_bd_ring[i];
  2159. for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
  2160. if (ugeth->rx_skbuff[i][j]) {
  2161. dma_unmap_single(NULL,
  2162. ((struct qe_bd *)bd)->buf,
  2163. ugeth->ug_info->
  2164. uf_info.max_rx_buf_length +
  2165. UCC_GETH_RX_DATA_BUF_ALIGNMENT,
  2166. DMA_FROM_DEVICE);
  2167. dev_kfree_skb_any(
  2168. ugeth->rx_skbuff[i][j]);
  2169. ugeth->rx_skbuff[i][j] = NULL;
  2170. }
  2171. bd += sizeof(struct qe_bd);
  2172. }
  2173. kfree(ugeth->rx_skbuff[i]);
  2174. if (ugeth->ug_info->uf_info.bd_mem_part ==
  2175. MEM_PART_SYSTEM)
  2176. kfree((void *)ugeth->rx_bd_ring_offset[i]);
  2177. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2178. MEM_PART_MURAM)
  2179. qe_muram_free(ugeth->rx_bd_ring_offset[i]);
  2180. ugeth->p_rx_bd_ring[i] = NULL;
  2181. }
  2182. }
  2183. while (!list_empty(&ugeth->group_hash_q))
  2184. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  2185. (dequeue(&ugeth->group_hash_q)));
  2186. while (!list_empty(&ugeth->ind_hash_q))
  2187. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  2188. (dequeue(&ugeth->ind_hash_q)));
  2189. }
  2190. static void ucc_geth_set_multi(struct net_device *dev)
  2191. {
  2192. struct ucc_geth_private *ugeth;
  2193. struct dev_mc_list *dmi;
  2194. struct ucc_fast *uf_regs;
  2195. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  2196. u8 tempaddr[6];
  2197. u8 *mcptr, *tdptr;
  2198. int i, j;
  2199. ugeth = netdev_priv(dev);
  2200. uf_regs = ugeth->uccf->uf_regs;
  2201. if (dev->flags & IFF_PROMISC) {
  2202. uf_regs->upsmr |= UPSMR_PRO;
  2203. } else {
  2204. uf_regs->upsmr &= ~UPSMR_PRO;
  2205. p_82xx_addr_filt =
  2206. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->
  2207. p_rx_glbl_pram->addressfiltering;
  2208. if (dev->flags & IFF_ALLMULTI) {
  2209. /* Catch all multicast addresses, so set the
  2210. * filter to all 1's.
  2211. */
  2212. out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
  2213. out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
  2214. } else {
  2215. /* Clear filter and add the addresses in the list.
  2216. */
  2217. out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
  2218. out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
  2219. dmi = dev->mc_list;
  2220. for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
  2221. /* Only support group multicast for now.
  2222. */
  2223. if (!(dmi->dmi_addr[0] & 1))
  2224. continue;
  2225. /* The address in dmi_addr is LSB first,
  2226. * and taddr is MSB first. We have to
  2227. * copy bytes MSB first from dmi_addr.
  2228. */
  2229. mcptr = (u8 *) dmi->dmi_addr + 5;
  2230. tdptr = (u8 *) tempaddr;
  2231. for (j = 0; j < 6; j++)
  2232. *tdptr++ = *mcptr--;
  2233. /* Ask CPM to run CRC and set bit in
  2234. * filter mask.
  2235. */
  2236. hw_add_addr_in_hash(ugeth, tempaddr);
  2237. }
  2238. }
  2239. }
  2240. }
  2241. static void ucc_geth_stop(struct ucc_geth_private *ugeth)
  2242. {
  2243. struct ucc_geth *ug_regs = ugeth->ug_regs;
  2244. u32 tempval;
  2245. ugeth_vdbg("%s: IN", __FUNCTION__);
  2246. /* Disable the controller */
  2247. ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
  2248. /* Tell the kernel the link is down */
  2249. ugeth->mii_info->link = 0;
  2250. adjust_link(ugeth->dev);
  2251. /* Mask all interrupts */
  2252. out_be32(ugeth->uccf->p_ucce, 0x00000000);
  2253. /* Clear all interrupts */
  2254. out_be32(ugeth->uccf->p_ucce, 0xffffffff);
  2255. /* Disable Rx and Tx */
  2256. tempval = in_be32(&ug_regs->maccfg1);
  2257. tempval &= ~(MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
  2258. out_be32(&ug_regs->maccfg1, tempval);
  2259. if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
  2260. /* Clear any pending interrupts */
  2261. mii_clear_phy_interrupt(ugeth->mii_info);
  2262. /* Disable PHY Interrupts */
  2263. mii_configure_phy_interrupt(ugeth->mii_info,
  2264. MII_INTERRUPT_DISABLED);
  2265. }
  2266. free_irq(ugeth->ug_info->uf_info.irq, ugeth->dev);
  2267. if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
  2268. free_irq(ugeth->ug_info->phy_interrupt, ugeth->dev);
  2269. } else {
  2270. del_timer_sync(&ugeth->phy_info_timer);
  2271. }
  2272. ucc_geth_memclean(ugeth);
  2273. }
  2274. static int ucc_geth_startup(struct ucc_geth_private *ugeth)
  2275. {
  2276. struct ucc_geth_82xx_address_filtering_pram *p_82xx_addr_filt;
  2277. struct ucc_geth_init_pram *p_init_enet_pram;
  2278. struct ucc_fast_private *uccf;
  2279. struct ucc_geth_info *ug_info;
  2280. struct ucc_fast_info *uf_info;
  2281. struct ucc_fast *uf_regs;
  2282. struct ucc_geth *ug_regs;
  2283. int ret_val = -EINVAL;
  2284. u32 remoder = UCC_GETH_REMODER_INIT;
  2285. u32 init_enet_pram_offset, cecr_subblock, command, maccfg1;
  2286. u32 ifstat, i, j, size, l2qt, l3qt, length;
  2287. u16 temoder = UCC_GETH_TEMODER_INIT;
  2288. u16 test;
  2289. u8 function_code = 0;
  2290. u8 *bd, *endOfRing;
  2291. u8 numThreadsRxNumerical, numThreadsTxNumerical;
  2292. ugeth_vdbg("%s: IN", __FUNCTION__);
  2293. ug_info = ugeth->ug_info;
  2294. uf_info = &ug_info->uf_info;
  2295. if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
  2296. (uf_info->bd_mem_part == MEM_PART_MURAM))) {
  2297. ugeth_err("%s: Bad memory partition value.", __FUNCTION__);
  2298. return -EINVAL;
  2299. }
  2300. /* Rx BD lengths */
  2301. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2302. if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
  2303. (ug_info->bdRingLenRx[i] %
  2304. UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
  2305. ugeth_err
  2306. ("%s: Rx BD ring length must be multiple of 4,"
  2307. " no smaller than 8.", __FUNCTION__);
  2308. return -EINVAL;
  2309. }
  2310. }
  2311. /* Tx BD lengths */
  2312. for (i = 0; i < ug_info->numQueuesTx; i++) {
  2313. if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
  2314. ugeth_err
  2315. ("%s: Tx BD ring length must be no smaller than 2.",
  2316. __FUNCTION__);
  2317. return -EINVAL;
  2318. }
  2319. }
  2320. /* mrblr */
  2321. if ((uf_info->max_rx_buf_length == 0) ||
  2322. (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
  2323. ugeth_err
  2324. ("%s: max_rx_buf_length must be non-zero multiple of 128.",
  2325. __FUNCTION__);
  2326. return -EINVAL;
  2327. }
  2328. /* num Tx queues */
  2329. if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
  2330. ugeth_err("%s: number of tx queues too large.", __FUNCTION__);
  2331. return -EINVAL;
  2332. }
  2333. /* num Rx queues */
  2334. if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
  2335. ugeth_err("%s: number of rx queues too large.", __FUNCTION__);
  2336. return -EINVAL;
  2337. }
  2338. /* l2qt */
  2339. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
  2340. if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
  2341. ugeth_err
  2342. ("%s: VLAN priority table entry must not be"
  2343. " larger than number of Rx queues.",
  2344. __FUNCTION__);
  2345. return -EINVAL;
  2346. }
  2347. }
  2348. /* l3qt */
  2349. for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
  2350. if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
  2351. ugeth_err
  2352. ("%s: IP priority table entry must not be"
  2353. " larger than number of Rx queues.",
  2354. __FUNCTION__);
  2355. return -EINVAL;
  2356. }
  2357. }
  2358. if (ug_info->cam && !ug_info->ecamptr) {
  2359. ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
  2360. __FUNCTION__);
  2361. return -EINVAL;
  2362. }
  2363. if ((ug_info->numStationAddresses !=
  2364. UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
  2365. && ug_info->rxExtendedFiltering) {
  2366. ugeth_err("%s: Number of station addresses greater than 1 "
  2367. "not allowed in extended parsing mode.",
  2368. __FUNCTION__);
  2369. return -EINVAL;
  2370. }
  2371. /* Generate uccm_mask for receive */
  2372. uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
  2373. for (i = 0; i < ug_info->numQueuesRx; i++)
  2374. uf_info->uccm_mask |= (UCCE_RXBF_SINGLE_MASK << i);
  2375. for (i = 0; i < ug_info->numQueuesTx; i++)
  2376. uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i);
  2377. /* Initialize the general fast UCC block. */
  2378. if (ucc_fast_init(uf_info, &uccf)) {
  2379. ugeth_err("%s: Failed to init uccf.", __FUNCTION__);
  2380. ucc_geth_memclean(ugeth);
  2381. return -ENOMEM;
  2382. }
  2383. ugeth->uccf = uccf;
  2384. switch (ug_info->numThreadsRx) {
  2385. case UCC_GETH_NUM_OF_THREADS_1:
  2386. numThreadsRxNumerical = 1;
  2387. break;
  2388. case UCC_GETH_NUM_OF_THREADS_2:
  2389. numThreadsRxNumerical = 2;
  2390. break;
  2391. case UCC_GETH_NUM_OF_THREADS_4:
  2392. numThreadsRxNumerical = 4;
  2393. break;
  2394. case UCC_GETH_NUM_OF_THREADS_6:
  2395. numThreadsRxNumerical = 6;
  2396. break;
  2397. case UCC_GETH_NUM_OF_THREADS_8:
  2398. numThreadsRxNumerical = 8;
  2399. break;
  2400. default:
  2401. ugeth_err("%s: Bad number of Rx threads value.", __FUNCTION__);
  2402. ucc_geth_memclean(ugeth);
  2403. return -EINVAL;
  2404. break;
  2405. }
  2406. switch (ug_info->numThreadsTx) {
  2407. case UCC_GETH_NUM_OF_THREADS_1:
  2408. numThreadsTxNumerical = 1;
  2409. break;
  2410. case UCC_GETH_NUM_OF_THREADS_2:
  2411. numThreadsTxNumerical = 2;
  2412. break;
  2413. case UCC_GETH_NUM_OF_THREADS_4:
  2414. numThreadsTxNumerical = 4;
  2415. break;
  2416. case UCC_GETH_NUM_OF_THREADS_6:
  2417. numThreadsTxNumerical = 6;
  2418. break;
  2419. case UCC_GETH_NUM_OF_THREADS_8:
  2420. numThreadsTxNumerical = 8;
  2421. break;
  2422. default:
  2423. ugeth_err("%s: Bad number of Tx threads value.", __FUNCTION__);
  2424. ucc_geth_memclean(ugeth);
  2425. return -EINVAL;
  2426. break;
  2427. }
  2428. /* Calculate rx_extended_features */
  2429. ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
  2430. ug_info->ipAddressAlignment ||
  2431. (ug_info->numStationAddresses !=
  2432. UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
  2433. ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
  2434. (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
  2435. || (ug_info->vlanOperationNonTagged !=
  2436. UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
  2437. uf_regs = uccf->uf_regs;
  2438. ug_regs = (struct ucc_geth *) (uccf->uf_regs);
  2439. ugeth->ug_regs = ug_regs;
  2440. init_default_reg_vals(&uf_regs->upsmr,
  2441. &ug_regs->maccfg1, &ug_regs->maccfg2);
  2442. /* Set UPSMR */
  2443. /* For more details see the hardware spec. */
  2444. init_rx_parameters(ug_info->bro,
  2445. ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
  2446. /* We're going to ignore other registers for now, */
  2447. /* except as needed to get up and running */
  2448. /* Set MACCFG1 */
  2449. /* For more details see the hardware spec. */
  2450. init_flow_control_params(ug_info->aufc,
  2451. ug_info->receiveFlowControl,
  2452. 1,
  2453. ug_info->pausePeriod,
  2454. ug_info->extensionField,
  2455. &uf_regs->upsmr,
  2456. &ug_regs->uempr, &ug_regs->maccfg1);
  2457. maccfg1 = in_be32(&ug_regs->maccfg1);
  2458. maccfg1 |= MACCFG1_ENABLE_RX;
  2459. maccfg1 |= MACCFG1_ENABLE_TX;
  2460. out_be32(&ug_regs->maccfg1, maccfg1);
  2461. /* Set IPGIFG */
  2462. /* For more details see the hardware spec. */
  2463. ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
  2464. ug_info->nonBackToBackIfgPart2,
  2465. ug_info->
  2466. miminumInterFrameGapEnforcement,
  2467. ug_info->backToBackInterFrameGap,
  2468. &ug_regs->ipgifg);
  2469. if (ret_val != 0) {
  2470. ugeth_err("%s: IPGIFG initialization parameter too large.",
  2471. __FUNCTION__);
  2472. ucc_geth_memclean(ugeth);
  2473. return ret_val;
  2474. }
  2475. /* Set HAFDUP */
  2476. /* For more details see the hardware spec. */
  2477. ret_val = init_half_duplex_params(ug_info->altBeb,
  2478. ug_info->backPressureNoBackoff,
  2479. ug_info->noBackoff,
  2480. ug_info->excessDefer,
  2481. ug_info->altBebTruncation,
  2482. ug_info->maxRetransmission,
  2483. ug_info->collisionWindow,
  2484. &ug_regs->hafdup);
  2485. if (ret_val != 0) {
  2486. ugeth_err("%s: Half Duplex initialization parameter too large.",
  2487. __FUNCTION__);
  2488. ucc_geth_memclean(ugeth);
  2489. return ret_val;
  2490. }
  2491. /* Set IFSTAT */
  2492. /* For more details see the hardware spec. */
  2493. /* Read only - resets upon read */
  2494. ifstat = in_be32(&ug_regs->ifstat);
  2495. /* Clear UEMPR */
  2496. /* For more details see the hardware spec. */
  2497. out_be32(&ug_regs->uempr, 0);
  2498. /* Set UESCR */
  2499. /* For more details see the hardware spec. */
  2500. init_hw_statistics_gathering_mode((ug_info->statisticsMode &
  2501. UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
  2502. 0, &uf_regs->upsmr, &ug_regs->uescr);
  2503. /* Allocate Tx bds */
  2504. for (j = 0; j < ug_info->numQueuesTx; j++) {
  2505. /* Allocate in multiple of
  2506. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
  2507. according to spec */
  2508. length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
  2509. / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  2510. * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  2511. if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
  2512. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  2513. length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  2514. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  2515. u32 align = 4;
  2516. if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
  2517. align = UCC_GETH_TX_BD_RING_ALIGNMENT;
  2518. ugeth->tx_bd_ring_offset[j] =
  2519. (u32) (kmalloc((u32) (length + align),
  2520. GFP_KERNEL));
  2521. if (ugeth->tx_bd_ring_offset[j] != 0)
  2522. ugeth->p_tx_bd_ring[j] =
  2523. (void*)((ugeth->tx_bd_ring_offset[j] +
  2524. align) & ~(align - 1));
  2525. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  2526. ugeth->tx_bd_ring_offset[j] =
  2527. qe_muram_alloc(length,
  2528. UCC_GETH_TX_BD_RING_ALIGNMENT);
  2529. if (!IS_MURAM_ERR(ugeth->tx_bd_ring_offset[j]))
  2530. ugeth->p_tx_bd_ring[j] =
  2531. (u8 *) qe_muram_addr(ugeth->
  2532. tx_bd_ring_offset[j]);
  2533. }
  2534. if (!ugeth->p_tx_bd_ring[j]) {
  2535. ugeth_err
  2536. ("%s: Can not allocate memory for Tx bd rings.",
  2537. __FUNCTION__);
  2538. ucc_geth_memclean(ugeth);
  2539. return -ENOMEM;
  2540. }
  2541. /* Zero unused end of bd ring, according to spec */
  2542. memset(ugeth->p_tx_bd_ring[j] +
  2543. ug_info->bdRingLenTx[j] * sizeof(struct qe_bd), 0,
  2544. length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
  2545. }
  2546. /* Allocate Rx bds */
  2547. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2548. length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
  2549. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  2550. u32 align = 4;
  2551. if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
  2552. align = UCC_GETH_RX_BD_RING_ALIGNMENT;
  2553. ugeth->rx_bd_ring_offset[j] =
  2554. (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
  2555. if (ugeth->rx_bd_ring_offset[j] != 0)
  2556. ugeth->p_rx_bd_ring[j] =
  2557. (void*)((ugeth->rx_bd_ring_offset[j] +
  2558. align) & ~(align - 1));
  2559. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  2560. ugeth->rx_bd_ring_offset[j] =
  2561. qe_muram_alloc(length,
  2562. UCC_GETH_RX_BD_RING_ALIGNMENT);
  2563. if (!IS_MURAM_ERR(ugeth->rx_bd_ring_offset[j]))
  2564. ugeth->p_rx_bd_ring[j] =
  2565. (u8 *) qe_muram_addr(ugeth->
  2566. rx_bd_ring_offset[j]);
  2567. }
  2568. if (!ugeth->p_rx_bd_ring[j]) {
  2569. ugeth_err
  2570. ("%s: Can not allocate memory for Rx bd rings.",
  2571. __FUNCTION__);
  2572. ucc_geth_memclean(ugeth);
  2573. return -ENOMEM;
  2574. }
  2575. }
  2576. /* Init Tx bds */
  2577. for (j = 0; j < ug_info->numQueuesTx; j++) {
  2578. /* Setup the skbuff rings */
  2579. ugeth->tx_skbuff[j] =
  2580. (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
  2581. ugeth->ug_info->bdRingLenTx[j],
  2582. GFP_KERNEL);
  2583. if (ugeth->tx_skbuff[j] == NULL) {
  2584. ugeth_err("%s: Could not allocate tx_skbuff",
  2585. __FUNCTION__);
  2586. ucc_geth_memclean(ugeth);
  2587. return -ENOMEM;
  2588. }
  2589. for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
  2590. ugeth->tx_skbuff[j][i] = NULL;
  2591. ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
  2592. bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
  2593. for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
  2594. /* clear bd buffer */
  2595. out_be32(&((struct qe_bd *)bd)->buf, 0);
  2596. /* set bd status and length */
  2597. out_be32((u32 *)bd, 0);
  2598. bd += sizeof(struct qe_bd);
  2599. }
  2600. bd -= sizeof(struct qe_bd);
  2601. /* set bd status and length */
  2602. out_be32((u32 *)bd, T_W); /* for last BD set Wrap bit */
  2603. }
  2604. /* Init Rx bds */
  2605. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2606. /* Setup the skbuff rings */
  2607. ugeth->rx_skbuff[j] =
  2608. (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
  2609. ugeth->ug_info->bdRingLenRx[j],
  2610. GFP_KERNEL);
  2611. if (ugeth->rx_skbuff[j] == NULL) {
  2612. ugeth_err("%s: Could not allocate rx_skbuff",
  2613. __FUNCTION__);
  2614. ucc_geth_memclean(ugeth);
  2615. return -ENOMEM;
  2616. }
  2617. for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
  2618. ugeth->rx_skbuff[j][i] = NULL;
  2619. ugeth->skb_currx[j] = 0;
  2620. bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
  2621. for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
  2622. /* set bd status and length */
  2623. out_be32((u32 *)bd, R_I);
  2624. /* clear bd buffer */
  2625. out_be32(&((struct qe_bd *)bd)->buf, 0);
  2626. bd += sizeof(struct qe_bd);
  2627. }
  2628. bd -= sizeof(struct qe_bd);
  2629. /* set bd status and length */
  2630. out_be32((u32 *)bd, R_W); /* for last BD set Wrap bit */
  2631. }
  2632. /*
  2633. * Global PRAM
  2634. */
  2635. /* Tx global PRAM */
  2636. /* Allocate global tx parameter RAM page */
  2637. ugeth->tx_glbl_pram_offset =
  2638. qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
  2639. UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
  2640. if (IS_MURAM_ERR(ugeth->tx_glbl_pram_offset)) {
  2641. ugeth_err
  2642. ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
  2643. __FUNCTION__);
  2644. ucc_geth_memclean(ugeth);
  2645. return -ENOMEM;
  2646. }
  2647. ugeth->p_tx_glbl_pram =
  2648. (struct ucc_geth_tx_global_pram *) qe_muram_addr(ugeth->
  2649. tx_glbl_pram_offset);
  2650. /* Zero out p_tx_glbl_pram */
  2651. memset(ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
  2652. /* Fill global PRAM */
  2653. /* TQPTR */
  2654. /* Size varies with number of Tx threads */
  2655. ugeth->thread_dat_tx_offset =
  2656. qe_muram_alloc(numThreadsTxNumerical *
  2657. sizeof(struct ucc_geth_thread_data_tx) +
  2658. 32 * (numThreadsTxNumerical == 1),
  2659. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2660. if (IS_MURAM_ERR(ugeth->thread_dat_tx_offset)) {
  2661. ugeth_err
  2662. ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
  2663. __FUNCTION__);
  2664. ucc_geth_memclean(ugeth);
  2665. return -ENOMEM;
  2666. }
  2667. ugeth->p_thread_data_tx =
  2668. (struct ucc_geth_thread_data_tx *) qe_muram_addr(ugeth->
  2669. thread_dat_tx_offset);
  2670. out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
  2671. /* vtagtable */
  2672. for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
  2673. out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
  2674. ug_info->vtagtable[i]);
  2675. /* iphoffset */
  2676. for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
  2677. ugeth->p_tx_glbl_pram->iphoffset[i] = ug_info->iphoffset[i];
  2678. /* SQPTR */
  2679. /* Size varies with number of Tx queues */
  2680. ugeth->send_q_mem_reg_offset =
  2681. qe_muram_alloc(ug_info->numQueuesTx *
  2682. sizeof(struct ucc_geth_send_queue_qd),
  2683. UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
  2684. if (IS_MURAM_ERR(ugeth->send_q_mem_reg_offset)) {
  2685. ugeth_err
  2686. ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
  2687. __FUNCTION__);
  2688. ucc_geth_memclean(ugeth);
  2689. return -ENOMEM;
  2690. }
  2691. ugeth->p_send_q_mem_reg =
  2692. (struct ucc_geth_send_queue_mem_region *) qe_muram_addr(ugeth->
  2693. send_q_mem_reg_offset);
  2694. out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
  2695. /* Setup the table */
  2696. /* Assume BD rings are already established */
  2697. for (i = 0; i < ug_info->numQueuesTx; i++) {
  2698. endOfRing =
  2699. ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
  2700. 1) * sizeof(struct qe_bd);
  2701. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2702. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2703. (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
  2704. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2705. last_bd_completed_address,
  2706. (u32) virt_to_phys(endOfRing));
  2707. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2708. MEM_PART_MURAM) {
  2709. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2710. (u32) immrbar_virt_to_phys(ugeth->
  2711. p_tx_bd_ring[i]));
  2712. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2713. last_bd_completed_address,
  2714. (u32) immrbar_virt_to_phys(endOfRing));
  2715. }
  2716. }
  2717. /* schedulerbasepointer */
  2718. if (ug_info->numQueuesTx > 1) {
  2719. /* scheduler exists only if more than 1 tx queue */
  2720. ugeth->scheduler_offset =
  2721. qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
  2722. UCC_GETH_SCHEDULER_ALIGNMENT);
  2723. if (IS_MURAM_ERR(ugeth->scheduler_offset)) {
  2724. ugeth_err
  2725. ("%s: Can not allocate DPRAM memory for p_scheduler.",
  2726. __FUNCTION__);
  2727. ucc_geth_memclean(ugeth);
  2728. return -ENOMEM;
  2729. }
  2730. ugeth->p_scheduler =
  2731. (struct ucc_geth_scheduler *) qe_muram_addr(ugeth->
  2732. scheduler_offset);
  2733. out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
  2734. ugeth->scheduler_offset);
  2735. /* Zero out p_scheduler */
  2736. memset(ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
  2737. /* Set values in scheduler */
  2738. out_be32(&ugeth->p_scheduler->mblinterval,
  2739. ug_info->mblinterval);
  2740. out_be16(&ugeth->p_scheduler->nortsrbytetime,
  2741. ug_info->nortsrbytetime);
  2742. ugeth->p_scheduler->fracsiz = ug_info->fracsiz;
  2743. ugeth->p_scheduler->strictpriorityq = ug_info->strictpriorityq;
  2744. ugeth->p_scheduler->txasap = ug_info->txasap;
  2745. ugeth->p_scheduler->extrabw = ug_info->extrabw;
  2746. for (i = 0; i < NUM_TX_QUEUES; i++)
  2747. ugeth->p_scheduler->weightfactor[i] =
  2748. ug_info->weightfactor[i];
  2749. /* Set pointers to cpucount registers in scheduler */
  2750. ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
  2751. ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
  2752. ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
  2753. ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
  2754. ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
  2755. ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
  2756. ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
  2757. ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
  2758. }
  2759. /* schedulerbasepointer */
  2760. /* TxRMON_PTR (statistics) */
  2761. if (ug_info->
  2762. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  2763. ugeth->tx_fw_statistics_pram_offset =
  2764. qe_muram_alloc(sizeof
  2765. (struct ucc_geth_tx_firmware_statistics_pram),
  2766. UCC_GETH_TX_STATISTICS_ALIGNMENT);
  2767. if (IS_MURAM_ERR(ugeth->tx_fw_statistics_pram_offset)) {
  2768. ugeth_err
  2769. ("%s: Can not allocate DPRAM memory for"
  2770. " p_tx_fw_statistics_pram.", __FUNCTION__);
  2771. ucc_geth_memclean(ugeth);
  2772. return -ENOMEM;
  2773. }
  2774. ugeth->p_tx_fw_statistics_pram =
  2775. (struct ucc_geth_tx_firmware_statistics_pram *)
  2776. qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
  2777. /* Zero out p_tx_fw_statistics_pram */
  2778. memset(ugeth->p_tx_fw_statistics_pram,
  2779. 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
  2780. }
  2781. /* temoder */
  2782. /* Already has speed set */
  2783. if (ug_info->numQueuesTx > 1)
  2784. temoder |= TEMODER_SCHEDULER_ENABLE;
  2785. if (ug_info->ipCheckSumGenerate)
  2786. temoder |= TEMODER_IP_CHECKSUM_GENERATE;
  2787. temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
  2788. out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
  2789. test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
  2790. /* Function code register value to be used later */
  2791. function_code = QE_BMR_BYTE_ORDER_BO_MOT | UCC_FAST_FUNCTION_CODE_GBL;
  2792. /* Required for QE */
  2793. /* function code register */
  2794. out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
  2795. /* Rx global PRAM */
  2796. /* Allocate global rx parameter RAM page */
  2797. ugeth->rx_glbl_pram_offset =
  2798. qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
  2799. UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
  2800. if (IS_MURAM_ERR(ugeth->rx_glbl_pram_offset)) {
  2801. ugeth_err
  2802. ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
  2803. __FUNCTION__);
  2804. ucc_geth_memclean(ugeth);
  2805. return -ENOMEM;
  2806. }
  2807. ugeth->p_rx_glbl_pram =
  2808. (struct ucc_geth_rx_global_pram *) qe_muram_addr(ugeth->
  2809. rx_glbl_pram_offset);
  2810. /* Zero out p_rx_glbl_pram */
  2811. memset(ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
  2812. /* Fill global PRAM */
  2813. /* RQPTR */
  2814. /* Size varies with number of Rx threads */
  2815. ugeth->thread_dat_rx_offset =
  2816. qe_muram_alloc(numThreadsRxNumerical *
  2817. sizeof(struct ucc_geth_thread_data_rx),
  2818. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2819. if (IS_MURAM_ERR(ugeth->thread_dat_rx_offset)) {
  2820. ugeth_err
  2821. ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
  2822. __FUNCTION__);
  2823. ucc_geth_memclean(ugeth);
  2824. return -ENOMEM;
  2825. }
  2826. ugeth->p_thread_data_rx =
  2827. (struct ucc_geth_thread_data_rx *) qe_muram_addr(ugeth->
  2828. thread_dat_rx_offset);
  2829. out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
  2830. /* typeorlen */
  2831. out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
  2832. /* rxrmonbaseptr (statistics) */
  2833. if (ug_info->
  2834. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
  2835. ugeth->rx_fw_statistics_pram_offset =
  2836. qe_muram_alloc(sizeof
  2837. (struct ucc_geth_rx_firmware_statistics_pram),
  2838. UCC_GETH_RX_STATISTICS_ALIGNMENT);
  2839. if (IS_MURAM_ERR(ugeth->rx_fw_statistics_pram_offset)) {
  2840. ugeth_err
  2841. ("%s: Can not allocate DPRAM memory for"
  2842. " p_rx_fw_statistics_pram.", __FUNCTION__);
  2843. ucc_geth_memclean(ugeth);
  2844. return -ENOMEM;
  2845. }
  2846. ugeth->p_rx_fw_statistics_pram =
  2847. (struct ucc_geth_rx_firmware_statistics_pram *)
  2848. qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
  2849. /* Zero out p_rx_fw_statistics_pram */
  2850. memset(ugeth->p_rx_fw_statistics_pram, 0,
  2851. sizeof(struct ucc_geth_rx_firmware_statistics_pram));
  2852. }
  2853. /* intCoalescingPtr */
  2854. /* Size varies with number of Rx queues */
  2855. ugeth->rx_irq_coalescing_tbl_offset =
  2856. qe_muram_alloc(ug_info->numQueuesRx *
  2857. sizeof(struct ucc_geth_rx_interrupt_coalescing_entry),
  2858. UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
  2859. if (IS_MURAM_ERR(ugeth->rx_irq_coalescing_tbl_offset)) {
  2860. ugeth_err
  2861. ("%s: Can not allocate DPRAM memory for"
  2862. " p_rx_irq_coalescing_tbl.", __FUNCTION__);
  2863. ucc_geth_memclean(ugeth);
  2864. return -ENOMEM;
  2865. }
  2866. ugeth->p_rx_irq_coalescing_tbl =
  2867. (struct ucc_geth_rx_interrupt_coalescing_table *)
  2868. qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
  2869. out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
  2870. ugeth->rx_irq_coalescing_tbl_offset);
  2871. /* Fill interrupt coalescing table */
  2872. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2873. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2874. interruptcoalescingmaxvalue,
  2875. ug_info->interruptcoalescingmaxvalue[i]);
  2876. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2877. interruptcoalescingcounter,
  2878. ug_info->interruptcoalescingmaxvalue[i]);
  2879. }
  2880. /* MRBLR */
  2881. init_max_rx_buff_len(uf_info->max_rx_buf_length,
  2882. &ugeth->p_rx_glbl_pram->mrblr);
  2883. /* MFLR */
  2884. out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
  2885. /* MINFLR */
  2886. init_min_frame_len(ug_info->minFrameLength,
  2887. &ugeth->p_rx_glbl_pram->minflr,
  2888. &ugeth->p_rx_glbl_pram->mrblr);
  2889. /* MAXD1 */
  2890. out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
  2891. /* MAXD2 */
  2892. out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
  2893. /* l2qt */
  2894. l2qt = 0;
  2895. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
  2896. l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
  2897. out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
  2898. /* l3qt */
  2899. for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
  2900. l3qt = 0;
  2901. for (i = 0; i < 8; i++)
  2902. l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
  2903. out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
  2904. }
  2905. /* vlantype */
  2906. out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
  2907. /* vlantci */
  2908. out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
  2909. /* ecamptr */
  2910. out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
  2911. /* RBDQPTR */
  2912. /* Size varies with number of Rx queues */
  2913. ugeth->rx_bd_qs_tbl_offset =
  2914. qe_muram_alloc(ug_info->numQueuesRx *
  2915. (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2916. sizeof(struct ucc_geth_rx_prefetched_bds)),
  2917. UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
  2918. if (IS_MURAM_ERR(ugeth->rx_bd_qs_tbl_offset)) {
  2919. ugeth_err
  2920. ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
  2921. __FUNCTION__);
  2922. ucc_geth_memclean(ugeth);
  2923. return -ENOMEM;
  2924. }
  2925. ugeth->p_rx_bd_qs_tbl =
  2926. (struct ucc_geth_rx_bd_queues_entry *) qe_muram_addr(ugeth->
  2927. rx_bd_qs_tbl_offset);
  2928. out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
  2929. /* Zero out p_rx_bd_qs_tbl */
  2930. memset(ugeth->p_rx_bd_qs_tbl,
  2931. 0,
  2932. ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2933. sizeof(struct ucc_geth_rx_prefetched_bds)));
  2934. /* Setup the table */
  2935. /* Assume BD rings are already established */
  2936. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2937. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2938. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2939. (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
  2940. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2941. MEM_PART_MURAM) {
  2942. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2943. (u32) immrbar_virt_to_phys(ugeth->
  2944. p_rx_bd_ring[i]));
  2945. }
  2946. /* rest of fields handled by QE */
  2947. }
  2948. /* remoder */
  2949. /* Already has speed set */
  2950. if (ugeth->rx_extended_features)
  2951. remoder |= REMODER_RX_EXTENDED_FEATURES;
  2952. if (ug_info->rxExtendedFiltering)
  2953. remoder |= REMODER_RX_EXTENDED_FILTERING;
  2954. if (ug_info->dynamicMaxFrameLength)
  2955. remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
  2956. if (ug_info->dynamicMinFrameLength)
  2957. remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
  2958. remoder |=
  2959. ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
  2960. remoder |=
  2961. ug_info->
  2962. vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
  2963. remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
  2964. remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
  2965. if (ug_info->ipCheckSumCheck)
  2966. remoder |= REMODER_IP_CHECKSUM_CHECK;
  2967. if (ug_info->ipAddressAlignment)
  2968. remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
  2969. out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
  2970. /* Note that this function must be called */
  2971. /* ONLY AFTER p_tx_fw_statistics_pram */
  2972. /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
  2973. init_firmware_statistics_gathering_mode((ug_info->
  2974. statisticsMode &
  2975. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
  2976. (ug_info->statisticsMode &
  2977. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
  2978. &ugeth->p_tx_glbl_pram->txrmonbaseptr,
  2979. ugeth->tx_fw_statistics_pram_offset,
  2980. &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
  2981. ugeth->rx_fw_statistics_pram_offset,
  2982. &ugeth->p_tx_glbl_pram->temoder,
  2983. &ugeth->p_rx_glbl_pram->remoder);
  2984. /* function code register */
  2985. ugeth->p_rx_glbl_pram->rstate = function_code;
  2986. /* initialize extended filtering */
  2987. if (ug_info->rxExtendedFiltering) {
  2988. if (!ug_info->extendedFilteringChainPointer) {
  2989. ugeth_err("%s: Null Extended Filtering Chain Pointer.",
  2990. __FUNCTION__);
  2991. ucc_geth_memclean(ugeth);
  2992. return -EINVAL;
  2993. }
  2994. /* Allocate memory for extended filtering Mode Global
  2995. Parameters */
  2996. ugeth->exf_glbl_param_offset =
  2997. qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
  2998. UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
  2999. if (IS_MURAM_ERR(ugeth->exf_glbl_param_offset)) {
  3000. ugeth_err
  3001. ("%s: Can not allocate DPRAM memory for"
  3002. " p_exf_glbl_param.", __FUNCTION__);
  3003. ucc_geth_memclean(ugeth);
  3004. return -ENOMEM;
  3005. }
  3006. ugeth->p_exf_glbl_param =
  3007. (struct ucc_geth_exf_global_pram *) qe_muram_addr(ugeth->
  3008. exf_glbl_param_offset);
  3009. out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
  3010. ugeth->exf_glbl_param_offset);
  3011. out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
  3012. (u32) ug_info->extendedFilteringChainPointer);
  3013. } else { /* initialize 82xx style address filtering */
  3014. /* Init individual address recognition registers to disabled */
  3015. for (j = 0; j < NUM_OF_PADDRS; j++)
  3016. ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
  3017. /* Create CQs for hash tables */
  3018. if (ug_info->maxGroupAddrInHash > 0) {
  3019. INIT_LIST_HEAD(&ugeth->group_hash_q);
  3020. }
  3021. if (ug_info->maxIndAddrInHash > 0) {
  3022. INIT_LIST_HEAD(&ugeth->ind_hash_q);
  3023. }
  3024. p_82xx_addr_filt =
  3025. (struct ucc_geth_82xx_address_filtering_pram *) ugeth->
  3026. p_rx_glbl_pram->addressfiltering;
  3027. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  3028. ENET_ADDR_TYPE_GROUP);
  3029. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  3030. ENET_ADDR_TYPE_INDIVIDUAL);
  3031. }
  3032. /*
  3033. * Initialize UCC at QE level
  3034. */
  3035. command = QE_INIT_TX_RX;
  3036. /* Allocate shadow InitEnet command parameter structure.
  3037. * This is needed because after the InitEnet command is executed,
  3038. * the structure in DPRAM is released, because DPRAM is a premium
  3039. * resource.
  3040. * This shadow structure keeps a copy of what was done so that the
  3041. * allocated resources can be released when the channel is freed.
  3042. */
  3043. if (!(ugeth->p_init_enet_param_shadow =
  3044. (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
  3045. GFP_KERNEL))) {
  3046. ugeth_err
  3047. ("%s: Can not allocate memory for"
  3048. " p_UccInitEnetParamShadows.", __FUNCTION__);
  3049. ucc_geth_memclean(ugeth);
  3050. return -ENOMEM;
  3051. }
  3052. /* Zero out *p_init_enet_param_shadow */
  3053. memset((char *)ugeth->p_init_enet_param_shadow,
  3054. 0, sizeof(struct ucc_geth_init_pram));
  3055. /* Fill shadow InitEnet command parameter structure */
  3056. ugeth->p_init_enet_param_shadow->resinit1 =
  3057. ENET_INIT_PARAM_MAGIC_RES_INIT1;
  3058. ugeth->p_init_enet_param_shadow->resinit2 =
  3059. ENET_INIT_PARAM_MAGIC_RES_INIT2;
  3060. ugeth->p_init_enet_param_shadow->resinit3 =
  3061. ENET_INIT_PARAM_MAGIC_RES_INIT3;
  3062. ugeth->p_init_enet_param_shadow->resinit4 =
  3063. ENET_INIT_PARAM_MAGIC_RES_INIT4;
  3064. ugeth->p_init_enet_param_shadow->resinit5 =
  3065. ENET_INIT_PARAM_MAGIC_RES_INIT5;
  3066. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  3067. ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
  3068. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  3069. ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
  3070. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  3071. ugeth->rx_glbl_pram_offset | ug_info->riscRx;
  3072. if ((ug_info->largestexternallookupkeysize !=
  3073. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE)
  3074. && (ug_info->largestexternallookupkeysize !=
  3075. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
  3076. && (ug_info->largestexternallookupkeysize !=
  3077. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
  3078. ugeth_err("%s: Invalid largest External Lookup Key Size.",
  3079. __FUNCTION__);
  3080. ucc_geth_memclean(ugeth);
  3081. return -EINVAL;
  3082. }
  3083. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
  3084. ug_info->largestexternallookupkeysize;
  3085. size = sizeof(struct ucc_geth_thread_rx_pram);
  3086. if (ug_info->rxExtendedFiltering) {
  3087. size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
  3088. if (ug_info->largestexternallookupkeysize ==
  3089. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
  3090. size +=
  3091. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
  3092. if (ug_info->largestexternallookupkeysize ==
  3093. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
  3094. size +=
  3095. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
  3096. }
  3097. if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
  3098. p_init_enet_param_shadow->rxthread[0]),
  3099. (u8) (numThreadsRxNumerical + 1)
  3100. /* Rx needs one extra for terminator */
  3101. , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
  3102. ug_info->riscRx, 1)) != 0) {
  3103. ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
  3104. __FUNCTION__);
  3105. ucc_geth_memclean(ugeth);
  3106. return ret_val;
  3107. }
  3108. ugeth->p_init_enet_param_shadow->txglobal =
  3109. ugeth->tx_glbl_pram_offset | ug_info->riscTx;
  3110. if ((ret_val =
  3111. fill_init_enet_entries(ugeth,
  3112. &(ugeth->p_init_enet_param_shadow->
  3113. txthread[0]), numThreadsTxNumerical,
  3114. sizeof(struct ucc_geth_thread_tx_pram),
  3115. UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
  3116. ug_info->riscTx, 0)) != 0) {
  3117. ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
  3118. __FUNCTION__);
  3119. ucc_geth_memclean(ugeth);
  3120. return ret_val;
  3121. }
  3122. /* Load Rx bds with buffers */
  3123. for (i = 0; i < ug_info->numQueuesRx; i++) {
  3124. if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
  3125. ugeth_err("%s: Can not fill Rx bds with buffers.",
  3126. __FUNCTION__);
  3127. ucc_geth_memclean(ugeth);
  3128. return ret_val;
  3129. }
  3130. }
  3131. /* Allocate InitEnet command parameter structure */
  3132. init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
  3133. if (IS_MURAM_ERR(init_enet_pram_offset)) {
  3134. ugeth_err
  3135. ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
  3136. __FUNCTION__);
  3137. ucc_geth_memclean(ugeth);
  3138. return -ENOMEM;
  3139. }
  3140. p_init_enet_pram =
  3141. (struct ucc_geth_init_pram *) qe_muram_addr(init_enet_pram_offset);
  3142. /* Copy shadow InitEnet command parameter structure into PRAM */
  3143. p_init_enet_pram->resinit1 = ugeth->p_init_enet_param_shadow->resinit1;
  3144. p_init_enet_pram->resinit2 = ugeth->p_init_enet_param_shadow->resinit2;
  3145. p_init_enet_pram->resinit3 = ugeth->p_init_enet_param_shadow->resinit3;
  3146. p_init_enet_pram->resinit4 = ugeth->p_init_enet_param_shadow->resinit4;
  3147. out_be16(&p_init_enet_pram->resinit5,
  3148. ugeth->p_init_enet_param_shadow->resinit5);
  3149. p_init_enet_pram->largestexternallookupkeysize =
  3150. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize;
  3151. out_be32(&p_init_enet_pram->rgftgfrxglobal,
  3152. ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
  3153. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
  3154. out_be32(&p_init_enet_pram->rxthread[i],
  3155. ugeth->p_init_enet_param_shadow->rxthread[i]);
  3156. out_be32(&p_init_enet_pram->txglobal,
  3157. ugeth->p_init_enet_param_shadow->txglobal);
  3158. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
  3159. out_be32(&p_init_enet_pram->txthread[i],
  3160. ugeth->p_init_enet_param_shadow->txthread[i]);
  3161. /* Issue QE command */
  3162. cecr_subblock =
  3163. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  3164. qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
  3165. init_enet_pram_offset);
  3166. /* Free InitEnet command parameter */
  3167. qe_muram_free(init_enet_pram_offset);
  3168. return 0;
  3169. }
  3170. /* returns a net_device_stats structure pointer */
  3171. static struct net_device_stats *ucc_geth_get_stats(struct net_device *dev)
  3172. {
  3173. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3174. return &(ugeth->stats);
  3175. }
  3176. /* ucc_geth_timeout gets called when a packet has not been
  3177. * transmitted after a set amount of time.
  3178. * For now, assume that clearing out all the structures, and
  3179. * starting over will fix the problem. */
  3180. static void ucc_geth_timeout(struct net_device *dev)
  3181. {
  3182. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3183. ugeth_vdbg("%s: IN", __FUNCTION__);
  3184. ugeth->stats.tx_errors++;
  3185. ugeth_dump_regs(ugeth);
  3186. if (dev->flags & IFF_UP) {
  3187. ucc_geth_stop(ugeth);
  3188. ucc_geth_startup(ugeth);
  3189. }
  3190. netif_schedule(dev);
  3191. }
  3192. /* This is called by the kernel when a frame is ready for transmission. */
  3193. /* It is pointed to by the dev->hard_start_xmit function pointer */
  3194. static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3195. {
  3196. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3197. u8 *bd; /* BD pointer */
  3198. u32 bd_status;
  3199. u8 txQ = 0;
  3200. ugeth_vdbg("%s: IN", __FUNCTION__);
  3201. spin_lock_irq(&ugeth->lock);
  3202. ugeth->stats.tx_bytes += skb->len;
  3203. /* Start from the next BD that should be filled */
  3204. bd = ugeth->txBd[txQ];
  3205. bd_status = in_be32((u32 *)bd);
  3206. /* Save the skb pointer so we can free it later */
  3207. ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
  3208. /* Update the current skb pointer (wrapping if this was the last) */
  3209. ugeth->skb_curtx[txQ] =
  3210. (ugeth->skb_curtx[txQ] +
  3211. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  3212. /* set up the buffer descriptor */
  3213. out_be32(&((struct qe_bd *)bd)->buf,
  3214. dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE));
  3215. /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
  3216. bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
  3217. /* set bd status and length */
  3218. out_be32((u32 *)bd, bd_status);
  3219. dev->trans_start = jiffies;
  3220. /* Move to next BD in the ring */
  3221. if (!(bd_status & T_W))
  3222. ugeth->txBd[txQ] = bd + sizeof(struct qe_bd);
  3223. else
  3224. ugeth->txBd[txQ] = ugeth->p_tx_bd_ring[txQ];
  3225. /* If the next BD still needs to be cleaned up, then the bds
  3226. are full. We need to tell the kernel to stop sending us stuff. */
  3227. if (bd == ugeth->confBd[txQ]) {
  3228. if (!netif_queue_stopped(dev))
  3229. netif_stop_queue(dev);
  3230. }
  3231. if (ugeth->p_scheduler) {
  3232. ugeth->cpucount[txQ]++;
  3233. /* Indicate to QE that there are more Tx bds ready for
  3234. transmission */
  3235. /* This is done by writing a running counter of the bd
  3236. count to the scheduler PRAM. */
  3237. out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
  3238. }
  3239. spin_unlock_irq(&ugeth->lock);
  3240. return 0;
  3241. }
  3242. static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
  3243. {
  3244. struct sk_buff *skb;
  3245. u8 *bd;
  3246. u16 length, howmany = 0;
  3247. u32 bd_status;
  3248. u8 *bdBuffer;
  3249. ugeth_vdbg("%s: IN", __FUNCTION__);
  3250. spin_lock(&ugeth->lock);
  3251. /* collect received buffers */
  3252. bd = ugeth->rxBd[rxQ];
  3253. bd_status = in_be32((u32 *)bd);
  3254. /* while there are received buffers and BD is full (~R_E) */
  3255. while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
  3256. bdBuffer = (u8 *) in_be32(&((struct qe_bd *)bd)->buf);
  3257. length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
  3258. skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
  3259. /* determine whether buffer is first, last, first and last
  3260. (single buffer frame) or middle (not first and not last) */
  3261. if (!skb ||
  3262. (!(bd_status & (R_F | R_L))) ||
  3263. (bd_status & R_ERRORS_FATAL)) {
  3264. ugeth_vdbg("%s, %d: ERROR!!! skb - 0x%08x",
  3265. __FUNCTION__, __LINE__, (u32) skb);
  3266. if (skb)
  3267. dev_kfree_skb_any(skb);
  3268. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
  3269. ugeth->stats.rx_dropped++;
  3270. } else {
  3271. ugeth->stats.rx_packets++;
  3272. howmany++;
  3273. /* Prep the skb for the packet */
  3274. skb_put(skb, length);
  3275. /* Tell the skb what kind of packet this is */
  3276. skb->protocol = eth_type_trans(skb, ugeth->dev);
  3277. ugeth->stats.rx_bytes += length;
  3278. /* Send the packet up the stack */
  3279. #ifdef CONFIG_UGETH_NAPI
  3280. netif_receive_skb(skb);
  3281. #else
  3282. netif_rx(skb);
  3283. #endif /* CONFIG_UGETH_NAPI */
  3284. }
  3285. ugeth->dev->last_rx = jiffies;
  3286. skb = get_new_skb(ugeth, bd);
  3287. if (!skb) {
  3288. ugeth_warn("%s: No Rx Data Buffer", __FUNCTION__);
  3289. spin_unlock(&ugeth->lock);
  3290. ugeth->stats.rx_dropped++;
  3291. break;
  3292. }
  3293. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
  3294. /* update to point at the next skb */
  3295. ugeth->skb_currx[rxQ] =
  3296. (ugeth->skb_currx[rxQ] +
  3297. 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
  3298. if (bd_status & R_W)
  3299. bd = ugeth->p_rx_bd_ring[rxQ];
  3300. else
  3301. bd += sizeof(struct qe_bd);
  3302. bd_status = in_be32((u32 *)bd);
  3303. }
  3304. ugeth->rxBd[rxQ] = bd;
  3305. spin_unlock(&ugeth->lock);
  3306. return howmany;
  3307. }
  3308. static int ucc_geth_tx(struct net_device *dev, u8 txQ)
  3309. {
  3310. /* Start from the next BD that should be filled */
  3311. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3312. u8 *bd; /* BD pointer */
  3313. u32 bd_status;
  3314. bd = ugeth->confBd[txQ];
  3315. bd_status = in_be32((u32 *)bd);
  3316. /* Normal processing. */
  3317. while ((bd_status & T_R) == 0) {
  3318. /* BD contains already transmitted buffer. */
  3319. /* Handle the transmitted buffer and release */
  3320. /* the BD to be used with the current frame */
  3321. if ((bd = ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
  3322. break;
  3323. ugeth->stats.tx_packets++;
  3324. /* Free the sk buffer associated with this TxBD */
  3325. dev_kfree_skb_irq(ugeth->
  3326. tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]]);
  3327. ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
  3328. ugeth->skb_dirtytx[txQ] =
  3329. (ugeth->skb_dirtytx[txQ] +
  3330. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  3331. /* We freed a buffer, so now we can restart transmission */
  3332. if (netif_queue_stopped(dev))
  3333. netif_wake_queue(dev);
  3334. /* Advance the confirmation BD pointer */
  3335. if (!(bd_status & T_W))
  3336. ugeth->confBd[txQ] += sizeof(struct qe_bd);
  3337. else
  3338. ugeth->confBd[txQ] = ugeth->p_tx_bd_ring[txQ];
  3339. }
  3340. return 0;
  3341. }
  3342. #ifdef CONFIG_UGETH_NAPI
  3343. static int ucc_geth_poll(struct net_device *dev, int *budget)
  3344. {
  3345. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3346. int howmany;
  3347. int rx_work_limit = *budget;
  3348. u8 rxQ = 0;
  3349. if (rx_work_limit > dev->quota)
  3350. rx_work_limit = dev->quota;
  3351. howmany = ucc_geth_rx(ugeth, rxQ, rx_work_limit);
  3352. dev->quota -= howmany;
  3353. rx_work_limit -= howmany;
  3354. *budget -= howmany;
  3355. if (rx_work_limit >= 0)
  3356. netif_rx_complete(dev);
  3357. return (rx_work_limit < 0) ? 1 : 0;
  3358. }
  3359. #endif /* CONFIG_UGETH_NAPI */
  3360. static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
  3361. {
  3362. struct net_device *dev = (struct net_device *)info;
  3363. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3364. struct ucc_fast_private *uccf;
  3365. struct ucc_geth_info *ug_info;
  3366. register u32 ucce = 0;
  3367. register u32 bit_mask = UCCE_RXBF_SINGLE_MASK;
  3368. register u32 tx_mask = UCCE_TXBF_SINGLE_MASK;
  3369. register u8 i;
  3370. ugeth_vdbg("%s: IN", __FUNCTION__);
  3371. if (!ugeth)
  3372. return IRQ_NONE;
  3373. uccf = ugeth->uccf;
  3374. ug_info = ugeth->ug_info;
  3375. do {
  3376. ucce |= (u32) (in_be32(uccf->p_ucce) & in_be32(uccf->p_uccm));
  3377. /* clear event bits for next time */
  3378. /* Side effect here is to mask ucce variable
  3379. for future processing below. */
  3380. out_be32(uccf->p_ucce, ucce); /* Clear with ones,
  3381. but only bits in UCCM */
  3382. /* We ignore Tx interrupts because Tx confirmation is
  3383. done inside Tx routine */
  3384. for (i = 0; i < ug_info->numQueuesRx; i++) {
  3385. if (ucce & bit_mask)
  3386. ucc_geth_rx(ugeth, i,
  3387. (int)ugeth->ug_info->
  3388. bdRingLenRx[i]);
  3389. ucce &= ~bit_mask;
  3390. bit_mask <<= 1;
  3391. }
  3392. for (i = 0; i < ug_info->numQueuesTx; i++) {
  3393. if (ucce & tx_mask)
  3394. ucc_geth_tx(dev, i);
  3395. ucce &= ~tx_mask;
  3396. tx_mask <<= 1;
  3397. }
  3398. /* Exceptions */
  3399. if (ucce & UCCE_BSY) {
  3400. ugeth_vdbg("Got BUSY irq!!!!");
  3401. ugeth->stats.rx_errors++;
  3402. ucce &= ~UCCE_BSY;
  3403. }
  3404. if (ucce & UCCE_OTHER) {
  3405. ugeth_vdbg("Got frame with error (ucce - 0x%08x)!!!!",
  3406. ucce);
  3407. ugeth->stats.rx_errors++;
  3408. ucce &= ~ucce;
  3409. }
  3410. }
  3411. while (ucce);
  3412. return IRQ_HANDLED;
  3413. }
  3414. static irqreturn_t phy_interrupt(int irq, void *dev_id)
  3415. {
  3416. struct net_device *dev = (struct net_device *)dev_id;
  3417. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3418. ugeth_vdbg("%s: IN", __FUNCTION__);
  3419. /* Clear the interrupt */
  3420. mii_clear_phy_interrupt(ugeth->mii_info);
  3421. /* Disable PHY interrupts */
  3422. mii_configure_phy_interrupt(ugeth->mii_info, MII_INTERRUPT_DISABLED);
  3423. /* Schedule the phy change */
  3424. schedule_work(&ugeth->tq);
  3425. return IRQ_HANDLED;
  3426. }
  3427. /* Scheduled by the phy_interrupt/timer to handle PHY changes */
  3428. static void ugeth_phy_change(void *data)
  3429. {
  3430. struct net_device *dev = (struct net_device *)data;
  3431. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3432. struct ucc_geth *ug_regs;
  3433. int result = 0;
  3434. ugeth_vdbg("%s: IN", __FUNCTION__);
  3435. ug_regs = ugeth->ug_regs;
  3436. /* Delay to give the PHY a chance to change the
  3437. * register state */
  3438. msleep(1);
  3439. /* Update the link, speed, duplex */
  3440. result = ugeth->mii_info->phyinfo->read_status(ugeth->mii_info);
  3441. /* Adjust the known status as long as the link
  3442. * isn't still coming up */
  3443. if ((0 == result) || (ugeth->mii_info->link == 0))
  3444. adjust_link(dev);
  3445. /* Reenable interrupts, if needed */
  3446. if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR)
  3447. mii_configure_phy_interrupt(ugeth->mii_info,
  3448. MII_INTERRUPT_ENABLED);
  3449. }
  3450. /* Called every so often on systems that don't interrupt
  3451. * the core for PHY changes */
  3452. static void ugeth_phy_timer(unsigned long data)
  3453. {
  3454. struct net_device *dev = (struct net_device *)data;
  3455. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3456. schedule_work(&ugeth->tq);
  3457. mod_timer(&ugeth->phy_info_timer, jiffies + PHY_CHANGE_TIME * HZ);
  3458. }
  3459. /* Keep trying aneg for some time
  3460. * If, after GFAR_AN_TIMEOUT seconds, it has not
  3461. * finished, we switch to forced.
  3462. * Either way, once the process has completed, we either
  3463. * request the interrupt, or switch the timer over to
  3464. * using ugeth_phy_timer to check status */
  3465. static void ugeth_phy_startup_timer(unsigned long data)
  3466. {
  3467. struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
  3468. struct ucc_geth_private *ugeth = netdev_priv(mii_info->dev);
  3469. static int secondary = UGETH_AN_TIMEOUT;
  3470. int result;
  3471. /* Configure the Auto-negotiation */
  3472. result = mii_info->phyinfo->config_aneg(mii_info);
  3473. /* If autonegotiation failed to start, and
  3474. * we haven't timed out, reset the timer, and return */
  3475. if (result && secondary--) {
  3476. mod_timer(&ugeth->phy_info_timer, jiffies + HZ);
  3477. return;
  3478. } else if (result) {
  3479. /* Couldn't start autonegotiation.
  3480. * Try switching to forced */
  3481. mii_info->autoneg = 0;
  3482. result = mii_info->phyinfo->config_aneg(mii_info);
  3483. /* Forcing failed! Give up */
  3484. if (result) {
  3485. ugeth_err("%s: Forcing failed!", mii_info->dev->name);
  3486. return;
  3487. }
  3488. }
  3489. /* Kill the timer so it can be restarted */
  3490. del_timer_sync(&ugeth->phy_info_timer);
  3491. /* Grab the PHY interrupt, if necessary/possible */
  3492. if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
  3493. if (request_irq(ugeth->ug_info->phy_interrupt,
  3494. phy_interrupt,
  3495. SA_SHIRQ, "phy_interrupt", mii_info->dev) < 0) {
  3496. ugeth_err("%s: Can't get IRQ %d (PHY)",
  3497. mii_info->dev->name,
  3498. ugeth->ug_info->phy_interrupt);
  3499. } else {
  3500. mii_configure_phy_interrupt(ugeth->mii_info,
  3501. MII_INTERRUPT_ENABLED);
  3502. return;
  3503. }
  3504. }
  3505. /* Start the timer again, this time in order to
  3506. * handle a change in status */
  3507. init_timer(&ugeth->phy_info_timer);
  3508. ugeth->phy_info_timer.function = &ugeth_phy_timer;
  3509. ugeth->phy_info_timer.data = (unsigned long)mii_info->dev;
  3510. mod_timer(&ugeth->phy_info_timer, jiffies + PHY_CHANGE_TIME * HZ);
  3511. }
  3512. /* Called when something needs to use the ethernet device */
  3513. /* Returns 0 for success. */
  3514. static int ucc_geth_open(struct net_device *dev)
  3515. {
  3516. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3517. int err;
  3518. ugeth_vdbg("%s: IN", __FUNCTION__);
  3519. /* Test station address */
  3520. if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
  3521. ugeth_err("%s: Multicast address used for station address"
  3522. " - is this what you wanted?", __FUNCTION__);
  3523. return -EINVAL;
  3524. }
  3525. err = ucc_geth_startup(ugeth);
  3526. if (err) {
  3527. ugeth_err("%s: Cannot configure net device, aborting.",
  3528. dev->name);
  3529. return err;
  3530. }
  3531. err = adjust_enet_interface(ugeth);
  3532. if (err) {
  3533. ugeth_err("%s: Cannot configure net device, aborting.",
  3534. dev->name);
  3535. return err;
  3536. }
  3537. /* Set MACSTNADDR1, MACSTNADDR2 */
  3538. /* For more details see the hardware spec. */
  3539. init_mac_station_addr_regs(dev->dev_addr[0],
  3540. dev->dev_addr[1],
  3541. dev->dev_addr[2],
  3542. dev->dev_addr[3],
  3543. dev->dev_addr[4],
  3544. dev->dev_addr[5],
  3545. &ugeth->ug_regs->macstnaddr1,
  3546. &ugeth->ug_regs->macstnaddr2);
  3547. err = init_phy(dev);
  3548. if (err) {
  3549. ugeth_err("%s: Cannot initialzie PHY, aborting.", dev->name);
  3550. return err;
  3551. }
  3552. #ifndef CONFIG_UGETH_NAPI
  3553. err =
  3554. request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler, 0,
  3555. "UCC Geth", dev);
  3556. if (err) {
  3557. ugeth_err("%s: Cannot get IRQ for net device, aborting.",
  3558. dev->name);
  3559. ucc_geth_stop(ugeth);
  3560. return err;
  3561. }
  3562. #endif /* CONFIG_UGETH_NAPI */
  3563. /* Set up the PHY change work queue */
  3564. INIT_WORK(&ugeth->tq, ugeth_phy_change, dev);
  3565. init_timer(&ugeth->phy_info_timer);
  3566. ugeth->phy_info_timer.function = &ugeth_phy_startup_timer;
  3567. ugeth->phy_info_timer.data = (unsigned long)ugeth->mii_info;
  3568. mod_timer(&ugeth->phy_info_timer, jiffies + HZ);
  3569. err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
  3570. if (err) {
  3571. ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
  3572. ucc_geth_stop(ugeth);
  3573. return err;
  3574. }
  3575. netif_start_queue(dev);
  3576. return err;
  3577. }
  3578. /* Stops the kernel queue, and halts the controller */
  3579. static int ucc_geth_close(struct net_device *dev)
  3580. {
  3581. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3582. ugeth_vdbg("%s: IN", __FUNCTION__);
  3583. ucc_geth_stop(ugeth);
  3584. /* Shutdown the PHY */
  3585. if (ugeth->mii_info->phyinfo->close)
  3586. ugeth->mii_info->phyinfo->close(ugeth->mii_info);
  3587. kfree(ugeth->mii_info);
  3588. netif_stop_queue(dev);
  3589. return 0;
  3590. }
  3591. const struct ethtool_ops ucc_geth_ethtool_ops = { };
  3592. static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match)
  3593. {
  3594. struct device *device = &ofdev->dev;
  3595. struct device_node *np = ofdev->node;
  3596. struct net_device *dev = NULL;
  3597. struct ucc_geth_private *ugeth = NULL;
  3598. struct ucc_geth_info *ug_info;
  3599. struct resource res;
  3600. struct device_node *phy;
  3601. int err, ucc_num, phy_interface;
  3602. static int mii_mng_configured = 0;
  3603. const phandle *ph;
  3604. const unsigned int *prop;
  3605. ugeth_vdbg("%s: IN", __FUNCTION__);
  3606. prop = get_property(np, "device-id", NULL);
  3607. ucc_num = *prop - 1;
  3608. if ((ucc_num < 0) || (ucc_num > 7))
  3609. return -ENODEV;
  3610. ug_info = &ugeth_info[ucc_num];
  3611. ug_info->uf_info.ucc_num = ucc_num;
  3612. prop = get_property(np, "rx-clock", NULL);
  3613. ug_info->uf_info.rx_clock = *prop;
  3614. prop = get_property(np, "tx-clock", NULL);
  3615. ug_info->uf_info.tx_clock = *prop;
  3616. err = of_address_to_resource(np, 0, &res);
  3617. if (err)
  3618. return -EINVAL;
  3619. ug_info->uf_info.regs = res.start;
  3620. ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
  3621. ph = get_property(np, "phy-handle", NULL);
  3622. phy = of_find_node_by_phandle(*ph);
  3623. if (phy == NULL)
  3624. return -ENODEV;
  3625. prop = get_property(phy, "reg", NULL);
  3626. ug_info->phy_address = *prop;
  3627. prop = get_property(phy, "interface", NULL);
  3628. ug_info->enet_interface = *prop;
  3629. ug_info->phy_interrupt = irq_of_parse_and_map(phy, 0);
  3630. ug_info->board_flags = (ug_info->phy_interrupt == NO_IRQ)?
  3631. 0:FSL_UGETH_BRD_HAS_PHY_INTR;
  3632. printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
  3633. ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
  3634. ug_info->uf_info.irq);
  3635. if (ug_info == NULL) {
  3636. ugeth_err("%s: [%d] Missing additional data!", __FUNCTION__,
  3637. ucc_num);
  3638. return -ENODEV;
  3639. }
  3640. /* FIXME: Work around for early chip rev. */
  3641. /* There's a bug in initial chip rev(s) in the RGMII ac */
  3642. /* timing. */
  3643. /* The following compensates by writing to the reserved */
  3644. /* QE Port Output Hold Registers (CPOH1?). */
  3645. prop = get_property(phy, "interface", NULL);
  3646. phy_interface = *prop;
  3647. if ((phy_interface == ENET_1000_RGMII) ||
  3648. (phy_interface == ENET_100_RGMII) ||
  3649. (phy_interface == ENET_10_RGMII)) {
  3650. struct device_node *soc;
  3651. phys_addr_t immrbase = -1;
  3652. u32 *tmp_reg;
  3653. u32 tmp_val;
  3654. soc = of_find_node_by_type(NULL, "soc");
  3655. if (soc) {
  3656. unsigned int size;
  3657. const void *prop = get_property(soc, "reg", &size);
  3658. immrbase = of_translate_address(soc, prop);
  3659. of_node_put(soc);
  3660. };
  3661. tmp_reg = (u32 *) ioremap(immrbase + 0x14A8, 0x4);
  3662. tmp_val = in_be32(tmp_reg);
  3663. if (ucc_num == 1)
  3664. out_be32(tmp_reg, tmp_val | 0x00003000);
  3665. else if (ucc_num == 2)
  3666. out_be32(tmp_reg, tmp_val | 0x0c000000);
  3667. iounmap(tmp_reg);
  3668. }
  3669. if (!mii_mng_configured) {
  3670. ucc_set_qe_mux_mii_mng(ucc_num);
  3671. mii_mng_configured = 1;
  3672. }
  3673. /* Create an ethernet device instance */
  3674. dev = alloc_etherdev(sizeof(*ugeth));
  3675. if (dev == NULL)
  3676. return -ENOMEM;
  3677. ugeth = netdev_priv(dev);
  3678. spin_lock_init(&ugeth->lock);
  3679. dev_set_drvdata(device, dev);
  3680. /* Set the dev->base_addr to the gfar reg region */
  3681. dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
  3682. SET_MODULE_OWNER(dev);
  3683. SET_NETDEV_DEV(dev, device);
  3684. /* Fill in the dev structure */
  3685. dev->open = ucc_geth_open;
  3686. dev->hard_start_xmit = ucc_geth_start_xmit;
  3687. dev->tx_timeout = ucc_geth_timeout;
  3688. dev->watchdog_timeo = TX_TIMEOUT;
  3689. #ifdef CONFIG_UGETH_NAPI
  3690. dev->poll = ucc_geth_poll;
  3691. dev->weight = UCC_GETH_DEV_WEIGHT;
  3692. #endif /* CONFIG_UGETH_NAPI */
  3693. dev->stop = ucc_geth_close;
  3694. dev->get_stats = ucc_geth_get_stats;
  3695. // dev->change_mtu = ucc_geth_change_mtu;
  3696. dev->mtu = 1500;
  3697. dev->set_multicast_list = ucc_geth_set_multi;
  3698. dev->ethtool_ops = &ucc_geth_ethtool_ops;
  3699. err = register_netdev(dev);
  3700. if (err) {
  3701. ugeth_err("%s: Cannot register net device, aborting.",
  3702. dev->name);
  3703. free_netdev(dev);
  3704. return err;
  3705. }
  3706. ugeth->ug_info = ug_info;
  3707. ugeth->dev = dev;
  3708. memcpy(dev->dev_addr, get_property(np, "mac-address", NULL), 6);
  3709. return 0;
  3710. }
  3711. static int ucc_geth_remove(struct of_device* ofdev)
  3712. {
  3713. struct device *device = &ofdev->dev;
  3714. struct net_device *dev = dev_get_drvdata(device);
  3715. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3716. dev_set_drvdata(device, NULL);
  3717. ucc_geth_memclean(ugeth);
  3718. free_netdev(dev);
  3719. return 0;
  3720. }
  3721. static struct of_device_id ucc_geth_match[] = {
  3722. {
  3723. .type = "network",
  3724. .compatible = "ucc_geth",
  3725. },
  3726. {},
  3727. };
  3728. MODULE_DEVICE_TABLE(of, ucc_geth_match);
  3729. static struct of_platform_driver ucc_geth_driver = {
  3730. .name = DRV_NAME,
  3731. .match_table = ucc_geth_match,
  3732. .probe = ucc_geth_probe,
  3733. .remove = ucc_geth_remove,
  3734. };
  3735. static int __init ucc_geth_init(void)
  3736. {
  3737. int i;
  3738. printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
  3739. for (i = 0; i < 8; i++)
  3740. memcpy(&(ugeth_info[i]), &ugeth_primary_info,
  3741. sizeof(ugeth_primary_info));
  3742. return of_register_driver(&ucc_geth_driver);
  3743. }
  3744. static void __exit ucc_geth_exit(void)
  3745. {
  3746. of_unregister_driver(&ucc_geth_driver);
  3747. }
  3748. module_init(ucc_geth_init);
  3749. module_exit(ucc_geth_exit);
  3750. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  3751. MODULE_DESCRIPTION(DRV_DESC);
  3752. MODULE_LICENSE("GPL");