ucc_geth.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027
  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,
  109. .minFrameLength = 64,
  110. .maxD1Length = 1520,
  111. .maxD2Length = 1520,
  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", *((u8 *) (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 = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
  198. UCC_GETH_RX_DATA_BUF_ALIGNMENT);
  199. if (skb == NULL)
  200. return NULL;
  201. /* We need the data buffer to be aligned properly. We will reserve
  202. * as many bytes as needed to align the data properly
  203. */
  204. skb_reserve(skb,
  205. UCC_GETH_RX_DATA_BUF_ALIGNMENT -
  206. (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
  207. 1)));
  208. skb->dev = ugeth->ndev;
  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_memclean(struct ucc_geth_private *ugeth)
  1640. {
  1641. u16 i, j;
  1642. u8 __iomem *bd;
  1643. if (!ugeth)
  1644. return;
  1645. if (ugeth->uccf) {
  1646. ucc_fast_free(ugeth->uccf);
  1647. ugeth->uccf = NULL;
  1648. }
  1649. if (ugeth->p_thread_data_tx) {
  1650. qe_muram_free(ugeth->thread_dat_tx_offset);
  1651. ugeth->p_thread_data_tx = NULL;
  1652. }
  1653. if (ugeth->p_thread_data_rx) {
  1654. qe_muram_free(ugeth->thread_dat_rx_offset);
  1655. ugeth->p_thread_data_rx = NULL;
  1656. }
  1657. if (ugeth->p_exf_glbl_param) {
  1658. qe_muram_free(ugeth->exf_glbl_param_offset);
  1659. ugeth->p_exf_glbl_param = NULL;
  1660. }
  1661. if (ugeth->p_rx_glbl_pram) {
  1662. qe_muram_free(ugeth->rx_glbl_pram_offset);
  1663. ugeth->p_rx_glbl_pram = NULL;
  1664. }
  1665. if (ugeth->p_tx_glbl_pram) {
  1666. qe_muram_free(ugeth->tx_glbl_pram_offset);
  1667. ugeth->p_tx_glbl_pram = NULL;
  1668. }
  1669. if (ugeth->p_send_q_mem_reg) {
  1670. qe_muram_free(ugeth->send_q_mem_reg_offset);
  1671. ugeth->p_send_q_mem_reg = NULL;
  1672. }
  1673. if (ugeth->p_scheduler) {
  1674. qe_muram_free(ugeth->scheduler_offset);
  1675. ugeth->p_scheduler = NULL;
  1676. }
  1677. if (ugeth->p_tx_fw_statistics_pram) {
  1678. qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
  1679. ugeth->p_tx_fw_statistics_pram = NULL;
  1680. }
  1681. if (ugeth->p_rx_fw_statistics_pram) {
  1682. qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
  1683. ugeth->p_rx_fw_statistics_pram = NULL;
  1684. }
  1685. if (ugeth->p_rx_irq_coalescing_tbl) {
  1686. qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
  1687. ugeth->p_rx_irq_coalescing_tbl = NULL;
  1688. }
  1689. if (ugeth->p_rx_bd_qs_tbl) {
  1690. qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
  1691. ugeth->p_rx_bd_qs_tbl = NULL;
  1692. }
  1693. if (ugeth->p_init_enet_param_shadow) {
  1694. return_init_enet_entries(ugeth,
  1695. &(ugeth->p_init_enet_param_shadow->
  1696. rxthread[0]),
  1697. ENET_INIT_PARAM_MAX_ENTRIES_RX,
  1698. ugeth->ug_info->riscRx, 1);
  1699. return_init_enet_entries(ugeth,
  1700. &(ugeth->p_init_enet_param_shadow->
  1701. txthread[0]),
  1702. ENET_INIT_PARAM_MAX_ENTRIES_TX,
  1703. ugeth->ug_info->riscTx, 0);
  1704. kfree(ugeth->p_init_enet_param_shadow);
  1705. ugeth->p_init_enet_param_shadow = NULL;
  1706. }
  1707. for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
  1708. bd = ugeth->p_tx_bd_ring[i];
  1709. if (!bd)
  1710. continue;
  1711. for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
  1712. if (ugeth->tx_skbuff[i][j]) {
  1713. dma_unmap_single(ugeth->dev,
  1714. in_be32(&((struct qe_bd __iomem *)bd)->buf),
  1715. (in_be32((u32 __iomem *)bd) &
  1716. BD_LENGTH_MASK),
  1717. DMA_TO_DEVICE);
  1718. dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
  1719. ugeth->tx_skbuff[i][j] = NULL;
  1720. }
  1721. }
  1722. kfree(ugeth->tx_skbuff[i]);
  1723. if (ugeth->p_tx_bd_ring[i]) {
  1724. if (ugeth->ug_info->uf_info.bd_mem_part ==
  1725. MEM_PART_SYSTEM)
  1726. kfree((void *)ugeth->tx_bd_ring_offset[i]);
  1727. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  1728. MEM_PART_MURAM)
  1729. qe_muram_free(ugeth->tx_bd_ring_offset[i]);
  1730. ugeth->p_tx_bd_ring[i] = NULL;
  1731. }
  1732. }
  1733. for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
  1734. if (ugeth->p_rx_bd_ring[i]) {
  1735. /* Return existing data buffers in ring */
  1736. bd = ugeth->p_rx_bd_ring[i];
  1737. for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
  1738. if (ugeth->rx_skbuff[i][j]) {
  1739. dma_unmap_single(ugeth->dev,
  1740. in_be32(&((struct qe_bd __iomem *)bd)->buf),
  1741. ugeth->ug_info->
  1742. uf_info.max_rx_buf_length +
  1743. UCC_GETH_RX_DATA_BUF_ALIGNMENT,
  1744. DMA_FROM_DEVICE);
  1745. dev_kfree_skb_any(
  1746. ugeth->rx_skbuff[i][j]);
  1747. ugeth->rx_skbuff[i][j] = NULL;
  1748. }
  1749. bd += sizeof(struct qe_bd);
  1750. }
  1751. kfree(ugeth->rx_skbuff[i]);
  1752. if (ugeth->ug_info->uf_info.bd_mem_part ==
  1753. MEM_PART_SYSTEM)
  1754. kfree((void *)ugeth->rx_bd_ring_offset[i]);
  1755. else if (ugeth->ug_info->uf_info.bd_mem_part ==
  1756. MEM_PART_MURAM)
  1757. qe_muram_free(ugeth->rx_bd_ring_offset[i]);
  1758. ugeth->p_rx_bd_ring[i] = NULL;
  1759. }
  1760. }
  1761. while (!list_empty(&ugeth->group_hash_q))
  1762. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  1763. (dequeue(&ugeth->group_hash_q)));
  1764. while (!list_empty(&ugeth->ind_hash_q))
  1765. put_enet_addr_container(ENET_ADDR_CONT_ENTRY
  1766. (dequeue(&ugeth->ind_hash_q)));
  1767. if (ugeth->ug_regs) {
  1768. iounmap(ugeth->ug_regs);
  1769. ugeth->ug_regs = NULL;
  1770. }
  1771. skb_queue_purge(&ugeth->rx_recycle);
  1772. }
  1773. static void ucc_geth_set_multi(struct net_device *dev)
  1774. {
  1775. struct ucc_geth_private *ugeth;
  1776. struct netdev_hw_addr *ha;
  1777. struct ucc_fast __iomem *uf_regs;
  1778. struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
  1779. ugeth = netdev_priv(dev);
  1780. uf_regs = ugeth->uccf->uf_regs;
  1781. if (dev->flags & IFF_PROMISC) {
  1782. setbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
  1783. } else {
  1784. clrbits32(&uf_regs->upsmr, UCC_GETH_UPSMR_PRO);
  1785. p_82xx_addr_filt =
  1786. (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
  1787. p_rx_glbl_pram->addressfiltering;
  1788. if (dev->flags & IFF_ALLMULTI) {
  1789. /* Catch all multicast addresses, so set the
  1790. * filter to all 1's.
  1791. */
  1792. out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
  1793. out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
  1794. } else {
  1795. /* Clear filter and add the addresses in the list.
  1796. */
  1797. out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
  1798. out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
  1799. netdev_for_each_mc_addr(ha, dev) {
  1800. /* Ask CPM to run CRC and set bit in
  1801. * filter mask.
  1802. */
  1803. hw_add_addr_in_hash(ugeth, ha->addr);
  1804. }
  1805. }
  1806. }
  1807. }
  1808. static void ucc_geth_stop(struct ucc_geth_private *ugeth)
  1809. {
  1810. struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
  1811. struct phy_device *phydev = ugeth->phydev;
  1812. ugeth_vdbg("%s: IN", __func__);
  1813. /*
  1814. * Tell the kernel the link is down.
  1815. * Must be done before disabling the controller
  1816. * or deadlock may happen.
  1817. */
  1818. phy_stop(phydev);
  1819. /* Disable the controller */
  1820. ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
  1821. /* Mask all interrupts */
  1822. out_be32(ugeth->uccf->p_uccm, 0x00000000);
  1823. /* Clear all interrupts */
  1824. out_be32(ugeth->uccf->p_ucce, 0xffffffff);
  1825. /* Disable Rx and Tx */
  1826. clrbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
  1827. ucc_geth_memclean(ugeth);
  1828. }
  1829. static int ucc_struct_init(struct ucc_geth_private *ugeth)
  1830. {
  1831. struct ucc_geth_info *ug_info;
  1832. struct ucc_fast_info *uf_info;
  1833. int i;
  1834. ug_info = ugeth->ug_info;
  1835. uf_info = &ug_info->uf_info;
  1836. if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
  1837. (uf_info->bd_mem_part == MEM_PART_MURAM))) {
  1838. if (netif_msg_probe(ugeth))
  1839. ugeth_err("%s: Bad memory partition value.",
  1840. __func__);
  1841. return -EINVAL;
  1842. }
  1843. /* Rx BD lengths */
  1844. for (i = 0; i < ug_info->numQueuesRx; i++) {
  1845. if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
  1846. (ug_info->bdRingLenRx[i] %
  1847. UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
  1848. if (netif_msg_probe(ugeth))
  1849. ugeth_err
  1850. ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
  1851. __func__);
  1852. return -EINVAL;
  1853. }
  1854. }
  1855. /* Tx BD lengths */
  1856. for (i = 0; i < ug_info->numQueuesTx; i++) {
  1857. if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
  1858. if (netif_msg_probe(ugeth))
  1859. ugeth_err
  1860. ("%s: Tx BD ring length must be no smaller than 2.",
  1861. __func__);
  1862. return -EINVAL;
  1863. }
  1864. }
  1865. /* mrblr */
  1866. if ((uf_info->max_rx_buf_length == 0) ||
  1867. (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
  1868. if (netif_msg_probe(ugeth))
  1869. ugeth_err
  1870. ("%s: max_rx_buf_length must be non-zero multiple of 128.",
  1871. __func__);
  1872. return -EINVAL;
  1873. }
  1874. /* num Tx queues */
  1875. if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
  1876. if (netif_msg_probe(ugeth))
  1877. ugeth_err("%s: number of tx queues too large.", __func__);
  1878. return -EINVAL;
  1879. }
  1880. /* num Rx queues */
  1881. if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
  1882. if (netif_msg_probe(ugeth))
  1883. ugeth_err("%s: number of rx queues too large.", __func__);
  1884. return -EINVAL;
  1885. }
  1886. /* l2qt */
  1887. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
  1888. if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
  1889. if (netif_msg_probe(ugeth))
  1890. ugeth_err
  1891. ("%s: VLAN priority table entry must not be"
  1892. " larger than number of Rx queues.",
  1893. __func__);
  1894. return -EINVAL;
  1895. }
  1896. }
  1897. /* l3qt */
  1898. for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
  1899. if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
  1900. if (netif_msg_probe(ugeth))
  1901. ugeth_err
  1902. ("%s: IP priority table entry must not be"
  1903. " larger than number of Rx queues.",
  1904. __func__);
  1905. return -EINVAL;
  1906. }
  1907. }
  1908. if (ug_info->cam && !ug_info->ecamptr) {
  1909. if (netif_msg_probe(ugeth))
  1910. ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
  1911. __func__);
  1912. return -EINVAL;
  1913. }
  1914. if ((ug_info->numStationAddresses !=
  1915. UCC_GETH_NUM_OF_STATION_ADDRESSES_1) &&
  1916. ug_info->rxExtendedFiltering) {
  1917. if (netif_msg_probe(ugeth))
  1918. ugeth_err("%s: Number of station addresses greater than 1 "
  1919. "not allowed in extended parsing mode.",
  1920. __func__);
  1921. return -EINVAL;
  1922. }
  1923. /* Generate uccm_mask for receive */
  1924. uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
  1925. for (i = 0; i < ug_info->numQueuesRx; i++)
  1926. uf_info->uccm_mask |= (UCC_GETH_UCCE_RXF0 << i);
  1927. for (i = 0; i < ug_info->numQueuesTx; i++)
  1928. uf_info->uccm_mask |= (UCC_GETH_UCCE_TXB0 << i);
  1929. /* Initialize the general fast UCC block. */
  1930. if (ucc_fast_init(uf_info, &ugeth->uccf)) {
  1931. if (netif_msg_probe(ugeth))
  1932. ugeth_err("%s: Failed to init uccf.", __func__);
  1933. return -ENOMEM;
  1934. }
  1935. /* read the number of risc engines, update the riscTx and riscRx
  1936. * if there are 4 riscs in QE
  1937. */
  1938. if (qe_get_num_of_risc() == 4) {
  1939. ug_info->riscTx = QE_RISC_ALLOCATION_FOUR_RISCS;
  1940. ug_info->riscRx = QE_RISC_ALLOCATION_FOUR_RISCS;
  1941. }
  1942. ugeth->ug_regs = ioremap(uf_info->regs, sizeof(*ugeth->ug_regs));
  1943. if (!ugeth->ug_regs) {
  1944. if (netif_msg_probe(ugeth))
  1945. ugeth_err("%s: Failed to ioremap regs.", __func__);
  1946. return -ENOMEM;
  1947. }
  1948. skb_queue_head_init(&ugeth->rx_recycle);
  1949. return 0;
  1950. }
  1951. static int ucc_geth_startup(struct ucc_geth_private *ugeth)
  1952. {
  1953. struct ucc_geth_82xx_address_filtering_pram __iomem *p_82xx_addr_filt;
  1954. struct ucc_geth_init_pram __iomem *p_init_enet_pram;
  1955. struct ucc_fast_private *uccf;
  1956. struct ucc_geth_info *ug_info;
  1957. struct ucc_fast_info *uf_info;
  1958. struct ucc_fast __iomem *uf_regs;
  1959. struct ucc_geth __iomem *ug_regs;
  1960. int ret_val = -EINVAL;
  1961. u32 remoder = UCC_GETH_REMODER_INIT;
  1962. u32 init_enet_pram_offset, cecr_subblock, command;
  1963. u32 ifstat, i, j, size, l2qt, l3qt, length;
  1964. u16 temoder = UCC_GETH_TEMODER_INIT;
  1965. u16 test;
  1966. u8 function_code = 0;
  1967. u8 __iomem *bd;
  1968. u8 __iomem *endOfRing;
  1969. u8 numThreadsRxNumerical, numThreadsTxNumerical;
  1970. ugeth_vdbg("%s: IN", __func__);
  1971. uccf = ugeth->uccf;
  1972. ug_info = ugeth->ug_info;
  1973. uf_info = &ug_info->uf_info;
  1974. uf_regs = uccf->uf_regs;
  1975. ug_regs = ugeth->ug_regs;
  1976. switch (ug_info->numThreadsRx) {
  1977. case UCC_GETH_NUM_OF_THREADS_1:
  1978. numThreadsRxNumerical = 1;
  1979. break;
  1980. case UCC_GETH_NUM_OF_THREADS_2:
  1981. numThreadsRxNumerical = 2;
  1982. break;
  1983. case UCC_GETH_NUM_OF_THREADS_4:
  1984. numThreadsRxNumerical = 4;
  1985. break;
  1986. case UCC_GETH_NUM_OF_THREADS_6:
  1987. numThreadsRxNumerical = 6;
  1988. break;
  1989. case UCC_GETH_NUM_OF_THREADS_8:
  1990. numThreadsRxNumerical = 8;
  1991. break;
  1992. default:
  1993. if (netif_msg_ifup(ugeth))
  1994. ugeth_err("%s: Bad number of Rx threads value.",
  1995. __func__);
  1996. return -EINVAL;
  1997. break;
  1998. }
  1999. switch (ug_info->numThreadsTx) {
  2000. case UCC_GETH_NUM_OF_THREADS_1:
  2001. numThreadsTxNumerical = 1;
  2002. break;
  2003. case UCC_GETH_NUM_OF_THREADS_2:
  2004. numThreadsTxNumerical = 2;
  2005. break;
  2006. case UCC_GETH_NUM_OF_THREADS_4:
  2007. numThreadsTxNumerical = 4;
  2008. break;
  2009. case UCC_GETH_NUM_OF_THREADS_6:
  2010. numThreadsTxNumerical = 6;
  2011. break;
  2012. case UCC_GETH_NUM_OF_THREADS_8:
  2013. numThreadsTxNumerical = 8;
  2014. break;
  2015. default:
  2016. if (netif_msg_ifup(ugeth))
  2017. ugeth_err("%s: Bad number of Tx threads value.",
  2018. __func__);
  2019. return -EINVAL;
  2020. break;
  2021. }
  2022. /* Calculate rx_extended_features */
  2023. ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
  2024. ug_info->ipAddressAlignment ||
  2025. (ug_info->numStationAddresses !=
  2026. UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
  2027. ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
  2028. (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP) ||
  2029. (ug_info->vlanOperationNonTagged !=
  2030. UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
  2031. init_default_reg_vals(&uf_regs->upsmr,
  2032. &ug_regs->maccfg1, &ug_regs->maccfg2);
  2033. /* Set UPSMR */
  2034. /* For more details see the hardware spec. */
  2035. init_rx_parameters(ug_info->bro,
  2036. ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
  2037. /* We're going to ignore other registers for now, */
  2038. /* except as needed to get up and running */
  2039. /* Set MACCFG1 */
  2040. /* For more details see the hardware spec. */
  2041. init_flow_control_params(ug_info->aufc,
  2042. ug_info->receiveFlowControl,
  2043. ug_info->transmitFlowControl,
  2044. ug_info->pausePeriod,
  2045. ug_info->extensionField,
  2046. &uf_regs->upsmr,
  2047. &ug_regs->uempr, &ug_regs->maccfg1);
  2048. setbits32(&ug_regs->maccfg1, MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
  2049. /* Set IPGIFG */
  2050. /* For more details see the hardware spec. */
  2051. ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
  2052. ug_info->nonBackToBackIfgPart2,
  2053. ug_info->
  2054. miminumInterFrameGapEnforcement,
  2055. ug_info->backToBackInterFrameGap,
  2056. &ug_regs->ipgifg);
  2057. if (ret_val != 0) {
  2058. if (netif_msg_ifup(ugeth))
  2059. ugeth_err("%s: IPGIFG initialization parameter too large.",
  2060. __func__);
  2061. return ret_val;
  2062. }
  2063. /* Set HAFDUP */
  2064. /* For more details see the hardware spec. */
  2065. ret_val = init_half_duplex_params(ug_info->altBeb,
  2066. ug_info->backPressureNoBackoff,
  2067. ug_info->noBackoff,
  2068. ug_info->excessDefer,
  2069. ug_info->altBebTruncation,
  2070. ug_info->maxRetransmission,
  2071. ug_info->collisionWindow,
  2072. &ug_regs->hafdup);
  2073. if (ret_val != 0) {
  2074. if (netif_msg_ifup(ugeth))
  2075. ugeth_err("%s: Half Duplex initialization parameter too large.",
  2076. __func__);
  2077. return ret_val;
  2078. }
  2079. /* Set IFSTAT */
  2080. /* For more details see the hardware spec. */
  2081. /* Read only - resets upon read */
  2082. ifstat = in_be32(&ug_regs->ifstat);
  2083. /* Clear UEMPR */
  2084. /* For more details see the hardware spec. */
  2085. out_be32(&ug_regs->uempr, 0);
  2086. /* Set UESCR */
  2087. /* For more details see the hardware spec. */
  2088. init_hw_statistics_gathering_mode((ug_info->statisticsMode &
  2089. UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
  2090. 0, &uf_regs->upsmr, &ug_regs->uescr);
  2091. /* Allocate Tx bds */
  2092. for (j = 0; j < ug_info->numQueuesTx; j++) {
  2093. /* Allocate in multiple of
  2094. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
  2095. according to spec */
  2096. length = ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd))
  2097. / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  2098. * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  2099. if ((ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)) %
  2100. UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
  2101. length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
  2102. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  2103. u32 align = 4;
  2104. if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
  2105. align = UCC_GETH_TX_BD_RING_ALIGNMENT;
  2106. ugeth->tx_bd_ring_offset[j] =
  2107. (u32) kmalloc((u32) (length + align), GFP_KERNEL);
  2108. if (ugeth->tx_bd_ring_offset[j] != 0)
  2109. ugeth->p_tx_bd_ring[j] =
  2110. (u8 __iomem *)((ugeth->tx_bd_ring_offset[j] +
  2111. align) & ~(align - 1));
  2112. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  2113. ugeth->tx_bd_ring_offset[j] =
  2114. qe_muram_alloc(length,
  2115. UCC_GETH_TX_BD_RING_ALIGNMENT);
  2116. if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
  2117. ugeth->p_tx_bd_ring[j] =
  2118. (u8 __iomem *) qe_muram_addr(ugeth->
  2119. tx_bd_ring_offset[j]);
  2120. }
  2121. if (!ugeth->p_tx_bd_ring[j]) {
  2122. if (netif_msg_ifup(ugeth))
  2123. ugeth_err
  2124. ("%s: Can not allocate memory for Tx bd rings.",
  2125. __func__);
  2126. return -ENOMEM;
  2127. }
  2128. /* Zero unused end of bd ring, according to spec */
  2129. memset_io((void __iomem *)(ugeth->p_tx_bd_ring[j] +
  2130. ug_info->bdRingLenTx[j] * sizeof(struct qe_bd)), 0,
  2131. length - ug_info->bdRingLenTx[j] * sizeof(struct qe_bd));
  2132. }
  2133. /* Allocate Rx bds */
  2134. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2135. length = ug_info->bdRingLenRx[j] * sizeof(struct qe_bd);
  2136. if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
  2137. u32 align = 4;
  2138. if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
  2139. align = UCC_GETH_RX_BD_RING_ALIGNMENT;
  2140. ugeth->rx_bd_ring_offset[j] =
  2141. (u32) kmalloc((u32) (length + align), GFP_KERNEL);
  2142. if (ugeth->rx_bd_ring_offset[j] != 0)
  2143. ugeth->p_rx_bd_ring[j] =
  2144. (u8 __iomem *)((ugeth->rx_bd_ring_offset[j] +
  2145. align) & ~(align - 1));
  2146. } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
  2147. ugeth->rx_bd_ring_offset[j] =
  2148. qe_muram_alloc(length,
  2149. UCC_GETH_RX_BD_RING_ALIGNMENT);
  2150. if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
  2151. ugeth->p_rx_bd_ring[j] =
  2152. (u8 __iomem *) qe_muram_addr(ugeth->
  2153. rx_bd_ring_offset[j]);
  2154. }
  2155. if (!ugeth->p_rx_bd_ring[j]) {
  2156. if (netif_msg_ifup(ugeth))
  2157. ugeth_err
  2158. ("%s: Can not allocate memory for Rx bd rings.",
  2159. __func__);
  2160. return -ENOMEM;
  2161. }
  2162. }
  2163. /* Init Tx bds */
  2164. for (j = 0; j < ug_info->numQueuesTx; j++) {
  2165. /* Setup the skbuff rings */
  2166. ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
  2167. ugeth->ug_info->bdRingLenTx[j],
  2168. GFP_KERNEL);
  2169. if (ugeth->tx_skbuff[j] == NULL) {
  2170. if (netif_msg_ifup(ugeth))
  2171. ugeth_err("%s: Could not allocate tx_skbuff",
  2172. __func__);
  2173. return -ENOMEM;
  2174. }
  2175. for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
  2176. ugeth->tx_skbuff[j][i] = NULL;
  2177. ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
  2178. bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
  2179. for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
  2180. /* clear bd buffer */
  2181. out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
  2182. /* set bd status and length */
  2183. out_be32((u32 __iomem *)bd, 0);
  2184. bd += sizeof(struct qe_bd);
  2185. }
  2186. bd -= sizeof(struct qe_bd);
  2187. /* set bd status and length */
  2188. out_be32((u32 __iomem *)bd, T_W); /* for last BD set Wrap bit */
  2189. }
  2190. /* Init Rx bds */
  2191. for (j = 0; j < ug_info->numQueuesRx; j++) {
  2192. /* Setup the skbuff rings */
  2193. ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
  2194. ugeth->ug_info->bdRingLenRx[j],
  2195. GFP_KERNEL);
  2196. if (ugeth->rx_skbuff[j] == NULL) {
  2197. if (netif_msg_ifup(ugeth))
  2198. ugeth_err("%s: Could not allocate rx_skbuff",
  2199. __func__);
  2200. return -ENOMEM;
  2201. }
  2202. for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
  2203. ugeth->rx_skbuff[j][i] = NULL;
  2204. ugeth->skb_currx[j] = 0;
  2205. bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
  2206. for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
  2207. /* set bd status and length */
  2208. out_be32((u32 __iomem *)bd, R_I);
  2209. /* clear bd buffer */
  2210. out_be32(&((struct qe_bd __iomem *)bd)->buf, 0);
  2211. bd += sizeof(struct qe_bd);
  2212. }
  2213. bd -= sizeof(struct qe_bd);
  2214. /* set bd status and length */
  2215. out_be32((u32 __iomem *)bd, R_W); /* for last BD set Wrap bit */
  2216. }
  2217. /*
  2218. * Global PRAM
  2219. */
  2220. /* Tx global PRAM */
  2221. /* Allocate global tx parameter RAM page */
  2222. ugeth->tx_glbl_pram_offset =
  2223. qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
  2224. UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
  2225. if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
  2226. if (netif_msg_ifup(ugeth))
  2227. ugeth_err
  2228. ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
  2229. __func__);
  2230. return -ENOMEM;
  2231. }
  2232. ugeth->p_tx_glbl_pram =
  2233. (struct ucc_geth_tx_global_pram __iomem *) qe_muram_addr(ugeth->
  2234. tx_glbl_pram_offset);
  2235. /* Zero out p_tx_glbl_pram */
  2236. memset_io((void __iomem *)ugeth->p_tx_glbl_pram, 0, sizeof(struct ucc_geth_tx_global_pram));
  2237. /* Fill global PRAM */
  2238. /* TQPTR */
  2239. /* Size varies with number of Tx threads */
  2240. ugeth->thread_dat_tx_offset =
  2241. qe_muram_alloc(numThreadsTxNumerical *
  2242. sizeof(struct ucc_geth_thread_data_tx) +
  2243. 32 * (numThreadsTxNumerical == 1),
  2244. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2245. if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
  2246. if (netif_msg_ifup(ugeth))
  2247. ugeth_err
  2248. ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
  2249. __func__);
  2250. return -ENOMEM;
  2251. }
  2252. ugeth->p_thread_data_tx =
  2253. (struct ucc_geth_thread_data_tx __iomem *) qe_muram_addr(ugeth->
  2254. thread_dat_tx_offset);
  2255. out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
  2256. /* vtagtable */
  2257. for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
  2258. out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
  2259. ug_info->vtagtable[i]);
  2260. /* iphoffset */
  2261. for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
  2262. out_8(&ugeth->p_tx_glbl_pram->iphoffset[i],
  2263. ug_info->iphoffset[i]);
  2264. /* SQPTR */
  2265. /* Size varies with number of Tx queues */
  2266. ugeth->send_q_mem_reg_offset =
  2267. qe_muram_alloc(ug_info->numQueuesTx *
  2268. sizeof(struct ucc_geth_send_queue_qd),
  2269. UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
  2270. if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
  2271. if (netif_msg_ifup(ugeth))
  2272. ugeth_err
  2273. ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
  2274. __func__);
  2275. return -ENOMEM;
  2276. }
  2277. ugeth->p_send_q_mem_reg =
  2278. (struct ucc_geth_send_queue_mem_region __iomem *) qe_muram_addr(ugeth->
  2279. send_q_mem_reg_offset);
  2280. out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
  2281. /* Setup the table */
  2282. /* Assume BD rings are already established */
  2283. for (i = 0; i < ug_info->numQueuesTx; i++) {
  2284. endOfRing =
  2285. ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
  2286. 1) * sizeof(struct qe_bd);
  2287. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2288. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2289. (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
  2290. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2291. last_bd_completed_address,
  2292. (u32) virt_to_phys(endOfRing));
  2293. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2294. MEM_PART_MURAM) {
  2295. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
  2296. (u32) immrbar_virt_to_phys(ugeth->
  2297. p_tx_bd_ring[i]));
  2298. out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
  2299. last_bd_completed_address,
  2300. (u32) immrbar_virt_to_phys(endOfRing));
  2301. }
  2302. }
  2303. /* schedulerbasepointer */
  2304. if (ug_info->numQueuesTx > 1) {
  2305. /* scheduler exists only if more than 1 tx queue */
  2306. ugeth->scheduler_offset =
  2307. qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
  2308. UCC_GETH_SCHEDULER_ALIGNMENT);
  2309. if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
  2310. if (netif_msg_ifup(ugeth))
  2311. ugeth_err
  2312. ("%s: Can not allocate DPRAM memory for p_scheduler.",
  2313. __func__);
  2314. return -ENOMEM;
  2315. }
  2316. ugeth->p_scheduler =
  2317. (struct ucc_geth_scheduler __iomem *) qe_muram_addr(ugeth->
  2318. scheduler_offset);
  2319. out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
  2320. ugeth->scheduler_offset);
  2321. /* Zero out p_scheduler */
  2322. memset_io((void __iomem *)ugeth->p_scheduler, 0, sizeof(struct ucc_geth_scheduler));
  2323. /* Set values in scheduler */
  2324. out_be32(&ugeth->p_scheduler->mblinterval,
  2325. ug_info->mblinterval);
  2326. out_be16(&ugeth->p_scheduler->nortsrbytetime,
  2327. ug_info->nortsrbytetime);
  2328. out_8(&ugeth->p_scheduler->fracsiz, ug_info->fracsiz);
  2329. out_8(&ugeth->p_scheduler->strictpriorityq,
  2330. ug_info->strictpriorityq);
  2331. out_8(&ugeth->p_scheduler->txasap, ug_info->txasap);
  2332. out_8(&ugeth->p_scheduler->extrabw, ug_info->extrabw);
  2333. for (i = 0; i < NUM_TX_QUEUES; i++)
  2334. out_8(&ugeth->p_scheduler->weightfactor[i],
  2335. ug_info->weightfactor[i]);
  2336. /* Set pointers to cpucount registers in scheduler */
  2337. ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
  2338. ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
  2339. ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
  2340. ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
  2341. ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
  2342. ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
  2343. ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
  2344. ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
  2345. }
  2346. /* schedulerbasepointer */
  2347. /* TxRMON_PTR (statistics) */
  2348. if (ug_info->
  2349. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  2350. ugeth->tx_fw_statistics_pram_offset =
  2351. qe_muram_alloc(sizeof
  2352. (struct ucc_geth_tx_firmware_statistics_pram),
  2353. UCC_GETH_TX_STATISTICS_ALIGNMENT);
  2354. if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
  2355. if (netif_msg_ifup(ugeth))
  2356. ugeth_err
  2357. ("%s: Can not allocate DPRAM memory for"
  2358. " p_tx_fw_statistics_pram.",
  2359. __func__);
  2360. return -ENOMEM;
  2361. }
  2362. ugeth->p_tx_fw_statistics_pram =
  2363. (struct ucc_geth_tx_firmware_statistics_pram __iomem *)
  2364. qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
  2365. /* Zero out p_tx_fw_statistics_pram */
  2366. memset_io((void __iomem *)ugeth->p_tx_fw_statistics_pram,
  2367. 0, sizeof(struct ucc_geth_tx_firmware_statistics_pram));
  2368. }
  2369. /* temoder */
  2370. /* Already has speed set */
  2371. if (ug_info->numQueuesTx > 1)
  2372. temoder |= TEMODER_SCHEDULER_ENABLE;
  2373. if (ug_info->ipCheckSumGenerate)
  2374. temoder |= TEMODER_IP_CHECKSUM_GENERATE;
  2375. temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
  2376. out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
  2377. test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
  2378. /* Function code register value to be used later */
  2379. function_code = UCC_BMR_BO_BE | UCC_BMR_GBL;
  2380. /* Required for QE */
  2381. /* function code register */
  2382. out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
  2383. /* Rx global PRAM */
  2384. /* Allocate global rx parameter RAM page */
  2385. ugeth->rx_glbl_pram_offset =
  2386. qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
  2387. UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
  2388. if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
  2389. if (netif_msg_ifup(ugeth))
  2390. ugeth_err
  2391. ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
  2392. __func__);
  2393. return -ENOMEM;
  2394. }
  2395. ugeth->p_rx_glbl_pram =
  2396. (struct ucc_geth_rx_global_pram __iomem *) qe_muram_addr(ugeth->
  2397. rx_glbl_pram_offset);
  2398. /* Zero out p_rx_glbl_pram */
  2399. memset_io((void __iomem *)ugeth->p_rx_glbl_pram, 0, sizeof(struct ucc_geth_rx_global_pram));
  2400. /* Fill global PRAM */
  2401. /* RQPTR */
  2402. /* Size varies with number of Rx threads */
  2403. ugeth->thread_dat_rx_offset =
  2404. qe_muram_alloc(numThreadsRxNumerical *
  2405. sizeof(struct ucc_geth_thread_data_rx),
  2406. UCC_GETH_THREAD_DATA_ALIGNMENT);
  2407. if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
  2408. if (netif_msg_ifup(ugeth))
  2409. ugeth_err
  2410. ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
  2411. __func__);
  2412. return -ENOMEM;
  2413. }
  2414. ugeth->p_thread_data_rx =
  2415. (struct ucc_geth_thread_data_rx __iomem *) qe_muram_addr(ugeth->
  2416. thread_dat_rx_offset);
  2417. out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
  2418. /* typeorlen */
  2419. out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
  2420. /* rxrmonbaseptr (statistics) */
  2421. if (ug_info->
  2422. statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
  2423. ugeth->rx_fw_statistics_pram_offset =
  2424. qe_muram_alloc(sizeof
  2425. (struct ucc_geth_rx_firmware_statistics_pram),
  2426. UCC_GETH_RX_STATISTICS_ALIGNMENT);
  2427. if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
  2428. if (netif_msg_ifup(ugeth))
  2429. ugeth_err
  2430. ("%s: Can not allocate DPRAM memory for"
  2431. " p_rx_fw_statistics_pram.", __func__);
  2432. return -ENOMEM;
  2433. }
  2434. ugeth->p_rx_fw_statistics_pram =
  2435. (struct ucc_geth_rx_firmware_statistics_pram __iomem *)
  2436. qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
  2437. /* Zero out p_rx_fw_statistics_pram */
  2438. memset_io((void __iomem *)ugeth->p_rx_fw_statistics_pram, 0,
  2439. sizeof(struct ucc_geth_rx_firmware_statistics_pram));
  2440. }
  2441. /* intCoalescingPtr */
  2442. /* Size varies with number of Rx queues */
  2443. ugeth->rx_irq_coalescing_tbl_offset =
  2444. qe_muram_alloc(ug_info->numQueuesRx *
  2445. sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
  2446. + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
  2447. if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
  2448. if (netif_msg_ifup(ugeth))
  2449. ugeth_err
  2450. ("%s: Can not allocate DPRAM memory for"
  2451. " p_rx_irq_coalescing_tbl.", __func__);
  2452. return -ENOMEM;
  2453. }
  2454. ugeth->p_rx_irq_coalescing_tbl =
  2455. (struct ucc_geth_rx_interrupt_coalescing_table __iomem *)
  2456. qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
  2457. out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
  2458. ugeth->rx_irq_coalescing_tbl_offset);
  2459. /* Fill interrupt coalescing table */
  2460. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2461. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2462. interruptcoalescingmaxvalue,
  2463. ug_info->interruptcoalescingmaxvalue[i]);
  2464. out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
  2465. interruptcoalescingcounter,
  2466. ug_info->interruptcoalescingmaxvalue[i]);
  2467. }
  2468. /* MRBLR */
  2469. init_max_rx_buff_len(uf_info->max_rx_buf_length,
  2470. &ugeth->p_rx_glbl_pram->mrblr);
  2471. /* MFLR */
  2472. out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
  2473. /* MINFLR */
  2474. init_min_frame_len(ug_info->minFrameLength,
  2475. &ugeth->p_rx_glbl_pram->minflr,
  2476. &ugeth->p_rx_glbl_pram->mrblr);
  2477. /* MAXD1 */
  2478. out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
  2479. /* MAXD2 */
  2480. out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
  2481. /* l2qt */
  2482. l2qt = 0;
  2483. for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
  2484. l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
  2485. out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
  2486. /* l3qt */
  2487. for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
  2488. l3qt = 0;
  2489. for (i = 0; i < 8; i++)
  2490. l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
  2491. out_be32(&ugeth->p_rx_glbl_pram->l3qt[j/8], l3qt);
  2492. }
  2493. /* vlantype */
  2494. out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
  2495. /* vlantci */
  2496. out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
  2497. /* ecamptr */
  2498. out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
  2499. /* RBDQPTR */
  2500. /* Size varies with number of Rx queues */
  2501. ugeth->rx_bd_qs_tbl_offset =
  2502. qe_muram_alloc(ug_info->numQueuesRx *
  2503. (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2504. sizeof(struct ucc_geth_rx_prefetched_bds)),
  2505. UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
  2506. if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
  2507. if (netif_msg_ifup(ugeth))
  2508. ugeth_err
  2509. ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
  2510. __func__);
  2511. return -ENOMEM;
  2512. }
  2513. ugeth->p_rx_bd_qs_tbl =
  2514. (struct ucc_geth_rx_bd_queues_entry __iomem *) qe_muram_addr(ugeth->
  2515. rx_bd_qs_tbl_offset);
  2516. out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
  2517. /* Zero out p_rx_bd_qs_tbl */
  2518. memset_io((void __iomem *)ugeth->p_rx_bd_qs_tbl,
  2519. 0,
  2520. ug_info->numQueuesRx * (sizeof(struct ucc_geth_rx_bd_queues_entry) +
  2521. sizeof(struct ucc_geth_rx_prefetched_bds)));
  2522. /* Setup the table */
  2523. /* Assume BD rings are already established */
  2524. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2525. if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
  2526. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2527. (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
  2528. } else if (ugeth->ug_info->uf_info.bd_mem_part ==
  2529. MEM_PART_MURAM) {
  2530. out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
  2531. (u32) immrbar_virt_to_phys(ugeth->
  2532. p_rx_bd_ring[i]));
  2533. }
  2534. /* rest of fields handled by QE */
  2535. }
  2536. /* remoder */
  2537. /* Already has speed set */
  2538. if (ugeth->rx_extended_features)
  2539. remoder |= REMODER_RX_EXTENDED_FEATURES;
  2540. if (ug_info->rxExtendedFiltering)
  2541. remoder |= REMODER_RX_EXTENDED_FILTERING;
  2542. if (ug_info->dynamicMaxFrameLength)
  2543. remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
  2544. if (ug_info->dynamicMinFrameLength)
  2545. remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
  2546. remoder |=
  2547. ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
  2548. remoder |=
  2549. ug_info->
  2550. vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
  2551. remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
  2552. remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
  2553. if (ug_info->ipCheckSumCheck)
  2554. remoder |= REMODER_IP_CHECKSUM_CHECK;
  2555. if (ug_info->ipAddressAlignment)
  2556. remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
  2557. out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
  2558. /* Note that this function must be called */
  2559. /* ONLY AFTER p_tx_fw_statistics_pram */
  2560. /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
  2561. init_firmware_statistics_gathering_mode((ug_info->
  2562. statisticsMode &
  2563. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
  2564. (ug_info->statisticsMode &
  2565. UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
  2566. &ugeth->p_tx_glbl_pram->txrmonbaseptr,
  2567. ugeth->tx_fw_statistics_pram_offset,
  2568. &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
  2569. ugeth->rx_fw_statistics_pram_offset,
  2570. &ugeth->p_tx_glbl_pram->temoder,
  2571. &ugeth->p_rx_glbl_pram->remoder);
  2572. /* function code register */
  2573. out_8(&ugeth->p_rx_glbl_pram->rstate, function_code);
  2574. /* initialize extended filtering */
  2575. if (ug_info->rxExtendedFiltering) {
  2576. if (!ug_info->extendedFilteringChainPointer) {
  2577. if (netif_msg_ifup(ugeth))
  2578. ugeth_err("%s: Null Extended Filtering Chain Pointer.",
  2579. __func__);
  2580. return -EINVAL;
  2581. }
  2582. /* Allocate memory for extended filtering Mode Global
  2583. Parameters */
  2584. ugeth->exf_glbl_param_offset =
  2585. qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
  2586. UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
  2587. if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
  2588. if (netif_msg_ifup(ugeth))
  2589. ugeth_err
  2590. ("%s: Can not allocate DPRAM memory for"
  2591. " p_exf_glbl_param.", __func__);
  2592. return -ENOMEM;
  2593. }
  2594. ugeth->p_exf_glbl_param =
  2595. (struct ucc_geth_exf_global_pram __iomem *) qe_muram_addr(ugeth->
  2596. exf_glbl_param_offset);
  2597. out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
  2598. ugeth->exf_glbl_param_offset);
  2599. out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
  2600. (u32) ug_info->extendedFilteringChainPointer);
  2601. } else { /* initialize 82xx style address filtering */
  2602. /* Init individual address recognition registers to disabled */
  2603. for (j = 0; j < NUM_OF_PADDRS; j++)
  2604. ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
  2605. p_82xx_addr_filt =
  2606. (struct ucc_geth_82xx_address_filtering_pram __iomem *) ugeth->
  2607. p_rx_glbl_pram->addressfiltering;
  2608. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  2609. ENET_ADDR_TYPE_GROUP);
  2610. ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
  2611. ENET_ADDR_TYPE_INDIVIDUAL);
  2612. }
  2613. /*
  2614. * Initialize UCC at QE level
  2615. */
  2616. command = QE_INIT_TX_RX;
  2617. /* Allocate shadow InitEnet command parameter structure.
  2618. * This is needed because after the InitEnet command is executed,
  2619. * the structure in DPRAM is released, because DPRAM is a premium
  2620. * resource.
  2621. * This shadow structure keeps a copy of what was done so that the
  2622. * allocated resources can be released when the channel is freed.
  2623. */
  2624. if (!(ugeth->p_init_enet_param_shadow =
  2625. kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
  2626. if (netif_msg_ifup(ugeth))
  2627. ugeth_err
  2628. ("%s: Can not allocate memory for"
  2629. " p_UccInitEnetParamShadows.", __func__);
  2630. return -ENOMEM;
  2631. }
  2632. /* Zero out *p_init_enet_param_shadow */
  2633. memset((char *)ugeth->p_init_enet_param_shadow,
  2634. 0, sizeof(struct ucc_geth_init_pram));
  2635. /* Fill shadow InitEnet command parameter structure */
  2636. ugeth->p_init_enet_param_shadow->resinit1 =
  2637. ENET_INIT_PARAM_MAGIC_RES_INIT1;
  2638. ugeth->p_init_enet_param_shadow->resinit2 =
  2639. ENET_INIT_PARAM_MAGIC_RES_INIT2;
  2640. ugeth->p_init_enet_param_shadow->resinit3 =
  2641. ENET_INIT_PARAM_MAGIC_RES_INIT3;
  2642. ugeth->p_init_enet_param_shadow->resinit4 =
  2643. ENET_INIT_PARAM_MAGIC_RES_INIT4;
  2644. ugeth->p_init_enet_param_shadow->resinit5 =
  2645. ENET_INIT_PARAM_MAGIC_RES_INIT5;
  2646. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2647. ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
  2648. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2649. ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
  2650. ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
  2651. ugeth->rx_glbl_pram_offset | ug_info->riscRx;
  2652. if ((ug_info->largestexternallookupkeysize !=
  2653. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE) &&
  2654. (ug_info->largestexternallookupkeysize !=
  2655. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES) &&
  2656. (ug_info->largestexternallookupkeysize !=
  2657. QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
  2658. if (netif_msg_ifup(ugeth))
  2659. ugeth_err("%s: Invalid largest External Lookup Key Size.",
  2660. __func__);
  2661. return -EINVAL;
  2662. }
  2663. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
  2664. ug_info->largestexternallookupkeysize;
  2665. size = sizeof(struct ucc_geth_thread_rx_pram);
  2666. if (ug_info->rxExtendedFiltering) {
  2667. size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
  2668. if (ug_info->largestexternallookupkeysize ==
  2669. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
  2670. size +=
  2671. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
  2672. if (ug_info->largestexternallookupkeysize ==
  2673. QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
  2674. size +=
  2675. THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
  2676. }
  2677. if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
  2678. p_init_enet_param_shadow->rxthread[0]),
  2679. (u8) (numThreadsRxNumerical + 1)
  2680. /* Rx needs one extra for terminator */
  2681. , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
  2682. ug_info->riscRx, 1)) != 0) {
  2683. if (netif_msg_ifup(ugeth))
  2684. ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
  2685. __func__);
  2686. return ret_val;
  2687. }
  2688. ugeth->p_init_enet_param_shadow->txglobal =
  2689. ugeth->tx_glbl_pram_offset | ug_info->riscTx;
  2690. if ((ret_val =
  2691. fill_init_enet_entries(ugeth,
  2692. &(ugeth->p_init_enet_param_shadow->
  2693. txthread[0]), numThreadsTxNumerical,
  2694. sizeof(struct ucc_geth_thread_tx_pram),
  2695. UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
  2696. ug_info->riscTx, 0)) != 0) {
  2697. if (netif_msg_ifup(ugeth))
  2698. ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
  2699. __func__);
  2700. return ret_val;
  2701. }
  2702. /* Load Rx bds with buffers */
  2703. for (i = 0; i < ug_info->numQueuesRx; i++) {
  2704. if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
  2705. if (netif_msg_ifup(ugeth))
  2706. ugeth_err("%s: Can not fill Rx bds with buffers.",
  2707. __func__);
  2708. return ret_val;
  2709. }
  2710. }
  2711. /* Allocate InitEnet command parameter structure */
  2712. init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
  2713. if (IS_ERR_VALUE(init_enet_pram_offset)) {
  2714. if (netif_msg_ifup(ugeth))
  2715. ugeth_err
  2716. ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
  2717. __func__);
  2718. return -ENOMEM;
  2719. }
  2720. p_init_enet_pram =
  2721. (struct ucc_geth_init_pram __iomem *) qe_muram_addr(init_enet_pram_offset);
  2722. /* Copy shadow InitEnet command parameter structure into PRAM */
  2723. out_8(&p_init_enet_pram->resinit1,
  2724. ugeth->p_init_enet_param_shadow->resinit1);
  2725. out_8(&p_init_enet_pram->resinit2,
  2726. ugeth->p_init_enet_param_shadow->resinit2);
  2727. out_8(&p_init_enet_pram->resinit3,
  2728. ugeth->p_init_enet_param_shadow->resinit3);
  2729. out_8(&p_init_enet_pram->resinit4,
  2730. ugeth->p_init_enet_param_shadow->resinit4);
  2731. out_be16(&p_init_enet_pram->resinit5,
  2732. ugeth->p_init_enet_param_shadow->resinit5);
  2733. out_8(&p_init_enet_pram->largestexternallookupkeysize,
  2734. ugeth->p_init_enet_param_shadow->largestexternallookupkeysize);
  2735. out_be32(&p_init_enet_pram->rgftgfrxglobal,
  2736. ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
  2737. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
  2738. out_be32(&p_init_enet_pram->rxthread[i],
  2739. ugeth->p_init_enet_param_shadow->rxthread[i]);
  2740. out_be32(&p_init_enet_pram->txglobal,
  2741. ugeth->p_init_enet_param_shadow->txglobal);
  2742. for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
  2743. out_be32(&p_init_enet_pram->txthread[i],
  2744. ugeth->p_init_enet_param_shadow->txthread[i]);
  2745. /* Issue QE command */
  2746. cecr_subblock =
  2747. ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
  2748. qe_issue_cmd(command, cecr_subblock, QE_CR_PROTOCOL_ETHERNET,
  2749. init_enet_pram_offset);
  2750. /* Free InitEnet command parameter */
  2751. qe_muram_free(init_enet_pram_offset);
  2752. return 0;
  2753. }
  2754. /* This is called by the kernel when a frame is ready for transmission. */
  2755. /* It is pointed to by the dev->hard_start_xmit function pointer */
  2756. static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2757. {
  2758. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2759. #ifdef CONFIG_UGETH_TX_ON_DEMAND
  2760. struct ucc_fast_private *uccf;
  2761. #endif
  2762. u8 __iomem *bd; /* BD pointer */
  2763. u32 bd_status;
  2764. u8 txQ = 0;
  2765. unsigned long flags;
  2766. ugeth_vdbg("%s: IN", __func__);
  2767. spin_lock_irqsave(&ugeth->lock, flags);
  2768. dev->stats.tx_bytes += skb->len;
  2769. /* Start from the next BD that should be filled */
  2770. bd = ugeth->txBd[txQ];
  2771. bd_status = in_be32((u32 __iomem *)bd);
  2772. /* Save the skb pointer so we can free it later */
  2773. ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
  2774. /* Update the current skb pointer (wrapping if this was the last) */
  2775. ugeth->skb_curtx[txQ] =
  2776. (ugeth->skb_curtx[txQ] +
  2777. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  2778. /* set up the buffer descriptor */
  2779. out_be32(&((struct qe_bd __iomem *)bd)->buf,
  2780. dma_map_single(ugeth->dev, skb->data,
  2781. skb->len, DMA_TO_DEVICE));
  2782. /* printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data); */
  2783. bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
  2784. /* set bd status and length */
  2785. out_be32((u32 __iomem *)bd, bd_status);
  2786. /* Move to next BD in the ring */
  2787. if (!(bd_status & T_W))
  2788. bd += sizeof(struct qe_bd);
  2789. else
  2790. bd = ugeth->p_tx_bd_ring[txQ];
  2791. /* If the next BD still needs to be cleaned up, then the bds
  2792. are full. We need to tell the kernel to stop sending us stuff. */
  2793. if (bd == ugeth->confBd[txQ]) {
  2794. if (!netif_queue_stopped(dev))
  2795. netif_stop_queue(dev);
  2796. }
  2797. ugeth->txBd[txQ] = bd;
  2798. skb_tx_timestamp(skb);
  2799. if (ugeth->p_scheduler) {
  2800. ugeth->cpucount[txQ]++;
  2801. /* Indicate to QE that there are more Tx bds ready for
  2802. transmission */
  2803. /* This is done by writing a running counter of the bd
  2804. count to the scheduler PRAM. */
  2805. out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
  2806. }
  2807. #ifdef CONFIG_UGETH_TX_ON_DEMAND
  2808. uccf = ugeth->uccf;
  2809. out_be16(uccf->p_utodr, UCC_FAST_TOD);
  2810. #endif
  2811. spin_unlock_irqrestore(&ugeth->lock, flags);
  2812. return NETDEV_TX_OK;
  2813. }
  2814. static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
  2815. {
  2816. struct sk_buff *skb;
  2817. u8 __iomem *bd;
  2818. u16 length, howmany = 0;
  2819. u32 bd_status;
  2820. u8 *bdBuffer;
  2821. struct net_device *dev;
  2822. ugeth_vdbg("%s: IN", __func__);
  2823. dev = ugeth->ndev;
  2824. /* collect received buffers */
  2825. bd = ugeth->rxBd[rxQ];
  2826. bd_status = in_be32((u32 __iomem *)bd);
  2827. /* while there are received buffers and BD is full (~R_E) */
  2828. while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
  2829. bdBuffer = (u8 *) in_be32(&((struct qe_bd __iomem *)bd)->buf);
  2830. length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
  2831. skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
  2832. /* determine whether buffer is first, last, first and last
  2833. (single buffer frame) or middle (not first and not last) */
  2834. if (!skb ||
  2835. (!(bd_status & (R_F | R_L))) ||
  2836. (bd_status & R_ERRORS_FATAL)) {
  2837. if (netif_msg_rx_err(ugeth))
  2838. ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
  2839. __func__, __LINE__, (u32) skb);
  2840. if (skb) {
  2841. skb->data = skb->head + NET_SKB_PAD;
  2842. skb->len = 0;
  2843. skb_reset_tail_pointer(skb);
  2844. __skb_queue_head(&ugeth->rx_recycle, skb);
  2845. }
  2846. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
  2847. dev->stats.rx_dropped++;
  2848. } else {
  2849. dev->stats.rx_packets++;
  2850. howmany++;
  2851. /* Prep the skb for the packet */
  2852. skb_put(skb, length);
  2853. /* Tell the skb what kind of packet this is */
  2854. skb->protocol = eth_type_trans(skb, ugeth->ndev);
  2855. dev->stats.rx_bytes += length;
  2856. /* Send the packet up the stack */
  2857. netif_receive_skb(skb);
  2858. }
  2859. skb = get_new_skb(ugeth, bd);
  2860. if (!skb) {
  2861. if (netif_msg_rx_err(ugeth))
  2862. ugeth_warn("%s: No Rx Data Buffer", __func__);
  2863. dev->stats.rx_dropped++;
  2864. break;
  2865. }
  2866. ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
  2867. /* update to point at the next skb */
  2868. ugeth->skb_currx[rxQ] =
  2869. (ugeth->skb_currx[rxQ] +
  2870. 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
  2871. if (bd_status & R_W)
  2872. bd = ugeth->p_rx_bd_ring[rxQ];
  2873. else
  2874. bd += sizeof(struct qe_bd);
  2875. bd_status = in_be32((u32 __iomem *)bd);
  2876. }
  2877. ugeth->rxBd[rxQ] = bd;
  2878. return howmany;
  2879. }
  2880. static int ucc_geth_tx(struct net_device *dev, u8 txQ)
  2881. {
  2882. /* Start from the next BD that should be filled */
  2883. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2884. u8 __iomem *bd; /* BD pointer */
  2885. u32 bd_status;
  2886. bd = ugeth->confBd[txQ];
  2887. bd_status = in_be32((u32 __iomem *)bd);
  2888. /* Normal processing. */
  2889. while ((bd_status & T_R) == 0) {
  2890. struct sk_buff *skb;
  2891. /* BD contains already transmitted buffer. */
  2892. /* Handle the transmitted buffer and release */
  2893. /* the BD to be used with the current frame */
  2894. skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]];
  2895. if (!skb)
  2896. break;
  2897. dev->stats.tx_packets++;
  2898. if (skb_queue_len(&ugeth->rx_recycle) < RX_BD_RING_LEN &&
  2899. skb_recycle_check(skb,
  2900. ugeth->ug_info->uf_info.max_rx_buf_length +
  2901. UCC_GETH_RX_DATA_BUF_ALIGNMENT))
  2902. __skb_queue_head(&ugeth->rx_recycle, skb);
  2903. else
  2904. dev_kfree_skb(skb);
  2905. ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
  2906. ugeth->skb_dirtytx[txQ] =
  2907. (ugeth->skb_dirtytx[txQ] +
  2908. 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
  2909. /* We freed a buffer, so now we can restart transmission */
  2910. if (netif_queue_stopped(dev))
  2911. netif_wake_queue(dev);
  2912. /* Advance the confirmation BD pointer */
  2913. if (!(bd_status & T_W))
  2914. bd += sizeof(struct qe_bd);
  2915. else
  2916. bd = ugeth->p_tx_bd_ring[txQ];
  2917. bd_status = in_be32((u32 __iomem *)bd);
  2918. }
  2919. ugeth->confBd[txQ] = bd;
  2920. return 0;
  2921. }
  2922. static int ucc_geth_poll(struct napi_struct *napi, int budget)
  2923. {
  2924. struct ucc_geth_private *ugeth = container_of(napi, struct ucc_geth_private, napi);
  2925. struct ucc_geth_info *ug_info;
  2926. int howmany, i;
  2927. ug_info = ugeth->ug_info;
  2928. /* Tx event processing */
  2929. spin_lock(&ugeth->lock);
  2930. for (i = 0; i < ug_info->numQueuesTx; i++)
  2931. ucc_geth_tx(ugeth->ndev, i);
  2932. spin_unlock(&ugeth->lock);
  2933. howmany = 0;
  2934. for (i = 0; i < ug_info->numQueuesRx; i++)
  2935. howmany += ucc_geth_rx(ugeth, i, budget - howmany);
  2936. if (howmany < budget) {
  2937. napi_complete(napi);
  2938. setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS);
  2939. }
  2940. return howmany;
  2941. }
  2942. static irqreturn_t ucc_geth_irq_handler(int irq, void *info)
  2943. {
  2944. struct net_device *dev = info;
  2945. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2946. struct ucc_fast_private *uccf;
  2947. struct ucc_geth_info *ug_info;
  2948. register u32 ucce;
  2949. register u32 uccm;
  2950. ugeth_vdbg("%s: IN", __func__);
  2951. uccf = ugeth->uccf;
  2952. ug_info = ugeth->ug_info;
  2953. /* read and clear events */
  2954. ucce = (u32) in_be32(uccf->p_ucce);
  2955. uccm = (u32) in_be32(uccf->p_uccm);
  2956. ucce &= uccm;
  2957. out_be32(uccf->p_ucce, ucce);
  2958. /* check for receive events that require processing */
  2959. if (ucce & (UCCE_RX_EVENTS | UCCE_TX_EVENTS)) {
  2960. if (napi_schedule_prep(&ugeth->napi)) {
  2961. uccm &= ~(UCCE_RX_EVENTS | UCCE_TX_EVENTS);
  2962. out_be32(uccf->p_uccm, uccm);
  2963. __napi_schedule(&ugeth->napi);
  2964. }
  2965. }
  2966. /* Errors and other events */
  2967. if (ucce & UCCE_OTHER) {
  2968. if (ucce & UCC_GETH_UCCE_BSY)
  2969. dev->stats.rx_errors++;
  2970. if (ucce & UCC_GETH_UCCE_TXE)
  2971. dev->stats.tx_errors++;
  2972. }
  2973. return IRQ_HANDLED;
  2974. }
  2975. #ifdef CONFIG_NET_POLL_CONTROLLER
  2976. /*
  2977. * Polling 'interrupt' - used by things like netconsole to send skbs
  2978. * without having to re-enable interrupts. It's not called while
  2979. * the interrupt routine is executing.
  2980. */
  2981. static void ucc_netpoll(struct net_device *dev)
  2982. {
  2983. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2984. int irq = ugeth->ug_info->uf_info.irq;
  2985. disable_irq(irq);
  2986. ucc_geth_irq_handler(irq, dev);
  2987. enable_irq(irq);
  2988. }
  2989. #endif /* CONFIG_NET_POLL_CONTROLLER */
  2990. static int ucc_geth_set_mac_addr(struct net_device *dev, void *p)
  2991. {
  2992. struct ucc_geth_private *ugeth = netdev_priv(dev);
  2993. struct sockaddr *addr = p;
  2994. if (!is_valid_ether_addr(addr->sa_data))
  2995. return -EADDRNOTAVAIL;
  2996. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2997. /*
  2998. * If device is not running, we will set mac addr register
  2999. * when opening the device.
  3000. */
  3001. if (!netif_running(dev))
  3002. return 0;
  3003. spin_lock_irq(&ugeth->lock);
  3004. init_mac_station_addr_regs(dev->dev_addr[0],
  3005. dev->dev_addr[1],
  3006. dev->dev_addr[2],
  3007. dev->dev_addr[3],
  3008. dev->dev_addr[4],
  3009. dev->dev_addr[5],
  3010. &ugeth->ug_regs->macstnaddr1,
  3011. &ugeth->ug_regs->macstnaddr2);
  3012. spin_unlock_irq(&ugeth->lock);
  3013. return 0;
  3014. }
  3015. static int ucc_geth_init_mac(struct ucc_geth_private *ugeth)
  3016. {
  3017. struct net_device *dev = ugeth->ndev;
  3018. int err;
  3019. err = ucc_struct_init(ugeth);
  3020. if (err) {
  3021. if (netif_msg_ifup(ugeth))
  3022. ugeth_err("%s: Cannot configure internal struct, "
  3023. "aborting.", dev->name);
  3024. goto err;
  3025. }
  3026. err = ucc_geth_startup(ugeth);
  3027. if (err) {
  3028. if (netif_msg_ifup(ugeth))
  3029. ugeth_err("%s: Cannot configure net device, aborting.",
  3030. dev->name);
  3031. goto err;
  3032. }
  3033. err = adjust_enet_interface(ugeth);
  3034. if (err) {
  3035. if (netif_msg_ifup(ugeth))
  3036. ugeth_err("%s: Cannot configure net device, aborting.",
  3037. dev->name);
  3038. goto err;
  3039. }
  3040. /* Set MACSTNADDR1, MACSTNADDR2 */
  3041. /* For more details see the hardware spec. */
  3042. init_mac_station_addr_regs(dev->dev_addr[0],
  3043. dev->dev_addr[1],
  3044. dev->dev_addr[2],
  3045. dev->dev_addr[3],
  3046. dev->dev_addr[4],
  3047. dev->dev_addr[5],
  3048. &ugeth->ug_regs->macstnaddr1,
  3049. &ugeth->ug_regs->macstnaddr2);
  3050. err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
  3051. if (err) {
  3052. if (netif_msg_ifup(ugeth))
  3053. ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
  3054. goto err;
  3055. }
  3056. return 0;
  3057. err:
  3058. ucc_geth_stop(ugeth);
  3059. return err;
  3060. }
  3061. /* Called when something needs to use the ethernet device */
  3062. /* Returns 0 for success. */
  3063. static int ucc_geth_open(struct net_device *dev)
  3064. {
  3065. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3066. int err;
  3067. ugeth_vdbg("%s: IN", __func__);
  3068. /* Test station address */
  3069. if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
  3070. if (netif_msg_ifup(ugeth))
  3071. ugeth_err("%s: Multicast address used for station "
  3072. "address - is this what you wanted?",
  3073. __func__);
  3074. return -EINVAL;
  3075. }
  3076. err = init_phy(dev);
  3077. if (err) {
  3078. if (netif_msg_ifup(ugeth))
  3079. ugeth_err("%s: Cannot initialize PHY, aborting.",
  3080. dev->name);
  3081. return err;
  3082. }
  3083. err = ucc_geth_init_mac(ugeth);
  3084. if (err) {
  3085. if (netif_msg_ifup(ugeth))
  3086. ugeth_err("%s: Cannot initialize MAC, aborting.",
  3087. dev->name);
  3088. goto err;
  3089. }
  3090. err = request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler,
  3091. 0, "UCC Geth", dev);
  3092. if (err) {
  3093. if (netif_msg_ifup(ugeth))
  3094. ugeth_err("%s: Cannot get IRQ for net device, aborting.",
  3095. dev->name);
  3096. goto err;
  3097. }
  3098. phy_start(ugeth->phydev);
  3099. napi_enable(&ugeth->napi);
  3100. netif_start_queue(dev);
  3101. device_set_wakeup_capable(&dev->dev,
  3102. qe_alive_during_sleep() || ugeth->phydev->irq);
  3103. device_set_wakeup_enable(&dev->dev, ugeth->wol_en);
  3104. return err;
  3105. err:
  3106. ucc_geth_stop(ugeth);
  3107. return err;
  3108. }
  3109. /* Stops the kernel queue, and halts the controller */
  3110. static int ucc_geth_close(struct net_device *dev)
  3111. {
  3112. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3113. ugeth_vdbg("%s: IN", __func__);
  3114. napi_disable(&ugeth->napi);
  3115. cancel_work_sync(&ugeth->timeout_work);
  3116. ucc_geth_stop(ugeth);
  3117. phy_disconnect(ugeth->phydev);
  3118. ugeth->phydev = NULL;
  3119. free_irq(ugeth->ug_info->uf_info.irq, ugeth->ndev);
  3120. netif_stop_queue(dev);
  3121. return 0;
  3122. }
  3123. /* Reopen device. This will reset the MAC and PHY. */
  3124. static void ucc_geth_timeout_work(struct work_struct *work)
  3125. {
  3126. struct ucc_geth_private *ugeth;
  3127. struct net_device *dev;
  3128. ugeth = container_of(work, struct ucc_geth_private, timeout_work);
  3129. dev = ugeth->ndev;
  3130. ugeth_vdbg("%s: IN", __func__);
  3131. dev->stats.tx_errors++;
  3132. ugeth_dump_regs(ugeth);
  3133. if (dev->flags & IFF_UP) {
  3134. /*
  3135. * Must reset MAC *and* PHY. This is done by reopening
  3136. * the device.
  3137. */
  3138. netif_tx_stop_all_queues(dev);
  3139. ucc_geth_stop(ugeth);
  3140. ucc_geth_init_mac(ugeth);
  3141. /* Must start PHY here */
  3142. phy_start(ugeth->phydev);
  3143. netif_tx_start_all_queues(dev);
  3144. }
  3145. netif_tx_schedule_all(dev);
  3146. }
  3147. /*
  3148. * ucc_geth_timeout gets called when a packet has not been
  3149. * transmitted after a set amount of time.
  3150. */
  3151. static void ucc_geth_timeout(struct net_device *dev)
  3152. {
  3153. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3154. schedule_work(&ugeth->timeout_work);
  3155. }
  3156. #ifdef CONFIG_PM
  3157. static int ucc_geth_suspend(struct platform_device *ofdev, pm_message_t state)
  3158. {
  3159. struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
  3160. struct ucc_geth_private *ugeth = netdev_priv(ndev);
  3161. if (!netif_running(ndev))
  3162. return 0;
  3163. netif_device_detach(ndev);
  3164. napi_disable(&ugeth->napi);
  3165. /*
  3166. * Disable the controller, otherwise we'll wakeup on any network
  3167. * activity.
  3168. */
  3169. ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
  3170. if (ugeth->wol_en & WAKE_MAGIC) {
  3171. setbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
  3172. setbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
  3173. ucc_fast_enable(ugeth->uccf, COMM_DIR_RX_AND_TX);
  3174. } else if (!(ugeth->wol_en & WAKE_PHY)) {
  3175. phy_stop(ugeth->phydev);
  3176. }
  3177. return 0;
  3178. }
  3179. static int ucc_geth_resume(struct platform_device *ofdev)
  3180. {
  3181. struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
  3182. struct ucc_geth_private *ugeth = netdev_priv(ndev);
  3183. int err;
  3184. if (!netif_running(ndev))
  3185. return 0;
  3186. if (qe_alive_during_sleep()) {
  3187. if (ugeth->wol_en & WAKE_MAGIC) {
  3188. ucc_fast_disable(ugeth->uccf, COMM_DIR_RX_AND_TX);
  3189. clrbits32(&ugeth->ug_regs->maccfg2, MACCFG2_MPE);
  3190. clrbits32(ugeth->uccf->p_uccm, UCC_GETH_UCCE_MPD);
  3191. }
  3192. ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
  3193. } else {
  3194. /*
  3195. * Full reinitialization is required if QE shuts down
  3196. * during sleep.
  3197. */
  3198. ucc_geth_memclean(ugeth);
  3199. err = ucc_geth_init_mac(ugeth);
  3200. if (err) {
  3201. ugeth_err("%s: Cannot initialize MAC, aborting.",
  3202. ndev->name);
  3203. return err;
  3204. }
  3205. }
  3206. ugeth->oldlink = 0;
  3207. ugeth->oldspeed = 0;
  3208. ugeth->oldduplex = -1;
  3209. phy_stop(ugeth->phydev);
  3210. phy_start(ugeth->phydev);
  3211. napi_enable(&ugeth->napi);
  3212. netif_device_attach(ndev);
  3213. return 0;
  3214. }
  3215. #else
  3216. #define ucc_geth_suspend NULL
  3217. #define ucc_geth_resume NULL
  3218. #endif
  3219. static phy_interface_t to_phy_interface(const char *phy_connection_type)
  3220. {
  3221. if (strcasecmp(phy_connection_type, "mii") == 0)
  3222. return PHY_INTERFACE_MODE_MII;
  3223. if (strcasecmp(phy_connection_type, "gmii") == 0)
  3224. return PHY_INTERFACE_MODE_GMII;
  3225. if (strcasecmp(phy_connection_type, "tbi") == 0)
  3226. return PHY_INTERFACE_MODE_TBI;
  3227. if (strcasecmp(phy_connection_type, "rmii") == 0)
  3228. return PHY_INTERFACE_MODE_RMII;
  3229. if (strcasecmp(phy_connection_type, "rgmii") == 0)
  3230. return PHY_INTERFACE_MODE_RGMII;
  3231. if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
  3232. return PHY_INTERFACE_MODE_RGMII_ID;
  3233. if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
  3234. return PHY_INTERFACE_MODE_RGMII_TXID;
  3235. if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
  3236. return PHY_INTERFACE_MODE_RGMII_RXID;
  3237. if (strcasecmp(phy_connection_type, "rtbi") == 0)
  3238. return PHY_INTERFACE_MODE_RTBI;
  3239. if (strcasecmp(phy_connection_type, "sgmii") == 0)
  3240. return PHY_INTERFACE_MODE_SGMII;
  3241. return PHY_INTERFACE_MODE_MII;
  3242. }
  3243. static int ucc_geth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3244. {
  3245. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3246. if (!netif_running(dev))
  3247. return -EINVAL;
  3248. if (!ugeth->phydev)
  3249. return -ENODEV;
  3250. return phy_mii_ioctl(ugeth->phydev, rq, cmd);
  3251. }
  3252. static const struct net_device_ops ucc_geth_netdev_ops = {
  3253. .ndo_open = ucc_geth_open,
  3254. .ndo_stop = ucc_geth_close,
  3255. .ndo_start_xmit = ucc_geth_start_xmit,
  3256. .ndo_validate_addr = eth_validate_addr,
  3257. .ndo_set_mac_address = ucc_geth_set_mac_addr,
  3258. .ndo_change_mtu = eth_change_mtu,
  3259. .ndo_set_rx_mode = ucc_geth_set_multi,
  3260. .ndo_tx_timeout = ucc_geth_timeout,
  3261. .ndo_do_ioctl = ucc_geth_ioctl,
  3262. #ifdef CONFIG_NET_POLL_CONTROLLER
  3263. .ndo_poll_controller = ucc_netpoll,
  3264. #endif
  3265. };
  3266. static int ucc_geth_probe(struct platform_device* ofdev)
  3267. {
  3268. struct device *device = &ofdev->dev;
  3269. struct device_node *np = ofdev->dev.of_node;
  3270. struct net_device *dev = NULL;
  3271. struct ucc_geth_private *ugeth = NULL;
  3272. struct ucc_geth_info *ug_info;
  3273. struct resource res;
  3274. int err, ucc_num, max_speed = 0;
  3275. const unsigned int *prop;
  3276. const char *sprop;
  3277. const void *mac_addr;
  3278. phy_interface_t phy_interface;
  3279. static const int enet_to_speed[] = {
  3280. SPEED_10, SPEED_10, SPEED_10,
  3281. SPEED_100, SPEED_100, SPEED_100,
  3282. SPEED_1000, SPEED_1000, SPEED_1000, SPEED_1000,
  3283. };
  3284. static const phy_interface_t enet_to_phy_interface[] = {
  3285. PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_RMII,
  3286. PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_MII,
  3287. PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII,
  3288. PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_RGMII,
  3289. PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RTBI,
  3290. PHY_INTERFACE_MODE_SGMII,
  3291. };
  3292. ugeth_vdbg("%s: IN", __func__);
  3293. prop = of_get_property(np, "cell-index", NULL);
  3294. if (!prop) {
  3295. prop = of_get_property(np, "device-id", NULL);
  3296. if (!prop)
  3297. return -ENODEV;
  3298. }
  3299. ucc_num = *prop - 1;
  3300. if ((ucc_num < 0) || (ucc_num > 7))
  3301. return -ENODEV;
  3302. ug_info = &ugeth_info[ucc_num];
  3303. if (ug_info == NULL) {
  3304. if (netif_msg_probe(&debug))
  3305. ugeth_err("%s: [%d] Missing additional data!",
  3306. __func__, ucc_num);
  3307. return -ENODEV;
  3308. }
  3309. ug_info->uf_info.ucc_num = ucc_num;
  3310. sprop = of_get_property(np, "rx-clock-name", NULL);
  3311. if (sprop) {
  3312. ug_info->uf_info.rx_clock = qe_clock_source(sprop);
  3313. if ((ug_info->uf_info.rx_clock < QE_CLK_NONE) ||
  3314. (ug_info->uf_info.rx_clock > QE_CLK24)) {
  3315. printk(KERN_ERR
  3316. "ucc_geth: invalid rx-clock-name property\n");
  3317. return -EINVAL;
  3318. }
  3319. } else {
  3320. prop = of_get_property(np, "rx-clock", NULL);
  3321. if (!prop) {
  3322. /* If both rx-clock-name and rx-clock are missing,
  3323. we want to tell people to use rx-clock-name. */
  3324. printk(KERN_ERR
  3325. "ucc_geth: missing rx-clock-name property\n");
  3326. return -EINVAL;
  3327. }
  3328. if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
  3329. printk(KERN_ERR
  3330. "ucc_geth: invalid rx-clock propperty\n");
  3331. return -EINVAL;
  3332. }
  3333. ug_info->uf_info.rx_clock = *prop;
  3334. }
  3335. sprop = of_get_property(np, "tx-clock-name", NULL);
  3336. if (sprop) {
  3337. ug_info->uf_info.tx_clock = qe_clock_source(sprop);
  3338. if ((ug_info->uf_info.tx_clock < QE_CLK_NONE) ||
  3339. (ug_info->uf_info.tx_clock > QE_CLK24)) {
  3340. printk(KERN_ERR
  3341. "ucc_geth: invalid tx-clock-name property\n");
  3342. return -EINVAL;
  3343. }
  3344. } else {
  3345. prop = of_get_property(np, "tx-clock", NULL);
  3346. if (!prop) {
  3347. printk(KERN_ERR
  3348. "ucc_geth: missing tx-clock-name property\n");
  3349. return -EINVAL;
  3350. }
  3351. if ((*prop < QE_CLK_NONE) || (*prop > QE_CLK24)) {
  3352. printk(KERN_ERR
  3353. "ucc_geth: invalid tx-clock property\n");
  3354. return -EINVAL;
  3355. }
  3356. ug_info->uf_info.tx_clock = *prop;
  3357. }
  3358. err = of_address_to_resource(np, 0, &res);
  3359. if (err)
  3360. return -EINVAL;
  3361. ug_info->uf_info.regs = res.start;
  3362. ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
  3363. ug_info->phy_node = of_parse_phandle(np, "phy-handle", 0);
  3364. /* Find the TBI PHY node. If it's not there, we don't support SGMII */
  3365. ug_info->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
  3366. /* get the phy interface type, or default to MII */
  3367. prop = of_get_property(np, "phy-connection-type", NULL);
  3368. if (!prop) {
  3369. /* handle interface property present in old trees */
  3370. prop = of_get_property(ug_info->phy_node, "interface", NULL);
  3371. if (prop != NULL) {
  3372. phy_interface = enet_to_phy_interface[*prop];
  3373. max_speed = enet_to_speed[*prop];
  3374. } else
  3375. phy_interface = PHY_INTERFACE_MODE_MII;
  3376. } else {
  3377. phy_interface = to_phy_interface((const char *)prop);
  3378. }
  3379. /* get speed, or derive from PHY interface */
  3380. if (max_speed == 0)
  3381. switch (phy_interface) {
  3382. case PHY_INTERFACE_MODE_GMII:
  3383. case PHY_INTERFACE_MODE_RGMII:
  3384. case PHY_INTERFACE_MODE_RGMII_ID:
  3385. case PHY_INTERFACE_MODE_RGMII_RXID:
  3386. case PHY_INTERFACE_MODE_RGMII_TXID:
  3387. case PHY_INTERFACE_MODE_TBI:
  3388. case PHY_INTERFACE_MODE_RTBI:
  3389. case PHY_INTERFACE_MODE_SGMII:
  3390. max_speed = SPEED_1000;
  3391. break;
  3392. default:
  3393. max_speed = SPEED_100;
  3394. break;
  3395. }
  3396. if (max_speed == SPEED_1000) {
  3397. /* configure muram FIFOs for gigabit operation */
  3398. ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
  3399. ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
  3400. ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
  3401. ug_info->uf_info.utfs = UCC_GETH_UTFS_GIGA_INIT;
  3402. ug_info->uf_info.utfet = UCC_GETH_UTFET_GIGA_INIT;
  3403. ug_info->uf_info.utftt = UCC_GETH_UTFTT_GIGA_INIT;
  3404. ug_info->numThreadsTx = UCC_GETH_NUM_OF_THREADS_4;
  3405. /* If QE's snum number is 46 which means we need to support
  3406. * 4 UECs at 1000Base-T simultaneously, we need to allocate
  3407. * more Threads to Rx.
  3408. */
  3409. if (qe_get_num_of_snums() == 46)
  3410. ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_6;
  3411. else
  3412. ug_info->numThreadsRx = UCC_GETH_NUM_OF_THREADS_4;
  3413. }
  3414. if (netif_msg_probe(&debug))
  3415. printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d)\n",
  3416. ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
  3417. ug_info->uf_info.irq);
  3418. /* Create an ethernet device instance */
  3419. dev = alloc_etherdev(sizeof(*ugeth));
  3420. if (dev == NULL)
  3421. return -ENOMEM;
  3422. ugeth = netdev_priv(dev);
  3423. spin_lock_init(&ugeth->lock);
  3424. /* Create CQs for hash tables */
  3425. INIT_LIST_HEAD(&ugeth->group_hash_q);
  3426. INIT_LIST_HEAD(&ugeth->ind_hash_q);
  3427. dev_set_drvdata(device, dev);
  3428. /* Set the dev->base_addr to the gfar reg region */
  3429. dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
  3430. SET_NETDEV_DEV(dev, device);
  3431. /* Fill in the dev structure */
  3432. uec_set_ethtool_ops(dev);
  3433. dev->netdev_ops = &ucc_geth_netdev_ops;
  3434. dev->watchdog_timeo = TX_TIMEOUT;
  3435. INIT_WORK(&ugeth->timeout_work, ucc_geth_timeout_work);
  3436. netif_napi_add(dev, &ugeth->napi, ucc_geth_poll, 64);
  3437. dev->mtu = 1500;
  3438. ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
  3439. ugeth->phy_interface = phy_interface;
  3440. ugeth->max_speed = max_speed;
  3441. err = register_netdev(dev);
  3442. if (err) {
  3443. if (netif_msg_probe(ugeth))
  3444. ugeth_err("%s: Cannot register net device, aborting.",
  3445. dev->name);
  3446. free_netdev(dev);
  3447. return err;
  3448. }
  3449. mac_addr = of_get_mac_address(np);
  3450. if (mac_addr)
  3451. memcpy(dev->dev_addr, mac_addr, 6);
  3452. ugeth->ug_info = ug_info;
  3453. ugeth->dev = device;
  3454. ugeth->ndev = dev;
  3455. ugeth->node = np;
  3456. return 0;
  3457. }
  3458. static int ucc_geth_remove(struct platform_device* ofdev)
  3459. {
  3460. struct device *device = &ofdev->dev;
  3461. struct net_device *dev = dev_get_drvdata(device);
  3462. struct ucc_geth_private *ugeth = netdev_priv(dev);
  3463. unregister_netdev(dev);
  3464. free_netdev(dev);
  3465. ucc_geth_memclean(ugeth);
  3466. dev_set_drvdata(device, NULL);
  3467. return 0;
  3468. }
  3469. static struct of_device_id ucc_geth_match[] = {
  3470. {
  3471. .type = "network",
  3472. .compatible = "ucc_geth",
  3473. },
  3474. {},
  3475. };
  3476. MODULE_DEVICE_TABLE(of, ucc_geth_match);
  3477. static struct platform_driver ucc_geth_driver = {
  3478. .driver = {
  3479. .name = DRV_NAME,
  3480. .owner = THIS_MODULE,
  3481. .of_match_table = ucc_geth_match,
  3482. },
  3483. .probe = ucc_geth_probe,
  3484. .remove = ucc_geth_remove,
  3485. .suspend = ucc_geth_suspend,
  3486. .resume = ucc_geth_resume,
  3487. };
  3488. static int __init ucc_geth_init(void)
  3489. {
  3490. int i, ret;
  3491. if (netif_msg_drv(&debug))
  3492. printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
  3493. for (i = 0; i < 8; i++)
  3494. memcpy(&(ugeth_info[i]), &ugeth_primary_info,
  3495. sizeof(ugeth_primary_info));
  3496. ret = platform_driver_register(&ucc_geth_driver);
  3497. return ret;
  3498. }
  3499. static void __exit ucc_geth_exit(void)
  3500. {
  3501. platform_driver_unregister(&ucc_geth_driver);
  3502. }
  3503. module_init(ucc_geth_init);
  3504. module_exit(ucc_geth_exit);
  3505. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  3506. MODULE_DESCRIPTION(DRV_DESC);
  3507. MODULE_VERSION(DRV_VERSION);
  3508. MODULE_LICENSE("GPL");