ucc_geth.c 114 KB

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