ucc_geth.c 118 KB

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