ucc_geth.c 112 KB

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