ucc_geth.c 119 KB

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