ucc_geth.c 118 KB

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