ucc_geth.c 118 KB

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