ucc_geth.c 125 KB

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