ucc_geth.c 120 KB

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