ucc_geth.c 113 KB

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