ucc_geth.c 114 KB

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