ucc_geth.c 116 KB

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