ucc_geth.c 119 KB

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