ucc_geth.c 114 KB

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