ucc_geth.c 114 KB

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