ucc_geth.c 122 KB

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