ucc_geth.c 118 KB

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