ucc_geth.c 107 KB

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