ucc_geth.c 117 KB

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