ucc_geth.c 118 KB

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