ucc_geth.c 122 KB

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