ucc_geth.c 126 KB

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