ucc_geth.c 125 KB

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