ucc_geth.c 119 KB

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