ucc_geth.c 121 KB

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