ucc_geth.c 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  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. dev_err(&dev->dev, "Could not attach to PHY\n");
  1533. return -ENODEV;
  1534. }
  1535. if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII)
  1536. uec_configure_serdes(dev);
  1537. phydev->supported &= (SUPPORTED_MII |
  1538. SUPPORTED_Autoneg |
  1539. ADVERTISED_10baseT_Half |
  1540. ADVERTISED_10baseT_Full |
  1541. ADVERTISED_100baseT_Half |
  1542. ADVERTISED_100baseT_Full);
  1543. if (priv->max_speed == SPEED_1000)
  1544. phydev->supported |= ADVERTISED_1000baseT_Full;
  1545. phydev->advertising = phydev->supported;
  1546. priv->phydev = phydev;
  1547. return 0;
  1548. }
  1549. static void ugeth_dump_regs(struct ucc_geth_private *ugeth)
  1550. {
  1551. #ifdef DEBUG
  1552. ucc_fast_dump_regs(ugeth->uccf);
  1553. dump_regs(ugeth);
  1554. dump_bds(ugeth);
  1555. #endif
  1556. }
  1557. static int ugeth_82xx_filtering_clear_all_addr_in_hash(struct ucc_geth_private *
  1558. ugeth,
  1559. enum enet_addr_type
  1560. enet_addr_type)
  1561. {
  1562. struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
  1563. struct ucc_fast_private *uccf;
  1564. enum comm_dir comm_dir;
  1565. struct list_head *p_lh;
  1566. u16 i, num;
  1567. u32 __iomem *addr_h;
  1568. u32 __iomem *addr_l;
  1569. u8 *p_counter;
  1570. uccf = ugeth->uccf;
  1571. p_82xx_addr_filt =
  1572. (struct ucc_geth_82xx_address_filtering_pram __iomem *)
  1573. ugeth->p_rx_glbl_pram->addressfiltering;
  1574. if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
  1575. addr_h = &(p_82xx_addr_filt->gaddr_h);
  1576. addr_l = &(p_82xx_addr_filt->gaddr_l);
  1577. p_lh = &ugeth->group_hash_q;
  1578. p_counter = &(ugeth->numGroupAddrInHash);
  1579. } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
  1580. addr_h = &(p_82xx_addr_filt->iaddr_h);
  1581. addr_l = &(p_82xx_addr_filt->iaddr_l);
  1582. p_lh = &ugeth->ind_hash_q;
  1583. p_counter = &(ugeth->numIndAddrInHash);
  1584. } else
  1585. return -EINVAL;
  1586. comm_dir = 0;
  1587. if (uccf->enabled_tx)
  1588. comm_dir |= COMM_DIR_TX;
  1589. if (uccf->enabled_rx)
  1590. comm_dir |= COMM_DIR_RX;
  1591. if (comm_dir)
  1592. ugeth_disable(ugeth, comm_dir);
  1593. /* Clear the hash table. */
  1594. out_be32(addr_h, 0x00000000);
  1595. out_be32(addr_l, 0x00000000);
  1596. if (!p_lh)
  1597. return 0;
  1598. num = *p_counter;
  1599. /* Delete all remaining CQ elements */
  1600. for (i = 0; i < num; i++)
  1601. put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
  1602. *p_counter = 0;
  1603. if (comm_dir)
  1604. ugeth_enable(ugeth, comm_dir);
  1605. return 0;
  1606. }
  1607. static int ugeth_82xx_filtering_clear_addr_in_paddr(struct ucc_geth_private *ugeth,
  1608. u8 paddr_num)
  1609. {
  1610. ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
  1611. return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
  1612. }
  1613. static void ucc_geth_free_rx(struct ucc_geth_private *ugeth)
  1614. {
  1615. struct ucc_geth_info *ug_info;
  1616. struct ucc_fast_info *uf_info;
  1617. u16 i, j;
  1618. u8 __iomem *bd;
  1619. ug_info = ugeth->ug_info;
  1620. uf_info = &ug_info->uf_info;
  1621. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  1622. if (ugeth->p_rx_bd_ring[i]) {
  1623. /* Return existing data buffers in ring */
  1624. bd = ugeth->p_rx_bd_ring[i];
  1625. for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
  1626. if (ugeth->rx_skbuff[i][j]) {
  1627. dma_unmap_single(ugeth->dev,
  1628. in_be32(&((struct qe_bd __iomem *)bd)->buf),
  1629. ugeth->ug_info->
  1630. uf_info.max_rx_buf_length +
  1631. UCC_GETH_RX_DATA_BUF_ALIGNMENT,
  1632. DMA_FROM_DEVICE);
  1633. dev_kfree_skb_any(
  1634. ugeth->rx_skbuff[i][j]);
  1635. ugeth->rx_skbuff[i][j] = NULL;
  1636. }
  1637. bd += sizeof(struct qe_bd);
  1638. }
  1639. kfree(ugeth->rx_skbuff[i]);
  1640. if (ugeth->ug_info->uf_info.bd_mem_part ==
  1641. MEM_PART_SYSTEM)
  1642. kfree((void *)ugeth->rx_bd_ring_offset[i]);
  1643. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  1644. MEM_PART_MURAM)
  1645. qe_muram_free(ugeth->rx_bd_ring_offset[i]);
  1646. ugeth->p_rx_bd_ring[i] = NULL;
  1647. }
  1648. }
  1649. }
  1650. static void ucc_geth_free_tx(struct ucc_geth_private *ugeth)
  1651. {
  1652. struct ucc_geth_info *ug_info;
  1653. struct ucc_fast_info *uf_info;
  1654. u16 i, j;
  1655. u8 __iomem *bd;
  1656. ug_info = ugeth->ug_info;
  1657. uf_info = &ug_info->uf_info;
  1658. for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
  1659. bd = ugeth->p_tx_bd_ring[i];
  1660. if (!bd)
  1661. continue;
  1662. for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
  1663. if (ugeth->tx_skbuff[i][j]) {
  1664. dma_unmap_single(ugeth->dev,
  1665. in_be32(&((struct qe_bd __iomem *)bd)->buf),
  1666. (in_be32((u32 __iomem *)bd) &
  1667. BD_LENGTH_MASK),
  1668. DMA_TO_DEVICE);
  1669. dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
  1670. ugeth->tx_skbuff[i][j] = NULL;
  1671. }
  1672. }
  1673. kfree(ugeth->tx_skbuff[i]);
  1674. if (ugeth->p_tx_bd_ring[i]) {
  1675. if (ugeth->ug_info->uf_info.bd_mem_part ==
  1676. MEM_PART_SYSTEM)
  1677. kfree((void *)ugeth->tx_bd_ring_offset[i]);
  1678. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  1679. MEM_PART_MURAM)
  1680. qe_muram_free(ugeth->tx_bd_ring_offset[i]);
  1681. ugeth->p_tx_bd_ring[i] = NULL;
  1682. }
  1683. }
  1684. }
  1685. static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
  1686. {
  1687. if (!ugeth)
  1688. return;
  1689. if (ugeth->uccf) {
  1690. ucc_fast_free(ugeth->uccf);
  1691. ugeth->uccf = NULL;
  1692. }
  1693. if (ugeth->p_thread_data_tx) {
  1694. qe_muram_free(ugeth->thread_dat_tx_offset);
  1695. ugeth->p_thread_data_tx = NULL;
  1696. }
  1697. if (ugeth->p_thread_data_rx) {
  1698. qe_muram_free(ugeth->thread_dat_rx_offset);
  1699. ugeth->p_thread_data_rx = NULL;
  1700. }
  1701. if (ugeth->p_exf_glbl_param) {
  1702. qe_muram_free(ugeth->exf_glbl_param_offset);
  1703. ugeth->p_exf_glbl_param = NULL;
  1704. }
  1705. if (ugeth->p_rx_glbl_pram) {
  1706. qe_muram_free(ugeth->rx_glbl_pram_offset);
  1707. ugeth->p_rx_glbl_pram = NULL;
  1708. }
  1709. if (ugeth->p_tx_glbl_pram) {
  1710. qe_muram_free(ugeth->tx_glbl_pram_offset);
  1711. ugeth->p_tx_glbl_pram = NULL;
  1712. }
  1713. if (ugeth->p_send_q_mem_reg) {
  1714. qe_muram_free(ugeth->send_q_mem_reg_offset);
  1715. ugeth->p_send_q_mem_reg = NULL;
  1716. }
  1717. if (ugeth->p_scheduler) {
  1718. qe_muram_free(ugeth->scheduler_offset);
  1719. ugeth->p_scheduler = NULL;
  1720. }
  1721. if (ugeth->p_tx_fw_statistics_pram) {
  1722. qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
  1723. ugeth->p_tx_fw_statistics_pram = NULL;
  1724. }
  1725. if (ugeth->p_rx_fw_statistics_pram) {
  1726. qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
  1727. ugeth->p_rx_fw_statistics_pram = NULL;
  1728. }
  1729. if (ugeth->p_rx_irq_coalescing_tbl) {
  1730. qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
  1731. ugeth->p_rx_irq_coalescing_tbl = NULL;
  1732. }
  1733. if (ugeth->p_rx_bd_qs_tbl) {
  1734. qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
  1735. ugeth->p_rx_bd_qs_tbl = NULL;
  1736. }
  1737. if (ugeth->p_init_enet_param_shadow) {
  1738. return_init_enet_entries(ugeth,
  1739. &(ugeth->p_init_enet_param_shadow->
  1740. rxthread[0]),
  1741. ENET_INIT_PARAM_MAX_ENTRIES_RX,
  1742. ugeth->ug_info->riscRx, 1);
  1743. return_init_enet_entries(ugeth,
  1744. &(ugeth->p_init_enet_param_shadow->
  1745. txthread[0]),
  1746. ENET_INIT_PARAM_MAX_ENTRIES_TX,
  1747. ugeth->ug_info->riscTx, 0);
  1748. kfree(ugeth->p_init_enet_param_shadow);
  1749. ugeth->p_init_enet_param_shadow = NULL;
  1750. }
  1751. ucc_geth_free_tx(ugeth);
  1752. ucc_geth_free_rx(ugeth);
  1753. while (!list_empty(&ugeth->group_hash_q))
  1754. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  1755. (dequeue(&ugeth->group_hash_q)));
  1756. while (!list_empty(&ugeth->ind_hash_q))
  1757. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  1758. (dequeue(&ugeth->ind_hash_q)));
  1759. if (ugeth->ug_regs) {
  1760. iounmap(ugeth->ug_regs);
  1761. ugeth->ug_regs = NULL;
  1762. }
  1763. }
  1764. static void ucc_geth_set_multi(struct net_device *dev)
  1765. {
  1766. struct ucc_geth_private *ugeth;
  1767. struct netdev_hw_addr *ha;
  1768. struct ucc_fast __iomem *uf_regs;
  1769. struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
  1770. ugeth = netdev_priv(dev);
  1771. uf_regs = ugeth->uccf->uf_regs;
  1772. if (dev->flags & IFF_PROMISC) {
  1773. setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
  1774. } else {
  1775. clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
  1776. p_82xx_addr_filt =
  1777. (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
  1778. p_rx_glbl_pram->addressfiltering;
  1779. if (dev->flags & IFF_ALLMULTI) {
  1780. /* Catch all multicast addresses, so set the
  1781. * filter to all 1's.
  1782. */
  1783. out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
  1784. out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
  1785. } else {
  1786. /* Clear filter and add the addresses in the list.
  1787. */
  1788. out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
  1789. out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
  1790. netdev_for_each_mc_addr(ha, dev) {
  1791. /* Ask CPM to run CRC and set bit in
  1792. * filter mask.
  1793. */
  1794. hw_add_addr_in_hash(ugeth, ha->addr);
  1795. }
  1796. }
  1797. }
  1798. }
  1799. static void ucc_geth_stop(struct ucc_geth_private *ugeth)
  1800. {
  1801. struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
  1802. struct phy_device *phydev = ugeth->phydev;
  1803. ugeth_vdbg("%s: IN", __func__);
  1804. /*
  1805. * Tell the kernel the link is down.
  1806. * Must be done before disabling the controller
  1807. * or deadlock may happen.
  1808. */
  1809. phy_stop(phydev);
  1810. /* Disable the controller */
  1811. ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
  1812. /* Mask all interrupts */
  1813. out_be32(ugeth->uccf->p_uccm, 0x00000000);
  1814. /* Clear all interrupts */
  1815. out_be32(ugeth->uccf->p_ucce, 0xffffffff);
  1816. /* Disable Rx and Tx */
  1817. clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
  1818. ucc_geth_memclean(ugeth);
  1819. }
  1820. static int ucc_struct_init(struct ucc_geth_private *ugeth)
  1821. {
  1822. struct ucc_geth_info *ug_info;
  1823. struct ucc_fast_info *uf_info;
  1824. int i;
  1825. ug_info = ugeth->ug_info;
  1826. uf_info = &ug_info->uf_info;
  1827. if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
  1828. (uf_info->bd_mem_part == MEM_PART_MURAM))) {
  1829. if (netif_msg_probe(ugeth))
  1830. pr_err("Bad memory partition value\n");
  1831. return -EINVAL;
  1832. }
  1833. /* Rx BD lengths */
  1834. for (i = 0; i < ug_info->numQueuesRx; i++) {
  1835. if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
  1836. (ug_info->bdRingLenRx[i] %
  1837. UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
  1838. if (netif_msg_probe(ugeth))
  1839. pr_err("Rx BD ring length must be multiple of 4, no smaller than 8\n");
  1840. return -EINVAL;
  1841. }
  1842. }
  1843. /* Tx BD lengths */
  1844. for (i = 0; i < ug_info->numQueuesTx; i++) {
  1845. if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
  1846. if (netif_msg_probe(ugeth))
  1847. pr_err("Tx BD ring length must be no smaller than 2\n");
  1848. return -EINVAL;
  1849. }
  1850. }
  1851. /* mrblr */
  1852. if ((uf_info->max_rx_buf_length == 0) ||
  1853. (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
  1854. if (netif_msg_probe(ugeth))
  1855. pr_err("max_rx_buf_length must be non-zero multiple of 128\n");
  1856. return -EINVAL;
  1857. }
  1858. /* num Tx queues */
  1859. if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
  1860. if (netif_msg_probe(ugeth))
  1861. pr_err("number of tx queues too large\n");
  1862. return -EINVAL;
  1863. }
  1864. /* num Rx queues */
  1865. if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
  1866. if (netif_msg_probe(ugeth))
  1867. pr_err("number of rx queues too large\n");
  1868. return -EINVAL;
  1869. }
  1870. /* l2qt */
  1871. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
  1872. if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
  1873. if (netif_msg_probe(ugeth))
  1874. pr_err("VLAN priority table entry must not be larger than number of Rx queues\n");
  1875. return -EINVAL;
  1876. }
  1877. }
  1878. /* l3qt */
  1879. for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
  1880. if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
  1881. if (netif_msg_probe(ugeth))
  1882. pr_err("IP priority table entry must not be larger than number of Rx queues\n");
  1883. return -EINVAL;
  1884. }
  1885. }
  1886. if (ug_info->cam && !ug_info->ecamptr) {
  1887. if (netif_msg_probe(ugeth))
  1888. pr_err("If cam mode is chosen, must supply cam ptr\n");
  1889. return -EINVAL;
  1890. }
  1891. if ((ug_info->numStationAddresses !=
  1892. UCC_GETH_NUM_OF_STATION_ADDRESSES_1) &&
  1893. ug_info->rxExtendedFiltering) {
  1894. if (netif_msg_probe(ugeth))
  1895. pr_err("Number of station addresses greater than 1 not allowed in extended parsing mode\n");
  1896. return -EINVAL;
  1897. }
  1898. /* Generate uccm_mask for receive */
  1899. uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
  1900. for (i = 0; i < ug_info->numQueuesRx; i++)
  1901. uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
  1902. for (i = 0; i < ug_info->numQueuesTx; i++)
  1903. uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
  1904. /* Initialize the general fast UCC block. */
  1905. if (ucc_fast_init(uf_info, &ugeth->uccf)) {
  1906. if (netif_msg_probe(ugeth))
  1907. pr_err("Failed to init uccf\n");
  1908. return -ENOMEM;
  1909. }
  1910. /* read the number of risc engines, update the riscTx and riscRx
  1911. * if there are 4 riscs in QE
  1912. */
  1913. if (qe_get_num_of_risc() == 4) {
  1914. ug_info->riscTx = QE_RISC_ALLOCATION_FOUR_RISCS;
  1915. ug_info->riscRx = QE_RISC_ALLOCATION_FOUR_RISCS;
  1916. }
  1917. ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
  1918. if (!ugeth->ug_regs) {
  1919. if (netif_msg_probe(ugeth))
  1920. pr_err("Failed to ioremap regs\n");
  1921. return -ENOMEM;
  1922. }
  1923. return 0;
  1924. }
  1925. static int ucc_geth_alloc_tx(struct ucc_geth_private *ugeth)
  1926. {
  1927. struct ucc_geth_info *ug_info;
  1928. struct ucc_fast_info *uf_info;
  1929. int length;
  1930. u16 i, j;
  1931. u8 __iomem *bd;
  1932. ug_info = ugeth->ug_info;
  1933. uf_info = &ug_info->uf_info;
  1934. /* Allocate Tx bds */
  1935. for (j = 0; j < ug_info->numQueuesTx; j++) {
  1936. /* Allocate in multiple of
  1937. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
  1938. according to spec */
  1939. length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
  1940. / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  1941. * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  1942. if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
  1943. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  1944. length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  1945. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  1946. u32 align = 4;
  1947. if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
  1948. align = UCC_GETH_TX_BD_RING_ALIGNMENT;
  1949. ugeth->tx_bd_ring_offset[j] =
  1950. (u32) kmalloc((u32) (length + align), GFP_KERNEL);
  1951. if (ugeth->tx_bd_ring_offset[j] != 0)
  1952. ugeth->p_tx_bd_ring[j] =
  1953. (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] +
  1954. align) & ~(align - 1));
  1955. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  1956. ugeth->tx_bd_ring_offset[j] =
  1957. qe_muram_alloc(length,
  1958. UCC_GETH_TX_BD_RING_ALIGNMENT);
  1959. if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
  1960. ugeth->p_tx_bd_ring[j] =
  1961. (u8 __iomem *) qe_muram_addr(ugeth->
  1962. tx_bd_ring_offset[j]);
  1963. }
  1964. if (!ugeth->p_tx_bd_ring[j]) {
  1965. if (netif_msg_ifup(ugeth))
  1966. pr_err("Can not allocate memory for Tx bd rings\n");
  1967. return -ENOMEM;
  1968. }
  1969. /* Zero unused end of bd ring, according to spec */
  1970. memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] +
  1971. ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0,
  1972. length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
  1973. }
  1974. /* Init Tx bds */
  1975. for (j = 0; j < ug_info->numQueuesTx; j++) {
  1976. /* Setup the skbuff rings */
  1977. ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
  1978. ugeth->ug_info->bdRingLenTx[j],
  1979. GFP_KERNEL);
  1980. if (ugeth->tx_skbuff[j] == NULL) {
  1981. if (netif_msg_ifup(ugeth))
  1982. pr_err("Could not allocate tx_skbuff\n");
  1983. return -ENOMEM;
  1984. }
  1985. for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
  1986. ugeth->tx_skbuff[j][i] = NULL;
  1987. ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
  1988. bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
  1989. for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
  1990. /* clear bd buffer */
  1991. out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
  1992. /* set bd status and length */
  1993. out_be32((u32 __iomem *)bd, 0);
  1994. bd += sizeof(struct qe_bd);
  1995. }
  1996. bd -= sizeof(struct qe_bd);
  1997. /* set bd status and length */
  1998. out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */
  1999. }
  2000. return 0;
  2001. }
  2002. static int ucc_geth_alloc_rx(struct ucc_geth_private *ugeth)
  2003. {
  2004. struct ucc_geth_info *ug_info;
  2005. struct ucc_fast_info *uf_info;
  2006. int length;
  2007. u16 i, j;
  2008. u8 __iomem *bd;
  2009. ug_info = ugeth->ug_info;
  2010. uf_info = &ug_info->uf_info;
  2011. /* Allocate Rx bds */
  2012. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2013. length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
  2014. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  2015. u32 align = 4;
  2016. if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
  2017. align = UCC_GETH_RX_BD_RING_ALIGNMENT;
  2018. ugeth->rx_bd_ring_offset[j] =
  2019. (u32) kmalloc((u32) (length + align), GFP_KERNEL);
  2020. if (ugeth->rx_bd_ring_offset[j] != 0)
  2021. ugeth->p_rx_bd_ring[j] =
  2022. (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] +
  2023. align) & ~(align - 1));
  2024. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  2025. ugeth->rx_bd_ring_offset[j] =
  2026. qe_muram_alloc(length,
  2027. UCC_GETH_RX_BD_RING_ALIGNMENT);
  2028. if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
  2029. ugeth->p_rx_bd_ring[j] =
  2030. (u8 __iomem *) qe_muram_addr(ugeth->
  2031. rx_bd_ring_offset[j]);
  2032. }
  2033. if (!ugeth->p_rx_bd_ring[j]) {
  2034. if (netif_msg_ifup(ugeth))
  2035. pr_err("Can not allocate memory for Rx bd rings\n");
  2036. return -ENOMEM;
  2037. }
  2038. }
  2039. /* Init Rx bds */
  2040. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2041. /* Setup the skbuff rings */
  2042. ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
  2043. ugeth->ug_info->bdRingLenRx[j],
  2044. GFP_KERNEL);
  2045. if (ugeth->rx_skbuff[j] == NULL) {
  2046. if (netif_msg_ifup(ugeth))
  2047. pr_err("Could not allocate rx_skbuff\n");
  2048. return -ENOMEM;
  2049. }
  2050. for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
  2051. ugeth->rx_skbuff[j][i] = NULL;
  2052. ugeth->skb_currx[j] = 0;
  2053. bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
  2054. for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
  2055. /* set bd status and length */
  2056. out_be32((u32 __iomem *)bd, R_I);
  2057. /* clear bd buffer */
  2058. out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
  2059. bd += sizeof(struct qe_bd);
  2060. }
  2061. bd -= sizeof(struct qe_bd);
  2062. /* set bd status and length */
  2063. out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */
  2064. }
  2065. return 0;
  2066. }
  2067. static int ucc_geth_startup(struct ucc_geth_private *ugeth)
  2068. {
  2069. struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
  2070. struct ucc_geth_init_pram __iomem *p_init_enet_pram;
  2071. struct ucc_fast_private *uccf;
  2072. struct ucc_geth_info *ug_info;
  2073. struct ucc_fast_info *uf_info;
  2074. struct ucc_fast __iomem *uf_regs;
  2075. struct ucc_geth __iomem *ug_regs;
  2076. int ret_val = -EINVAL;
  2077. u32 remoder = UCC_GETH_REMODER_INIT;
  2078. u32 init_enet_pram_offset, cecr_subblock, command;
  2079. u32 ifstat, i, j, size, l2qt, l3qt;
  2080. u16 temoder = UCC_GETH_TEMODER_INIT;
  2081. u16 test;
  2082. u8 function_code = 0;
  2083. u8 __iomem *endOfRing;
  2084. u8 numThreadsRxNumerical, numThreadsTxNumerical;
  2085. ugeth_vdbg("%s: IN", __func__);
  2086. uccf = ugeth->uccf;
  2087. ug_info = ugeth->ug_info;
  2088. uf_info = &ug_info->uf_info;
  2089. uf_regs = uccf->uf_regs;
  2090. ug_regs = ugeth->ug_regs;
  2091. switch (ug_info->numThreadsRx) {
  2092. case UCC_GETH_NUM_OF_THREADS_1:
  2093. numThreadsRxNumerical = 1;
  2094. break;
  2095. case UCC_GETH_NUM_OF_THREADS_2:
  2096. numThreadsRxNumerical = 2;
  2097. break;
  2098. case UCC_GETH_NUM_OF_THREADS_4:
  2099. numThreadsRxNumerical = 4;
  2100. break;
  2101. case UCC_GETH_NUM_OF_THREADS_6:
  2102. numThreadsRxNumerical = 6;
  2103. break;
  2104. case UCC_GETH_NUM_OF_THREADS_8:
  2105. numThreadsRxNumerical = 8;
  2106. break;
  2107. default:
  2108. if (netif_msg_ifup(ugeth))
  2109. pr_err("Bad number of Rx threads value\n");
  2110. return -EINVAL;
  2111. }
  2112. switch (ug_info->numThreadsTx) {
  2113. case UCC_GETH_NUM_OF_THREADS_1:
  2114. numThreadsTxNumerical = 1;
  2115. break;
  2116. case UCC_GETH_NUM_OF_THREADS_2:
  2117. numThreadsTxNumerical = 2;
  2118. break;
  2119. case UCC_GETH_NUM_OF_THREADS_4:
  2120. numThreadsTxNumerical = 4;
  2121. break;
  2122. case UCC_GETH_NUM_OF_THREADS_6:
  2123. numThreadsTxNumerical = 6;
  2124. break;
  2125. case UCC_GETH_NUM_OF_THREADS_8:
  2126. numThreadsTxNumerical = 8;
  2127. break;
  2128. default:
  2129. if (netif_msg_ifup(ugeth))
  2130. pr_err("Bad number of Tx threads value\n");
  2131. return -EINVAL;
  2132. }
  2133. /* Calculate rx_extended_features */
  2134. ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
  2135. ug_info->ipAddressAlignment ||
  2136. (ug_info->numStationAddresses !=
  2137. UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
  2138. ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
  2139. (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP) ||
  2140. (ug_info->vlanOperationNonTagged !=
  2141. UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
  2142. init_default_reg_vals(&uf_regs->upsmr,
  2143. &ug_regs->maccfg1, &ug_regs->maccfg2);
  2144. /* Set UPSMR */
  2145. /* For more details see the hardware spec. */
  2146. init_rx_parameters(ug_info->bro,
  2147. ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
  2148. /* We're going to ignore other registers for now, */
  2149. /* except as needed to get up and running */
  2150. /* Set MACCFG1 */
  2151. /* For more details see the hardware spec. */
  2152. init_flow_control_params(ug_info->aufc,
  2153. ug_info->receiveFlowControl,
  2154. ug_info->transmitFlowControl,
  2155. ug_info->pausePeriod,
  2156. ug_info->extensionField,
  2157. &uf_regs->upsmr,
  2158. &ug_regs->uempr, &ug_regs->maccfg1);
  2159. setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
  2160. /* Set IPGIFG */
  2161. /* For more details see the hardware spec. */
  2162. ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
  2163. ug_info->nonBackToBackIfgPart2,
  2164. ug_info->
  2165. miminumInterFrameGapEnforcement,
  2166. ug_info->backToBackInterFrameGap,
  2167. &ug_regs->ipgifg);
  2168. if (ret_val != 0) {
  2169. if (netif_msg_ifup(ugeth))
  2170. pr_err("IPGIFG initialization parameter too large\n");
  2171. return ret_val;
  2172. }
  2173. /* Set HAFDUP */
  2174. /* For more details see the hardware spec. */
  2175. ret_val = init_half_duplex_params(ug_info->altBeb,
  2176. ug_info->backPressureNoBackoff,
  2177. ug_info->noBackoff,
  2178. ug_info->excessDefer,
  2179. ug_info->altBebTruncation,
  2180. ug_info->maxRetransmission,
  2181. ug_info->collisionWindow,
  2182. &ug_regs->hafdup);
  2183. if (ret_val != 0) {
  2184. if (netif_msg_ifup(ugeth))
  2185. pr_err("Half Duplex initialization parameter too large\n");
  2186. return ret_val;
  2187. }
  2188. /* Set IFSTAT */
  2189. /* For more details see the hardware spec. */
  2190. /* Read only - resets upon read */
  2191. ifstat = in_be32(&ug_regs->ifstat);
  2192. /* Clear UEMPR */
  2193. /* For more details see the hardware spec. */
  2194. out_be32(&ug_regs->uempr, 0);
  2195. /* Set UESCR */
  2196. /* For more details see the hardware spec. */
  2197. init_hw_statistics_gathering_mode((ug_info->statisticsMode &
  2198. UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
  2199. 0, &uf_regs->upsmr, &ug_regs->uescr);
  2200. ret_val = ucc_geth_alloc_tx(ugeth);
  2201. if (ret_val != 0)
  2202. return ret_val;
  2203. ret_val = ucc_geth_alloc_rx(ugeth);
  2204. if (ret_val != 0)
  2205. return ret_val;
  2206. /*
  2207. * Global PRAM
  2208. */
  2209. /* Tx global PRAM */
  2210. /* Allocate global tx parameter RAM page */
  2211. ugeth->tx_glbl_pram_offset =
  2212. qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
  2213. UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
  2214. if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
  2215. if (netif_msg_ifup(ugeth))
  2216. pr_err("Can not allocate DPRAM memory for p_tx_glbl_pram\n");
  2217. return -ENOMEM;
  2218. }
  2219. ugeth->p_tx_glbl_pram =
  2220. (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth->
  2221. tx_glbl_pram_offset);
  2222. /* Zero out p_tx_glbl_pram */
  2223. memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
  2224. /* Fill global PRAM */
  2225. /* TQPTR */
  2226. /* Size varies with number of Tx threads */
  2227. ugeth->thread_dat_tx_offset =
  2228. qe_muram_alloc(numThreadsTxNumerical *
  2229. sizeof(struct ucc_geth_thread_data_tx) +
  2230. 32 * (numThreadsTxNumerical == 1),
  2231. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2232. if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
  2233. if (netif_msg_ifup(ugeth))
  2234. pr_err("Can not allocate DPRAM memory for p_thread_data_tx\n");
  2235. return -ENOMEM;
  2236. }
  2237. ugeth->p_thread_data_tx =
  2238. (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth->
  2239. thread_dat_tx_offset);
  2240. out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
  2241. /* vtagtable */
  2242. for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
  2243. out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
  2244. ug_info->vtagtable[i]);
  2245. /* iphoffset */
  2246. for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
  2247. out_8(&ugeth->p_tx_glbl_pram->iphoffset[i],
  2248. ug_info->iphoffset[i]);
  2249. /* SQPTR */
  2250. /* Size varies with number of Tx queues */
  2251. ugeth->send_q_mem_reg_offset =
  2252. qe_muram_alloc(ug_info->numQueuesTx *
  2253. sizeof(struct ucc_geth_send_queue_qd),
  2254. UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
  2255. if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
  2256. if (netif_msg_ifup(ugeth))
  2257. pr_err("Can not allocate DPRAM memory for p_send_q_mem_reg\n");
  2258. return -ENOMEM;
  2259. }
  2260. ugeth->p_send_q_mem_reg =
  2261. (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth->
  2262. send_q_mem_reg_offset);
  2263. out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
  2264. /* Setup the table */
  2265. /* Assume BD rings are already established */
  2266. for (i = 0; i < ug_info->numQueuesTx; i++) {
  2267. endOfRing =
  2268. ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
  2269. 1) * sizeof(struct qe_bd);
  2270. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2271. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2272. (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
  2273. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2274. last_bd_completed_address,
  2275. (u32) virt_to_phys(endOfRing));
  2276. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2277. MEM_PART_MURAM) {
  2278. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2279. (u32) immrbar_virt_to_phys(ugeth->
  2280. p_tx_bd_ring[i]));
  2281. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2282. last_bd_completed_address,
  2283. (u32) immrbar_virt_to_phys(endOfRing));
  2284. }
  2285. }
  2286. /* schedulerbasepointer */
  2287. if (ug_info->numQueuesTx > 1) {
  2288. /* scheduler exists only if more than 1 tx queue */
  2289. ugeth->scheduler_offset =
  2290. qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
  2291. UCC_GETH_SCHEDULER_ALIGNMENT);
  2292. if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
  2293. if (netif_msg_ifup(ugeth))
  2294. pr_err("Can not allocate DPRAM memory for p_scheduler\n");
  2295. return -ENOMEM;
  2296. }
  2297. ugeth->p_scheduler =
  2298. (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth->
  2299. scheduler_offset);
  2300. out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
  2301. ugeth->scheduler_offset);
  2302. /* Zero out p_scheduler */
  2303. memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
  2304. /* Set values in scheduler */
  2305. out_be32(&ugeth->p_scheduler->mblinterval,
  2306. ug_info->mblinterval);
  2307. out_be16(&ugeth->p_scheduler->nortsrbytetime,
  2308. ug_info->nortsrbytetime);
  2309. out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz);
  2310. out_8(&ugeth->p_scheduler->strictpriorityq,
  2311. ug_info->strictpriorityq);
  2312. out_8(&ugeth->p_scheduler->txasap, ug_info->txasap);
  2313. out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw);
  2314. for (i = 0; i < NUM_TX_QUEUES; i++)
  2315. out_8(&ugeth->p_scheduler->weightfactor[i],
  2316. ug_info->weightfactor[i]);
  2317. /* Set pointers to cpucount registers in scheduler */
  2318. ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
  2319. ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
  2320. ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
  2321. ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
  2322. ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
  2323. ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
  2324. ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
  2325. ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
  2326. }
  2327. /* schedulerbasepointer */
  2328. /* TxRMON_PTR (statistics) */
  2329. if (ug_info->
  2330. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  2331. ugeth->tx_fw_statistics_pram_offset =
  2332. qe_muram_alloc(sizeof
  2333. (struct ucc_geth_tx_firmware_statistics_pram),
  2334. UCC_GETH_TX_STATISTICS_ALIGNMENT);
  2335. if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
  2336. if (netif_msg_ifup(ugeth))
  2337. pr_err("Can not allocate DPRAM memory for p_tx_fw_statistics_pram\n");
  2338. return -ENOMEM;
  2339. }
  2340. ugeth->p_tx_fw_statistics_pram =
  2341. (struct ucc_geth_tx_firmware_statistics_pram __iomem *)
  2342. qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
  2343. /* Zero out p_tx_fw_statistics_pram */
  2344. memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram,
  2345. 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
  2346. }
  2347. /* temoder */
  2348. /* Already has speed set */
  2349. if (ug_info->numQueuesTx > 1)
  2350. temoder |= TEMODER_SCHEDULER_ENABLE;
  2351. if (ug_info->ipCheckSumGenerate)
  2352. temoder |= TEMODER_IP_CHECKSUM_GENERATE;
  2353. temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
  2354. out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
  2355. test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
  2356. /* Function code register value to be used later */
  2357. function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
  2358. /* Required for QE */
  2359. /* function code register */
  2360. out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
  2361. /* Rx global PRAM */
  2362. /* Allocate global rx parameter RAM page */
  2363. ugeth->rx_glbl_pram_offset =
  2364. qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
  2365. UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
  2366. if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
  2367. if (netif_msg_ifup(ugeth))
  2368. pr_err("Can not allocate DPRAM memory for p_rx_glbl_pram\n");
  2369. return -ENOMEM;
  2370. }
  2371. ugeth->p_rx_glbl_pram =
  2372. (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth->
  2373. rx_glbl_pram_offset);
  2374. /* Zero out p_rx_glbl_pram */
  2375. memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
  2376. /* Fill global PRAM */
  2377. /* RQPTR */
  2378. /* Size varies with number of Rx threads */
  2379. ugeth->thread_dat_rx_offset =
  2380. qe_muram_alloc(numThreadsRxNumerical *
  2381. sizeof(struct ucc_geth_thread_data_rx),
  2382. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2383. if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
  2384. if (netif_msg_ifup(ugeth))
  2385. pr_err("Can not allocate DPRAM memory for p_thread_data_rx\n");
  2386. return -ENOMEM;
  2387. }
  2388. ugeth->p_thread_data_rx =
  2389. (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth->
  2390. thread_dat_rx_offset);
  2391. out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
  2392. /* typeorlen */
  2393. out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
  2394. /* rxrmonbaseptr (statistics) */
  2395. if (ug_info->
  2396. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
  2397. ugeth->rx_fw_statistics_pram_offset =
  2398. qe_muram_alloc(sizeof
  2399. (struct ucc_geth_rx_firmware_statistics_pram),
  2400. UCC_GETH_RX_STATISTICS_ALIGNMENT);
  2401. if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
  2402. if (netif_msg_ifup(ugeth))
  2403. pr_err("Can not allocate DPRAM memory for p_rx_fw_statistics_pram\n");
  2404. return -ENOMEM;
  2405. }
  2406. ugeth->p_rx_fw_statistics_pram =
  2407. (struct ucc_geth_rx_firmware_statistics_pram __iomem *)
  2408. qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
  2409. /* Zero out p_rx_fw_statistics_pram */
  2410. memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0,
  2411. sizeof(struct ucc_geth_rx_firmware_statistics_pram));
  2412. }
  2413. /* intCoalescingPtr */
  2414. /* Size varies with number of Rx queues */
  2415. ugeth->rx_irq_coalescing_tbl_offset =
  2416. qe_muram_alloc(ug_info->numQueuesRx *
  2417. sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
  2418. + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
  2419. if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
  2420. if (netif_msg_ifup(ugeth))
  2421. pr_err("Can not allocate DPRAM memory for p_rx_irq_coalescing_tbl\n");
  2422. return -ENOMEM;
  2423. }
  2424. ugeth->p_rx_irq_coalescing_tbl =
  2425. (struct ucc_geth_rx_interrupt_coalescing_table __iomem *)
  2426. qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
  2427. out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
  2428. ugeth->rx_irq_coalescing_tbl_offset);
  2429. /* Fill interrupt coalescing table */
  2430. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2431. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2432. interruptcoalescingmaxvalue,
  2433. ug_info->interruptcoalescingmaxvalue[i]);
  2434. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2435. interruptcoalescingcounter,
  2436. ug_info->interruptcoalescingmaxvalue[i]);
  2437. }
  2438. /* MRBLR */
  2439. init_max_rx_buff_len(uf_info->max_rx_buf_length,
  2440. &ugeth->p_rx_glbl_pram->mrblr);
  2441. /* MFLR */
  2442. out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
  2443. /* MINFLR */
  2444. init_min_frame_len(ug_info->minFrameLength,
  2445. &ugeth->p_rx_glbl_pram->minflr,
  2446. &ugeth->p_rx_glbl_pram->mrblr);
  2447. /* MAXD1 */
  2448. out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
  2449. /* MAXD2 */
  2450. out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
  2451. /* l2qt */
  2452. l2qt = 0;
  2453. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
  2454. l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
  2455. out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
  2456. /* l3qt */
  2457. for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
  2458. l3qt = 0;
  2459. for (i = 0; i < 8; i++)
  2460. l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
  2461. out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
  2462. }
  2463. /* vlantype */
  2464. out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
  2465. /* vlantci */
  2466. out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
  2467. /* ecamptr */
  2468. out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
  2469. /* RBDQPTR */
  2470. /* Size varies with number of Rx queues */
  2471. ugeth->rx_bd_qs_tbl_offset =
  2472. qe_muram_alloc(ug_info->numQueuesRx *
  2473. (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2474. sizeof(struct ucc_geth_rx_prefetched_bds)),
  2475. UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
  2476. if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
  2477. if (netif_msg_ifup(ugeth))
  2478. pr_err("Can not allocate DPRAM memory for p_rx_bd_qs_tbl\n");
  2479. return -ENOMEM;
  2480. }
  2481. ugeth->p_rx_bd_qs_tbl =
  2482. (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth->
  2483. rx_bd_qs_tbl_offset);
  2484. out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
  2485. /* Zero out p_rx_bd_qs_tbl */
  2486. memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl,
  2487. 0,
  2488. ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2489. sizeof(struct ucc_geth_rx_prefetched_bds)));
  2490. /* Setup the table */
  2491. /* Assume BD rings are already established */
  2492. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2493. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2494. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2495. (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
  2496. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2497. MEM_PART_MURAM) {
  2498. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2499. (u32) immrbar_virt_to_phys(ugeth->
  2500. p_rx_bd_ring[i]));
  2501. }
  2502. /* rest of fields handled by QE */
  2503. }
  2504. /* remoder */
  2505. /* Already has speed set */
  2506. if (ugeth->rx_extended_features)
  2507. remoder |= REMODER_RX_EXTENDED_FEATURES;
  2508. if (ug_info->rxExtendedFiltering)
  2509. remoder |= REMODER_RX_EXTENDED_FILTERING;
  2510. if (ug_info->dynamicMaxFrameLength)
  2511. remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
  2512. if (ug_info->dynamicMinFrameLength)
  2513. remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
  2514. remoder |=
  2515. ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
  2516. remoder |=
  2517. ug_info->
  2518. vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
  2519. remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
  2520. remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
  2521. if (ug_info->ipCheckSumCheck)
  2522. remoder |= REMODER_IP_CHECKSUM_CHECK;
  2523. if (ug_info->ipAddressAlignment)
  2524. remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
  2525. out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
  2526. /* Note that this function must be called */
  2527. /* ONLY AFTER p_tx_fw_statistics_pram */
  2528. /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
  2529. init_firmware_statistics_gathering_mode((ug_info->
  2530. statisticsMode &
  2531. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
  2532. (ug_info->statisticsMode &
  2533. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
  2534. &ugeth->p_tx_glbl_pram->txrmonbaseptr,
  2535. ugeth->tx_fw_statistics_pram_offset,
  2536. &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
  2537. ugeth->rx_fw_statistics_pram_offset,
  2538. &ugeth->p_tx_glbl_pram->temoder,
  2539. &ugeth->p_rx_glbl_pram->remoder);
  2540. /* function code register */
  2541. out_8(&ugeth->p_rx_glbl_pram->rstate, function_code);
  2542. /* initialize extended filtering */
  2543. if (ug_info->rxExtendedFiltering) {
  2544. if (!ug_info->extendedFilteringChainPointer) {
  2545. if (netif_msg_ifup(ugeth))
  2546. pr_err("Null Extended Filtering Chain Pointer\n");
  2547. return -EINVAL;
  2548. }
  2549. /* Allocate memory for extended filtering Mode Global
  2550. Parameters */
  2551. ugeth->exf_glbl_param_offset =
  2552. qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
  2553. UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
  2554. if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
  2555. if (netif_msg_ifup(ugeth))
  2556. pr_err("Can not allocate DPRAM memory for p_exf_glbl_param\n");
  2557. return -ENOMEM;
  2558. }
  2559. ugeth->p_exf_glbl_param =
  2560. (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth->
  2561. exf_glbl_param_offset);
  2562. out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
  2563. ugeth->exf_glbl_param_offset);
  2564. out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
  2565. (u32) ug_info->extendedFilteringChainPointer);
  2566. } else { /* initialize 82xx style address filtering */
  2567. /* Init individual address recognition registers to disabled */
  2568. for (j = 0; j < NUM_OF_PADDRS; j++)
  2569. ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
  2570. p_82xx_addr_filt =
  2571. (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
  2572. p_rx_glbl_pram->addressfiltering;
  2573. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  2574. ENET_ADDR_TYPE_GROUP);
  2575. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  2576. ENET_ADDR_TYPE_INDIVIDUAL);
  2577. }
  2578. /*
  2579. * Initialize UCC at QE level
  2580. */
  2581. command = QE_INIT_TX_RX;
  2582. /* Allocate shadow InitEnet command parameter structure.
  2583. * This is needed because after the InitEnet command is executed,
  2584. * the structure in DPRAM is released, because DPRAM is a premium
  2585. * resource.
  2586. * This shadow structure keeps a copy of what was done so that the
  2587. * allocated resources can be released when the channel is freed.
  2588. */
  2589. if (!(ugeth->p_init_enet_param_shadow =
  2590. kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
  2591. if (netif_msg_ifup(ugeth))
  2592. pr_err("Can not allocate memory for p_UccInitEnetParamShadows\n");
  2593. return -ENOMEM;
  2594. }
  2595. /* Zero out *p_init_enet_param_shadow */
  2596. memset((char *)ugeth->p_init_enet_param_shadow,
  2597. 0, sizeof(struct ucc_geth_init_pram));
  2598. /* Fill shadow InitEnet command parameter structure */
  2599. ugeth->p_init_enet_param_shadow->resinit1 =
  2600. ENET_INIT_PARAM_MAGIC_RES_INIT1;
  2601. ugeth->p_init_enet_param_shadow->resinit2 =
  2602. ENET_INIT_PARAM_MAGIC_RES_INIT2;
  2603. ugeth->p_init_enet_param_shadow->resinit3 =
  2604. ENET_INIT_PARAM_MAGIC_RES_INIT3;
  2605. ugeth->p_init_enet_param_shadow->resinit4 =
  2606. ENET_INIT_PARAM_MAGIC_RES_INIT4;
  2607. ugeth->p_init_enet_param_shadow->resinit5 =
  2608. ENET_INIT_PARAM_MAGIC_RES_INIT5;
  2609. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2610. ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
  2611. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2612. ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
  2613. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2614. ugeth->rx_glbl_pram_offset | ug_info->riscRx;
  2615. if ((ug_info->largestexternallookupkeysize !=
  2616. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE) &&
  2617. (ug_info->largestexternallookupkeysize !=
  2618. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES) &&
  2619. (ug_info->largestexternallookupkeysize !=
  2620. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
  2621. if (netif_msg_ifup(ugeth))
  2622. pr_err("Invalid largest External Lookup Key Size\n");
  2623. return -EINVAL;
  2624. }
  2625. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
  2626. ug_info->largestexternallookupkeysize;
  2627. size = sizeof(struct ucc_geth_thread_rx_pram);
  2628. if (ug_info->rxExtendedFiltering) {
  2629. size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
  2630. if (ug_info->largestexternallookupkeysize ==
  2631. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
  2632. size +=
  2633. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
  2634. if (ug_info->largestexternallookupkeysize ==
  2635. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
  2636. size +=
  2637. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
  2638. }
  2639. if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
  2640. p_init_enet_param_shadow->rxthread[0]),
  2641. (u8) (numThreadsRxNumerical + 1)
  2642. /* Rx needs one extra for terminator */
  2643. , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
  2644. ug_info->riscRx, 1)) != 0) {
  2645. if (netif_msg_ifup(ugeth))
  2646. pr_err("Can not fill p_init_enet_param_shadow\n");
  2647. return ret_val;
  2648. }
  2649. ugeth->p_init_enet_param_shadow->txglobal =
  2650. ugeth->tx_glbl_pram_offset | ug_info->riscTx;
  2651. if ((ret_val =
  2652. fill_init_enet_entries(ugeth,
  2653. &(ugeth->p_init_enet_param_shadow->
  2654. txthread[0]), numThreadsTxNumerical,
  2655. sizeof(struct ucc_geth_thread_tx_pram),
  2656. UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
  2657. ug_info->riscTx, 0)) != 0) {
  2658. if (netif_msg_ifup(ugeth))
  2659. pr_err("Can not fill p_init_enet_param_shadow\n");
  2660. return ret_val;
  2661. }
  2662. /* Load Rx bds with buffers */
  2663. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2664. if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
  2665. if (netif_msg_ifup(ugeth))
  2666. pr_err("Can not fill Rx bds with buffers\n");
  2667. return ret_val;
  2668. }
  2669. }
  2670. /* Allocate InitEnet command parameter structure */
  2671. init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
  2672. if (IS_ERR_VALUE(init_enet_pram_offset)) {
  2673. if (netif_msg_ifup(ugeth))
  2674. pr_err("Can not allocate DPRAM memory for p_init_enet_pram\n");
  2675. return -ENOMEM;
  2676. }
  2677. p_init_enet_pram =
  2678. (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset);
  2679. /* Copy shadow InitEnet command parameter structure into PRAM */
  2680. out_8(&p_init_enet_pram->resinit1,
  2681. ugeth->p_init_enet_param_shadow->resinit1);
  2682. out_8(&p_init_enet_pram->resinit2,
  2683. ugeth->p_init_enet_param_shadow->resinit2);
  2684. out_8(&p_init_enet_pram->resinit3,
  2685. ugeth->p_init_enet_param_shadow->resinit3);
  2686. out_8(&p_init_enet_pram->resinit4,
  2687. ugeth->p_init_enet_param_shadow->resinit4);
  2688. out_be16(&p_init_enet_pram->resinit5,
  2689. ugeth->p_init_enet_param_shadow->resinit5);
  2690. out_8(&p_init_enet_pram->largestexternallookupkeysize,
  2691. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize);
  2692. out_be32(&p_init_enet_pram->rgftgfrxglobal,
  2693. ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
  2694. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
  2695. out_be32(&p_init_enet_pram->rxthread[i],
  2696. ugeth->p_init_enet_param_shadow->rxthread[i]);
  2697. out_be32(&p_init_enet_pram->txglobal,
  2698. ugeth->p_init_enet_param_shadow->txglobal);
  2699. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
  2700. out_be32(&p_init_enet_pram->txthread[i],
  2701. ugeth->p_init_enet_param_shadow->txthread[i]);
  2702. /* Issue QE command */
  2703. cecr_subblock =
  2704. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  2705. qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
  2706. init_enet_pram_offset);
  2707. /* Free InitEnet command parameter */
  2708. qe_muram_free(init_enet_pram_offset);
  2709. return 0;
  2710. }
  2711. /* This is called by the kernel when a frame is ready for transmission. */
  2712. /* It is pointed to by the dev->hard_start_xmit function pointer */
  2713. static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2714. {
  2715. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2716. #ifdef CONFIG_UGETH_TX_ON_DEMAND
  2717. struct ucc_fast_private *uccf;
  2718. #endif
  2719. u8 __iomem *bd; /* BD pointer */
  2720. u32 bd_status;
  2721. u8 txQ = 0;
  2722. unsigned long flags;
  2723. ugeth_vdbg("%s: IN", __func__);
  2724. spin_lock_irqsave(&ugeth->lock, flags);
  2725. dev->stats.tx_bytes += skb->len;
  2726. /* Start from the next BD that should be filled */
  2727. bd = ugeth->txBd[txQ];
  2728. bd_status = in_be32((u32 __iomem *)bd);
  2729. /* Save the skb pointer so we can free it later */
  2730. ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
  2731. /* Update the current skb pointer (wrapping if this was the last) */
  2732. ugeth->skb_curtx[txQ] =
  2733. (ugeth->skb_curtx[txQ] +
  2734. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  2735. /* set up the buffer descriptor */
  2736. out_be32(&((struct qe_bd __iomem *)bd)->buf,
  2737. dma_map_single(ugeth->dev, skb->data,
  2738. skb->len, DMA_TO_DEVICE));
  2739. /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
  2740. bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
  2741. /* set bd status and length */
  2742. out_be32((u32 __iomem *)bd, bd_status);
  2743. /* Move to next BD in the ring */
  2744. if (!(bd_status & T_W))
  2745. bd += sizeof(struct qe_bd);
  2746. else
  2747. bd = ugeth->p_tx_bd_ring[txQ];
  2748. /* If the next BD still needs to be cleaned up, then the bds
  2749. are full. We need to tell the kernel to stop sending us stuff. */
  2750. if (bd == ugeth->confBd[txQ]) {
  2751. if (!netif_queue_stopped(dev))
  2752. netif_stop_queue(dev);
  2753. }
  2754. ugeth->txBd[txQ] = bd;
  2755. skb_tx_timestamp(skb);
  2756. if (ugeth->p_scheduler) {
  2757. ugeth->cpucount[txQ]++;
  2758. /* Indicate to QE that there are more Tx bds ready for
  2759. transmission */
  2760. /* This is done by writing a running counter of the bd
  2761. count to the scheduler PRAM. */
  2762. out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
  2763. }
  2764. #ifdef CONFIG_UGETH_TX_ON_DEMAND
  2765. uccf = ugeth->uccf;
  2766. out_be16(uccf->p_utodr, UCC_FAST_TOD);
  2767. #endif
  2768. spin_unlock_irqrestore(&ugeth->lock, flags);
  2769. return NETDEV_TX_OK;
  2770. }
  2771. static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
  2772. {
  2773. struct sk_buff *skb;
  2774. u8 __iomem *bd;
  2775. u16 length, howmany = 0;
  2776. u32 bd_status;
  2777. u8 *bdBuffer;
  2778. struct net_device *dev;
  2779. ugeth_vdbg("%s: IN", __func__);
  2780. dev = ugeth->ndev;
  2781. /* collect received buffers */
  2782. bd = ugeth->rxBd[rxQ];
  2783. bd_status = in_be32((u32 __iomem *)bd);
  2784. /* while there are received buffers and BD is full (~R_E) */
  2785. while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
  2786. bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf);
  2787. length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
  2788. skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
  2789. /* determine whether buffer is first, last, first and last
  2790. (single buffer frame) or middle (not first and not last) */
  2791. if (!skb ||
  2792. (!(bd_status & (R_F | R_L))) ||
  2793. (bd_status & R_ERRORS_FATAL)) {
  2794. if (netif_msg_rx_err(ugeth))
  2795. pr_err("%d: ERROR!!! skb - 0x%08x\n",
  2796. __LINE__, (u32)skb);
  2797. dev_kfree_skb(skb);
  2798. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
  2799. dev->stats.rx_dropped++;
  2800. } else {
  2801. dev->stats.rx_packets++;
  2802. howmany++;
  2803. /* Prep the skb for the packet */
  2804. skb_put(skb, length);
  2805. /* Tell the skb what kind of packet this is */
  2806. skb->protocol = eth_type_trans(skb, ugeth->ndev);
  2807. dev->stats.rx_bytes += length;
  2808. /* Send the packet up the stack */
  2809. netif_receive_skb(skb);
  2810. }
  2811. skb = get_new_skb(ugeth, bd);
  2812. if (!skb) {
  2813. if (netif_msg_rx_err(ugeth))
  2814. pr_warn("No Rx Data Buffer\n");
  2815. dev->stats.rx_dropped++;
  2816. break;
  2817. }
  2818. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
  2819. /* update to point at the next skb */
  2820. ugeth->skb_currx[rxQ] =
  2821. (ugeth->skb_currx[rxQ] +
  2822. 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
  2823. if (bd_status & R_W)
  2824. bd = ugeth->p_rx_bd_ring[rxQ];
  2825. else
  2826. bd += sizeof(struct qe_bd);
  2827. bd_status = in_be32((u32 __iomem *)bd);
  2828. }
  2829. ugeth->rxBd[rxQ] = bd;
  2830. return howmany;
  2831. }
  2832. static int ucc_geth_tx(struct net_device *dev, u8 txQ)
  2833. {
  2834. /* Start from the next BD that should be filled */
  2835. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2836. u8 __iomem *bd; /* BD pointer */
  2837. u32 bd_status;
  2838. bd = ugeth->confBd[txQ];
  2839. bd_status = in_be32((u32 __iomem *)bd);
  2840. /* Normal processing. */
  2841. while ((bd_status & T_R) == 0) {
  2842. struct sk_buff *skb;
  2843. /* BD contains already transmitted buffer. */
  2844. /* Handle the transmitted buffer and release */
  2845. /* the BD to be used with the current frame */
  2846. skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]];
  2847. if (!skb)
  2848. break;
  2849. dev->stats.tx_packets++;
  2850. dev_consume_skb_any(skb);
  2851. ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
  2852. ugeth->skb_dirtytx[txQ] =
  2853. (ugeth->skb_dirtytx[txQ] +
  2854. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  2855. /* We freed a buffer, so now we can restart transmission */
  2856. if (netif_queue_stopped(dev))
  2857. netif_wake_queue(dev);
  2858. /* Advance the confirmation BD pointer */
  2859. if (!(bd_status & T_W))
  2860. bd += sizeof(struct qe_bd);
  2861. else
  2862. bd = ugeth->p_tx_bd_ring[txQ];
  2863. bd_status = in_be32((u32 __iomem *)bd);
  2864. }
  2865. ugeth->confBd[txQ] = bd;
  2866. return 0;
  2867. }
  2868. static int ucc_geth_poll(struct napi_struct *napi, int budget)
  2869. {
  2870. struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
  2871. struct ucc_geth_info *ug_info;
  2872. int howmany, i;
  2873. ug_info = ugeth->ug_info;
  2874. /* Tx event processing */
  2875. spin_lock(&ugeth->lock);
  2876. for (i = 0; i < ug_info->numQueuesTx; i++)
  2877. ucc_geth_tx(ugeth->ndev, i);
  2878. spin_unlock(&ugeth->lock);
  2879. howmany = 0;
  2880. for (i = 0; i < ug_info->numQueuesRx; i++)
  2881. howmany += ucc_geth_rx(ugeth, i, budget - howmany);
  2882. if (howmany < budget) {
  2883. napi_complete(napi);
  2884. setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS);
  2885. }
  2886. return howmany;
  2887. }
  2888. static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
  2889. {
  2890. struct net_device *dev = info;
  2891. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2892. struct ucc_fast_private *uccf;
  2893. struct ucc_geth_info *ug_info;
  2894. register u32 ucce;
  2895. register u32 uccm;
  2896. ugeth_vdbg("%s: IN", __func__);
  2897. uccf = ugeth->uccf;
  2898. ug_info = ugeth->ug_info;
  2899. /* read and clear events */
  2900. ucce = (u32) in_be32(uccf->p_ucce);
  2901. uccm = (u32) in_be32(uccf->p_uccm);
  2902. ucce &= uccm;
  2903. out_be32(uccf->p_ucce, ucce);
  2904. /* check for receive events that require processing */
  2905. if (ucce & (UCCE_RX_EVENTS | UCCE_TX_EVENTS)) {
  2906. if (napi_schedule_prep(&ugeth->napi)) {
  2907. uccm &= ~(UCCE_RX_EVENTS | UCCE_TX_EVENTS);
  2908. out_be32(uccf->p_uccm, uccm);
  2909. __napi_schedule(&ugeth->napi);
  2910. }
  2911. }
  2912. /* Errors and other events */
  2913. if (ucce & UCCE_OTHER) {
  2914. if (ucce & UCC_GETH_UCCE_BSY)
  2915. dev->stats.rx_errors++;
  2916. if (ucce & UCC_GETH_UCCE_TXE)
  2917. dev->stats.tx_errors++;
  2918. }
  2919. return IRQ_HANDLED;
  2920. }
  2921. #ifdef CONFIG_NET_POLL_CONTROLLER
  2922. /*
  2923. * Polling 'interrupt' - used by things like netconsole to send skbs
  2924. * without having to re-enable interrupts. It's not called while
  2925. * the interrupt routine is executing.
  2926. */
  2927. static void ucc_netpoll(struct net_device *dev)
  2928. {
  2929. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2930. int irq = ugeth->ug_info->uf_info.irq;
  2931. disable_irq(irq);
  2932. ucc_geth_irq_handler(irq, dev);
  2933. enable_irq(irq);
  2934. }
  2935. #endif /* CONFIG_NET_POLL_CONTROLLER */
  2936. static int ucc_geth_set_mac_addr(struct net_device *dev, void *p)
  2937. {
  2938. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2939. struct sockaddr *addr = p;
  2940. if (!is_valid_ether_addr(addr->sa_data))
  2941. return -EADDRNOTAVAIL;
  2942. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2943. /*
  2944. * If device is not running, we will set mac addr register
  2945. * when opening the device.
  2946. */
  2947. if (!netif_running(dev))
  2948. return 0;
  2949. spin_lock_irq(&ugeth->lock);
  2950. init_mac_station_addr_regs(dev->dev_addr[0],
  2951. dev->dev_addr[1],
  2952. dev->dev_addr[2],
  2953. dev->dev_addr[3],
  2954. dev->dev_addr[4],
  2955. dev->dev_addr[5],
  2956. &ugeth->ug_regs->macstnaddr1,
  2957. &ugeth->ug_regs->macstnaddr2);
  2958. spin_unlock_irq(&ugeth->lock);
  2959. return 0;
  2960. }
  2961. static int ucc_geth_init_mac(struct ucc_geth_private *ugeth)
  2962. {
  2963. struct net_device *dev = ugeth->ndev;
  2964. int err;
  2965. err = ucc_struct_init(ugeth);
  2966. if (err) {
  2967. netif_err(ugeth, ifup, dev, "Cannot configure internal struct, aborting\n");
  2968. goto err;
  2969. }
  2970. err = ucc_geth_startup(ugeth);
  2971. if (err) {
  2972. netif_err(ugeth, ifup, dev, "Cannot configure net device, aborting\n");
  2973. goto err;
  2974. }
  2975. err = adjust_enet_interface(ugeth);
  2976. if (err) {
  2977. netif_err(ugeth, ifup, dev, "Cannot configure net device, aborting\n");
  2978. goto err;
  2979. }
  2980. /* Set MACSTNADDR1, MACSTNADDR2 */
  2981. /* For more details see the hardware spec. */
  2982. init_mac_station_addr_regs(dev->dev_addr[0],
  2983. dev->dev_addr[1],
  2984. dev->dev_addr[2],
  2985. dev->dev_addr[3],
  2986. dev->dev_addr[4],
  2987. dev->dev_addr[5],
  2988. &ugeth->ug_regs->macstnaddr1,
  2989. &ugeth->ug_regs->macstnaddr2);
  2990. err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
  2991. if (err) {
  2992. netif_err(ugeth, ifup, dev, "Cannot enable net device, aborting\n");
  2993. goto err;
  2994. }
  2995. return 0;
  2996. err:
  2997. ucc_geth_stop(ugeth);
  2998. return err;
  2999. }
  3000. /* Called when something needs to use the ethernet device */
  3001. /* Returns 0 for success. */
  3002. static int ucc_geth_open(struct net_device *dev)
  3003. {
  3004. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3005. int err;
  3006. ugeth_vdbg("%s: IN", __func__);
  3007. /* Test station address */
  3008. if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
  3009. netif_err(ugeth, ifup, dev,
  3010. "Multicast address used for station address - is this what you wanted?\n");
  3011. return -EINVAL;
  3012. }
  3013. err = init_phy(dev);
  3014. if (err) {
  3015. netif_err(ugeth, ifup, dev, "Cannot initialize PHY, aborting\n");
  3016. return err;
  3017. }
  3018. err = ucc_geth_init_mac(ugeth);
  3019. if (err) {
  3020. netif_err(ugeth, ifup, dev, "Cannot initialize MAC, aborting\n");
  3021. goto err;
  3022. }
  3023. err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler,
  3024. 0, "UCC Geth", dev);
  3025. if (err) {
  3026. netif_err(ugeth, ifup, dev, "Cannot get IRQ for net device, aborting\n");
  3027. goto err;
  3028. }
  3029. phy_start(ugeth->phydev);
  3030. napi_enable(&ugeth->napi);
  3031. netif_start_queue(dev);
  3032. device_set_wakeup_capable(&dev->dev,
  3033. qe_alive_during_sleep() || ugeth->phydev->irq);
  3034. device_set_wakeup_enable(&dev->dev, ugeth->wol_en);
  3035. return err;
  3036. err:
  3037. ucc_geth_stop(ugeth);
  3038. return err;
  3039. }
  3040. /* Stops the kernel queue, and halts the controller */
  3041. static int ucc_geth_close(struct net_device *dev)
  3042. {
  3043. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3044. ugeth_vdbg("%s: IN", __func__);
  3045. napi_disable(&ugeth->napi);
  3046. cancel_work_sync(&ugeth->timeout_work);
  3047. ucc_geth_stop(ugeth);
  3048. phy_disconnect(ugeth->phydev);
  3049. ugeth->phydev = NULL;
  3050. free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev);
  3051. netif_stop_queue(dev);
  3052. return 0;
  3053. }
  3054. /* Reopen device. This will reset the MAC and PHY. */
  3055. static void ucc_geth_timeout_work(struct work_struct *work)
  3056. {
  3057. struct ucc_geth_private *ugeth;
  3058. struct net_device *dev;
  3059. ugeth = container_of(work, struct ucc_geth_private, timeout_work);
  3060. dev = ugeth->ndev;
  3061. ugeth_vdbg("%s: IN", __func__);
  3062. dev->stats.tx_errors++;
  3063. ugeth_dump_regs(ugeth);
  3064. if (dev->flags & IFF_UP) {
  3065. /*
  3066. * Must reset MAC *and* PHY. This is done by reopening
  3067. * the device.
  3068. */
  3069. netif_tx_stop_all_queues(dev);
  3070. ucc_geth_stop(ugeth);
  3071. ucc_geth_init_mac(ugeth);
  3072. /* Must start PHY here */
  3073. phy_start(ugeth->phydev);
  3074. netif_tx_start_all_queues(dev);
  3075. }
  3076. netif_tx_schedule_all(dev);
  3077. }
  3078. /*
  3079. * ucc_geth_timeout gets called when a packet has not been
  3080. * transmitted after a set amount of time.
  3081. */
  3082. static void ucc_geth_timeout(struct net_device *dev)
  3083. {
  3084. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3085. schedule_work(&ugeth->timeout_work);
  3086. }
  3087. #ifdef CONFIG_PM
  3088. static int ucc_geth_suspend(struct platform_device *ofdev, pm_message_t state)
  3089. {
  3090. struct net_device *ndev = platform_get_drvdata(ofdev);
  3091. struct ucc_geth_private *ugeth = netdev_priv(ndev);
  3092. if (!netif_running(ndev))
  3093. return 0;
  3094. netif_device_detach(ndev);
  3095. napi_disable(&ugeth->napi);
  3096. /*
  3097. * Disable the controller, otherwise we'll wakeup on any network
  3098. * activity.
  3099. */
  3100. ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
  3101. if (ugeth->wol_en & WAKE_MAGIC) {
  3102. setbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
  3103. setbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
  3104. ucc_fast_enable(ugeth->uccf, COMM_DIR_RX_AND_TX);
  3105. } else if (!(ugeth->wol_en & WAKE_PHY)) {
  3106. phy_stop(ugeth->phydev);
  3107. }
  3108. return 0;
  3109. }
  3110. static int ucc_geth_resume(struct platform_device *ofdev)
  3111. {
  3112. struct net_device *ndev = platform_get_drvdata(ofdev);
  3113. struct ucc_geth_private *ugeth = netdev_priv(ndev);
  3114. int err;
  3115. if (!netif_running(ndev))
  3116. return 0;
  3117. if (qe_alive_during_sleep()) {
  3118. if (ugeth->wol_en & WAKE_MAGIC) {
  3119. ucc_fast_disable(ugeth->uccf, COMM_DIR_RX_AND_TX);
  3120. clrbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
  3121. clrbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
  3122. }
  3123. ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
  3124. } else {
  3125. /*
  3126. * Full reinitialization is required if QE shuts down
  3127. * during sleep.
  3128. */
  3129. ucc_geth_memclean(ugeth);
  3130. err = ucc_geth_init_mac(ugeth);
  3131. if (err) {
  3132. netdev_err(ndev, "Cannot initialize MAC, aborting\n");
  3133. return err;
  3134. }
  3135. }
  3136. ugeth->oldlink = 0;
  3137. ugeth->oldspeed = 0;
  3138. ugeth->oldduplex = -1;
  3139. phy_stop(ugeth->phydev);
  3140. phy_start(ugeth->phydev);
  3141. napi_enable(&ugeth->napi);
  3142. netif_device_attach(ndev);
  3143. return 0;
  3144. }
  3145. #else
  3146. #define ucc_geth_suspend NULL
  3147. #define ucc_geth_resume NULL
  3148. #endif
  3149. static phy_interface_t to_phy_interface(const char *phy_connection_type)
  3150. {
  3151. if (strcasecmp(phy_connection_type, "mii") == 0)
  3152. return PHY_INTERFACE_MODE_MII;
  3153. if (strcasecmp(phy_connection_type, "gmii") == 0)
  3154. return PHY_INTERFACE_MODE_GMII;
  3155. if (strcasecmp(phy_connection_type, "tbi") == 0)
  3156. return PHY_INTERFACE_MODE_TBI;
  3157. if (strcasecmp(phy_connection_type, "rmii") == 0)
  3158. return PHY_INTERFACE_MODE_RMII;
  3159. if (strcasecmp(phy_connection_type, "rgmii") == 0)
  3160. return PHY_INTERFACE_MODE_RGMII;
  3161. if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
  3162. return PHY_INTERFACE_MODE_RGMII_ID;
  3163. if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
  3164. return PHY_INTERFACE_MODE_RGMII_TXID;
  3165. if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
  3166. return PHY_INTERFACE_MODE_RGMII_RXID;
  3167. if (strcasecmp(phy_connection_type, "rtbi") == 0)
  3168. return PHY_INTERFACE_MODE_RTBI;
  3169. if (strcasecmp(phy_connection_type, "sgmii") == 0)
  3170. return PHY_INTERFACE_MODE_SGMII;
  3171. return PHY_INTERFACE_MODE_MII;
  3172. }
  3173. static int ucc_geth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3174. {
  3175. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3176. if (!netif_running(dev))
  3177. return -EINVAL;
  3178. if (!ugeth->phydev)
  3179. return -ENODEV;
  3180. return phy_mii_ioctl(ugeth->phydev, rq, cmd);
  3181. }
  3182. static const struct net_device_ops ucc_geth_netdev_ops = {
  3183. .ndo_open = ucc_geth_open,
  3184. .ndo_stop = ucc_geth_close,
  3185. .ndo_start_xmit = ucc_geth_start_xmit,
  3186. .ndo_validate_addr = eth_validate_addr,
  3187. .ndo_set_mac_address = ucc_geth_set_mac_addr,
  3188. .ndo_change_mtu = eth_change_mtu,
  3189. .ndo_set_rx_mode = ucc_geth_set_multi,
  3190. .ndo_tx_timeout = ucc_geth_timeout,
  3191. .ndo_do_ioctl = ucc_geth_ioctl,
  3192. #ifdef CONFIG_NET_POLL_CONTROLLER
  3193. .ndo_poll_controller = ucc_netpoll,
  3194. #endif
  3195. };
  3196. static int ucc_geth_probe(struct platform_device* ofdev)
  3197. {
  3198. struct device *device = &ofdev->dev;
  3199. struct device_node *np = ofdev->dev.of_node;
  3200. struct net_device *dev = NULL;
  3201. struct ucc_geth_private *ugeth = NULL;
  3202. struct ucc_geth_info *ug_info;
  3203. struct resource res;
  3204. int err, ucc_num, max_speed = 0;
  3205. const unsigned int *prop;
  3206. const char *sprop;
  3207. const void *mac_addr;
  3208. phy_interface_t phy_interface;
  3209. static const int enet_to_speed[] = {
  3210. SPEED_10, SPEED_10, SPEED_10,
  3211. SPEED_100, SPEED_100, SPEED_100,
  3212. SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000,
  3213. };
  3214. static const phy_interface_t enet_to_phy_interface[] = {
  3215. PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII,
  3216. PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII,
  3217. PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII,
  3218. PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII,
  3219. PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI,
  3220. PHY_INTERFACE_MODE_SGMII,
  3221. };
  3222. ugeth_vdbg("%s: IN", __func__);
  3223. prop = of_get_property(np, "cell-index", NULL);
  3224. if (!prop) {
  3225. prop = of_get_property(np, "device-id", NULL);
  3226. if (!prop)
  3227. return -ENODEV;
  3228. }
  3229. ucc_num = *prop - 1;
  3230. if ((ucc_num < 0) || (ucc_num > 7))
  3231. return -ENODEV;
  3232. ug_info = &ugeth_info[ucc_num];
  3233. if (ug_info == NULL) {
  3234. if (netif_msg_probe(&debug))
  3235. pr_err("[%d] Missing additional data!\n", ucc_num);
  3236. return -ENODEV;
  3237. }
  3238. ug_info->uf_info.ucc_num = ucc_num;
  3239. sprop = of_get_property(np, "rx-clock-name", NULL);
  3240. if (sprop) {
  3241. ug_info->uf_info.rx_clock = qe_clock_source(sprop);
  3242. if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) ||
  3243. (ug_info->uf_info.rx_clock > QE_CLK24)) {
  3244. pr_err("invalid rx-clock-name property\n");
  3245. return -EINVAL;
  3246. }
  3247. } else {
  3248. prop = of_get_property(np, "rx-clock", NULL);
  3249. if (!prop) {
  3250. /* If both rx-clock-name and rx-clock are missing,
  3251. we want to tell people to use rx-clock-name. */
  3252. pr_err("missing rx-clock-name property\n");
  3253. return -EINVAL;
  3254. }
  3255. if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
  3256. pr_err("invalid rx-clock propperty\n");
  3257. return -EINVAL;
  3258. }
  3259. ug_info->uf_info.rx_clock = *prop;
  3260. }
  3261. sprop = of_get_property(np, "tx-clock-name", NULL);
  3262. if (sprop) {
  3263. ug_info->uf_info.tx_clock = qe_clock_source(sprop);
  3264. if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) ||
  3265. (ug_info->uf_info.tx_clock > QE_CLK24)) {
  3266. pr_err("invalid tx-clock-name property\n");
  3267. return -EINVAL;
  3268. }
  3269. } else {
  3270. prop = of_get_property(np, "tx-clock", NULL);
  3271. if (!prop) {
  3272. pr_err("missing tx-clock-name property\n");
  3273. return -EINVAL;
  3274. }
  3275. if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
  3276. pr_err("invalid tx-clock property\n");
  3277. return -EINVAL;
  3278. }
  3279. ug_info->uf_info.tx_clock = *prop;
  3280. }
  3281. err = of_address_to_resource(np, 0, &res);
  3282. if (err)
  3283. return -EINVAL;
  3284. ug_info->uf_info.regs = res.start;
  3285. ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
  3286. ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0);
  3287. if (!ug_info->phy_node && of_phy_is_fixed_link(np)) {
  3288. /*
  3289. * In the case of a fixed PHY, the DT node associated
  3290. * to the PHY is the Ethernet MAC DT node.
  3291. */
  3292. err = of_phy_register_fixed_link(np);
  3293. if (err)
  3294. return err;
  3295. ug_info->phy_node = of_node_get(np);
  3296. }
  3297. /* Find the TBI PHY node. If it's not there, we don't support SGMII */
  3298. ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
  3299. /* get the phy interface type, or default to MII */
  3300. prop = of_get_property(np, "phy-connection-type", NULL);
  3301. if (!prop) {
  3302. /* handle interface property present in old trees */
  3303. prop = of_get_property(ug_info->phy_node, "interface", NULL);
  3304. if (prop != NULL) {
  3305. phy_interface = enet_to_phy_interface[*prop];
  3306. max_speed = enet_to_speed[*prop];
  3307. } else
  3308. phy_interface = PHY_INTERFACE_MODE_MII;
  3309. } else {
  3310. phy_interface = to_phy_interface((const char *)prop);
  3311. }
  3312. /* get speed, or derive from PHY interface */
  3313. if (max_speed == 0)
  3314. switch (phy_interface) {
  3315. case PHY_INTERFACE_MODE_GMII:
  3316. case PHY_INTERFACE_MODE_RGMII:
  3317. case PHY_INTERFACE_MODE_RGMII_ID:
  3318. case PHY_INTERFACE_MODE_RGMII_RXID:
  3319. case PHY_INTERFACE_MODE_RGMII_TXID:
  3320. case PHY_INTERFACE_MODE_TBI:
  3321. case PHY_INTERFACE_MODE_RTBI:
  3322. case PHY_INTERFACE_MODE_SGMII:
  3323. max_speed = SPEED_1000;
  3324. break;
  3325. default:
  3326. max_speed = SPEED_100;
  3327. break;
  3328. }
  3329. if (max_speed == SPEED_1000) {
  3330. unsigned int snums = qe_get_num_of_snums();
  3331. /* configure muram FIFOs for gigabit operation */
  3332. ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
  3333. ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
  3334. ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
  3335. ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT;
  3336. ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT;
  3337. ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
  3338. ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
  3339. /* If QE's snum number is 46/76 which means we need to support
  3340. * 4 UECs at 1000Base-T simultaneously, we need to allocate
  3341. * more Threads to Rx.
  3342. */
  3343. if ((snums == 76) || (snums == 46))
  3344. ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6;
  3345. else
  3346. ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
  3347. }
  3348. if (netif_msg_probe(&debug))
  3349. pr_info("UCC%1d at 0x%8x (irq = %d)\n",
  3350. ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
  3351. ug_info->uf_info.irq);
  3352. /* Create an ethernet device instance */
  3353. dev = alloc_etherdev(sizeof(*ugeth));
  3354. if (dev == NULL) {
  3355. of_node_put(ug_info->tbi_node);
  3356. of_node_put(ug_info->phy_node);
  3357. return -ENOMEM;
  3358. }
  3359. ugeth = netdev_priv(dev);
  3360. spin_lock_init(&ugeth->lock);
  3361. /* Create CQs for hash tables */
  3362. INIT_LIST_HEAD(&ugeth->group_hash_q);
  3363. INIT_LIST_HEAD(&ugeth->ind_hash_q);
  3364. dev_set_drvdata(device, dev);
  3365. /* Set the dev->base_addr to the gfar reg region */
  3366. dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
  3367. SET_NETDEV_DEV(dev, device);
  3368. /* Fill in the dev structure */
  3369. uec_set_ethtool_ops(dev);
  3370. dev->netdev_ops = &ucc_geth_netdev_ops;
  3371. dev->watchdog_timeo = TX_TIMEOUT;
  3372. INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work);
  3373. netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, 64);
  3374. dev->mtu = 1500;
  3375. ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
  3376. ugeth->phy_interface = phy_interface;
  3377. ugeth->max_speed = max_speed;
  3378. /* Carrier starts down, phylib will bring it up */
  3379. netif_carrier_off(dev);
  3380. err = register_netdev(dev);
  3381. if (err) {
  3382. if (netif_msg_probe(ugeth))
  3383. pr_err("%s: Cannot register net device, aborting\n",
  3384. dev->name);
  3385. free_netdev(dev);
  3386. of_node_put(ug_info->tbi_node);
  3387. of_node_put(ug_info->phy_node);
  3388. return err;
  3389. }
  3390. mac_addr = of_get_mac_address(np);
  3391. if (mac_addr)
  3392. memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
  3393. ugeth->ug_info = ug_info;
  3394. ugeth->dev = device;
  3395. ugeth->ndev = dev;
  3396. ugeth->node = np;
  3397. return 0;
  3398. }
  3399. static int ucc_geth_remove(struct platform_device* ofdev)
  3400. {
  3401. struct net_device *dev = platform_get_drvdata(ofdev);
  3402. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3403. unregister_netdev(dev);
  3404. free_netdev(dev);
  3405. ucc_geth_memclean(ugeth);
  3406. of_node_put(ugeth->ug_info->tbi_node);
  3407. of_node_put(ugeth->ug_info->phy_node);
  3408. return 0;
  3409. }
  3410. static const struct of_device_id ucc_geth_match[] = {
  3411. {
  3412. .type = "network",
  3413. .compatible = "ucc_geth",
  3414. },
  3415. {},
  3416. };
  3417. MODULE_DEVICE_TABLE(of, ucc_geth_match);
  3418. static struct platform_driver ucc_geth_driver = {
  3419. .driver = {
  3420. .name = DRV_NAME,
  3421. .of_match_table = ucc_geth_match,
  3422. },
  3423. .probe = ucc_geth_probe,
  3424. .remove = ucc_geth_remove,
  3425. .suspend = ucc_geth_suspend,
  3426. .resume = ucc_geth_resume,
  3427. };
  3428. static int __init ucc_geth_init(void)
  3429. {
  3430. int i, ret;
  3431. if (netif_msg_drv(&debug))
  3432. pr_info(DRV_DESC "\n");
  3433. for (i = 0; i < 8; i++)
  3434. memcpy(&(ugeth_info[i]), &ugeth_primary_info,
  3435. sizeof(ugeth_primary_info));
  3436. ret = platform_driver_register(&ucc_geth_driver);
  3437. return ret;
  3438. }
  3439. static void __exit ucc_geth_exit(void)
  3440. {
  3441. platform_driver_unregister(&ucc_geth_driver);
  3442. }
  3443. module_init(ucc_geth_init);
  3444. module_exit(ucc_geth_exit);
  3445. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  3446. MODULE_DESCRIPTION(DRV_DESC);
  3447. MODULE_VERSION(DRV_VERSION);
  3448. MODULE_LICENSE("GPL");