ucc_geth.c 117 KB

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