ucc_geth.c 126 KB

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