ucc_geth.c 117 KB

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