ucc_geth.c 123 KB

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