ucc_geth.c 119 KB

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