ucc_geth.c 118 KB

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