ucc_geth.c 121 KB

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