120-net-add-gemini-gmac-driver.patch 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953
  1. --- /dev/null
  2. +++ b/arch/arm/mach-gemini/include/mach/gmac.h
  3. @@ -0,0 +1,21 @@
  4. +/*
  5. + * Gemini GMAC specific defines
  6. + *
  7. + * Copyright (C) 2008, Paulius Zaleckas <paulius.zaleckas@gmail.com>
  8. + *
  9. + * This program is free software; you can redistribute it and/or modify
  10. + * it under the terms of the GNU General Public License as published by
  11. + * the Free Software Foundation; either version 2 of the License, or
  12. + * (at your option) any later version.
  13. + */
  14. +#ifndef __NET_GEMINI_PLATFORM_H__
  15. +#define __NET_GEMINI_PLATFORM_H__
  16. +
  17. +#include <linux/phy.h>
  18. +
  19. +struct gemini_gmac_platform_data {
  20. + char *bus_id[2]; /* NULL means that this port is not used */
  21. + phy_interface_t interface[2];
  22. +};
  23. +
  24. +#endif /* __NET_GEMINI_PLATFORM_H__ */
  25. --- a/arch/arm/mach-gemini/common.h
  26. +++ b/arch/arm/mach-gemini/common.h
  27. @@ -13,6 +13,7 @@
  28. #define __GEMINI_COMMON_H__
  29. struct mtd_partition;
  30. +struct gemini_gmac_platform_data;
  31. extern void gemini_map_io(void);
  32. extern void gemini_init_irq(void);
  33. @@ -26,6 +27,7 @@ extern int platform_register_pflash(unsi
  34. struct mtd_partition *parts,
  35. unsigned int nr_parts);
  36. extern int platform_register_watchdog(void);
  37. +extern int platform_register_ethernet(struct gemini_gmac_platform_data *pdata);
  38. extern void gemini_restart(enum reboot_mode mode, const char *cmd);
  39. --- a/arch/arm/mach-gemini/devices.c
  40. +++ b/arch/arm/mach-gemini/devices.c
  41. @@ -17,6 +17,7 @@
  42. #include <mach/irqs.h>
  43. #include <mach/hardware.h>
  44. #include <mach/global_reg.h>
  45. +#include <mach/gmac.h>
  46. #include "common.h"
  47. static struct plat_serial8250_port serial_platform_data[] = {
  48. @@ -134,3 +135,56 @@ int __init platform_register_watchdog(vo
  49. {
  50. return platform_device_register(&wdt_device);
  51. }
  52. +
  53. +static struct resource gmac_resources[] = {
  54. + {
  55. + .start = GEMINI_TOE_BASE,
  56. + .end = GEMINI_TOE_BASE + 0xffff,
  57. + .flags = IORESOURCE_MEM,
  58. + },
  59. + {
  60. + .start = IRQ_GMAC0,
  61. + .end = IRQ_GMAC0,
  62. + .flags = IORESOURCE_IRQ,
  63. + },
  64. + {
  65. + .start = IRQ_GMAC1,
  66. + .end = IRQ_GMAC1,
  67. + .flags = IORESOURCE_IRQ,
  68. + },
  69. +};
  70. +
  71. +static u64 gmac_dmamask = 0xffffffffUL;
  72. +
  73. +static struct platform_device ethernet_device = {
  74. + .name = "gmac-gemini",
  75. + .id = 0,
  76. + .dev = {
  77. + .dma_mask = &gmac_dmamask,
  78. + .coherent_dma_mask = 0xffffffff,
  79. + },
  80. + .num_resources = ARRAY_SIZE(gmac_resources),
  81. + .resource = gmac_resources,
  82. +};
  83. +
  84. +int platform_register_ethernet(struct gemini_gmac_platform_data *pdata)
  85. +{
  86. + unsigned int reg;
  87. +
  88. + reg = readl((void __iomem*)(IO_ADDRESS(GEMINI_GLOBAL_BASE) +
  89. + GLOBAL_MISC_CTRL));
  90. +
  91. + reg &= ~(GMAC_GMII | GMAC_1_ENABLE);
  92. +
  93. + if (pdata->bus_id[1])
  94. + reg |= GMAC_1_ENABLE;
  95. + else if (pdata->interface[0] == PHY_INTERFACE_MODE_GMII)
  96. + reg |= GMAC_GMII;
  97. +
  98. + writel(reg, (void __iomem*)(IO_ADDRESS(GEMINI_GLOBAL_BASE) +
  99. + GLOBAL_MISC_CTRL));
  100. +
  101. + ethernet_device.dev.platform_data = pdata;
  102. +
  103. + return platform_device_register(&ethernet_device);
  104. +}
  105. --- a/drivers/net/ethernet/Kconfig
  106. +++ b/drivers/net/ethernet/Kconfig
  107. @@ -70,6 +70,7 @@ source "drivers/net/ethernet/neterion/Kc
  108. source "drivers/net/ethernet/faraday/Kconfig"
  109. source "drivers/net/ethernet/freescale/Kconfig"
  110. source "drivers/net/ethernet/fujitsu/Kconfig"
  111. +source "drivers/net/ethernet/gemini/Kconfig"
  112. source "drivers/net/ethernet/hisilicon/Kconfig"
  113. source "drivers/net/ethernet/hp/Kconfig"
  114. source "drivers/net/ethernet/ibm/Kconfig"
  115. --- a/drivers/net/ethernet/Makefile
  116. +++ b/drivers/net/ethernet/Makefile
  117. @@ -33,6 +33,7 @@ obj-$(CONFIG_NET_VENDOR_EXAR) += neterio
  118. obj-$(CONFIG_NET_VENDOR_FARADAY) += faraday/
  119. obj-$(CONFIG_NET_VENDOR_FREESCALE) += freescale/
  120. obj-$(CONFIG_NET_VENDOR_FUJITSU) += fujitsu/
  121. +obj-$(CONFIG_NET_VENDOR_GEMINI) += gemini/
  122. obj-$(CONFIG_NET_VENDOR_HISILICON) += hisilicon/
  123. obj-$(CONFIG_NET_VENDOR_HP) += hp/
  124. obj-$(CONFIG_NET_VENDOR_IBM) += ibm/
  125. --- /dev/null
  126. +++ b/drivers/net/ethernet/gemini/Kconfig
  127. @@ -0,0 +1,31 @@
  128. +#
  129. +# Gemini device configuration
  130. +#
  131. +
  132. +config NET_VENDOR_GEMINI
  133. + bool "Cortina Gemini devices"
  134. + default y
  135. + depends on ARCH_GEMINI
  136. + ---help---
  137. + If you have a network (Ethernet) card belonging to this class, say Y
  138. + and read the Ethernet-HOWTO, available from
  139. + <http://www.tldp.org/docs.html#howto>.
  140. +
  141. + Note that the answer to this question doesn't directly affect the
  142. + kernel: saying N will just cause the configurator to skip all
  143. + the questions about D-Link devices. If you say Y, you will be asked for
  144. + your specific card in the following questions.
  145. +
  146. +if NET_VENDOR_GEMINI
  147. +
  148. +config GEMINI_SL351X
  149. + tristate "StorLink SL351x Gigabit Ethernet support"
  150. + depends on ARCH_GEMINI
  151. + select PHYLIB
  152. + select MDIO_BITBANG
  153. + select MDIO_GPIO
  154. + select CRC32
  155. + ---help---
  156. + This driver supports StorLink SL351x (Gemini) dual Gigabit Ethernet.
  157. +
  158. +endif # NET_VENDOR_GEMINI
  159. --- /dev/null
  160. +++ b/drivers/net/ethernet/gemini/Makefile
  161. @@ -0,0 +1,5 @@
  162. +#
  163. +# Makefile for the Cortina Gemini network device drivers.
  164. +#
  165. +
  166. +obj-$(CONFIG_GEMINI_SL351X) += sl351x.o
  167. --- /dev/null
  168. +++ b/drivers/net/ethernet/gemini/sl351x.c
  169. @@ -0,0 +1,2340 @@
  170. +/*
  171. + * Ethernet device driver for Gemini SoC (SL351x GMAC).
  172. + *
  173. + * Copyright (C) 2011, Tobias Waldvogel <tobias.waldvogel@gmail.com>
  174. + *
  175. + * Based on work by Michał Mirosław <mirq-linux@rere.qmqm.pl> and
  176. + * Paulius Zaleckas <paulius.zaleckas@gmail.com> and
  177. + * Giuseppe De Robertis <Giuseppe.DeRobertis@ba.infn.it> and
  178. + * GPLd spaghetti code from Raidsonic and other Gemini-based NAS vendors.
  179. + *
  180. + * This program is free software; you can redistribute it and/or modify
  181. + * it under the terms of the GNU General Public License as published by
  182. + * the Free Software Foundation; either version 2 of the License, or
  183. + * (at your option) any later version.
  184. + */
  185. +
  186. +#include <linux/module.h>
  187. +#include <linux/kernel.h>
  188. +#include <linux/init.h>
  189. +
  190. +#include <linux/spinlock.h>
  191. +#include <linux/slab.h>
  192. +#include <linux/dma-mapping.h>
  193. +#include <linux/cache.h>
  194. +#include <linux/interrupt.h>
  195. +
  196. +#include <linux/platform_device.h>
  197. +#include <linux/etherdevice.h>
  198. +#include <linux/if_vlan.h>
  199. +#include <linux/skbuff.h>
  200. +#include <linux/phy.h>
  201. +#include <linux/crc32.h>
  202. +#include <linux/ethtool.h>
  203. +#include <linux/tcp.h>
  204. +#include <linux/u64_stats_sync.h>
  205. +
  206. +#include <linux/in.h>
  207. +#include <linux/ip.h>
  208. +#include <linux/ipv6.h>
  209. +
  210. +#include <mach/hardware.h>
  211. +#include <mach/global_reg.h>
  212. +
  213. +#include <mach/gmac.h>
  214. +#include "sl351x_hw.h"
  215. +
  216. +#define DRV_NAME "gmac-gemini"
  217. +#define DRV_VERSION "1.0"
  218. +
  219. +#define HSIZE_8 0b00
  220. +#define HSIZE_16 0b01
  221. +#define HSIZE_32 0b10
  222. +
  223. +#define HBURST_SINGLE 0b00
  224. +#define HBURST_INCR 0b01
  225. +#define HBURST_INCR4 0b10
  226. +#define HBURST_INCR8 0b11
  227. +
  228. +#define HPROT_DATA_CACHE BIT(0)
  229. +#define HPROT_PRIVILIGED BIT(1)
  230. +#define HPROT_BUFFERABLE BIT(2)
  231. +#define HPROT_CACHABLE BIT(3)
  232. +
  233. +#define DEFAULT_RX_COALESCE_NSECS 0
  234. +#define DEFAULT_GMAC_RXQ_ORDER 9
  235. +#define DEFAULT_GMAC_TXQ_ORDER 8
  236. +#define DEFAULT_RX_BUF_ORDER 11
  237. +#define DEFAULT_NAPI_WEIGHT 64
  238. +#define TX_MAX_FRAGS 16
  239. +#define TX_QUEUE_NUM 1 /* max: 6 */
  240. +#define RX_MAX_ALLOC_ORDER 2
  241. +
  242. +#define GMAC0_IRQ0_2 (GMAC0_TXDERR_INT_BIT|GMAC0_TXPERR_INT_BIT| \
  243. + GMAC0_RXDERR_INT_BIT|GMAC0_RXPERR_INT_BIT)
  244. +#define GMAC0_IRQ0_TXQ0_INTS (GMAC0_SWTQ00_EOF_INT_BIT| \
  245. + GMAC0_SWTQ00_FIN_INT_BIT)
  246. +#define GMAC0_IRQ4_8 (GMAC0_MIB_INT_BIT|GMAC0_RX_OVERRUN_INT_BIT)
  247. +
  248. +#define GMAC_OFFLOAD_FEATURES (NETIF_F_SG | NETIF_F_IP_CSUM | \
  249. + NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | \
  250. + NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6)
  251. +
  252. +MODULE_AUTHOR("Tobias Waldvogel");
  253. +MODULE_DESCRIPTION("StorLink SL351x (Gemini) ethernet driver");
  254. +MODULE_LICENSE("GPL");
  255. +MODULE_ALIAS("platform:" DRV_NAME);
  256. +
  257. +struct toe_private {
  258. + void __iomem *iomem;
  259. + spinlock_t irq_lock;
  260. +
  261. + struct net_device *netdev[2];
  262. + __le32 mac_addr[2][3];
  263. +
  264. + struct device *dev;
  265. + int irq;
  266. +
  267. + unsigned int freeq_order;
  268. + unsigned int freeq_frag_order;
  269. + GMAC_RXDESC_T *freeq_ring;
  270. + dma_addr_t freeq_dma_base;
  271. + struct page **freeq_page_tab;
  272. + spinlock_t freeq_lock;
  273. +};
  274. +
  275. +struct gmac_txq {
  276. + GMAC_TXDESC_T *ring;
  277. + struct sk_buff **skb;
  278. + unsigned int cptr;
  279. + unsigned int noirq_packets;
  280. +};
  281. +
  282. +struct gmac_private {
  283. + unsigned int num;
  284. + struct toe_private *toe;
  285. + void __iomem *ctl_iomem;
  286. + void __iomem *dma_iomem;
  287. +
  288. + void __iomem *rxq_rwptr;
  289. + GMAC_RXDESC_T *rxq_ring;
  290. + unsigned int rxq_order;
  291. +
  292. + struct napi_struct napi;
  293. + struct hrtimer rx_coalesce_timer;
  294. + unsigned int rx_coalesce_nsecs;
  295. + unsigned int freeq_refill;
  296. + struct gmac_txq txq[TX_QUEUE_NUM];
  297. + unsigned int txq_order;
  298. + unsigned int irq_every_tx_packets;
  299. +
  300. + dma_addr_t rxq_dma_base;
  301. + dma_addr_t txq_dma_base;
  302. +
  303. + unsigned int msg_enable;
  304. + spinlock_t config_lock;
  305. +
  306. + struct u64_stats_sync tx_stats_syncp;
  307. + struct u64_stats_sync rx_stats_syncp;
  308. + struct u64_stats_sync ir_stats_syncp;
  309. +
  310. + struct rtnl_link_stats64 stats;
  311. + u64 hw_stats[RX_STATS_NUM];
  312. + u64 rx_stats[RX_STATUS_NUM];
  313. + u64 rx_csum_stats[RX_CHKSUM_NUM];
  314. + u64 rx_napi_exits;
  315. + u64 tx_frag_stats[TX_MAX_FRAGS];
  316. + u64 tx_frags_linearized;
  317. + u64 tx_hw_csummed;
  318. +};
  319. +
  320. +#define GMAC_STATS_NUM ( \
  321. + RX_STATS_NUM + RX_STATUS_NUM + RX_CHKSUM_NUM + 1 + \
  322. + TX_MAX_FRAGS + 2)
  323. +
  324. +static const char gmac_stats_strings[GMAC_STATS_NUM][ETH_GSTRING_LEN] = {
  325. + "GMAC_IN_DISCARDS",
  326. + "GMAC_IN_ERRORS",
  327. + "GMAC_IN_MCAST",
  328. + "GMAC_IN_BCAST",
  329. + "GMAC_IN_MAC1",
  330. + "GMAC_IN_MAC2",
  331. + "RX_STATUS_GOOD_FRAME",
  332. + "RX_STATUS_TOO_LONG_GOOD_CRC",
  333. + "RX_STATUS_RUNT_FRAME",
  334. + "RX_STATUS_SFD_NOT_FOUND",
  335. + "RX_STATUS_CRC_ERROR",
  336. + "RX_STATUS_TOO_LONG_BAD_CRC",
  337. + "RX_STATUS_ALIGNMENT_ERROR",
  338. + "RX_STATUS_TOO_LONG_BAD_ALIGN",
  339. + "RX_STATUS_RX_ERR",
  340. + "RX_STATUS_DA_FILTERED",
  341. + "RX_STATUS_BUFFER_FULL",
  342. + "RX_STATUS_11",
  343. + "RX_STATUS_12",
  344. + "RX_STATUS_13",
  345. + "RX_STATUS_14",
  346. + "RX_STATUS_15",
  347. + "RX_CHKSUM_IP_UDP_TCP_OK",
  348. + "RX_CHKSUM_IP_OK_ONLY",
  349. + "RX_CHKSUM_NONE",
  350. + "RX_CHKSUM_3",
  351. + "RX_CHKSUM_IP_ERR_UNKNOWN",
  352. + "RX_CHKSUM_IP_ERR",
  353. + "RX_CHKSUM_TCP_UDP_ERR",
  354. + "RX_CHKSUM_7",
  355. + "RX_NAPI_EXITS",
  356. + "TX_FRAGS[1]",
  357. + "TX_FRAGS[2]",
  358. + "TX_FRAGS[3]",
  359. + "TX_FRAGS[4]",
  360. + "TX_FRAGS[5]",
  361. + "TX_FRAGS[6]",
  362. + "TX_FRAGS[7]",
  363. + "TX_FRAGS[8]",
  364. + "TX_FRAGS[9]",
  365. + "TX_FRAGS[10]",
  366. + "TX_FRAGS[11]",
  367. + "TX_FRAGS[12]",
  368. + "TX_FRAGS[13]",
  369. + "TX_FRAGS[14]",
  370. + "TX_FRAGS[15]",
  371. + "TX_FRAGS[16+]",
  372. + "TX_FRAGS_LINEARIZED",
  373. + "TX_HW_CSUMMED",
  374. +};
  375. +
  376. +static void gmac_dump_dma_state(struct net_device *dev);
  377. +
  378. +static void gmac_update_config0_reg(struct net_device *dev, u32 val, u32 vmask)
  379. +{
  380. + struct gmac_private *gmac = netdev_priv(dev);
  381. + unsigned long flags;
  382. + u32 reg;
  383. +
  384. + spin_lock_irqsave(&gmac->config_lock, flags);
  385. +
  386. + reg = readl(gmac->ctl_iomem + GMAC_CONFIG0);
  387. + reg = (reg & ~vmask) | val;
  388. + writel(reg, gmac->ctl_iomem + GMAC_CONFIG0);
  389. +
  390. + spin_unlock_irqrestore(&gmac->config_lock, flags);
  391. +}
  392. +
  393. +static void gmac_enable_tx_rx(struct net_device *dev)
  394. +{
  395. + struct gmac_private *gmac = netdev_priv(dev);
  396. + void __iomem *config0 = gmac->ctl_iomem + GMAC_CONFIG0;
  397. + unsigned long flags;
  398. + u32 reg;
  399. +
  400. + spin_lock_irqsave(&gmac->config_lock, flags);
  401. +
  402. + reg = readl(config0);
  403. + reg &= ~CONFIG0_TX_RX_DISABLE;
  404. + writel(reg, config0);
  405. +
  406. + spin_unlock_irqrestore(&gmac->config_lock, flags);
  407. +}
  408. +
  409. +static void gmac_disable_tx_rx(struct net_device *dev)
  410. +{
  411. + struct gmac_private *gmac = netdev_priv(dev);
  412. + void __iomem *config0 = gmac->ctl_iomem + GMAC_CONFIG0;
  413. + unsigned long flags;
  414. + u32 reg;
  415. +
  416. + spin_lock_irqsave(&gmac->config_lock, flags);
  417. +
  418. + reg = readl(config0);
  419. + reg |= CONFIG0_TX_RX_DISABLE;
  420. + writel(reg, config0);
  421. +
  422. + spin_unlock_irqrestore(&gmac->config_lock, flags);
  423. +
  424. + mdelay(10); /* let GMAC consume packet */
  425. +}
  426. +
  427. +static void gmac_set_flow_control(struct net_device *dev, bool tx, bool rx)
  428. +{
  429. + struct gmac_private *gmac = netdev_priv(dev);
  430. + void __iomem *config0 = gmac->ctl_iomem + GMAC_CONFIG0;
  431. + unsigned long flags;
  432. + u32 reg;
  433. +
  434. + spin_lock_irqsave(&gmac->config_lock, flags);
  435. +
  436. + reg = readl(config0);
  437. + reg &= ~CONFIG0_FLOW_CTL;
  438. + if (tx)
  439. + reg |= CONFIG0_FLOW_TX;
  440. + if (rx)
  441. + reg |= CONFIG0_FLOW_RX;
  442. + writel(reg, config0);
  443. +
  444. + spin_unlock_irqrestore(&gmac->config_lock, flags);
  445. +}
  446. +
  447. +static void gmac_update_link_state(struct net_device *dev)
  448. +{
  449. + struct gmac_private *gmac = netdev_priv(dev);
  450. + void __iomem *status_reg = gmac->ctl_iomem + GMAC_STATUS;
  451. + struct phy_device *phydev = dev->phydev;
  452. + GMAC_STATUS_T status, old_status;
  453. + int pause_tx=0, pause_rx=0;
  454. +
  455. + old_status.bits32 = status.bits32 = readl(status_reg);
  456. +
  457. + status.bits.link = phydev->link;
  458. + status.bits.duplex = phydev->duplex;
  459. +
  460. + switch (phydev->speed) {
  461. + case 1000:
  462. + status.bits.speed = GMAC_SPEED_1000;
  463. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  464. + status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
  465. + break;
  466. + case 100:
  467. + status.bits.speed = GMAC_SPEED_100;
  468. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  469. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  470. + break;
  471. + case 10:
  472. + status.bits.speed = GMAC_SPEED_10;
  473. + if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  474. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  475. + break;
  476. + default:
  477. + netdev_warn(dev, "Not supported PHY speed (%d)\n",
  478. + phydev->speed);
  479. + }
  480. +
  481. + if (phydev->duplex == DUPLEX_FULL) {
  482. + u16 lcladv = phy_read(phydev, MII_ADVERTISE);
  483. + u16 rmtadv = phy_read(phydev, MII_LPA);
  484. + u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
  485. +
  486. + if (cap & FLOW_CTRL_RX)
  487. + pause_rx=1;
  488. + if (cap & FLOW_CTRL_TX)
  489. + pause_tx=1;
  490. + }
  491. +
  492. + gmac_set_flow_control(dev, pause_tx, pause_rx);
  493. +
  494. + if (old_status.bits32 == status.bits32)
  495. + return;
  496. +
  497. + if (netif_msg_link(gmac)) {
  498. + phy_print_status(phydev);
  499. + netdev_info(dev, "link flow control: %s\n",
  500. + phydev->pause
  501. + ? (phydev->asym_pause ? "tx" : "both")
  502. + : (phydev->asym_pause ? "rx" : "none")
  503. + );
  504. + }
  505. +
  506. + gmac_disable_tx_rx(dev);
  507. + writel(status.bits32, status_reg);
  508. + gmac_enable_tx_rx(dev);
  509. +}
  510. +
  511. +static int gmac_setup_phy(struct net_device *dev)
  512. +{
  513. + struct gmac_private *gmac = netdev_priv(dev);
  514. + struct toe_private *toe = gmac->toe;
  515. + struct gemini_gmac_platform_data *pdata = toe->dev->platform_data;
  516. + GMAC_STATUS_T status = { .bits32 = 0 };
  517. + int num = dev->dev_id;
  518. +
  519. + dev->phydev = phy_connect(dev, pdata->bus_id[num],
  520. + &gmac_update_link_state, pdata->interface[num]);
  521. +
  522. + if (IS_ERR(dev->phydev)) {
  523. + int err = PTR_ERR(dev->phydev);
  524. + dev->phydev = NULL;
  525. + return err;
  526. + }
  527. +
  528. + dev->phydev->supported &= PHY_GBIT_FEATURES;
  529. + dev->phydev->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause;
  530. + dev->phydev->advertising = dev->phydev->supported;
  531. +
  532. + /* set PHY interface type */
  533. + switch (dev->phydev->interface) {
  534. + case PHY_INTERFACE_MODE_MII:
  535. + status.bits.mii_rmii = GMAC_PHY_MII;
  536. + break;
  537. + case PHY_INTERFACE_MODE_GMII:
  538. + status.bits.mii_rmii = GMAC_PHY_GMII;
  539. + break;
  540. + case PHY_INTERFACE_MODE_RGMII:
  541. + status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
  542. + break;
  543. + default:
  544. + netdev_err(dev, "Unsupported MII interface\n");
  545. + phy_disconnect(dev->phydev);
  546. + dev->phydev = NULL;
  547. + return -EINVAL;
  548. + }
  549. + writel(status.bits32, gmac->ctl_iomem + GMAC_STATUS);
  550. +
  551. + return 0;
  552. +}
  553. +
  554. +static int gmac_pick_rx_max_len(int max_l3_len)
  555. +{
  556. + /* index = CONFIG_MAXLEN_XXX values */
  557. + static const int max_len[8] = {
  558. + 1536, 1518, 1522, 1542,
  559. + 9212, 10236, 1518, 1518
  560. + };
  561. + int i, n = 5;
  562. +
  563. + max_l3_len += ETH_HLEN + VLAN_HLEN;
  564. +
  565. + if (max_l3_len > max_len[n])
  566. + return -1;
  567. +
  568. + for (i = 0; i < 5; ++i) {
  569. + if (max_len[i] >= max_l3_len && max_len[i] < max_len[n])
  570. + n = i;
  571. + }
  572. +
  573. + return n;
  574. +}
  575. +
  576. +static int gmac_init(struct net_device *dev)
  577. +{
  578. + struct gmac_private *gmac = netdev_priv(dev);
  579. + u32 val;
  580. +
  581. + GMAC_CONFIG0_T config0 = { .bits = {
  582. + .dis_tx = 1,
  583. + .dis_rx = 1,
  584. + .ipv4_rx_chksum = 1,
  585. + .ipv6_rx_chksum = 1,
  586. + .rx_err_detect = 1,
  587. + .rgmm_edge = 1,
  588. + .port0_chk_hwq = 1,
  589. + .port1_chk_hwq = 1,
  590. + .port0_chk_toeq = 1,
  591. + .port1_chk_toeq = 1,
  592. + .port0_chk_classq = 1,
  593. + .port1_chk_classq = 1,
  594. + } };
  595. + GMAC_AHB_WEIGHT_T ahb_weight = { .bits = {
  596. + .rx_weight = 1,
  597. + .tx_weight = 1,
  598. + .hash_weight = 1,
  599. + .pre_req = 0x1f,
  600. + .tqDV_threshold = 0,
  601. + } };
  602. + GMAC_TX_WCR0_T hw_weigh = { .bits = {
  603. + .hw_tq3 = 1,
  604. + .hw_tq2 = 1,
  605. + .hw_tq1 = 1,
  606. + .hw_tq0 = 1,
  607. + } };
  608. + GMAC_TX_WCR1_T sw_weigh = { .bits = {
  609. + .sw_tq5 = 1,
  610. + .sw_tq4 = 1,
  611. + .sw_tq3 = 1,
  612. + .sw_tq2 = 1,
  613. + .sw_tq1 = 1,
  614. + .sw_tq0 = 1,
  615. + } };
  616. + GMAC_CONFIG1_T config1 = { .bits = {
  617. + .set_threshold = 16,
  618. + .rel_threshold = 24,
  619. + } };
  620. + GMAC_CONFIG2_T config2 = { .bits = {
  621. + .set_threshold = 16,
  622. + .rel_threshold = 32,
  623. + } };
  624. + GMAC_CONFIG3_T config3 = { .bits = {
  625. + .set_threshold = 0,
  626. + .rel_threshold = 0,
  627. + } };
  628. +
  629. + config0.bits.max_len = gmac_pick_rx_max_len(dev->mtu);
  630. +
  631. + val = readl(gmac->ctl_iomem + GMAC_CONFIG0);
  632. + config0.bits.reserved = ((GMAC_CONFIG0_T)val).bits.reserved;
  633. + writel(config0.bits32, gmac->ctl_iomem + GMAC_CONFIG0);
  634. + writel(config1.bits32, gmac->ctl_iomem + GMAC_CONFIG1);
  635. + writel(config2.bits32, gmac->ctl_iomem + GMAC_CONFIG2);
  636. + writel(config3.bits32, gmac->ctl_iomem + GMAC_CONFIG3);
  637. +
  638. + val = readl(gmac->dma_iomem + GMAC_AHB_WEIGHT_REG);
  639. + writel(ahb_weight.bits32, gmac->dma_iomem + GMAC_AHB_WEIGHT_REG);
  640. +
  641. + writel(hw_weigh.bits32,
  642. + gmac->dma_iomem + GMAC_TX_WEIGHTING_CTRL_0_REG);
  643. + writel(sw_weigh.bits32,
  644. + gmac->dma_iomem + GMAC_TX_WEIGHTING_CTRL_1_REG);
  645. +
  646. + gmac->rxq_order = DEFAULT_GMAC_RXQ_ORDER;
  647. + gmac->txq_order = DEFAULT_GMAC_TXQ_ORDER;
  648. + gmac->rx_coalesce_nsecs = DEFAULT_RX_COALESCE_NSECS;
  649. +
  650. + /* Mark every quarter of the queue a packet for interrupt
  651. + in order to be able to wake up the queue if it was stopped */
  652. + gmac->irq_every_tx_packets = 1 << (gmac->txq_order - 2);
  653. +
  654. + return 0;
  655. +}
  656. +
  657. +static void gmac_uninit(struct net_device *dev)
  658. +{
  659. + if (dev->phydev)
  660. + phy_disconnect(dev->phydev);
  661. +}
  662. +
  663. +static int gmac_setup_txqs(struct net_device *dev)
  664. +{
  665. + struct gmac_private *gmac = netdev_priv(dev);
  666. + struct toe_private *toe = gmac->toe;
  667. + void __iomem *rwptr_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE0_PTR_REG;
  668. + void __iomem *base_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE_BASE_REG;
  669. +
  670. + unsigned int n_txq = dev->num_tx_queues;
  671. + size_t entries = 1 <<gmac->txq_order;
  672. + size_t len = n_txq * entries;
  673. + struct gmac_txq *txq = gmac->txq;
  674. + GMAC_TXDESC_T *desc_ring;
  675. + struct sk_buff **skb_tab;
  676. + unsigned int r;
  677. + int i;
  678. +
  679. + skb_tab = kzalloc(len * sizeof(*skb_tab), GFP_KERNEL);
  680. + if (!skb_tab)
  681. + return -ENOMEM;
  682. +
  683. + desc_ring = dma_alloc_coherent(toe->dev, len * sizeof(*desc_ring),
  684. + &gmac->txq_dma_base, GFP_KERNEL);
  685. +
  686. + if (!desc_ring) {
  687. + kfree(skb_tab);
  688. + return -ENOMEM;
  689. + }
  690. +
  691. + BUG_ON(gmac->txq_dma_base & ~DMA_Q_BASE_MASK);
  692. +
  693. + writel(gmac->txq_dma_base | gmac->txq_order, base_reg);
  694. +
  695. + for (i = 0; i < n_txq; i++) {
  696. + txq->ring = desc_ring;
  697. + txq->skb = skb_tab;
  698. + txq->noirq_packets = 0;
  699. +
  700. + r = readw(rwptr_reg);
  701. + rwptr_reg += 2;
  702. + writew(r, rwptr_reg);
  703. + rwptr_reg +=2;
  704. + txq->cptr = r;
  705. +
  706. + txq++;
  707. + desc_ring += entries;
  708. + skb_tab += entries;
  709. + }
  710. +
  711. + return 0;
  712. +}
  713. +
  714. +static void gmac_clean_txq(struct net_device *dev, struct gmac_txq *txq,
  715. + unsigned int r)
  716. +{
  717. + struct gmac_private *gmac = netdev_priv(dev);
  718. + struct toe_private *toe = gmac->toe;
  719. + unsigned int errs = 0;
  720. + unsigned int pkts = 0;
  721. + unsigned int hwchksum = 0;
  722. + unsigned long bytes = 0;
  723. + unsigned int m = (1 << gmac->txq_order) - 1;
  724. + unsigned int c = txq->cptr;
  725. + GMAC_TXDESC_0_T word0;
  726. + GMAC_TXDESC_1_T word1;
  727. + unsigned int word3;
  728. + dma_addr_t mapping;
  729. + GMAC_TXDESC_T *txd;
  730. + unsigned short nfrags;
  731. +
  732. + if (unlikely(c == r))
  733. + return;
  734. +
  735. + rmb();
  736. + while (c != r) {
  737. + txd = txq->ring + c;
  738. + word0 = txd->word0;
  739. + word1 = txd->word1;
  740. + mapping = txd->word2.buf_adr;
  741. + word3 = txd->word3.bits32;
  742. +
  743. + dma_unmap_single(toe->dev, mapping, word0.bits.buffer_size, DMA_TO_DEVICE);
  744. +
  745. + if (word3 & EOF_BIT)
  746. + dev_kfree_skb(txq->skb[c]);
  747. +
  748. + c++;
  749. + c &= m;
  750. +
  751. + if (!(word3 & SOF_BIT))
  752. + continue;
  753. +
  754. + if (!word0.bits.status_tx_ok) {
  755. + errs++;
  756. + continue;
  757. + }
  758. +
  759. + pkts++;
  760. + bytes += txd->word1.bits.byte_count;
  761. +
  762. + if (word1.bits32 & TSS_CHECKUM_ENABLE)
  763. + hwchksum++;
  764. +
  765. + nfrags = word0.bits.desc_count - 1;
  766. + if (nfrags) {
  767. + if (nfrags >= TX_MAX_FRAGS)
  768. + nfrags = TX_MAX_FRAGS - 1;
  769. +
  770. + u64_stats_update_begin(&gmac->tx_stats_syncp);
  771. + gmac->tx_frag_stats[nfrags]++;
  772. + u64_stats_update_end(&gmac->ir_stats_syncp);
  773. + }
  774. + }
  775. +
  776. + u64_stats_update_begin(&gmac->ir_stats_syncp);
  777. + gmac->stats.tx_errors += errs;
  778. + gmac->stats.tx_packets += pkts;
  779. + gmac->stats.tx_bytes += bytes;
  780. + gmac->tx_hw_csummed += hwchksum;
  781. + u64_stats_update_end(&gmac->ir_stats_syncp);
  782. +
  783. + txq->cptr = c;
  784. +}
  785. +
  786. +static void gmac_cleanup_txqs(struct net_device *dev)
  787. +{
  788. + struct gmac_private *gmac = netdev_priv(dev);
  789. + struct toe_private *toe = gmac->toe;
  790. + void __iomem *rwptr_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE0_PTR_REG;
  791. + void __iomem *base_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE_BASE_REG;
  792. +
  793. + unsigned n_txq = dev->num_tx_queues;
  794. + unsigned int r, i;
  795. +
  796. + for (i = 0; i < n_txq; i++) {
  797. + r = readw(rwptr_reg);
  798. + rwptr_reg += 2;
  799. + writew(r, rwptr_reg);
  800. + rwptr_reg += 2;
  801. +
  802. + gmac_clean_txq(dev, gmac->txq + i, r);
  803. + }
  804. + writel(0, base_reg);
  805. +
  806. + kfree(gmac->txq->skb);
  807. + dma_free_coherent(toe->dev,
  808. + n_txq * sizeof(*gmac->txq->ring) << gmac->txq_order,
  809. + gmac->txq->ring, gmac->txq_dma_base);
  810. +}
  811. +
  812. +static int gmac_setup_rxq(struct net_device *dev)
  813. +{
  814. + struct gmac_private *gmac = netdev_priv(dev);
  815. + struct toe_private *toe = gmac->toe;
  816. + NONTOE_QHDR_T __iomem *qhdr = toe->iomem + TOE_DEFAULT_Q_HDR_BASE(dev->dev_id);
  817. +
  818. + gmac->rxq_rwptr = &qhdr->word1;
  819. + gmac->rxq_ring = dma_alloc_coherent(toe->dev,
  820. + sizeof(*gmac->rxq_ring) << gmac->rxq_order,
  821. + &gmac->rxq_dma_base, GFP_KERNEL);
  822. + if (!gmac->rxq_ring)
  823. + return -ENOMEM;
  824. +
  825. + BUG_ON(gmac->rxq_dma_base & ~NONTOE_QHDR0_BASE_MASK);
  826. +
  827. + writel(gmac->rxq_dma_base | gmac->rxq_order, &qhdr->word0);
  828. + writel(0, gmac->rxq_rwptr);
  829. + return 0;
  830. +}
  831. +
  832. +static void gmac_cleanup_rxq(struct net_device *dev)
  833. +{
  834. + struct gmac_private *gmac = netdev_priv(dev);
  835. + struct toe_private *toe = gmac->toe;
  836. +
  837. + NONTOE_QHDR_T __iomem *qhdr = toe->iomem + TOE_DEFAULT_Q_HDR_BASE(dev->dev_id);
  838. + void __iomem *dma_reg = &qhdr->word0;
  839. + void __iomem *ptr_reg = &qhdr->word1;
  840. + GMAC_RXDESC_T *rxd = gmac->rxq_ring;
  841. + DMA_RWPTR_T rw;
  842. + unsigned int r, w;
  843. + unsigned int m = (1 <<gmac->rxq_order) - 1;
  844. + struct page *page;
  845. + dma_addr_t mapping;
  846. +
  847. + rw.bits32 = readl(ptr_reg);
  848. + r = rw.bits.rptr;
  849. + w = rw.bits.wptr;
  850. + writew(r, ptr_reg + 2);
  851. +
  852. + writel(0, dma_reg);
  853. +
  854. + rmb();
  855. + while (r != w) {
  856. + mapping = rxd[r].word2.buf_adr;
  857. + r++;
  858. + r &= m;
  859. +
  860. + if (!mapping)
  861. + continue;
  862. +
  863. + page = pfn_to_page(dma_to_pfn(toe->dev, mapping));
  864. + put_page(page);
  865. + }
  866. +
  867. + dma_free_coherent(toe->dev, sizeof(*gmac->rxq_ring) << gmac->rxq_order,
  868. + gmac->rxq_ring, gmac->rxq_dma_base);
  869. +}
  870. +
  871. +static struct page *toe_freeq_alloc_map_page(struct toe_private *toe, int pn)
  872. +{
  873. + unsigned int fpp_order = PAGE_SHIFT - toe->freeq_frag_order;
  874. + unsigned int frag_len = 1 << toe->freeq_frag_order;
  875. + GMAC_RXDESC_T *freeq_entry;
  876. + dma_addr_t mapping;
  877. + struct page *page;
  878. + int i;
  879. +
  880. + page = alloc_page(__GFP_COLD | GFP_ATOMIC);
  881. + if (!page)
  882. + return NULL;
  883. +
  884. + mapping = dma_map_single(toe->dev, page_address(page),
  885. + PAGE_SIZE, DMA_FROM_DEVICE);
  886. +
  887. + if (unlikely(dma_mapping_error(toe->dev, mapping) || !mapping)) {
  888. + put_page(page);
  889. + return NULL;
  890. + }
  891. +
  892. + freeq_entry = toe->freeq_ring + (pn << fpp_order);
  893. + for (i = 1 << fpp_order; i > 0; --i) {
  894. + freeq_entry->word2.buf_adr = mapping;
  895. + freeq_entry++;
  896. + mapping += frag_len;
  897. + }
  898. +
  899. + if (toe->freeq_page_tab[pn]) {
  900. + mapping = toe->freeq_ring[pn << fpp_order].word2.buf_adr;
  901. + dma_unmap_single(toe->dev, mapping, frag_len, DMA_FROM_DEVICE);
  902. + put_page(toe->freeq_page_tab[pn]);
  903. + }
  904. +
  905. + toe->freeq_page_tab[pn] = page;
  906. + return page;
  907. +}
  908. +
  909. +static unsigned int toe_fill_freeq(struct toe_private *toe, int reset)
  910. +{
  911. + void __iomem *rwptr_reg = toe->iomem + GLOBAL_SWFQ_RWPTR_REG;
  912. +
  913. + DMA_RWPTR_T rw;
  914. + unsigned int pn, epn;
  915. + unsigned int fpp_order = PAGE_SHIFT - toe->freeq_frag_order;
  916. + unsigned int m_pn = (1 << (toe->freeq_order - fpp_order)) - 1;
  917. + struct page *page;
  918. + unsigned int count = 0;
  919. + unsigned long flags;
  920. +
  921. + spin_lock_irqsave(&toe->freeq_lock, flags);
  922. +
  923. + rw.bits32 = readl(rwptr_reg);
  924. + pn = (reset ? rw.bits.rptr : rw.bits.wptr) >> fpp_order;
  925. + epn = (rw.bits.rptr >> fpp_order) - 1;
  926. + epn &= m_pn;
  927. +
  928. + while (pn != epn) {
  929. + page = toe->freeq_page_tab[pn];
  930. +
  931. + if (atomic_read(&page->_count) > 1) {
  932. + unsigned int fl = (pn -epn) & m_pn;
  933. +
  934. + if (fl > 64 >> fpp_order)
  935. + break;
  936. +
  937. + page = toe_freeq_alloc_map_page(toe, pn);
  938. + if (!page)
  939. + break;
  940. + }
  941. +
  942. + atomic_add(1 << fpp_order, &page->_count);
  943. + count += 1 << fpp_order;
  944. + pn++;
  945. + pn &= m_pn;
  946. + }
  947. +
  948. + wmb();
  949. + writew(pn << fpp_order, rwptr_reg+2);
  950. +
  951. + spin_unlock_irqrestore(&toe->freeq_lock, flags);
  952. + return count;
  953. +}
  954. +
  955. +static int toe_setup_freeq(struct toe_private *toe)
  956. +{
  957. + void __iomem *dma_reg = toe->iomem + GLOBAL_SW_FREEQ_BASE_SIZE_REG;
  958. + QUEUE_THRESHOLD_T qt;
  959. + DMA_SKB_SIZE_T skbsz;
  960. + unsigned int filled;
  961. + unsigned int frag_len = 1 << toe->freeq_frag_order;
  962. + unsigned int len = 1 << toe->freeq_order;
  963. + unsigned int fpp_order = PAGE_SHIFT - toe->freeq_frag_order;
  964. + unsigned int pages = len >> fpp_order;
  965. + dma_addr_t mapping;
  966. + unsigned int pn;
  967. +
  968. + toe->freeq_ring = dma_alloc_coherent(toe->dev,
  969. + sizeof(*toe->freeq_ring) << toe->freeq_order,
  970. + &toe->freeq_dma_base, GFP_KERNEL);
  971. + if (!toe->freeq_ring)
  972. + return -ENOMEM;
  973. +
  974. + BUG_ON(toe->freeq_dma_base & ~DMA_Q_BASE_MASK);
  975. +
  976. + toe->freeq_page_tab = kzalloc(pages * sizeof(*toe->freeq_page_tab),
  977. + GFP_KERNEL);
  978. + if (!toe->freeq_page_tab)
  979. + goto err_freeq;
  980. +
  981. + for (pn = 0; pn < pages; pn++)
  982. + if (!toe_freeq_alloc_map_page(toe, pn))
  983. + goto err_freeq_alloc;
  984. +
  985. + filled = toe_fill_freeq(toe, 1);
  986. + if (!filled)
  987. + goto err_freeq_alloc;
  988. +
  989. + qt.bits32 = readl(toe->iomem + GLOBAL_QUEUE_THRESHOLD_REG);
  990. + qt.bits.swfq_empty = 32;
  991. + writel(qt.bits32, toe->iomem + GLOBAL_QUEUE_THRESHOLD_REG);
  992. +
  993. + skbsz.bits.sw_skb_size = 1 << toe->freeq_frag_order;
  994. + writel(skbsz.bits32, toe->iomem + GLOBAL_DMA_SKB_SIZE_REG);
  995. + writel(toe->freeq_dma_base | toe->freeq_order, dma_reg);
  996. +
  997. + return 0;
  998. +
  999. +err_freeq_alloc:
  1000. + while (pn > 0) {
  1001. + --pn;
  1002. + mapping = toe->freeq_ring[pn << fpp_order].word2.buf_adr;
  1003. + dma_unmap_single(toe->dev, mapping, frag_len, DMA_FROM_DEVICE);
  1004. + put_page(toe->freeq_page_tab[pn]);
  1005. + }
  1006. +
  1007. +err_freeq:
  1008. + dma_free_coherent(toe->dev,
  1009. + sizeof(*toe->freeq_ring) << toe->freeq_order,
  1010. + toe->freeq_ring, toe->freeq_dma_base);
  1011. + toe->freeq_ring = NULL;
  1012. + return -ENOMEM;
  1013. +}
  1014. +
  1015. +static void toe_cleanup_freeq(struct toe_private *toe)
  1016. +{
  1017. + void __iomem *dma_reg = toe->iomem + GLOBAL_SW_FREEQ_BASE_SIZE_REG;
  1018. + void __iomem *ptr_reg = toe->iomem + GLOBAL_SWFQ_RWPTR_REG;
  1019. +
  1020. + unsigned int frag_len = 1 << toe->freeq_frag_order;
  1021. + unsigned int len = 1 << toe->freeq_order;
  1022. + unsigned int fpp_order = PAGE_SHIFT - toe->freeq_frag_order;
  1023. + unsigned int pages = len >> fpp_order;
  1024. + struct page *page;
  1025. + dma_addr_t mapping;
  1026. + unsigned int pn;
  1027. +
  1028. + writew(readw(ptr_reg), ptr_reg + 2);
  1029. + writel(0, dma_reg);
  1030. +
  1031. + for (pn = 0; pn < pages; pn++) {
  1032. + mapping = toe->freeq_ring[pn << fpp_order].word2.buf_adr;
  1033. + dma_unmap_single(toe->dev, mapping, frag_len, DMA_FROM_DEVICE);
  1034. +
  1035. + page = toe->freeq_page_tab[pn];
  1036. + while (atomic_read(&page->_count) > 0)
  1037. + put_page(page);
  1038. + }
  1039. +
  1040. + kfree(toe->freeq_page_tab);
  1041. +
  1042. + dma_free_coherent(toe->dev,
  1043. + sizeof(*toe->freeq_ring) << toe->freeq_order,
  1044. + toe->freeq_ring, toe->freeq_dma_base);
  1045. +}
  1046. +
  1047. +static int toe_resize_freeq(struct toe_private *toe, int changing_dev_id)
  1048. +{
  1049. + void __iomem *irqen_reg = toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG;
  1050. + struct gmac_private *gmac;
  1051. + struct net_device *other = toe->netdev[1 - changing_dev_id];
  1052. + unsigned new_size = 0;
  1053. + unsigned new_order;
  1054. + int err;
  1055. + unsigned long flags;
  1056. + unsigned en;
  1057. +
  1058. + if (other && netif_running(other))
  1059. + return -EBUSY;
  1060. +
  1061. + if (toe->netdev[0]) {
  1062. + gmac = netdev_priv(toe->netdev[0]);
  1063. + new_size = 1 << (gmac->rxq_order + 1);
  1064. + }
  1065. +
  1066. + if (toe->netdev[1]) {
  1067. + gmac = netdev_priv(toe->netdev[1]);
  1068. + new_size += 1 << (gmac->rxq_order + 1);
  1069. + }
  1070. +
  1071. + new_order = min(15, ilog2(new_size - 1) + 1);
  1072. + if (toe->freeq_order == new_order)
  1073. + return 0;
  1074. +
  1075. + spin_lock_irqsave(&toe->irq_lock, flags);
  1076. + en = readl(irqen_reg);
  1077. + en &= ~SWFQ_EMPTY_INT_BIT;
  1078. + writel(en, irqen_reg);
  1079. +
  1080. + if (toe->freeq_ring)
  1081. + toe_cleanup_freeq(toe);
  1082. +
  1083. + toe->freeq_order = new_order;
  1084. + err = toe_setup_freeq(toe);
  1085. +
  1086. + en |= SWFQ_EMPTY_INT_BIT;
  1087. + writel(en, irqen_reg);
  1088. + spin_unlock_irqrestore(&toe->irq_lock, flags);
  1089. +
  1090. + return err;
  1091. +}
  1092. +
  1093. +static void gmac_tx_irq_enable(struct net_device *dev, unsigned txq, int en)
  1094. +{
  1095. + struct gmac_private *gmac = netdev_priv(dev);
  1096. + struct toe_private *toe = gmac->toe;
  1097. + unsigned val, mask;
  1098. +
  1099. + mask = GMAC0_IRQ0_TXQ0_INTS << (6 * dev->dev_id + txq);
  1100. +
  1101. + if (en)
  1102. + writel(mask, toe->iomem + GLOBAL_INTERRUPT_STATUS_0_REG);
  1103. +
  1104. + val = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1105. + val = en ? val | mask : val & ~mask;
  1106. + writel(val, toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1107. +}
  1108. +
  1109. +
  1110. +static void gmac_tx_irq(struct net_device *dev, unsigned txq_num)
  1111. +{
  1112. + struct netdev_queue *ntxq = netdev_get_tx_queue(dev, txq_num);
  1113. +
  1114. + gmac_tx_irq_enable(dev, txq_num, 0);
  1115. + netif_tx_wake_queue(ntxq);
  1116. +}
  1117. +
  1118. +static int gmac_map_tx_bufs(struct net_device *dev, struct sk_buff *skb,
  1119. + struct gmac_txq *txq, unsigned short *desc)
  1120. +{
  1121. + struct gmac_private *gmac = netdev_priv(dev);
  1122. + struct toe_private *toe = gmac->toe;
  1123. + struct skb_shared_info *skb_si = skb_shinfo(skb);
  1124. + skb_frag_t *skb_frag;
  1125. + short frag, last_frag = skb_si->nr_frags - 1;
  1126. + unsigned short m = (1 << gmac->txq_order) -1;
  1127. + unsigned short w = *desc;
  1128. + unsigned word1, word3, buflen;
  1129. + dma_addr_t mapping;
  1130. + void *buffer;
  1131. + unsigned short mtu;
  1132. + GMAC_TXDESC_T *txd;
  1133. +
  1134. + mtu = ETH_HLEN;
  1135. + mtu += dev->mtu;
  1136. + if (skb->protocol == htons(ETH_P_8021Q))
  1137. + mtu += VLAN_HLEN;
  1138. +
  1139. + word1 = skb->len;
  1140. + word3 = SOF_BIT;
  1141. +
  1142. + if (word1 > mtu) {
  1143. + word1 |= TSS_MTU_ENABLE_BIT;
  1144. + word3 += mtu;
  1145. + }
  1146. +
  1147. + if (skb->ip_summed != CHECKSUM_NONE) {
  1148. + int tcp = 0;
  1149. + if (skb->protocol == htons(ETH_P_IP)) {
  1150. + word1 |= TSS_IP_CHKSUM_BIT;
  1151. + tcp = ip_hdr(skb)->protocol == IPPROTO_TCP;
  1152. + } else { /* IPv6 */
  1153. + word1 |= TSS_IPV6_ENABLE_BIT;
  1154. + tcp = ipv6_hdr(skb)->nexthdr == IPPROTO_TCP;
  1155. + }
  1156. +
  1157. + word1 |= tcp ? TSS_TCP_CHKSUM_BIT : TSS_UDP_CHKSUM_BIT;
  1158. + }
  1159. +
  1160. + frag = -1;
  1161. + while (frag <= last_frag) {
  1162. + if (frag == -1) {
  1163. + buffer = skb->data;
  1164. + buflen = skb_headlen(skb);
  1165. + } else {
  1166. + skb_frag = skb_si->frags + frag;
  1167. + buffer = page_address(skb_frag_page(skb_frag)) +
  1168. + skb_frag->page_offset;
  1169. + buflen = skb_frag->size;
  1170. + }
  1171. +
  1172. + if (frag == last_frag) {
  1173. + word3 |= EOF_BIT;
  1174. + txq->skb[w] = skb;
  1175. + }
  1176. +
  1177. + mapping = dma_map_single(toe->dev, buffer, buflen,
  1178. + DMA_TO_DEVICE);
  1179. + if (dma_mapping_error(toe->dev, mapping) ||
  1180. + !(mapping & PAGE_MASK))
  1181. + goto map_error;
  1182. +
  1183. + txd = txq->ring + w;
  1184. + txd->word0.bits32 = buflen;
  1185. + txd->word1.bits32 = word1;
  1186. + txd->word2.buf_adr = mapping;
  1187. + txd->word3.bits32 = word3;
  1188. +
  1189. + word3 &= MTU_SIZE_BIT_MASK;
  1190. + w++;
  1191. + w &= m;
  1192. + frag++;
  1193. + }
  1194. +
  1195. + *desc = w;
  1196. + return 0;
  1197. +
  1198. +map_error:
  1199. + while (w != *desc) {
  1200. + w--;
  1201. + w &= m;
  1202. +
  1203. + dma_unmap_page(toe->dev, txq->ring[w].word2.buf_adr,
  1204. + txq->ring[w].word0.bits.buffer_size, DMA_TO_DEVICE);
  1205. + }
  1206. + return ENOMEM;
  1207. +}
  1208. +
  1209. +static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1210. +{
  1211. + struct gmac_private *gmac = netdev_priv(dev);
  1212. +
  1213. + void __iomem *ptr_reg;
  1214. + struct gmac_txq *txq;
  1215. + struct netdev_queue *ntxq;
  1216. + int txq_num, nfrags;
  1217. + DMA_RWPTR_T rw;
  1218. + unsigned short r, w, d;
  1219. + unsigned short m = (1 << gmac->txq_order) - 1;
  1220. +
  1221. + SKB_FRAG_ASSERT(skb);
  1222. +
  1223. + if (unlikely(skb->len >= 0x10000))
  1224. + goto out_drop_free;
  1225. +
  1226. + txq_num = skb_get_queue_mapping(skb);
  1227. + ptr_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE_PTR_REG(txq_num);
  1228. + txq = &gmac->txq[txq_num];
  1229. + ntxq = netdev_get_tx_queue(dev, txq_num);
  1230. + nfrags = skb_shinfo(skb)->nr_frags;
  1231. +
  1232. + rw.bits32 = readl(ptr_reg);
  1233. + r = rw.bits.rptr;
  1234. + w = rw.bits.wptr;
  1235. +
  1236. + d = txq->cptr - w - 1;
  1237. + d &= m;
  1238. +
  1239. + if (unlikely(d < nfrags+2))
  1240. + {
  1241. + gmac_clean_txq(dev, txq, r);
  1242. + d = txq->cptr - w - 1;
  1243. + d &= m;
  1244. +
  1245. + if (unlikely(d < nfrags+2)) {
  1246. + netif_tx_stop_queue(ntxq);
  1247. +
  1248. + d = txq->cptr + nfrags + 16;
  1249. + d &= m;
  1250. + txq->ring[d].word3.bits.eofie = 1;
  1251. + gmac_tx_irq_enable(dev, txq_num, 1);
  1252. +
  1253. + u64_stats_update_begin(&gmac->tx_stats_syncp);
  1254. + dev->stats.tx_fifo_errors++;
  1255. + u64_stats_update_end(&gmac->tx_stats_syncp);
  1256. + return NETDEV_TX_BUSY;
  1257. + }
  1258. + }
  1259. +
  1260. + if (unlikely(gmac_map_tx_bufs(dev, skb, txq, &w))) {
  1261. + if (skb_linearize(skb))
  1262. + goto out_drop;
  1263. +
  1264. + if (unlikely(gmac_map_tx_bufs(dev, skb, txq, &w)))
  1265. + goto out_drop_free;
  1266. +
  1267. + u64_stats_update_begin(&gmac->tx_stats_syncp);
  1268. + gmac->tx_frags_linearized++;
  1269. + u64_stats_update_end(&gmac->tx_stats_syncp);
  1270. + }
  1271. +
  1272. + writew(w, ptr_reg+2);
  1273. +
  1274. + gmac_clean_txq(dev, txq, r);
  1275. + return NETDEV_TX_OK;
  1276. +
  1277. +out_drop_free:
  1278. + dev_kfree_skb(skb);
  1279. +out_drop:
  1280. + u64_stats_update_begin(&gmac->tx_stats_syncp);
  1281. + gmac->stats.tx_dropped++;
  1282. + u64_stats_update_end(&gmac->tx_stats_syncp);
  1283. + return NETDEV_TX_OK;
  1284. +}
  1285. +
  1286. +static void gmac_tx_timeout(struct net_device *dev)
  1287. +{
  1288. + netdev_err(dev, "Tx timeout\n");
  1289. + gmac_dump_dma_state(dev);
  1290. +}
  1291. +
  1292. +static void gmac_enable_irq(struct net_device *dev, int enable)
  1293. +{
  1294. + struct gmac_private *gmac = netdev_priv(dev);
  1295. + struct toe_private *toe = gmac->toe;
  1296. + unsigned long flags;
  1297. + unsigned val, mask;
  1298. +
  1299. + spin_lock_irqsave(&toe->irq_lock, flags);
  1300. +
  1301. + mask = GMAC0_IRQ0_2 << (dev->dev_id * 2);
  1302. + val = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1303. + val = enable ? (val | mask) : (val & ~mask);
  1304. + writel(val, toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1305. +
  1306. + mask = DEFAULT_Q0_INT_BIT << dev->dev_id;
  1307. + val = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1308. + val = enable ? (val | mask) : (val & ~mask);
  1309. + writel(val, toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1310. +
  1311. + mask = GMAC0_IRQ4_8 << (dev->dev_id * 8);
  1312. + val = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG);
  1313. + val = enable ? (val | mask) : (val & ~mask);
  1314. + writel(val, toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG);
  1315. +
  1316. + spin_unlock_irqrestore(&toe->irq_lock, flags);
  1317. +}
  1318. +
  1319. +static void gmac_enable_rx_irq(struct net_device *dev, int enable)
  1320. +{
  1321. + struct gmac_private *gmac = netdev_priv(dev);
  1322. + struct toe_private *toe = gmac->toe;
  1323. + unsigned long flags;
  1324. + unsigned val, mask;
  1325. +
  1326. + spin_lock_irqsave(&toe->irq_lock, flags);
  1327. + mask = DEFAULT_Q0_INT_BIT << dev->dev_id;
  1328. +
  1329. + val = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1330. + val = enable ? (val | mask) : (val & ~mask);
  1331. + writel(val, toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1332. +
  1333. + spin_unlock_irqrestore(&toe->irq_lock, flags);
  1334. +}
  1335. +
  1336. +static struct sk_buff *gmac_skb_if_good_frame(struct gmac_private *gmac,
  1337. + GMAC_RXDESC_0_T word0, unsigned frame_len)
  1338. +{
  1339. + struct sk_buff *skb = NULL;
  1340. + unsigned rx_status = word0.bits.status;
  1341. + unsigned rx_csum = word0.bits.chksum_status;
  1342. +
  1343. + gmac->rx_stats[rx_status]++;
  1344. + gmac->rx_csum_stats[rx_csum]++;
  1345. +
  1346. + if (word0.bits.derr || word0.bits.perr ||
  1347. + rx_status || frame_len < ETH_ZLEN ||
  1348. + rx_csum >= RX_CHKSUM_IP_ERR_UNKNOWN) {
  1349. + gmac->stats.rx_errors++;
  1350. +
  1351. + if (frame_len < ETH_ZLEN || RX_ERROR_LENGTH(rx_status))
  1352. + gmac->stats.rx_length_errors++;
  1353. + if (RX_ERROR_OVER(rx_status))
  1354. + gmac->stats.rx_over_errors++;
  1355. + if (RX_ERROR_CRC(rx_status))
  1356. + gmac->stats.rx_crc_errors++;
  1357. + if (RX_ERROR_FRAME(rx_status))
  1358. + gmac->stats.rx_frame_errors++;
  1359. +
  1360. + return NULL;
  1361. + }
  1362. +
  1363. + skb = napi_get_frags(&gmac->napi);
  1364. + if (!skb)
  1365. + return NULL;
  1366. +
  1367. + if (rx_csum == RX_CHKSUM_IP_UDP_TCP_OK)
  1368. + skb->ip_summed = CHECKSUM_UNNECESSARY;
  1369. +
  1370. + gmac->stats.rx_bytes += frame_len;
  1371. + gmac->stats.rx_packets++;
  1372. + return skb;
  1373. +}
  1374. +
  1375. +static unsigned gmac_rx(struct net_device *dev, unsigned budget)
  1376. +{
  1377. + struct gmac_private *gmac = netdev_priv(dev);
  1378. + struct toe_private *toe = gmac->toe;
  1379. + void __iomem *ptr_reg = gmac->rxq_rwptr;
  1380. +
  1381. + static struct sk_buff *skb;
  1382. +
  1383. + DMA_RWPTR_T rw;
  1384. + unsigned short r, w;
  1385. + unsigned short m = (1 << gmac->rxq_order) -1;
  1386. + GMAC_RXDESC_T *rx = NULL;
  1387. + struct page* page = NULL;
  1388. + unsigned page_offs;
  1389. + unsigned int frame_len, frag_len;
  1390. + int frag_nr = 0;
  1391. +
  1392. + GMAC_RXDESC_0_T word0;
  1393. + GMAC_RXDESC_1_T word1;
  1394. + dma_addr_t mapping;
  1395. + GMAC_RXDESC_3_T word3;
  1396. +
  1397. + rw.bits32 = readl(ptr_reg);
  1398. + /* Reset interrupt as all packages until here are taken into account */
  1399. + writel(DEFAULT_Q0_INT_BIT << dev->dev_id,
  1400. + toe->iomem + GLOBAL_INTERRUPT_STATUS_1_REG);
  1401. + r = rw.bits.rptr;
  1402. + w = rw.bits.wptr;
  1403. +
  1404. + while (budget && w != r) {
  1405. + rx = gmac->rxq_ring + r;
  1406. + word0 = rx->word0;
  1407. + word1 = rx->word1;
  1408. + mapping = rx->word2.buf_adr;
  1409. + word3 = rx->word3;
  1410. +
  1411. + r++;
  1412. + r &= m;
  1413. +
  1414. + frag_len = word0.bits.buffer_size;
  1415. + frame_len =word1.bits.byte_count;
  1416. + page_offs = mapping & ~PAGE_MASK;
  1417. +
  1418. + if (unlikely(!mapping)) {
  1419. + netdev_err(dev, "rxq[%u]: HW BUG: zero DMA desc\n", r);
  1420. + goto err_drop;
  1421. + }
  1422. +
  1423. + page = pfn_to_page(dma_to_pfn(toe->dev, mapping));
  1424. +
  1425. + if (word3.bits32 & SOF_BIT) {
  1426. + if (unlikely(skb)) {
  1427. + napi_free_frags(&gmac->napi);
  1428. + gmac->stats.rx_dropped++;
  1429. + }
  1430. +
  1431. + skb = gmac_skb_if_good_frame(gmac, word0, frame_len);
  1432. + if (unlikely(!skb))
  1433. + goto err_drop;
  1434. +
  1435. + page_offs += NET_IP_ALIGN;
  1436. + frag_len -= NET_IP_ALIGN;
  1437. + frag_nr = 0;
  1438. +
  1439. + } else if (!skb) {
  1440. + put_page(page);
  1441. + continue;
  1442. + }
  1443. +
  1444. + if (word3.bits32 & EOF_BIT)
  1445. + frag_len = frame_len - skb->len;
  1446. +
  1447. + /* append page frag to skb */
  1448. + if (unlikely(frag_nr == MAX_SKB_FRAGS))
  1449. + goto err_drop;
  1450. +
  1451. + if (frag_len == 0)
  1452. + netdev_err(dev, "Received fragment with len = 0\n");
  1453. +
  1454. + skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
  1455. + skb->len += frag_len;
  1456. + skb->data_len += frag_len;
  1457. + skb->truesize += frag_len;
  1458. + frag_nr++;
  1459. +
  1460. + if (word3.bits32 & EOF_BIT) {
  1461. + napi_gro_frags(&gmac->napi);
  1462. + skb = NULL;
  1463. + --budget;
  1464. + }
  1465. + continue;
  1466. +
  1467. +err_drop:
  1468. + if (skb) {
  1469. + napi_free_frags(&gmac->napi);
  1470. + skb = NULL;
  1471. + }
  1472. +
  1473. + if (mapping)
  1474. + put_page(page);
  1475. +
  1476. + gmac->stats.rx_dropped++;
  1477. + }
  1478. +
  1479. + writew(r, ptr_reg);
  1480. + return budget;
  1481. +}
  1482. +
  1483. +static int gmac_napi_poll(struct napi_struct *napi, int budget)
  1484. +{
  1485. + struct gmac_private *gmac = netdev_priv(napi->dev);
  1486. + struct toe_private *toe = gmac->toe;
  1487. + unsigned rx;
  1488. + unsigned freeq_threshold = 1 << (toe->freeq_order - 1);
  1489. +
  1490. + u64_stats_update_begin(&gmac->rx_stats_syncp);
  1491. +
  1492. + rx = budget - gmac_rx(napi->dev, budget);
  1493. +
  1494. + if (rx == 0) {
  1495. + napi_gro_flush(napi, false);
  1496. + __napi_complete(napi);
  1497. + gmac_enable_rx_irq(napi->dev, 1);
  1498. + ++gmac->rx_napi_exits;
  1499. + }
  1500. +
  1501. + gmac->freeq_refill += rx;
  1502. + if (gmac->freeq_refill > freeq_threshold) {
  1503. + gmac->freeq_refill -= freeq_threshold;
  1504. + toe_fill_freeq(toe, 0);
  1505. + }
  1506. +
  1507. + u64_stats_update_end(&gmac->rx_stats_syncp);
  1508. + return rx;
  1509. +}
  1510. +
  1511. +static void gmac_dump_dma_state(struct net_device *dev)
  1512. +{
  1513. + struct gmac_private *gmac = netdev_priv(dev);
  1514. + struct toe_private *toe = gmac->toe;
  1515. + void __iomem *ptr_reg;
  1516. + unsigned reg[5];
  1517. +
  1518. + /* Interrupt status */
  1519. + reg[0] = readl(toe->iomem + GLOBAL_INTERRUPT_STATUS_0_REG);
  1520. + reg[1] = readl(toe->iomem + GLOBAL_INTERRUPT_STATUS_1_REG);
  1521. + reg[2] = readl(toe->iomem + GLOBAL_INTERRUPT_STATUS_2_REG);
  1522. + reg[3] = readl(toe->iomem + GLOBAL_INTERRUPT_STATUS_3_REG);
  1523. + reg[4] = readl(toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG);
  1524. + netdev_err(dev, "IRQ status: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1525. + reg[0], reg[1], reg[2], reg[3], reg[4]);
  1526. +
  1527. + /* Interrupt enable */
  1528. + reg[0] = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  1529. + reg[1] = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  1530. + reg[2] = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_2_REG);
  1531. + reg[3] = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_3_REG);
  1532. + reg[4] = readl(toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG);
  1533. + netdev_err(dev, "IRQ enable: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1534. + reg[0], reg[1], reg[2], reg[3], reg[4]);
  1535. +
  1536. + /* RX DMA status */
  1537. + reg[0] = readl(gmac->dma_iomem + GMAC_DMA_RX_FIRST_DESC_REG);
  1538. + reg[1] = readl(gmac->dma_iomem + GMAC_DMA_RX_CURR_DESC_REG);
  1539. + reg[2] = GET_RPTR(gmac->rxq_rwptr);
  1540. + reg[3] = GET_WPTR(gmac->rxq_rwptr);
  1541. + netdev_err(dev, "RX DMA regs: 0x%08x 0x%08x, ptr: %u %u\n",
  1542. + reg[0], reg[1], reg[2], reg[3]);
  1543. +
  1544. + reg[0] = readl(gmac->dma_iomem + GMAC_DMA_RX_DESC_WORD0_REG);
  1545. + reg[1] = readl(gmac->dma_iomem + GMAC_DMA_RX_DESC_WORD1_REG);
  1546. + reg[2] = readl(gmac->dma_iomem + GMAC_DMA_RX_DESC_WORD2_REG);
  1547. + reg[3] = readl(gmac->dma_iomem + GMAC_DMA_RX_DESC_WORD3_REG);
  1548. + netdev_err(dev, "RX DMA descriptor: 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1549. + reg[0], reg[1], reg[2], reg[3]);
  1550. +
  1551. + /* TX DMA status */
  1552. + ptr_reg = gmac->dma_iomem + GMAC_SW_TX_QUEUE0_PTR_REG;
  1553. +
  1554. + reg[0] = readl(gmac->dma_iomem + GMAC_DMA_TX_FIRST_DESC_REG);
  1555. + reg[1] = readl(gmac->dma_iomem + GMAC_DMA_TX_CURR_DESC_REG);
  1556. + reg[2] = GET_RPTR(ptr_reg);
  1557. + reg[3] = GET_WPTR(ptr_reg);
  1558. + netdev_err(dev, "TX DMA regs: 0x%08x 0x%08x, ptr: %u %u\n",
  1559. + reg[0], reg[1], reg[2], reg[3]);
  1560. +
  1561. + reg[0] = readl(gmac->dma_iomem + GMAC_DMA_TX_DESC_WORD0_REG);
  1562. + reg[1] = readl(gmac->dma_iomem + GMAC_DMA_TX_DESC_WORD1_REG);
  1563. + reg[2] = readl(gmac->dma_iomem + GMAC_DMA_TX_DESC_WORD2_REG);
  1564. + reg[3] = readl(gmac->dma_iomem + GMAC_DMA_TX_DESC_WORD3_REG);
  1565. + netdev_err(dev, "TX DMA descriptor: 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1566. + reg[0], reg[1], reg[2], reg[3]);
  1567. +
  1568. + /* FREE queues status */
  1569. + ptr_reg = toe->iomem + GLOBAL_SWFQ_RWPTR_REG;
  1570. +
  1571. + reg[0] = GET_RPTR(ptr_reg);
  1572. + reg[1] = GET_WPTR(ptr_reg);
  1573. +
  1574. + ptr_reg = toe->iomem + GLOBAL_HWFQ_RWPTR_REG;
  1575. +
  1576. + reg[2] = GET_RPTR(ptr_reg);
  1577. + reg[3] = GET_WPTR(ptr_reg);
  1578. + netdev_err(dev, "FQ SW ptr: %u %u, HW ptr: %u %u\n",
  1579. + reg[0], reg[1], reg[2], reg[3]);
  1580. +}
  1581. +
  1582. +static void gmac_update_hw_stats(struct net_device *dev)
  1583. +{
  1584. + struct gmac_private *gmac = netdev_priv(dev);
  1585. + struct toe_private *toe = gmac->toe;
  1586. + unsigned long flags;
  1587. + unsigned int rx_discards, rx_mcast, rx_bcast;
  1588. +
  1589. + spin_lock_irqsave(&toe->irq_lock, flags);
  1590. + u64_stats_update_begin(&gmac->ir_stats_syncp);
  1591. +
  1592. + gmac->hw_stats[0] += rx_discards = readl(gmac->ctl_iomem + GMAC_IN_DISCARDS);
  1593. + gmac->hw_stats[1] += readl(gmac->ctl_iomem + GMAC_IN_ERRORS);
  1594. + gmac->hw_stats[2] += rx_mcast = readl(gmac->ctl_iomem + GMAC_IN_MCAST);
  1595. + gmac->hw_stats[3] += rx_bcast = readl(gmac->ctl_iomem + GMAC_IN_BCAST);
  1596. + gmac->hw_stats[4] += readl(gmac->ctl_iomem + GMAC_IN_MAC1);
  1597. + gmac->hw_stats[5] += readl(gmac->ctl_iomem + GMAC_IN_MAC2);
  1598. +
  1599. + gmac->stats.rx_missed_errors += rx_discards;
  1600. + gmac->stats.multicast += rx_mcast;
  1601. + gmac->stats.multicast += rx_bcast;
  1602. +
  1603. + writel(GMAC0_MIB_INT_BIT << (dev->dev_id * 8),
  1604. + toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG);
  1605. +
  1606. + u64_stats_update_end(&gmac->ir_stats_syncp);
  1607. + spin_unlock_irqrestore(&toe->irq_lock, flags);
  1608. +}
  1609. +
  1610. +static inline unsigned gmac_get_intr_flags(struct net_device *dev, int i)
  1611. +{
  1612. + struct gmac_private *gmac = netdev_priv(dev);
  1613. + struct toe_private *toe = gmac->toe;
  1614. + void __iomem *irqif_reg, *irqen_reg;
  1615. + unsigned offs, val;
  1616. +
  1617. + offs = i * (GLOBAL_INTERRUPT_STATUS_1_REG - GLOBAL_INTERRUPT_STATUS_0_REG);
  1618. +
  1619. + irqif_reg = toe->iomem + GLOBAL_INTERRUPT_STATUS_0_REG + offs;
  1620. + irqen_reg = toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG + offs;
  1621. +
  1622. + val = readl(irqif_reg) & readl(irqen_reg);
  1623. + return val;
  1624. +}
  1625. +
  1626. +enum hrtimer_restart gmac_coalesce_delay_expired( struct hrtimer *timer )
  1627. +{
  1628. + struct gmac_private *gmac = container_of(timer, struct gmac_private, rx_coalesce_timer);
  1629. +
  1630. + napi_schedule(&gmac->napi);
  1631. + return HRTIMER_NORESTART;
  1632. +}
  1633. +
  1634. +static irqreturn_t gmac_irq(int irq, void *data)
  1635. +{
  1636. + struct net_device *dev = data;
  1637. + struct gmac_private *gmac = netdev_priv(dev);
  1638. + struct toe_private *toe = gmac->toe;
  1639. + unsigned val, orr = 0;
  1640. +
  1641. + orr |= val = gmac_get_intr_flags(dev, 0);
  1642. +
  1643. + if (unlikely(val & (GMAC0_IRQ0_2 << (dev->dev_id * 2)))) {
  1644. + /* oh, crap. */
  1645. + netdev_err(dev, "hw failure/sw bug\n");
  1646. + gmac_dump_dma_state(dev);
  1647. +
  1648. + /* don't know how to recover, just reduce losses */
  1649. + gmac_enable_irq(dev, 0);
  1650. + return IRQ_HANDLED;
  1651. + }
  1652. +
  1653. + if (val & (GMAC0_IRQ0_TXQ0_INTS << (dev->dev_id * 6)))
  1654. + gmac_tx_irq(dev, 0);
  1655. +
  1656. + orr |= val = gmac_get_intr_flags(dev, 1);
  1657. +
  1658. + if (val & (DEFAULT_Q0_INT_BIT << dev->dev_id)) {
  1659. +
  1660. + gmac_enable_rx_irq(dev, 0);
  1661. +
  1662. + if (!gmac->rx_coalesce_nsecs)
  1663. + napi_schedule(&gmac->napi);
  1664. + else {
  1665. + ktime_t ktime;
  1666. + ktime = ktime_set(0, gmac->rx_coalesce_nsecs);
  1667. + hrtimer_start(&gmac->rx_coalesce_timer, ktime, HRTIMER_MODE_REL);
  1668. + }
  1669. + }
  1670. +
  1671. + orr |= val = gmac_get_intr_flags(dev, 4);
  1672. +
  1673. + if (unlikely(val & (GMAC0_MIB_INT_BIT << (dev->dev_id * 8))))
  1674. + gmac_update_hw_stats(dev);
  1675. +
  1676. + if (unlikely(val & (GMAC0_RX_OVERRUN_INT_BIT << (dev->dev_id * 8)))) {
  1677. + writel(GMAC0_RXDERR_INT_BIT << (dev->dev_id * 8),
  1678. + toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG);
  1679. +
  1680. + spin_lock(&toe->irq_lock);
  1681. + u64_stats_update_begin(&gmac->ir_stats_syncp);
  1682. + ++gmac->stats.rx_fifo_errors;
  1683. + u64_stats_update_end(&gmac->ir_stats_syncp);
  1684. + spin_unlock(&toe->irq_lock);
  1685. + }
  1686. +
  1687. + return orr ? IRQ_HANDLED : IRQ_NONE;
  1688. +}
  1689. +
  1690. +static void gmac_start_dma(struct gmac_private *gmac)
  1691. +{
  1692. + void __iomem *dma_ctrl_reg = gmac->dma_iomem + GMAC_DMA_CTRL_REG;
  1693. + GMAC_DMA_CTRL_T dma_ctrl;
  1694. +
  1695. + dma_ctrl.bits32 = readl(dma_ctrl_reg);
  1696. + dma_ctrl.bits.rd_enable = 1;
  1697. + dma_ctrl.bits.td_enable = 1;
  1698. + dma_ctrl.bits.loopback = 0;
  1699. + dma_ctrl.bits.drop_small_ack = 0;
  1700. + dma_ctrl.bits.rd_insert_bytes = NET_IP_ALIGN;
  1701. + dma_ctrl.bits.rd_prot = HPROT_DATA_CACHE | HPROT_PRIVILIGED;
  1702. + dma_ctrl.bits.rd_burst_size = HBURST_INCR8;
  1703. + dma_ctrl.bits.rd_bus = HSIZE_8;
  1704. + dma_ctrl.bits.td_prot = HPROT_DATA_CACHE;
  1705. + dma_ctrl.bits.td_burst_size = HBURST_INCR8;
  1706. + dma_ctrl.bits.td_bus = HSIZE_8;
  1707. +
  1708. + writel(dma_ctrl.bits32, dma_ctrl_reg);
  1709. +}
  1710. +
  1711. +static void gmac_stop_dma(struct gmac_private *gmac)
  1712. +{
  1713. + void __iomem *dma_ctrl_reg = gmac->dma_iomem + GMAC_DMA_CTRL_REG;
  1714. + GMAC_DMA_CTRL_T dma_ctrl;
  1715. +
  1716. + dma_ctrl.bits32 = readl(dma_ctrl_reg);
  1717. + dma_ctrl.bits.rd_enable = 0;
  1718. + dma_ctrl.bits.td_enable = 0;
  1719. + writel(dma_ctrl.bits32, dma_ctrl_reg);
  1720. +}
  1721. +
  1722. +static int gmac_open(struct net_device *dev)
  1723. +{
  1724. + struct gmac_private *gmac = netdev_priv(dev);
  1725. + int err;
  1726. +
  1727. + if (!dev->phydev) {
  1728. + err = gmac_setup_phy(dev);
  1729. + if (err) {
  1730. + netif_err(gmac, ifup, dev,
  1731. + "PHY init failed: %d\n", err);
  1732. + return err;
  1733. + }
  1734. + }
  1735. +
  1736. + err = request_irq(dev->irq, gmac_irq,
  1737. + IRQF_SHARED, dev->name, dev);
  1738. + if (unlikely(err))
  1739. + return err;
  1740. +
  1741. + netif_carrier_off(dev);
  1742. + phy_start(dev->phydev);
  1743. +
  1744. + err = toe_resize_freeq(gmac->toe, dev->dev_id);
  1745. + if (unlikely(err))
  1746. + goto err_stop_phy;
  1747. +
  1748. + err = gmac_setup_rxq(dev);
  1749. + if (unlikely(err))
  1750. + goto err_stop_phy;
  1751. +
  1752. + err = gmac_setup_txqs(dev);
  1753. + if (unlikely(err)) {
  1754. + gmac_cleanup_rxq(dev);
  1755. + goto err_stop_phy;
  1756. + }
  1757. +
  1758. + napi_enable(&gmac->napi);
  1759. +
  1760. + gmac_start_dma(gmac);
  1761. + gmac_enable_irq(dev, 1);
  1762. + gmac_enable_tx_rx(dev);
  1763. + netif_tx_start_all_queues(dev);
  1764. +
  1765. + hrtimer_init(&gmac->rx_coalesce_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  1766. + gmac->rx_coalesce_timer.function = &gmac_coalesce_delay_expired;
  1767. + return 0;
  1768. +
  1769. +err_stop_phy:
  1770. + phy_stop(dev->phydev);
  1771. + free_irq(dev->irq, dev);
  1772. + return err;
  1773. +}
  1774. +
  1775. +static int gmac_stop(struct net_device *dev)
  1776. +{
  1777. + struct gmac_private *gmac = netdev_priv(dev);
  1778. +
  1779. + hrtimer_cancel(&gmac->rx_coalesce_timer);
  1780. + netif_tx_stop_all_queues(dev);
  1781. + gmac_disable_tx_rx(dev);
  1782. + gmac_stop_dma(gmac);
  1783. + napi_disable(&gmac->napi);
  1784. +
  1785. + gmac_enable_irq(dev, 0);
  1786. + gmac_cleanup_rxq(dev);
  1787. + gmac_cleanup_txqs(dev);
  1788. +
  1789. + phy_stop(dev->phydev);
  1790. + free_irq(dev->irq, dev);
  1791. +
  1792. + gmac_update_hw_stats(dev);
  1793. + return 0;
  1794. +}
  1795. +
  1796. +static void gmac_set_rx_mode(struct net_device *dev)
  1797. +{
  1798. + struct gmac_private *gmac = netdev_priv(dev);
  1799. + struct netdev_hw_addr *ha;
  1800. + __u32 mc_filter[2];
  1801. + unsigned bit_nr;
  1802. + GMAC_RX_FLTR_T filter = { .bits = {
  1803. + .broadcast = 1,
  1804. + .multicast = 1,
  1805. + .unicast = 1,
  1806. + } };
  1807. +
  1808. + mc_filter[1] = mc_filter[0] = 0;
  1809. +
  1810. + if (dev->flags & IFF_PROMISC) {
  1811. + filter.bits.error = 1;
  1812. + filter.bits.promiscuous = 1;
  1813. + } else if (!(dev->flags & IFF_ALLMULTI)) {
  1814. + mc_filter[1] = mc_filter[0] = 0;
  1815. + netdev_for_each_mc_addr(ha, dev) {
  1816. + bit_nr = ~crc32_le(~0, ha->addr, ETH_ALEN) & 0x3f;
  1817. + mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 0x1f);
  1818. + }
  1819. + }
  1820. +
  1821. + writel(mc_filter[0], gmac->ctl_iomem + GMAC_MCAST_FIL0);
  1822. + writel(mc_filter[1], gmac->ctl_iomem + GMAC_MCAST_FIL1);
  1823. + writel(filter.bits32, gmac->ctl_iomem + GMAC_RX_FLTR);
  1824. +}
  1825. +
  1826. +static void __gmac_set_mac_address(struct net_device *dev)
  1827. +{
  1828. + struct gmac_private *gmac = netdev_priv(dev);
  1829. + __le32 addr[3];
  1830. +
  1831. + memset(addr, 0, sizeof(addr));
  1832. + memcpy(addr, dev->dev_addr, ETH_ALEN);
  1833. +
  1834. + writel(le32_to_cpu(addr[0]), gmac->ctl_iomem + GMAC_STA_ADD0);
  1835. + writel(le32_to_cpu(addr[1]), gmac->ctl_iomem + GMAC_STA_ADD1);
  1836. + writel(le32_to_cpu(addr[2]), gmac->ctl_iomem + GMAC_STA_ADD2);
  1837. +}
  1838. +
  1839. +static int gmac_set_mac_address(struct net_device *dev, void *addr)
  1840. +{
  1841. + struct sockaddr *sa = addr;
  1842. +
  1843. + memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
  1844. + __gmac_set_mac_address(dev);
  1845. +
  1846. + return 0;
  1847. +}
  1848. +
  1849. +static void gmac_clear_hw_stats(struct net_device *dev)
  1850. +{
  1851. + struct gmac_private *gmac = netdev_priv(dev);
  1852. +
  1853. + readl(gmac->ctl_iomem + GMAC_IN_DISCARDS);
  1854. + readl(gmac->ctl_iomem + GMAC_IN_ERRORS);
  1855. + readl(gmac->ctl_iomem + GMAC_IN_MCAST);
  1856. + readl(gmac->ctl_iomem + GMAC_IN_BCAST);
  1857. + readl(gmac->ctl_iomem + GMAC_IN_MAC1);
  1858. + readl(gmac->ctl_iomem + GMAC_IN_MAC2);
  1859. +}
  1860. +
  1861. +static struct rtnl_link_stats64 *gmac_get_stats64(struct net_device *dev,
  1862. + struct rtnl_link_stats64 *storage)
  1863. +{
  1864. + struct gmac_private *gmac = netdev_priv(dev);
  1865. + unsigned int start;
  1866. +
  1867. + gmac_update_hw_stats(dev);
  1868. +
  1869. + /* racing with RX NAPI */
  1870. + do {
  1871. + start = u64_stats_fetch_begin(&gmac->rx_stats_syncp);
  1872. +
  1873. + storage->rx_packets = gmac->stats.rx_packets;
  1874. + storage->rx_bytes = gmac->stats.rx_bytes;
  1875. + storage->rx_errors = gmac->stats.rx_errors;
  1876. + storage->rx_dropped = gmac->stats.rx_dropped;
  1877. +
  1878. + storage->rx_length_errors = gmac->stats.rx_length_errors;
  1879. + storage->rx_over_errors = gmac->stats.rx_over_errors;
  1880. + storage->rx_crc_errors = gmac->stats.rx_crc_errors;
  1881. + storage->rx_frame_errors = gmac->stats.rx_frame_errors;
  1882. +
  1883. + } while (u64_stats_fetch_retry(&gmac->rx_stats_syncp, start));
  1884. +
  1885. + /* racing with MIB and TX completion interrupts */
  1886. + do {
  1887. + start = u64_stats_fetch_begin(&gmac->ir_stats_syncp);
  1888. +
  1889. + storage->tx_errors = gmac->stats.tx_errors;
  1890. + storage->tx_packets = gmac->stats.tx_packets;
  1891. + storage->tx_bytes = gmac->stats.tx_bytes;
  1892. +
  1893. + storage->multicast = gmac->stats.multicast;
  1894. + storage->rx_missed_errors = gmac->stats.rx_missed_errors;
  1895. + storage->rx_fifo_errors = gmac->stats.rx_fifo_errors;
  1896. +
  1897. + } while (u64_stats_fetch_retry(&gmac->ir_stats_syncp, start));
  1898. +
  1899. + /* racing with hard_start_xmit */
  1900. + do {
  1901. + start = u64_stats_fetch_begin(&gmac->tx_stats_syncp);
  1902. +
  1903. + storage->tx_dropped = gmac->stats.tx_dropped;
  1904. +
  1905. + } while (u64_stats_fetch_retry(&gmac->tx_stats_syncp, start));
  1906. +
  1907. + storage->rx_dropped += storage->rx_missed_errors;
  1908. +
  1909. + return storage;
  1910. +}
  1911. +
  1912. +static int gmac_change_mtu(struct net_device *dev, int new_mtu)
  1913. +{
  1914. + int max_len = gmac_pick_rx_max_len(new_mtu);
  1915. +
  1916. + if (max_len < 0)
  1917. + return -EINVAL;
  1918. +
  1919. + gmac_disable_tx_rx(dev);
  1920. +
  1921. + dev->mtu = new_mtu;
  1922. + gmac_update_config0_reg(dev,
  1923. + max_len << CONFIG0_MAXLEN_SHIFT,
  1924. + CONFIG0_MAXLEN_MASK);
  1925. +
  1926. + netdev_update_features(dev);
  1927. +
  1928. + gmac_enable_tx_rx(dev);
  1929. +
  1930. + return 0;
  1931. +}
  1932. +
  1933. +static netdev_features_t gmac_fix_features(struct net_device *dev, netdev_features_t features)
  1934. +{
  1935. + if (dev->mtu + ETH_HLEN + VLAN_HLEN > MTU_SIZE_BIT_MASK)
  1936. + features &= ~GMAC_OFFLOAD_FEATURES;
  1937. +
  1938. + return features;
  1939. +}
  1940. +
  1941. +static int gmac_set_features(struct net_device *dev, netdev_features_t features)
  1942. +{
  1943. + struct gmac_private *gmac = netdev_priv(dev);
  1944. + int enable = features & NETIF_F_RXCSUM;
  1945. + unsigned long flags;
  1946. + u32 reg;
  1947. +
  1948. + spin_lock_irqsave(&gmac->config_lock, flags);
  1949. +
  1950. + reg = readl(gmac->ctl_iomem + GMAC_CONFIG0);
  1951. + reg = enable ? reg | CONFIG0_RX_CHKSUM : reg & ~CONFIG0_RX_CHKSUM;
  1952. + writel(reg, gmac->ctl_iomem + GMAC_CONFIG0);
  1953. +
  1954. + spin_unlock_irqrestore(&gmac->config_lock, flags);
  1955. + return 0;
  1956. +}
  1957. +
  1958. +static int gmac_get_sset_count(struct net_device *dev, int sset)
  1959. +{
  1960. + return sset == ETH_SS_STATS ? GMAC_STATS_NUM : 0;
  1961. +}
  1962. +
  1963. +static void gmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  1964. +{
  1965. + if (stringset != ETH_SS_STATS)
  1966. + return;
  1967. +
  1968. + memcpy(data, gmac_stats_strings, sizeof(gmac_stats_strings));
  1969. +}
  1970. +
  1971. +static void gmac_get_ethtool_stats(struct net_device *dev,
  1972. + struct ethtool_stats *estats, u64 *values)
  1973. +{
  1974. + struct gmac_private *gmac = netdev_priv(dev);
  1975. + unsigned int start;
  1976. + u64 *p;
  1977. + int i;
  1978. +
  1979. + gmac_update_hw_stats(dev);
  1980. +
  1981. + /* racing with MIB interrupt */
  1982. + do {
  1983. + p = values;
  1984. + start = u64_stats_fetch_begin(&gmac->ir_stats_syncp);
  1985. +
  1986. + for (i = 0; i < RX_STATS_NUM; ++i)
  1987. + *p++ = gmac->hw_stats[i];
  1988. +
  1989. + } while (u64_stats_fetch_retry(&gmac->ir_stats_syncp, start));
  1990. + values = p;
  1991. +
  1992. + /* racing with RX NAPI */
  1993. + do {
  1994. + p = values;
  1995. + start = u64_stats_fetch_begin(&gmac->rx_stats_syncp);
  1996. +
  1997. + for (i = 0; i < RX_STATUS_NUM; ++i)
  1998. + *p++ = gmac->rx_stats[i];
  1999. + for (i = 0; i < RX_CHKSUM_NUM; ++i)
  2000. + *p++ = gmac->rx_csum_stats[i];
  2001. + *p++ = gmac->rx_napi_exits;
  2002. +
  2003. + } while (u64_stats_fetch_retry(&gmac->rx_stats_syncp, start));
  2004. + values = p;
  2005. +
  2006. + /* racing with TX start_xmit */
  2007. + do {
  2008. + p = values;
  2009. + start = u64_stats_fetch_begin(&gmac->tx_stats_syncp);
  2010. +
  2011. + for (i = 0; i < TX_MAX_FRAGS; ++i) {
  2012. + *values++ = gmac->tx_frag_stats[i];
  2013. + gmac->tx_frag_stats[i] = 0;
  2014. + }
  2015. + *values++ = gmac->tx_frags_linearized;
  2016. + *values++ = gmac->tx_hw_csummed;
  2017. +
  2018. + } while (u64_stats_fetch_retry(&gmac->tx_stats_syncp, start));
  2019. +}
  2020. +
  2021. +static int gmac_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2022. +{
  2023. + if (!dev->phydev)
  2024. + return -ENXIO;
  2025. + return phy_ethtool_gset(dev->phydev, cmd);
  2026. +}
  2027. +
  2028. +static int gmac_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2029. +{
  2030. + if (!dev->phydev)
  2031. + return -ENXIO;
  2032. + return phy_ethtool_sset(dev->phydev, cmd);
  2033. +}
  2034. +
  2035. +static int gmac_nway_reset(struct net_device *dev)
  2036. +{
  2037. + if (!dev->phydev)
  2038. + return -ENXIO;
  2039. + return phy_start_aneg(dev->phydev);
  2040. +}
  2041. +
  2042. +static void gmac_get_pauseparam(struct net_device *dev,
  2043. + struct ethtool_pauseparam *pparam)
  2044. +{
  2045. + struct gmac_private *gmac = netdev_priv(dev);
  2046. + GMAC_CONFIG0_T config0;
  2047. +
  2048. + config0.bits32 = readl(gmac->ctl_iomem + GMAC_CONFIG0);
  2049. +
  2050. + pparam->rx_pause = config0.bits.rx_fc_en;
  2051. + pparam->tx_pause = config0.bits.tx_fc_en;
  2052. + pparam->autoneg = true;
  2053. +}
  2054. +
  2055. +static void gmac_get_ringparam(struct net_device *dev,
  2056. + struct ethtool_ringparam *rp)
  2057. +{
  2058. + struct gmac_private *gmac = netdev_priv(dev);
  2059. + GMAC_CONFIG0_T config0;
  2060. +
  2061. + config0.bits32 = readl(gmac->ctl_iomem + GMAC_CONFIG0);
  2062. +
  2063. + rp->rx_max_pending = 1 << 15;
  2064. + rp->rx_mini_max_pending = 0;
  2065. + rp->rx_jumbo_max_pending = 0;
  2066. + rp->tx_max_pending = 1 << 15;
  2067. +
  2068. + rp->rx_pending = 1 << gmac->rxq_order;
  2069. + rp->rx_mini_pending = 0;
  2070. + rp->rx_jumbo_pending = 0;
  2071. + rp->tx_pending = 1 << gmac->txq_order;
  2072. +}
  2073. +
  2074. +static int toe_resize_freeq(struct toe_private *toe, int changing_dev_id);
  2075. +
  2076. +static int gmac_set_ringparam(struct net_device *dev,
  2077. + struct ethtool_ringparam *rp)
  2078. +{
  2079. + struct gmac_private *gmac = netdev_priv(dev);
  2080. + struct toe_private *toe = gmac->toe;
  2081. + int err = 0;
  2082. +
  2083. + if (netif_running(dev))
  2084. + return -EBUSY;
  2085. +
  2086. + if (rp->rx_pending) {
  2087. + gmac->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
  2088. + err = toe_resize_freeq(toe, dev->dev_id);
  2089. + }
  2090. +
  2091. + if (rp->tx_pending)
  2092. + {
  2093. + gmac->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
  2094. + gmac->irq_every_tx_packets = 1 << (gmac->txq_order - 2);
  2095. + }
  2096. +
  2097. + return err;
  2098. +}
  2099. +
  2100. +static int gmac_get_coalesce(struct net_device *dev,
  2101. + struct ethtool_coalesce *ecmd)
  2102. +{
  2103. + struct gmac_private *gmac = netdev_priv(dev);
  2104. +
  2105. + ecmd->rx_max_coalesced_frames = 1;
  2106. + ecmd->tx_max_coalesced_frames = gmac->irq_every_tx_packets;
  2107. + ecmd->rx_coalesce_usecs = gmac->rx_coalesce_nsecs/1000;
  2108. +
  2109. + return 0;
  2110. +}
  2111. +
  2112. +static int gmac_set_coalesce(struct net_device *dev,
  2113. + struct ethtool_coalesce *ecmd)
  2114. +{
  2115. + struct gmac_private *gmac = netdev_priv(dev);
  2116. +
  2117. + if (ecmd->tx_max_coalesced_frames < 1)
  2118. + return -EINVAL;
  2119. + if (ecmd->tx_max_coalesced_frames >= 1 << gmac->txq_order)
  2120. + return -EINVAL;
  2121. +
  2122. + gmac->irq_every_tx_packets = ecmd->tx_max_coalesced_frames;
  2123. + gmac->rx_coalesce_nsecs = ecmd->rx_coalesce_usecs * 1000;
  2124. +
  2125. + return 0;
  2126. +}
  2127. +
  2128. +static u32 gmac_get_msglevel(struct net_device *dev)
  2129. +{
  2130. + struct gmac_private *gmac = netdev_priv(dev);
  2131. + return gmac->msg_enable;
  2132. +}
  2133. +
  2134. +static void gmac_set_msglevel(struct net_device *dev, u32 level)
  2135. +{
  2136. + struct gmac_private *gmac = netdev_priv(dev);
  2137. + gmac->msg_enable = level;
  2138. +}
  2139. +
  2140. +static void gmac_get_drvinfo(struct net_device *dev,
  2141. + struct ethtool_drvinfo *info)
  2142. +{
  2143. + strcpy(info->driver, DRV_NAME);
  2144. + strcpy(info->version, DRV_VERSION);
  2145. + strcpy(info->bus_info, dev->dev_id ? "1" : "0");
  2146. +}
  2147. +
  2148. +static const struct net_device_ops gmac_351x_ops = {
  2149. + .ndo_init = gmac_init,
  2150. + .ndo_uninit = gmac_uninit,
  2151. + .ndo_open = gmac_open,
  2152. + .ndo_stop = gmac_stop,
  2153. + .ndo_start_xmit = gmac_start_xmit,
  2154. + .ndo_tx_timeout = gmac_tx_timeout,
  2155. + .ndo_set_rx_mode = gmac_set_rx_mode,
  2156. + .ndo_set_mac_address = gmac_set_mac_address,
  2157. + .ndo_get_stats64 = gmac_get_stats64,
  2158. + .ndo_change_mtu = gmac_change_mtu,
  2159. + .ndo_fix_features = gmac_fix_features,
  2160. + .ndo_set_features = gmac_set_features,
  2161. +};
  2162. +
  2163. +static const struct ethtool_ops gmac_351x_ethtool_ops = {
  2164. + .get_sset_count = gmac_get_sset_count,
  2165. + .get_strings = gmac_get_strings,
  2166. + .get_ethtool_stats = gmac_get_ethtool_stats,
  2167. + .get_settings = gmac_get_settings,
  2168. + .set_settings = gmac_set_settings,
  2169. + .get_link = ethtool_op_get_link,
  2170. + .nway_reset = gmac_nway_reset,
  2171. + .get_pauseparam = gmac_get_pauseparam,
  2172. + .get_ringparam = gmac_get_ringparam,
  2173. + .set_ringparam = gmac_set_ringparam,
  2174. + .get_coalesce = gmac_get_coalesce,
  2175. + .set_coalesce = gmac_set_coalesce,
  2176. + .get_msglevel = gmac_get_msglevel,
  2177. + .set_msglevel = gmac_set_msglevel,
  2178. + .get_drvinfo = gmac_get_drvinfo,
  2179. +};
  2180. +
  2181. +static int gmac_init_netdev(struct toe_private *toe, int num,
  2182. + struct platform_device *pdev)
  2183. +{
  2184. + struct gemini_gmac_platform_data *pdata = pdev->dev.platform_data;
  2185. + struct gmac_private *gmac;
  2186. + struct net_device *dev;
  2187. + int irq, err;
  2188. +
  2189. + if (!pdata->bus_id[num])
  2190. + return 0;
  2191. +
  2192. + irq = platform_get_irq(pdev, num);
  2193. + if (irq < 0) {
  2194. + dev_err(toe->dev, "No IRQ for ethernet device #%d\n", num);
  2195. + return irq;
  2196. + }
  2197. +
  2198. + dev = alloc_etherdev_mq(sizeof(*gmac), TX_QUEUE_NUM);
  2199. + if (!dev) {
  2200. + dev_err(toe->dev, "Can't allocate ethernet device #%d\n", num);
  2201. + return -ENOMEM;
  2202. + }
  2203. +
  2204. + gmac = netdev_priv(dev);
  2205. + gmac->num = num;
  2206. + gmac->toe = toe;
  2207. + SET_NETDEV_DEV(dev, toe->dev);
  2208. +
  2209. + toe->netdev[num] = dev;
  2210. + dev->dev_id = num;
  2211. +
  2212. + gmac->ctl_iomem = toe->iomem + TOE_GMAC_BASE(num);
  2213. + gmac->dma_iomem = toe->iomem + TOE_GMAC_DMA_BASE(num);
  2214. + dev->irq = irq;
  2215. +
  2216. + dev->netdev_ops = &gmac_351x_ops;
  2217. + dev->ethtool_ops = &gmac_351x_ethtool_ops;
  2218. +
  2219. + spin_lock_init(&gmac->config_lock);
  2220. + gmac_clear_hw_stats(dev);
  2221. +
  2222. + dev->hw_features = GMAC_OFFLOAD_FEATURES;
  2223. + dev->features |= GMAC_OFFLOAD_FEATURES | NETIF_F_GRO;
  2224. +
  2225. + gmac->freeq_refill = 0;
  2226. + netif_napi_add(dev, &gmac->napi, gmac_napi_poll, DEFAULT_NAPI_WEIGHT);
  2227. +
  2228. + if (is_valid_ether_addr((void *)toe->mac_addr[num]))
  2229. + memcpy(dev->dev_addr, toe->mac_addr[num], ETH_ALEN);
  2230. + else
  2231. + random_ether_addr(dev->dev_addr);
  2232. + __gmac_set_mac_address(dev);
  2233. +
  2234. + err = gmac_setup_phy(dev);
  2235. + if (err)
  2236. + netif_warn(gmac, probe, dev,
  2237. + "PHY init failed: %d, deferring to ifup time\n", err);
  2238. +
  2239. + err = register_netdev(dev);
  2240. + if (!err)
  2241. + {
  2242. + pr_info(DRV_NAME " %s: irq %d, dma base 0x%p, io base 0x%p\n",
  2243. + dev->name, irq, gmac->dma_iomem, gmac->ctl_iomem);
  2244. + return 0;
  2245. + }
  2246. +
  2247. + toe->netdev[num] = NULL;
  2248. + free_netdev(dev);
  2249. + return err;
  2250. +}
  2251. +
  2252. +static irqreturn_t toe_irq_thread(int irq, void *data)
  2253. +{
  2254. + struct toe_private *toe = data;
  2255. + void __iomem *irqen_reg = toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG;
  2256. + void __iomem *irqif_reg = toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG;
  2257. + unsigned long irqmask = SWFQ_EMPTY_INT_BIT;
  2258. + unsigned long flags;
  2259. +
  2260. + toe_fill_freeq(toe, 0);
  2261. +
  2262. + /* Ack and enable interrupt */
  2263. + spin_lock_irqsave(&toe->irq_lock, flags);
  2264. + writel(irqmask, irqif_reg);
  2265. + irqmask |= readl(irqen_reg);
  2266. + writel(irqmask, irqen_reg);
  2267. + spin_unlock_irqrestore(&toe->irq_lock, flags);
  2268. +
  2269. + return IRQ_HANDLED;
  2270. +}
  2271. +
  2272. +static irqreturn_t toe_irq(int irq, void *data)
  2273. +{
  2274. + struct toe_private *toe = data;
  2275. + void __iomem *irqif_reg = toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG;
  2276. + void __iomem *irqen_reg = toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG;
  2277. + unsigned long val, en;
  2278. + irqreturn_t ret = IRQ_NONE;
  2279. +
  2280. + spin_lock(&toe->irq_lock);
  2281. +
  2282. + val = readl(irqif_reg);
  2283. + en = readl(irqen_reg);
  2284. +
  2285. + if (val & en & SWFQ_EMPTY_INT_BIT) {
  2286. + en &= ~(SWFQ_EMPTY_INT_BIT | GMAC0_RX_OVERRUN_INT_BIT
  2287. + | GMAC1_RX_OVERRUN_INT_BIT);
  2288. + writel(en, irqen_reg);
  2289. + ret = IRQ_WAKE_THREAD;
  2290. + }
  2291. +
  2292. + spin_unlock(&toe->irq_lock);
  2293. + return ret;
  2294. +}
  2295. +
  2296. +static int toe_init(struct toe_private *toe,
  2297. + struct platform_device *pdev)
  2298. +{
  2299. + int err;
  2300. +
  2301. + writel(0, toe->iomem + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
  2302. + writel(0, toe->iomem + GLOBAL_HW_FREEQ_BASE_SIZE_REG);
  2303. + writel(0, toe->iomem + GLOBAL_SWFQ_RWPTR_REG);
  2304. + writel(0, toe->iomem + GLOBAL_HWFQ_RWPTR_REG);
  2305. +
  2306. + toe->freeq_frag_order = DEFAULT_RX_BUF_ORDER;
  2307. + toe->freeq_order = ~0;
  2308. +
  2309. + err = request_threaded_irq(toe->irq, toe_irq,
  2310. + toe_irq_thread, IRQF_SHARED, DRV_NAME " toe", toe);
  2311. + if (err)
  2312. + goto err_freeq;
  2313. +
  2314. + return 0;
  2315. +
  2316. +err_freeq:
  2317. + toe_cleanup_freeq(toe);
  2318. + return err;
  2319. +}
  2320. +
  2321. +static void toe_deinit(struct toe_private *toe)
  2322. +{
  2323. + free_irq(toe->irq, toe);
  2324. + toe_cleanup_freeq(toe);
  2325. +}
  2326. +
  2327. +static int toe_reset(struct toe_private *toe)
  2328. +{
  2329. + unsigned int reg = 0, retry = 5;
  2330. +
  2331. + reg = readl((void __iomem*)(IO_ADDRESS(GEMINI_GLOBAL_BASE) +
  2332. + GLOBAL_RESET));
  2333. + reg |= RESET_GMAC1 | RESET_GMAC0;
  2334. + writel(reg, (void __iomem*)(IO_ADDRESS(GEMINI_GLOBAL_BASE) +
  2335. + GLOBAL_RESET));
  2336. +
  2337. + do {
  2338. + udelay(2);
  2339. + reg = readl((void __iomem*)(toe->iomem +
  2340. + GLOBAL_TOE_VERSION_REG));
  2341. + barrier();
  2342. + } while (!reg && --retry);
  2343. +
  2344. + return reg ? 0 : -EIO;
  2345. +}
  2346. +
  2347. +/*
  2348. + * Interrupt config:
  2349. + *
  2350. + * GMAC0 intr bits ------> int0 ----> eth0
  2351. + * GMAC1 intr bits ------> int1 ----> eth1
  2352. + * TOE intr -------------> int1 ----> eth1
  2353. + * Classification Intr --> int0 ----> eth0
  2354. + * Default Q0 -----------> int0 ----> eth0
  2355. + * Default Q1 -----------> int1 ----> eth1
  2356. + * FreeQ intr -----------> int1 ----> eth1
  2357. + */
  2358. +static void toe_init_irq(struct toe_private *toe)
  2359. +{
  2360. + writel(0, toe->iomem + GLOBAL_INTERRUPT_ENABLE_0_REG);
  2361. + writel(0, toe->iomem + GLOBAL_INTERRUPT_ENABLE_1_REG);
  2362. + writel(0, toe->iomem + GLOBAL_INTERRUPT_ENABLE_2_REG);
  2363. + writel(0, toe->iomem + GLOBAL_INTERRUPT_ENABLE_3_REG);
  2364. + writel(0, toe->iomem + GLOBAL_INTERRUPT_ENABLE_4_REG);
  2365. +
  2366. + writel(0xCCFC0FC0, toe->iomem + GLOBAL_INTERRUPT_SELECT_0_REG);
  2367. + writel(0x00F00002, toe->iomem + GLOBAL_INTERRUPT_SELECT_1_REG);
  2368. + writel(0xFFFFFFFF, toe->iomem + GLOBAL_INTERRUPT_SELECT_2_REG);
  2369. + writel(0xFFFFFFFF, toe->iomem + GLOBAL_INTERRUPT_SELECT_3_REG);
  2370. + writel(0xFF000003, toe->iomem + GLOBAL_INTERRUPT_SELECT_4_REG);
  2371. +
  2372. + /* edge-triggered interrupts packed to level-triggered one... */
  2373. + writel(~0, toe->iomem + GLOBAL_INTERRUPT_STATUS_0_REG);
  2374. + writel(~0, toe->iomem + GLOBAL_INTERRUPT_STATUS_1_REG);
  2375. + writel(~0, toe->iomem + GLOBAL_INTERRUPT_STATUS_2_REG);
  2376. + writel(~0, toe->iomem + GLOBAL_INTERRUPT_STATUS_3_REG);
  2377. + writel(~0, toe->iomem + GLOBAL_INTERRUPT_STATUS_4_REG);
  2378. +}
  2379. +
  2380. +static void toe_save_mac_addr(struct toe_private *toe,
  2381. + struct platform_device *pdev)
  2382. +{
  2383. + struct gemini_gmac_platform_data *pdata = pdev->dev.platform_data;
  2384. + void __iomem *ctl;
  2385. + int i;
  2386. +
  2387. + for (i = 0; i < 2; i++) {
  2388. + if (pdata->bus_id[i]) {
  2389. + ctl = toe->iomem + TOE_GMAC_BASE(i);
  2390. + toe->mac_addr[i][0] = cpu_to_le32(readl(ctl + GMAC_STA_ADD0));
  2391. + toe->mac_addr[i][1] = cpu_to_le32(readl(ctl + GMAC_STA_ADD1));
  2392. + toe->mac_addr[i][2] = cpu_to_le32(readl(ctl + GMAC_STA_ADD2));
  2393. + }
  2394. + }
  2395. +}
  2396. +
  2397. +static int gemini_gmac_probe(struct platform_device *pdev)
  2398. +{
  2399. + struct resource *res;
  2400. + struct toe_private *toe;
  2401. + int irq, retval;
  2402. +
  2403. + if (!pdev->dev.platform_data)
  2404. + return -EINVAL;
  2405. +
  2406. + irq = platform_get_irq(pdev, 1);
  2407. + if (irq < 0)
  2408. + return irq;
  2409. +
  2410. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2411. + if (!res) {
  2412. + dev_err(&pdev->dev, "can't get device resources\n");
  2413. + return -ENODEV;
  2414. + }
  2415. +
  2416. + toe = kzalloc(sizeof(*toe), GFP_KERNEL);
  2417. + if (!toe)
  2418. + return -ENOMEM;
  2419. +
  2420. + platform_set_drvdata(pdev, toe);
  2421. + toe->dev = &pdev->dev;
  2422. + toe->irq = irq;
  2423. +
  2424. + toe->iomem = ioremap(res->start, resource_size(res));
  2425. + if (!toe->iomem) {
  2426. + dev_err(toe->dev, "ioremap failed\n");
  2427. + retval = -EIO;
  2428. + goto err_data;
  2429. + }
  2430. +
  2431. + toe_save_mac_addr(toe, pdev);
  2432. +
  2433. + retval = toe_reset(toe);
  2434. + if (retval < 0)
  2435. + goto err_unmap;
  2436. +
  2437. + pr_info(DRV_NAME " toe: irq %d, io base 0x%08x, version %d\n",
  2438. + irq, res->start, retval);
  2439. +
  2440. + spin_lock_init(&toe->irq_lock);
  2441. + spin_lock_init(&toe->freeq_lock);
  2442. +
  2443. + toe_init_irq(toe);
  2444. +
  2445. + retval = toe_init(toe, pdev);
  2446. + if (retval)
  2447. + goto err_unmap;
  2448. +
  2449. + retval = gmac_init_netdev(toe, 0, pdev);
  2450. + if (retval)
  2451. + goto err_uninit;
  2452. +
  2453. + retval = gmac_init_netdev(toe, 1, pdev);
  2454. + if (retval)
  2455. + goto err_uninit;
  2456. +
  2457. + return 0;
  2458. +
  2459. +err_uninit:
  2460. + if (toe->netdev[0])
  2461. + unregister_netdev(toe->netdev[0]);
  2462. + toe_deinit(toe);
  2463. +err_unmap:
  2464. + iounmap(toe->iomem);
  2465. +err_data:
  2466. + kfree(toe);
  2467. + return retval;
  2468. +}
  2469. +
  2470. +static int gemini_gmac_remove(struct platform_device *pdev)
  2471. +{
  2472. + struct toe_private *toe = platform_get_drvdata(pdev);
  2473. + int i;
  2474. +
  2475. + for (i = 0; i < 2; i++)
  2476. + if (toe->netdev[i])
  2477. + unregister_netdev(toe->netdev[i]);
  2478. +
  2479. + toe_init_irq(toe);
  2480. + toe_deinit(toe);
  2481. +
  2482. + iounmap(toe->iomem);
  2483. + kfree(toe);
  2484. +
  2485. + return 0;
  2486. +}
  2487. +
  2488. +static struct platform_driver gemini_gmac_driver = {
  2489. + .probe = gemini_gmac_probe,
  2490. + .remove = gemini_gmac_remove,
  2491. + .driver.name = DRV_NAME,
  2492. + .driver.owner = THIS_MODULE,
  2493. +};
  2494. +
  2495. +static int __init gemini_gmac_init(void)
  2496. +{
  2497. +#ifdef CONFIG_MDIO_GPIO_MODULE
  2498. + request_module("mdio-gpio");
  2499. +#endif
  2500. + return platform_driver_register(&gemini_gmac_driver);
  2501. +}
  2502. +
  2503. +static void __exit gemini_gmac_exit(void)
  2504. +{
  2505. + platform_driver_unregister(&gemini_gmac_driver);
  2506. +}
  2507. +
  2508. +module_init(gemini_gmac_init);
  2509. +module_exit(gemini_gmac_exit);
  2510. --- /dev/null
  2511. +++ b/drivers/net/ethernet/gemini/sl351x_hw.h
  2512. @@ -0,0 +1,1436 @@
  2513. +/*
  2514. + * Register definitions for Gemini LEPUS GMAC Ethernet device driver.
  2515. + *
  2516. + * Copyright (C) 2006, Storlink, Corp.
  2517. + * Copyright (C) 2008-2009, Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  2518. + * Copyright (C) 2010, Michał Mirosław <mirq-linux@rere.qmqm.pl>
  2519. + *
  2520. + * This program is free software; you can redistribute it and/or modify
  2521. + * it under the terms of the GNU General Public License as published by
  2522. + * the Free Software Foundation; either version 2 of the License, or
  2523. + * (at your option) any later version.
  2524. + */
  2525. +#ifndef _GMAC_HW_H
  2526. +#define _GMAC_HW_H
  2527. +
  2528. +#include <linux/bitops.h>
  2529. +
  2530. +/*
  2531. + * Base Registers
  2532. + */
  2533. +#define TOE_NONTOE_QUE_HDR_BASE 0x2000
  2534. +#define TOE_TOE_QUE_HDR_BASE 0x3000
  2535. +#define TOE_V_BIT_BASE 0x4000
  2536. +#define TOE_A_BIT_BASE 0x6000
  2537. +#define TOE_GMAC_DMA_BASE(x) (0x8000 + 0x4000 * (x))
  2538. +#define TOE_GMAC_BASE(x) (0xA000 + 0x4000 * (x))
  2539. +
  2540. +/*
  2541. + * Queue ID
  2542. + */
  2543. +#define TOE_SW_FREE_QID 0x00
  2544. +#define TOE_HW_FREE_QID 0x01
  2545. +#define TOE_GMAC0_SW_TXQ0_QID 0x02
  2546. +#define TOE_GMAC0_SW_TXQ1_QID 0x03
  2547. +#define TOE_GMAC0_SW_TXQ2_QID 0x04
  2548. +#define TOE_GMAC0_SW_TXQ3_QID 0x05
  2549. +#define TOE_GMAC0_SW_TXQ4_QID 0x06
  2550. +#define TOE_GMAC0_SW_TXQ5_QID 0x07
  2551. +#define TOE_GMAC0_HW_TXQ0_QID 0x08
  2552. +#define TOE_GMAC0_HW_TXQ1_QID 0x09
  2553. +#define TOE_GMAC0_HW_TXQ2_QID 0x0A
  2554. +#define TOE_GMAC0_HW_TXQ3_QID 0x0B
  2555. +#define TOE_GMAC1_SW_TXQ0_QID 0x12
  2556. +#define TOE_GMAC1_SW_TXQ1_QID 0x13
  2557. +#define TOE_GMAC1_SW_TXQ2_QID 0x14
  2558. +#define TOE_GMAC1_SW_TXQ3_QID 0x15
  2559. +#define TOE_GMAC1_SW_TXQ4_QID 0x16
  2560. +#define TOE_GMAC1_SW_TXQ5_QID 0x17
  2561. +#define TOE_GMAC1_HW_TXQ0_QID 0x18
  2562. +#define TOE_GMAC1_HW_TXQ1_QID 0x19
  2563. +#define TOE_GMAC1_HW_TXQ2_QID 0x1A
  2564. +#define TOE_GMAC1_HW_TXQ3_QID 0x1B
  2565. +#define TOE_GMAC0_DEFAULT_QID 0x20
  2566. +#define TOE_GMAC1_DEFAULT_QID 0x21
  2567. +#define TOE_CLASSIFICATION_QID(x) (0x22 + x) /* 0x22 ~ 0x2F */
  2568. +#define TOE_TOE_QID(x) (0x40 + x) /* 0x40 ~ 0x7F */
  2569. +
  2570. +/*
  2571. + * old info:
  2572. + * TOE DMA Queue Size should be 2^n, n = 6...12
  2573. + * TOE DMA Queues are the following queue types:
  2574. + * SW Free Queue, HW Free Queue,
  2575. + * GMAC 0/1 SW TX Q0-5, and GMAC 0/1 HW TX Q0-5
  2576. + * The base address and descriptor number are configured at
  2577. + * DMA Queues Descriptor Ring Base Address/Size Register (offset 0x0004)
  2578. + */
  2579. +
  2580. +#define GET_WPTR(addr) __raw_readw((addr) + 2)
  2581. +#define GET_RPTR(addr) __raw_readw((addr))
  2582. +#define SET_WPTR(addr, data) __raw_writew((data), (addr) + 2)
  2583. +#define SET_RPTR(addr, data) __raw_writew((data), (addr))
  2584. +#define __RWPTR_NEXT(x, mask) (((unsigned int)(x) + 1) & (mask))
  2585. +#define __RWPTR_PREV(x, mask) (((unsigned int)(x) - 1) & (mask))
  2586. +#define __RWPTR_DISTANCE(r, w, mask) (((unsigned int)(w) - (r)) & (mask))
  2587. +#define __RWPTR_MASK(order) ((1 << (order)) - 1)
  2588. +#define RWPTR_NEXT(x, order) __RWPTR_NEXT((x), __RWPTR_MASK((order)))
  2589. +#define RWPTR_PREV(x, order) __RWPTR_PREV((x), __RWPTR_MASK((order)))
  2590. +#define RWPTR_DISTANCE(r, w, order) __RWPTR_DISTANCE((r), (w), \
  2591. + __RWPTR_MASK((order)))
  2592. +
  2593. +/*
  2594. + * Global registers
  2595. + * #define TOE_GLOBAL_BASE (TOE_BASE + 0x0000)
  2596. + * Base 0x60000000
  2597. + */
  2598. +#define GLOBAL_TOE_VERSION_REG 0x0000
  2599. +#define GLOBAL_SW_FREEQ_BASE_SIZE_REG 0x0004
  2600. +#define GLOBAL_HW_FREEQ_BASE_SIZE_REG 0x0008
  2601. +#define GLOBAL_DMA_SKB_SIZE_REG 0x0010
  2602. +#define GLOBAL_SWFQ_RWPTR_REG 0x0014
  2603. +#define GLOBAL_HWFQ_RWPTR_REG 0x0018
  2604. +#define GLOBAL_INTERRUPT_STATUS_0_REG 0x0020
  2605. +#define GLOBAL_INTERRUPT_ENABLE_0_REG 0x0024
  2606. +#define GLOBAL_INTERRUPT_SELECT_0_REG 0x0028
  2607. +#define GLOBAL_INTERRUPT_STATUS_1_REG 0x0030
  2608. +#define GLOBAL_INTERRUPT_ENABLE_1_REG 0x0034
  2609. +#define GLOBAL_INTERRUPT_SELECT_1_REG 0x0038
  2610. +#define GLOBAL_INTERRUPT_STATUS_2_REG 0x0040
  2611. +#define GLOBAL_INTERRUPT_ENABLE_2_REG 0x0044
  2612. +#define GLOBAL_INTERRUPT_SELECT_2_REG 0x0048
  2613. +#define GLOBAL_INTERRUPT_STATUS_3_REG 0x0050
  2614. +#define GLOBAL_INTERRUPT_ENABLE_3_REG 0x0054
  2615. +#define GLOBAL_INTERRUPT_SELECT_3_REG 0x0058
  2616. +#define GLOBAL_INTERRUPT_STATUS_4_REG 0x0060
  2617. +#define GLOBAL_INTERRUPT_ENABLE_4_REG 0x0064
  2618. +#define GLOBAL_INTERRUPT_SELECT_4_REG 0x0068
  2619. +#define GLOBAL_HASH_TABLE_BASE_REG 0x006C
  2620. +#define GLOBAL_QUEUE_THRESHOLD_REG 0x0070
  2621. +
  2622. +/*
  2623. + * GMAC 0/1 DMA/TOE register
  2624. + * #define TOE_GMAC0_DMA_BASE (TOE_BASE + 0x8000)
  2625. + * #define TOE_GMAC1_DMA_BASE (TOE_BASE + 0xC000)
  2626. + * Base 0x60008000 or 0x6000C000
  2627. + */
  2628. +#define GMAC_DMA_CTRL_REG 0x0000
  2629. +#define GMAC_TX_WEIGHTING_CTRL_0_REG 0x0004
  2630. +#define GMAC_TX_WEIGHTING_CTRL_1_REG 0x0008
  2631. +#define GMAC_SW_TX_QUEUE0_PTR_REG 0x000C
  2632. +#define GMAC_SW_TX_QUEUE1_PTR_REG 0x0010
  2633. +#define GMAC_SW_TX_QUEUE2_PTR_REG 0x0014
  2634. +#define GMAC_SW_TX_QUEUE3_PTR_REG 0x0018
  2635. +#define GMAC_SW_TX_QUEUE4_PTR_REG 0x001C
  2636. +#define GMAC_SW_TX_QUEUE5_PTR_REG 0x0020
  2637. +#define GMAC_SW_TX_QUEUE_PTR_REG(i) (GMAC_SW_TX_QUEUE0_PTR_REG + 4 * (i))
  2638. +#define GMAC_HW_TX_QUEUE0_PTR_REG 0x0024
  2639. +#define GMAC_HW_TX_QUEUE1_PTR_REG 0x0028
  2640. +#define GMAC_HW_TX_QUEUE2_PTR_REG 0x002C
  2641. +#define GMAC_HW_TX_QUEUE3_PTR_REG 0x0030
  2642. +#define GMAC_HW_TX_QUEUE_PTR_REG(i) (GMAC_HW_TX_QUEUE0_PTR_REG + 4 * (i))
  2643. +#define GMAC_DMA_TX_FIRST_DESC_REG 0x0038
  2644. +#define GMAC_DMA_TX_CURR_DESC_REG 0x003C
  2645. +#define GMAC_DMA_TX_DESC_WORD0_REG 0x0040
  2646. +#define GMAC_DMA_TX_DESC_WORD1_REG 0x0044
  2647. +#define GMAC_DMA_TX_DESC_WORD2_REG 0x0048
  2648. +#define GMAC_DMA_TX_DESC_WORD3_REG 0x004C
  2649. +#define GMAC_SW_TX_QUEUE_BASE_REG 0x0050
  2650. +#define GMAC_HW_TX_QUEUE_BASE_REG 0x0054
  2651. +#define GMAC_DMA_RX_FIRST_DESC_REG 0x0058
  2652. +#define GMAC_DMA_RX_CURR_DESC_REG 0x005C
  2653. +#define GMAC_DMA_RX_DESC_WORD0_REG 0x0060
  2654. +#define GMAC_DMA_RX_DESC_WORD1_REG 0x0064
  2655. +#define GMAC_DMA_RX_DESC_WORD2_REG 0x0068
  2656. +#define GMAC_DMA_RX_DESC_WORD3_REG 0x006C
  2657. +#define GMAC_HASH_ENGINE_REG0 0x0070
  2658. +#define GMAC_HASH_ENGINE_REG1 0x0074
  2659. +/* matching rule 0 Control register 0 */
  2660. +#define GMAC_MR0CR0 0x0078
  2661. +#define GMAC_MR0CR1 0x007C
  2662. +#define GMAC_MR0CR2 0x0080
  2663. +#define GMAC_MR1CR0 0x0084
  2664. +#define GMAC_MR1CR1 0x0088
  2665. +#define GMAC_MR1CR2 0x008C
  2666. +#define GMAC_MR2CR0 0x0090
  2667. +#define GMAC_MR2CR1 0x0094
  2668. +#define GMAC_MR2CR2 0x0098
  2669. +#define GMAC_MR3CR0 0x009C
  2670. +#define GMAC_MR3CR1 0x00A0
  2671. +#define GMAC_MR3CR2 0x00A4
  2672. +/* Support Protocol Regsister 0 */
  2673. +#define GMAC_SPR0 0x00A8
  2674. +#define GMAC_SPR1 0x00AC
  2675. +#define GMAC_SPR2 0x00B0
  2676. +#define GMAC_SPR3 0x00B4
  2677. +#define GMAC_SPR4 0x00B8
  2678. +#define GMAC_SPR5 0x00BC
  2679. +#define GMAC_SPR6 0x00C0
  2680. +#define GMAC_SPR7 0x00C4
  2681. +/* GMAC Hash/Rx/Tx AHB Weighting register */
  2682. +#define GMAC_AHB_WEIGHT_REG 0x00C8
  2683. +
  2684. +/*
  2685. + * TOE GMAC 0/1 register
  2686. + * #define TOE_GMAC0_BASE (TOE_BASE + 0xA000)
  2687. + * #define TOE_GMAC1_BASE (TOE_BASE + 0xE000)
  2688. + * Base 0x6000A000 or 0x6000E000
  2689. + */
  2690. +enum GMAC_REGISTER {
  2691. + GMAC_STA_ADD0 = 0x0000,
  2692. + GMAC_STA_ADD1 = 0x0004,
  2693. + GMAC_STA_ADD2 = 0x0008,
  2694. + GMAC_RX_FLTR = 0x000c,
  2695. + GMAC_MCAST_FIL0 = 0x0010,
  2696. + GMAC_MCAST_FIL1 = 0x0014,
  2697. + GMAC_CONFIG0 = 0x0018,
  2698. + GMAC_CONFIG1 = 0x001c,
  2699. + GMAC_CONFIG2 = 0x0020,
  2700. + GMAC_CONFIG3 = 0x0024,
  2701. + GMAC_RESERVED = 0x0028,
  2702. + GMAC_STATUS = 0x002c,
  2703. + GMAC_IN_DISCARDS= 0x0030,
  2704. + GMAC_IN_ERRORS = 0x0034,
  2705. + GMAC_IN_MCAST = 0x0038,
  2706. + GMAC_IN_BCAST = 0x003c,
  2707. + GMAC_IN_MAC1 = 0x0040, /* for STA 1 MAC Address */
  2708. + GMAC_IN_MAC2 = 0x0044 /* for STA 2 MAC Address */
  2709. +};
  2710. +
  2711. +#define RX_STATS_NUM 6
  2712. +
  2713. +/*
  2714. + * DMA Queues description Ring Base Address/Size Register (offset 0x0004)
  2715. + */
  2716. +typedef union {
  2717. + unsigned int bits32;
  2718. + unsigned int base_size;
  2719. +} DMA_Q_BASE_SIZE_T;
  2720. +#define DMA_Q_BASE_MASK (~0x0f)
  2721. +
  2722. +/*
  2723. + * DMA SKB Buffer register (offset 0x0008)
  2724. + */
  2725. +typedef union {
  2726. + unsigned int bits32;
  2727. + struct bit_0008 {
  2728. + unsigned int sw_skb_size : 16; /* SW Free poll SKB Size */
  2729. + unsigned int hw_skb_size : 16; /* HW Free poll SKB Size */
  2730. + } bits;
  2731. +} DMA_SKB_SIZE_T;
  2732. +
  2733. +/*
  2734. + * DMA SW Free Queue Read/Write Pointer Register (offset 0x000C)
  2735. + */
  2736. +typedef union {
  2737. + unsigned int bits32;
  2738. + struct bit_000c {
  2739. + unsigned int rptr : 16; /* Read Ptr, RO */
  2740. + unsigned int wptr : 16; /* Write Ptr, RW */
  2741. + } bits;
  2742. +} DMA_RWPTR_T;
  2743. +
  2744. +/*
  2745. + * DMA HW Free Queue Read/Write Pointer Register (offset 0x0010)
  2746. + * see DMA_RWPTR_T structure
  2747. + */
  2748. +
  2749. +/*
  2750. + * Interrupt Status Register 0 (offset 0x0020)
  2751. + * Interrupt Mask Register 0 (offset 0x0024)
  2752. + * Interrupt Select Register 0 (offset 0x0028)
  2753. + */
  2754. +typedef union {
  2755. + unsigned int bits32;
  2756. + struct bit_0020 {
  2757. + /* GMAC0 SW Tx Queue 0 EOF Interrupt */
  2758. + unsigned int swtq00_eof : 1;
  2759. + unsigned int swtq01_eof : 1;
  2760. + unsigned int swtq02_eof : 1;
  2761. + unsigned int swtq03_eof : 1;
  2762. + unsigned int swtq04_eof : 1;
  2763. + unsigned int swtq05_eof : 1;
  2764. + /* GMAC1 SW Tx Queue 0 EOF Interrupt */
  2765. + unsigned int swtq10_eof : 1;
  2766. + unsigned int swtq11_eof : 1;
  2767. + unsigned int swtq12_eof : 1;
  2768. + unsigned int swtq13_eof : 1;
  2769. + unsigned int swtq14_eof : 1;
  2770. + unsigned int swtq15_eof : 1;
  2771. + /* GMAC0 SW Tx Queue 0 Finish Interrupt */
  2772. + unsigned int swtq00_fin : 1;
  2773. + unsigned int swtq01_fin : 1;
  2774. + unsigned int swtq02_fin : 1;
  2775. + unsigned int swtq03_fin : 1;
  2776. + unsigned int swtq04_fin : 1;
  2777. + unsigned int swtq05_fin : 1;
  2778. + /* GMAC1 SW Tx Queue 0 Finish Interrupt */
  2779. + unsigned int swtq10_fin : 1;
  2780. + unsigned int swtq11_fin : 1;
  2781. + unsigned int swtq12_fin : 1;
  2782. + unsigned int swtq13_fin : 1;
  2783. + unsigned int swtq14_fin : 1;
  2784. + unsigned int swtq15_fin : 1;
  2785. + /* GMAC0 Rx Descriptor Protocol Error */
  2786. + unsigned int rxPerr0 : 1;
  2787. + /* GMAC0 AHB Bus Error while Rx */
  2788. + unsigned int rxDerr0 : 1;
  2789. + /* GMAC1 Rx Descriptor Protocol Error */
  2790. + unsigned int rxPerr1 : 1;
  2791. + /* GMAC1 AHB Bus Error while Rx */
  2792. + unsigned int rxDerr1 : 1;
  2793. + /* GMAC0 Tx Descriptor Protocol Error */
  2794. + unsigned int txPerr0 : 1;
  2795. + /* GMAC0 AHB Bus Error while Tx */
  2796. + unsigned int txDerr0 : 1;
  2797. + /* GMAC1 Tx Descriptor Protocol Error */
  2798. + unsigned int txPerr1 : 1;
  2799. + /* GMAC1 AHB Bus Error while Tx */
  2800. + unsigned int txDerr1 : 1;
  2801. + } bits;
  2802. +} INTR_REG0_T;
  2803. +
  2804. +#define GMAC1_TXDERR_INT_BIT BIT(31)
  2805. +#define GMAC1_TXPERR_INT_BIT BIT(30)
  2806. +#define GMAC0_TXDERR_INT_BIT BIT(29)
  2807. +#define GMAC0_TXPERR_INT_BIT BIT(28)
  2808. +#define GMAC1_RXDERR_INT_BIT BIT(27)
  2809. +#define GMAC1_RXPERR_INT_BIT BIT(26)
  2810. +#define GMAC0_RXDERR_INT_BIT BIT(25)
  2811. +#define GMAC0_RXPERR_INT_BIT BIT(24)
  2812. +#define GMAC1_SWTQ15_FIN_INT_BIT BIT(23)
  2813. +#define GMAC1_SWTQ14_FIN_INT_BIT BIT(22)
  2814. +#define GMAC1_SWTQ13_FIN_INT_BIT BIT(21)
  2815. +#define GMAC1_SWTQ12_FIN_INT_BIT BIT(20)
  2816. +#define GMAC1_SWTQ11_FIN_INT_BIT BIT(19)
  2817. +#define GMAC1_SWTQ10_FIN_INT_BIT BIT(18)
  2818. +#define GMAC0_SWTQ05_FIN_INT_BIT BIT(17)
  2819. +#define GMAC0_SWTQ04_FIN_INT_BIT BIT(16)
  2820. +#define GMAC0_SWTQ03_FIN_INT_BIT BIT(15)
  2821. +#define GMAC0_SWTQ02_FIN_INT_BIT BIT(14)
  2822. +#define GMAC0_SWTQ01_FIN_INT_BIT BIT(13)
  2823. +#define GMAC0_SWTQ00_FIN_INT_BIT BIT(12)
  2824. +#define GMAC1_SWTQ15_EOF_INT_BIT BIT(11)
  2825. +#define GMAC1_SWTQ14_EOF_INT_BIT BIT(10)
  2826. +#define GMAC1_SWTQ13_EOF_INT_BIT BIT(9)
  2827. +#define GMAC1_SWTQ12_EOF_INT_BIT BIT(8)
  2828. +#define GMAC1_SWTQ11_EOF_INT_BIT BIT(7)
  2829. +#define GMAC1_SWTQ10_EOF_INT_BIT BIT(6)
  2830. +#define GMAC0_SWTQ05_EOF_INT_BIT BIT(5)
  2831. +#define GMAC0_SWTQ04_EOF_INT_BIT BIT(4)
  2832. +#define GMAC0_SWTQ03_EOF_INT_BIT BIT(3)
  2833. +#define GMAC0_SWTQ02_EOF_INT_BIT BIT(2)
  2834. +#define GMAC0_SWTQ01_EOF_INT_BIT BIT(1)
  2835. +#define GMAC0_SWTQ00_EOF_INT_BIT BIT(0)
  2836. +
  2837. +/*
  2838. + * Interrupt Status Register 1 (offset 0x0030)
  2839. + * Interrupt Mask Register 1 (offset 0x0034)
  2840. + * Interrupt Select Register 1 (offset 0x0038)
  2841. + */
  2842. +typedef union {
  2843. + unsigned int bits32;
  2844. + struct bit_0030 {
  2845. + unsigned int default_q0_eof : 1; /* Default Queue 0 EOF Interrupt */
  2846. + unsigned int default_q1_eof : 1; /* Default Queue 1 EOF Interrupt */
  2847. + unsigned int class_rx : 14; /* Classification Queue Rx Interrupt */
  2848. + unsigned int hwtq00_eof : 1; /* GMAC0 HW Tx Queue0 EOF Interrupt */
  2849. + unsigned int hwtq01_eof : 1; /* GMAC0 HW Tx Queue1 EOF Interrupt */
  2850. + unsigned int hwtq02_eof : 1; /* GMAC0 HW Tx Queue2 EOF Interrupt */
  2851. + unsigned int hwtq03_eof : 1; /* GMAC0 HW Tx Queue3 EOF Interrupt */
  2852. + unsigned int hwtq10_eof : 1; /* GMAC1 HW Tx Queue0 EOF Interrupt */
  2853. + unsigned int hwtq11_eof : 1; /* GMAC1 HW Tx Queue1 EOF Interrupt */
  2854. + unsigned int hwtq12_eof : 1; /* GMAC1 HW Tx Queue2 EOF Interrupt */
  2855. + unsigned int hwtq13_eof : 1; /* GMAC1 HW Tx Queue3 EOF Interrupt */
  2856. + unsigned int toe_iq0_intr : 1; /* TOE Interrupt Queue 0 with Interrupts */
  2857. + unsigned int toe_iq1_intr : 1; /* TOE Interrupt Queue 1 with Interrupts */
  2858. + unsigned int toe_iq2_intr : 1; /* TOE Interrupt Queue 2 with Interrupts */
  2859. + unsigned int toe_iq3_intr : 1; /* TOE Interrupt Queue 3 with Interrupts */
  2860. + unsigned int toe_iq0_full : 1; /* TOE Interrupt Queue 0 Full Interrupt */
  2861. + unsigned int toe_iq1_full : 1; /* TOE Interrupt Queue 1 Full Interrupt */
  2862. + unsigned int toe_iq2_full : 1; /* TOE Interrupt Queue 2 Full Interrupt */
  2863. + unsigned int toe_iq3_full : 1; /* TOE Interrupt Queue 3 Full Interrupt */
  2864. + } bits;
  2865. +} INTR_REG1_T;
  2866. +
  2867. +#define TOE_IQ3_FULL_INT_BIT BIT(31)
  2868. +#define TOE_IQ2_FULL_INT_BIT BIT(30)
  2869. +#define TOE_IQ1_FULL_INT_BIT BIT(29)
  2870. +#define TOE_IQ0_FULL_INT_BIT BIT(28)
  2871. +#define TOE_IQ3_INT_BIT BIT(27)
  2872. +#define TOE_IQ2_INT_BIT BIT(26)
  2873. +#define TOE_IQ1_INT_BIT BIT(25)
  2874. +#define TOE_IQ0_INT_BIT BIT(24)
  2875. +#define GMAC1_HWTQ13_EOF_INT_BIT BIT(23)
  2876. +#define GMAC1_HWTQ12_EOF_INT_BIT BIT(22)
  2877. +#define GMAC1_HWTQ11_EOF_INT_BIT BIT(21)
  2878. +#define GMAC1_HWTQ10_EOF_INT_BIT BIT(20)
  2879. +#define GMAC0_HWTQ03_EOF_INT_BIT BIT(19)
  2880. +#define GMAC0_HWTQ02_EOF_INT_BIT BIT(18)
  2881. +#define GMAC0_HWTQ01_EOF_INT_BIT BIT(17)
  2882. +#define GMAC0_HWTQ00_EOF_INT_BIT BIT(16)
  2883. +#define CLASS_RX_INT_BIT(x) BIT((x + 2))
  2884. +#define DEFAULT_Q1_INT_BIT BIT(1)
  2885. +#define DEFAULT_Q0_INT_BIT BIT(0)
  2886. +
  2887. +#define TOE_IQ_INT_BITS (TOE_IQ0_INT_BIT | TOE_IQ1_INT_BIT | \
  2888. + TOE_IQ2_INT_BIT | TOE_IQ3_INT_BIT)
  2889. +#define TOE_IQ_FULL_BITS (TOE_IQ0_FULL_INT_BIT | TOE_IQ1_FULL_INT_BIT | \
  2890. + TOE_IQ2_FULL_INT_BIT | TOE_IQ3_FULL_INT_BIT)
  2891. +#define TOE_IQ_ALL_BITS (TOE_IQ_INT_BITS | TOE_IQ_FULL_BITS)
  2892. +#define TOE_CLASS_RX_INT_BITS 0xfffc
  2893. +
  2894. +/*
  2895. + * Interrupt Status Register 2 (offset 0x0040)
  2896. + * Interrupt Mask Register 2 (offset 0x0044)
  2897. + * Interrupt Select Register 2 (offset 0x0048)
  2898. + */
  2899. +typedef union {
  2900. + unsigned int bits32;
  2901. + struct bit_0040 {
  2902. + unsigned int toe_q0_full : 1; /* bit 0 TOE Queue 0 Full Interrupt */
  2903. + unsigned int toe_q1_full : 1; /* bit 1 TOE Queue 1 Full Interrupt */
  2904. + unsigned int toe_q2_full : 1; /* bit 2 TOE Queue 2 Full Interrupt */
  2905. + unsigned int toe_q3_full : 1; /* bit 3 TOE Queue 3 Full Interrupt */
  2906. + unsigned int toe_q4_full : 1; /* bit 4 TOE Queue 4 Full Interrupt */
  2907. + unsigned int toe_q5_full : 1; /* bit 5 TOE Queue 5 Full Interrupt */
  2908. + unsigned int toe_q6_full : 1; /* bit 6 TOE Queue 6 Full Interrupt */
  2909. + unsigned int toe_q7_full : 1; /* bit 7 TOE Queue 7 Full Interrupt */
  2910. + unsigned int toe_q8_full : 1; /* bit 8 TOE Queue 8 Full Interrupt */
  2911. + unsigned int toe_q9_full : 1; /* bit 9 TOE Queue 9 Full Interrupt */
  2912. + unsigned int toe_q10_full : 1; /* bit 10 TOE Queue 10 Full Interrupt */
  2913. + unsigned int toe_q11_full : 1; /* bit 11 TOE Queue 11 Full Interrupt */
  2914. + unsigned int toe_q12_full : 1; /* bit 12 TOE Queue 12 Full Interrupt */
  2915. + unsigned int toe_q13_full : 1; /* bit 13 TOE Queue 13 Full Interrupt */
  2916. + unsigned int toe_q14_full : 1; /* bit 14 TOE Queue 14 Full Interrupt */
  2917. + unsigned int toe_q15_full : 1; /* bit 15 TOE Queue 15 Full Interrupt */
  2918. + unsigned int toe_q16_full : 1; /* bit 16 TOE Queue 16 Full Interrupt */
  2919. + unsigned int toe_q17_full : 1; /* bit 17 TOE Queue 17 Full Interrupt */
  2920. + unsigned int toe_q18_full : 1; /* bit 18 TOE Queue 18 Full Interrupt */
  2921. + unsigned int toe_q19_full : 1; /* bit 19 TOE Queue 19 Full Interrupt */
  2922. + unsigned int toe_q20_full : 1; /* bit 20 TOE Queue 20 Full Interrupt */
  2923. + unsigned int toe_q21_full : 1; /* bit 21 TOE Queue 21 Full Interrupt */
  2924. + unsigned int toe_q22_full : 1; /* bit 22 TOE Queue 22 Full Interrupt */
  2925. + unsigned int toe_q23_full : 1; /* bit 23 TOE Queue 23 Full Interrupt */
  2926. + unsigned int toe_q24_full : 1; /* bit 24 TOE Queue 24 Full Interrupt */
  2927. + unsigned int toe_q25_full : 1; /* bit 25 TOE Queue 25 Full Interrupt */
  2928. + unsigned int toe_q26_full : 1; /* bit 26 TOE Queue 26 Full Interrupt */
  2929. + unsigned int toe_q27_full : 1; /* bit 27 TOE Queue 27 Full Interrupt */
  2930. + unsigned int toe_q28_full : 1; /* bit 28 TOE Queue 28 Full Interrupt */
  2931. + unsigned int toe_q29_full : 1; /* bit 29 TOE Queue 29 Full Interrupt */
  2932. + unsigned int toe_q30_full : 1; /* bit 30 TOE Queue 30 Full Interrupt */
  2933. + unsigned int toe_q31_full : 1; /* bit 31 TOE Queue 31 Full Interrupt */
  2934. + } bits;
  2935. +} INTR_REG2_T;
  2936. +
  2937. +#define TOE_QL_FULL_INT_BIT(x) BIT(x)
  2938. +
  2939. +/*
  2940. + * Interrupt Status Register 3 (offset 0x0050)
  2941. + * Interrupt Mask Register 3 (offset 0x0054)
  2942. + * Interrupt Select Register 3 (offset 0x0058)
  2943. + */
  2944. +typedef union {
  2945. + unsigned int bits32;
  2946. + struct bit_0050 {
  2947. + unsigned int toe_q32_full : 1; /* bit 32 TOE Queue 32 Full Interrupt */
  2948. + unsigned int toe_q33_full : 1; /* bit 33 TOE Queue 33 Full Interrupt */
  2949. + unsigned int toe_q34_full : 1; /* bit 34 TOE Queue 34 Full Interrupt */
  2950. + unsigned int toe_q35_full : 1; /* bit 35 TOE Queue 35 Full Interrupt */
  2951. + unsigned int toe_q36_full : 1; /* bit 36 TOE Queue 36 Full Interrupt */
  2952. + unsigned int toe_q37_full : 1; /* bit 37 TOE Queue 37 Full Interrupt */
  2953. + unsigned int toe_q38_full : 1; /* bit 38 TOE Queue 38 Full Interrupt */
  2954. + unsigned int toe_q39_full : 1; /* bit 39 TOE Queue 39 Full Interrupt */
  2955. + unsigned int toe_q40_full : 1; /* bit 40 TOE Queue 40 Full Interrupt */
  2956. + unsigned int toe_q41_full : 1; /* bit 41 TOE Queue 41 Full Interrupt */
  2957. + unsigned int toe_q42_full : 1; /* bit 42 TOE Queue 42 Full Interrupt */
  2958. + unsigned int toe_q43_full : 1; /* bit 43 TOE Queue 43 Full Interrupt */
  2959. + unsigned int toe_q44_full : 1; /* bit 44 TOE Queue 44 Full Interrupt */
  2960. + unsigned int toe_q45_full : 1; /* bit 45 TOE Queue 45 Full Interrupt */
  2961. + unsigned int toe_q46_full : 1; /* bit 46 TOE Queue 46 Full Interrupt */
  2962. + unsigned int toe_q47_full : 1; /* bit 47 TOE Queue 47 Full Interrupt */
  2963. + unsigned int toe_q48_full : 1; /* bit 48 TOE Queue 48 Full Interrupt */
  2964. + unsigned int toe_q49_full : 1; /* bit 49 TOE Queue 49 Full Interrupt */
  2965. + unsigned int toe_q50_full : 1; /* bit 50 TOE Queue 50 Full Interrupt */
  2966. + unsigned int toe_q51_full : 1; /* bit 51 TOE Queue 51 Full Interrupt */
  2967. + unsigned int toe_q52_full : 1; /* bit 52 TOE Queue 52 Full Interrupt */
  2968. + unsigned int toe_q53_full : 1; /* bit 53 TOE Queue 53 Full Interrupt */
  2969. + unsigned int toe_q54_full : 1; /* bit 54 TOE Queue 54 Full Interrupt */
  2970. + unsigned int toe_q55_full : 1; /* bit 55 TOE Queue 55 Full Interrupt */
  2971. + unsigned int toe_q56_full : 1; /* bit 56 TOE Queue 56 Full Interrupt */
  2972. + unsigned int toe_q57_full : 1; /* bit 57 TOE Queue 57 Full Interrupt */
  2973. + unsigned int toe_q58_full : 1; /* bit 58 TOE Queue 58 Full Interrupt */
  2974. + unsigned int toe_q59_full : 1; /* bit 59 TOE Queue 59 Full Interrupt */
  2975. + unsigned int toe_q60_full : 1; /* bit 60 TOE Queue 60 Full Interrupt */
  2976. + unsigned int toe_q61_full : 1; /* bit 61 TOE Queue 61 Full Interrupt */
  2977. + unsigned int toe_q62_full : 1; /* bit 62 TOE Queue 62 Full Interrupt */
  2978. + unsigned int toe_q63_full : 1; /* bit 63 TOE Queue 63 Full Interrupt */
  2979. + } bits;
  2980. +} INTR_REG3_T;
  2981. +
  2982. +#define TOE_QH_FULL_INT_BIT(x) BIT(x-32)
  2983. +
  2984. +/*
  2985. + * Interrupt Status Register 4 (offset 0x0060)
  2986. + * Interrupt Mask Register 4 (offset 0x0064)
  2987. + * Interrupt Select Register 4 (offset 0x0068)
  2988. + */
  2989. +typedef union {
  2990. + unsigned char byte;
  2991. + struct bit_0060 {
  2992. + unsigned char status_changed : 1; /* Status Changed Intr for RGMII Mode */
  2993. + unsigned char rx_overrun : 1; /* GMAC Rx FIFO overrun interrupt */
  2994. + unsigned char tx_pause_off : 1; /* received pause off frame interrupt */
  2995. + unsigned char rx_pause_off : 1; /* received pause off frame interrupt */
  2996. + unsigned char tx_pause_on : 1; /* transmit pause on frame interrupt */
  2997. + unsigned char rx_pause_on : 1; /* received pause on frame interrupt */
  2998. + unsigned char cnt_full : 1; /* MIB counters half full interrupt */
  2999. + unsigned char reserved : 1; /* */
  3000. + } __packed bits;
  3001. +} __packed GMAC_INTR_T;
  3002. +
  3003. +typedef union {
  3004. + unsigned int bits32;
  3005. + struct bit_0060_2 {
  3006. + unsigned int swfq_empty : 1; /* bit 0 Software Free Queue Empty Intr. */
  3007. + unsigned int hwfq_empty : 1; /* bit 1 Hardware Free Queue Empty Intr. */
  3008. + unsigned int class_qf_int : 14; /* bit 15:2 Classification Rx Queue13-0 Full Intr. */
  3009. + GMAC_INTR_T gmac0;
  3010. + GMAC_INTR_T gmac1;
  3011. + } bits;
  3012. +} INTR_REG4_T;
  3013. +
  3014. +#define GMAC1_RESERVED_INT_BIT BIT(31)
  3015. +#define GMAC1_MIB_INT_BIT BIT(30)
  3016. +#define GMAC1_RX_PAUSE_ON_INT_BIT BIT(29)
  3017. +#define GMAC1_TX_PAUSE_ON_INT_BIT BIT(28)
  3018. +#define GMAC1_RX_PAUSE_OFF_INT_BIT BIT(27)
  3019. +#define GMAC1_TX_PAUSE_OFF_INT_BIT BIT(26)
  3020. +#define GMAC1_RX_OVERRUN_INT_BIT BIT(25)
  3021. +#define GMAC1_STATUS_CHANGE_INT_BIT BIT(24)
  3022. +#define GMAC0_RESERVED_INT_BIT BIT(23)
  3023. +#define GMAC0_MIB_INT_BIT BIT(22)
  3024. +#define GMAC0_RX_PAUSE_ON_INT_BIT BIT(21)
  3025. +#define GMAC0_TX_PAUSE_ON_INT_BIT BIT(20)
  3026. +#define GMAC0_RX_PAUSE_OFF_INT_BIT BIT(19)
  3027. +#define GMAC0_TX_PAUSE_OFF_INT_BIT BIT(18)
  3028. +#define GMAC0_RX_OVERRUN_INT_BIT BIT(17)
  3029. +#define GMAC0_STATUS_CHANGE_INT_BIT BIT(16)
  3030. +#define CLASS_RX_FULL_INT_BIT(x) BIT((x+2))
  3031. +#define HWFQ_EMPTY_INT_BIT BIT(1)
  3032. +#define SWFQ_EMPTY_INT_BIT BIT(0)
  3033. +
  3034. +#define GMAC0_INT_BITS (GMAC0_RESERVED_INT_BIT | GMAC0_MIB_INT_BIT | \
  3035. + GMAC0_RX_PAUSE_ON_INT_BIT | GMAC0_TX_PAUSE_ON_INT_BIT | \
  3036. + GMAC0_RX_PAUSE_OFF_INT_BIT | GMAC0_TX_PAUSE_OFF_INT_BIT | \
  3037. + GMAC0_RX_OVERRUN_INT_BIT | GMAC0_STATUS_CHANGE_INT_BIT)
  3038. +#define GMAC1_INT_BITS (GMAC1_RESERVED_INT_BIT | GMAC1_MIB_INT_BIT | \
  3039. + GMAC1_RX_PAUSE_ON_INT_BIT | GMAC1_TX_PAUSE_ON_INT_BIT | \
  3040. + GMAC1_RX_PAUSE_OFF_INT_BIT | GMAC1_TX_PAUSE_OFF_INT_BIT | \
  3041. + GMAC1_RX_OVERRUN_INT_BIT | GMAC1_STATUS_CHANGE_INT_BIT)
  3042. +
  3043. +#define CLASS_RX_FULL_INT_BITS 0xfffc
  3044. +
  3045. +/*
  3046. + * GLOBAL_QUEUE_THRESHOLD_REG (offset 0x0070)
  3047. + */
  3048. +typedef union {
  3049. + unsigned int bits32;
  3050. + struct bit_0070_2 {
  3051. + unsigned int swfq_empty : 8; /* 7:0 Software Free Queue Empty Threshold */
  3052. + unsigned int hwfq_empty : 8; /* 15:8 Hardware Free Queue Empty Threshold */
  3053. + unsigned int intrq : 8; /* 23:16 */
  3054. + unsigned int toe_class : 8; /* 31:24 */
  3055. + } bits;
  3056. +} QUEUE_THRESHOLD_T;
  3057. +
  3058. +
  3059. +/*
  3060. + * GMAC DMA Control Register
  3061. + * GMAC0 offset 0x8000
  3062. + * GMAC1 offset 0xC000
  3063. + */
  3064. +typedef union {
  3065. + unsigned int bits32;
  3066. + struct bit_8000 {
  3067. + unsigned int td_bus : 2; /* bit 1:0 Peripheral Bus Width */
  3068. + unsigned int td_burst_size : 2; /* bit 3:2 TxDMA max burst size for every AHB request */
  3069. + unsigned int td_prot : 4; /* bit 7:4 TxDMA protection control */
  3070. + unsigned int rd_bus : 2; /* bit 9:8 Peripheral Bus Width */
  3071. + unsigned int rd_burst_size : 2; /* bit 11:10 DMA max burst size for every AHB request */
  3072. + unsigned int rd_prot : 4; /* bit 15:12 DMA Protection Control */
  3073. + unsigned int rd_insert_bytes : 2; /* bit 17:16 */
  3074. + unsigned int reserved : 10; /* bit 27:18 */
  3075. + unsigned int drop_small_ack : 1; /* bit 28 1: Drop, 0: Accept */
  3076. + unsigned int loopback : 1; /* bit 29 Loopback TxDMA to RxDMA */
  3077. + unsigned int td_enable : 1; /* bit 30 Tx DMA Enable */
  3078. + unsigned int rd_enable : 1; /* bit 31 Rx DMA Enable */
  3079. + } bits;
  3080. +} GMAC_DMA_CTRL_T;
  3081. +
  3082. +/*
  3083. + * GMAC Tx Weighting Control Register 0
  3084. + * GMAC0 offset 0x8004
  3085. + * GMAC1 offset 0xC004
  3086. + */
  3087. +typedef union {
  3088. + unsigned int bits32;
  3089. + struct bit_8004 {
  3090. + unsigned int hw_tq0 : 6; /* bit 5:0 HW TX Queue 3 */
  3091. + unsigned int hw_tq1 : 6; /* bit 11:6 HW TX Queue 2 */
  3092. + unsigned int hw_tq2 : 6; /* bit 17:12 HW TX Queue 1 */
  3093. + unsigned int hw_tq3 : 6; /* bit 23:18 HW TX Queue 0 */
  3094. + unsigned int reserved : 8; /* bit 31:24 */
  3095. + } bits;
  3096. +} GMAC_TX_WCR0_T; /* Weighting Control Register 0 */
  3097. +
  3098. +/*
  3099. + * GMAC Tx Weighting Control Register 1
  3100. + * GMAC0 offset 0x8008
  3101. + * GMAC1 offset 0xC008
  3102. + */
  3103. +typedef union {
  3104. + unsigned int bits32;
  3105. + struct bit_8008 {
  3106. + unsigned int sw_tq0 : 5; /* bit 4:0 SW TX Queue 0 */
  3107. + unsigned int sw_tq1 : 5; /* bit 9:5 SW TX Queue 1 */
  3108. + unsigned int sw_tq2 : 5; /* bit 14:10 SW TX Queue 2 */
  3109. + unsigned int sw_tq3 : 5; /* bit 19:15 SW TX Queue 3 */
  3110. + unsigned int sw_tq4 : 5; /* bit 24:20 SW TX Queue 4 */
  3111. + unsigned int sw_tq5 : 5; /* bit 29:25 SW TX Queue 5 */
  3112. + unsigned int reserved : 2; /* bit 31:30 */
  3113. + } bits;
  3114. +} GMAC_TX_WCR1_T; /* Weighting Control Register 1 */
  3115. +
  3116. +/*
  3117. + * Queue Read/Write Pointer
  3118. + * GMAC SW TX Queue 0~5 Read/Write Pointer register
  3119. + * GMAC0 offset 0x800C ~ 0x8020
  3120. + * GMAC1 offset 0xC00C ~ 0xC020
  3121. + * GMAC HW TX Queue 0~3 Read/Write Pointer register
  3122. + * GMAC0 offset 0x8024 ~ 0x8030
  3123. + * GMAC1 offset 0xC024 ~ 0xC030
  3124. + *
  3125. + * see DMA_RWPTR_T structure
  3126. + */
  3127. +
  3128. +/*
  3129. + * GMAC DMA Tx First Description Address Register
  3130. + * GMAC0 offset 0x8038
  3131. + * GMAC1 offset 0xC038
  3132. + */
  3133. +typedef union {
  3134. + unsigned int bits32;
  3135. + struct bit_8038 {
  3136. + unsigned int reserved : 3;
  3137. + unsigned int td_busy : 1; /* bit 3 1: TxDMA busy; 0: TxDMA idle */
  3138. + unsigned int td_first_des_ptr : 28; /* bit 31:4 first descriptor address */
  3139. + } bits;
  3140. +} GMAC_TXDMA_FIRST_DESC_T;
  3141. +
  3142. +/*
  3143. + * GMAC DMA Tx Current Description Address Register
  3144. + * GMAC0 offset 0x803C
  3145. + * GMAC1 offset 0xC03C
  3146. + */
  3147. +typedef union {
  3148. + unsigned int bits32;
  3149. + struct bit_803C {
  3150. + unsigned int reserved : 4;
  3151. + unsigned int td_curr_desc_ptr : 28; /* bit 31:4 current descriptor address */
  3152. + } bits;
  3153. +} GMAC_TXDMA_CURR_DESC_T;
  3154. +
  3155. +/*
  3156. + * GMAC DMA Tx Description Word 0 Register
  3157. + * GMAC0 offset 0x8040
  3158. + * GMAC1 offset 0xC040
  3159. + */
  3160. +typedef union {
  3161. + unsigned int bits32;
  3162. + struct bit_8040 {
  3163. + unsigned int buffer_size : 16; /* bit 15:0 Transfer size */
  3164. + unsigned int desc_count : 6; /* bit 21:16 number of descriptors used for the current frame */
  3165. + unsigned int status_tx_ok : 1; /* bit 22 Tx Status, 1: Successful 0: Failed */
  3166. + unsigned int status_rvd : 6; /* bit 28:23 Tx Status, Reserved bits */
  3167. + unsigned int perr : 1; /* bit 29 protocol error during processing this descriptor */
  3168. + unsigned int derr : 1; /* bit 30 data error during processing this descriptor */
  3169. + unsigned int reserved : 1; /* bit 31 */
  3170. + } bits;
  3171. +} GMAC_TXDESC_0_T;
  3172. +
  3173. +/*
  3174. + * GMAC DMA Tx Description Word 1 Register
  3175. + * GMAC0 offset 0x8044
  3176. + * GMAC1 offset 0xC044
  3177. + */
  3178. +typedef union {
  3179. + unsigned int bits32;
  3180. + struct txdesc_word1 {
  3181. + unsigned int byte_count : 16; /* bit 15: 0 Tx Frame Byte Count */
  3182. + unsigned int mtu_enable : 1; /* bit 16 TSS segmentation use MTU setting */
  3183. + unsigned int ip_chksum : 1; /* bit 17 IPV4 Header Checksum Enable */
  3184. + unsigned int ipv6_enable : 1; /* bit 18 IPV6 Tx Enable */
  3185. + unsigned int tcp_chksum : 1; /* bit 19 TCP Checksum Enable */
  3186. + unsigned int udp_chksum : 1; /* bit 20 UDP Checksum Enable */
  3187. + unsigned int bypass_tss : 1; /* bit 21 Bypass HW offload engine */
  3188. + unsigned int ip_fixed_len : 1; /* bit 22 Don't update IP length field */
  3189. + unsigned int reserved : 9; /* bit 31:23 Tx Flag, Reserved */
  3190. + } bits;
  3191. +} GMAC_TXDESC_1_T;
  3192. +
  3193. +#define TSS_IP_FIXED_LEN_BIT BIT(22)
  3194. +#define TSS_BYPASS_BIT BIT(21)
  3195. +#define TSS_UDP_CHKSUM_BIT BIT(20)
  3196. +#define TSS_TCP_CHKSUM_BIT BIT(19)
  3197. +#define TSS_IPV6_ENABLE_BIT BIT(18)
  3198. +#define TSS_IP_CHKSUM_BIT BIT(17)
  3199. +#define TSS_MTU_ENABLE_BIT BIT(16)
  3200. +
  3201. +#define TSS_CHECKUM_ENABLE \
  3202. + (TSS_IP_CHKSUM_BIT|TSS_IPV6_ENABLE_BIT| \
  3203. + TSS_TCP_CHKSUM_BIT|TSS_UDP_CHKSUM_BIT)
  3204. +
  3205. +/*
  3206. + * GMAC DMA Tx Description Word 2 Register
  3207. + * GMAC0 offset 0x8048
  3208. + * GMAC1 offset 0xC048
  3209. + */
  3210. +typedef union {
  3211. + unsigned int bits32;
  3212. + unsigned int buf_adr;
  3213. +} GMAC_TXDESC_2_T;
  3214. +
  3215. +/*
  3216. + * GMAC DMA Tx Description Word 3 Register
  3217. + * GMAC0 offset 0x804C
  3218. + * GMAC1 offset 0xC04C
  3219. + */
  3220. +typedef union {
  3221. + unsigned int bits32;
  3222. + struct txdesc_word3 {
  3223. + unsigned int mtu_size : 13; /* bit 12: 0 Tx Frame Byte Count */
  3224. + unsigned int reserved : 16; /* bit 28:13 */
  3225. + unsigned int eofie : 1; /* bit 29 End of frame interrupt enable */
  3226. + unsigned int sof_eof : 2; /* bit 31:30 11: only one, 10: first, 01: last, 00: linking */
  3227. + } bits;
  3228. +} GMAC_TXDESC_3_T;
  3229. +#define SOF_EOF_BIT_MASK 0x3fffffff
  3230. +#define SOF_BIT 0x80000000
  3231. +#define EOF_BIT 0x40000000
  3232. +#define EOFIE_BIT BIT(29)
  3233. +#define MTU_SIZE_BIT_MASK 0x1fff
  3234. +
  3235. +/*
  3236. + * GMAC Tx Descriptor
  3237. + */
  3238. +typedef struct {
  3239. + GMAC_TXDESC_0_T word0;
  3240. + GMAC_TXDESC_1_T word1;
  3241. + GMAC_TXDESC_2_T word2;
  3242. + GMAC_TXDESC_3_T word3;
  3243. +} GMAC_TXDESC_T;
  3244. +
  3245. +/*
  3246. + * GMAC DMA Rx First Description Address Register
  3247. + * GMAC0 offset 0x8058
  3248. + * GMAC1 offset 0xC058
  3249. + */
  3250. +typedef union {
  3251. + unsigned int bits32;
  3252. + struct bit_8058 {
  3253. + unsigned int reserved : 3; /* bit 2:0 */
  3254. + unsigned int rd_busy : 1; /* bit 3 1-RxDMA busy; 0-RxDMA idle */
  3255. + unsigned int rd_first_des_ptr : 28; /* bit 31:4 first descriptor address */
  3256. + } bits;
  3257. +} GMAC_RXDMA_FIRST_DESC_T;
  3258. +
  3259. +/*
  3260. + * GMAC DMA Rx Current Description Address Register
  3261. + * GMAC0 offset 0x805C
  3262. + * GMAC1 offset 0xC05C
  3263. + */
  3264. +typedef union {
  3265. + unsigned int bits32;
  3266. + struct bit_805C {
  3267. + unsigned int reserved : 4; /* bit 3:0 */
  3268. + unsigned int rd_curr_des_ptr : 28; /* bit 31:4 current descriptor address */
  3269. + } bits;
  3270. +} GMAC_RXDMA_CURR_DESC_T;
  3271. +
  3272. +/*
  3273. + * GMAC DMA Rx Description Word 0 Register
  3274. + * GMAC0 offset 0x8060
  3275. + * GMAC1 offset 0xC060
  3276. + */
  3277. +typedef union {
  3278. + unsigned int bits32;
  3279. + struct bit_8060 {
  3280. + unsigned int buffer_size : 16; /* bit 15:0 number of descriptors used for the current frame */
  3281. + unsigned int desc_count : 6; /* bit 21:16 number of descriptors used for the current frame */
  3282. + unsigned int status : 4; /* bit 24:22 Status of rx frame */
  3283. + unsigned int chksum_status : 3; /* bit 28:26 Check Sum Status */
  3284. + unsigned int perr : 1; /* bit 29 protocol error during processing this descriptor */
  3285. + unsigned int derr : 1; /* bit 30 data error during processing this descriptor */
  3286. + unsigned int drop : 1; /* bit 31 TOE/CIS Queue Full dropped packet to default queue */
  3287. + } bits;
  3288. +} GMAC_RXDESC_0_T;
  3289. +
  3290. +#define GMAC_RXDESC_0_T_derr BIT(30)
  3291. +#define GMAC_RXDESC_0_T_perr BIT(29)
  3292. +#define GMAC_RXDESC_0_T_chksum_status(x) BIT((x+26))
  3293. +#define GMAC_RXDESC_0_T_status(x) BIT((x+22))
  3294. +#define GMAC_RXDESC_0_T_desc_count(x) BIT((x+16))
  3295. +
  3296. +#define RX_CHKSUM_IP_UDP_TCP_OK 0
  3297. +#define RX_CHKSUM_IP_OK_ONLY 1
  3298. +#define RX_CHKSUM_NONE 2
  3299. +#define RX_CHKSUM_IP_ERR_UNKNOWN 4
  3300. +#define RX_CHKSUM_IP_ERR 5
  3301. +#define RX_CHKSUM_TCP_UDP_ERR 6
  3302. +#define RX_CHKSUM_NUM 8
  3303. +
  3304. +#define RX_STATUS_GOOD_FRAME 0
  3305. +#define RX_STATUS_TOO_LONG_GOOD_CRC 1
  3306. +#define RX_STATUS_RUNT_FRAME 2
  3307. +#define RX_STATUS_SFD_NOT_FOUND 3
  3308. +#define RX_STATUS_CRC_ERROR 4
  3309. +#define RX_STATUS_TOO_LONG_BAD_CRC 5
  3310. +#define RX_STATUS_ALIGNMENT_ERROR 6
  3311. +#define RX_STATUS_TOO_LONG_BAD_ALIGN 7
  3312. +#define RX_STATUS_RX_ERR 8
  3313. +#define RX_STATUS_DA_FILTERED 9
  3314. +#define RX_STATUS_BUFFER_FULL 10
  3315. +#define RX_STATUS_NUM 16
  3316. +
  3317. +#define RX_ERROR_LENGTH(s) \
  3318. + ((s) == RX_STATUS_TOO_LONG_GOOD_CRC || \
  3319. + (s) == RX_STATUS_TOO_LONG_BAD_CRC || \
  3320. + (s) == RX_STATUS_TOO_LONG_BAD_ALIGN)
  3321. +#define RX_ERROR_OVER(s) \
  3322. + ((s) == RX_STATUS_BUFFER_FULL)
  3323. +#define RX_ERROR_CRC(s) \
  3324. + ((s) == RX_STATUS_CRC_ERROR || \
  3325. + (s) == RX_STATUS_TOO_LONG_BAD_CRC)
  3326. +#define RX_ERROR_FRAME(s) \
  3327. + ((s) == RX_STATUS_ALIGNMENT_ERROR || \
  3328. + (s) == RX_STATUS_TOO_LONG_BAD_ALIGN)
  3329. +#define RX_ERROR_FIFO(s) \
  3330. + (0)
  3331. +
  3332. +/*
  3333. + * GMAC DMA Rx Description Word 1 Register
  3334. + * GMAC0 offset 0x8064
  3335. + * GMAC1 offset 0xC064
  3336. + */
  3337. +typedef union {
  3338. + unsigned int bits32;
  3339. + struct rxdesc_word1 {
  3340. + unsigned int byte_count : 16; /* bit 15: 0 Rx Frame Byte Count */
  3341. + unsigned int sw_id : 16; /* bit 31:16 Software ID */
  3342. + } bits;
  3343. +} GMAC_RXDESC_1_T;
  3344. +
  3345. +/*
  3346. + * GMAC DMA Rx Description Word 2 Register
  3347. + * GMAC0 offset 0x8068
  3348. + * GMAC1 offset 0xC068
  3349. + */
  3350. +typedef union {
  3351. + unsigned int bits32;
  3352. + unsigned int buf_adr;
  3353. +} GMAC_RXDESC_2_T;
  3354. +
  3355. +#define RX_INSERT_NONE 0
  3356. +#define RX_INSERT_1_BYTE 1
  3357. +#define RX_INSERT_2_BYTE 2
  3358. +#define RX_INSERT_3_BYTE 3
  3359. +
  3360. +/*
  3361. + * GMAC DMA Rx Description Word 3 Register
  3362. + * GMAC0 offset 0x806C
  3363. + * GMAC1 offset 0xC06C
  3364. + */
  3365. +typedef union {
  3366. + unsigned int bits32;
  3367. + struct rxdesc_word3 {
  3368. + unsigned int l3_offset : 8; /* bit 7: 0 L3 data offset */
  3369. + unsigned int l4_offset : 8; /* bit 15: 8 L4 data offset */
  3370. + unsigned int l7_offset : 8; /* bit 23: 16 L7 data offset */
  3371. + unsigned int dup_ack : 1; /* bit 24 Duplicated ACK detected */
  3372. + unsigned int abnormal : 1; /* bit 25 abnormal case found */
  3373. + unsigned int option : 1; /* bit 26 IPV4 option or IPV6 extension header */
  3374. + unsigned int out_of_seq : 1; /* bit 27 Out of Sequence packet */
  3375. + unsigned int ctrl_flag : 1; /* bit 28 Control Flag is present */
  3376. + unsigned int eofie : 1; /* bit 29 End of frame interrupt enable */
  3377. + unsigned int sof_eof : 2; /* bit 31:30 11: only one, 10: first, 01: last, 00: linking */
  3378. + } bits;
  3379. +} GMAC_RXDESC_3_T;
  3380. +
  3381. +/*
  3382. + * GMAC Rx Descriptor
  3383. + */
  3384. +typedef struct {
  3385. + GMAC_RXDESC_0_T word0;
  3386. + GMAC_RXDESC_1_T word1;
  3387. + GMAC_RXDESC_2_T word2;
  3388. + GMAC_RXDESC_3_T word3;
  3389. +} GMAC_RXDESC_T;
  3390. +
  3391. +/*
  3392. + * GMAC Hash Engine Enable/Action Register 0 Offset Register
  3393. + * GMAC0 offset 0x8070
  3394. + * GMAC1 offset 0xC070
  3395. + */
  3396. +typedef union {
  3397. + unsigned int bits32;
  3398. + struct bit_8070 {
  3399. + unsigned int mr0hel : 6; /* bit 5:0 match rule 0 hash entry size */
  3400. + unsigned int mr0_action : 5; /* bit 10:6 Matching Rule 0 action offset */
  3401. + unsigned int reserved0 : 4; /* bit 14:11 */
  3402. + unsigned int mr0en : 1; /* bit 15 Enable Matching Rule 0 */
  3403. + unsigned int mr1hel : 6; /* bit 21:16 match rule 1 hash entry size */
  3404. + unsigned int mr1_action : 5; /* bit 26:22 Matching Rule 1 action offset */
  3405. + unsigned int timing : 3; /* bit 29:27 */
  3406. + unsigned int reserved1 : 1; /* bit 30 */
  3407. + unsigned int mr1en : 1; /* bit 31 Enable Matching Rule 1 */
  3408. + } bits;
  3409. +} GMAC_HASH_ENABLE_REG0_T;
  3410. +
  3411. +/*
  3412. + * GMAC Hash Engine Enable/Action Register 1 Offset Register
  3413. + * GMAC0 offset 0x8074
  3414. + * GMAC1 offset 0xC074
  3415. + */
  3416. +typedef union {
  3417. + unsigned int bits32;
  3418. + struct bit_8074 {
  3419. + unsigned int mr2hel : 6; /* bit 5:0 match rule 2 hash entry size */
  3420. + unsigned int mr2_action : 5; /* bit 10:6 Matching Rule 2 action offset */
  3421. + unsigned int reserved2 : 4; /* bit 14:11 */
  3422. + unsigned int mr2en : 1; /* bit 15 Enable Matching Rule 2 */
  3423. + unsigned int mr3hel : 6; /* bit 21:16 match rule 3 hash entry size */
  3424. + unsigned int mr3_action : 5; /* bit 26:22 Matching Rule 3 action offset */
  3425. + unsigned int reserved1 : 4; /* bit 30:27 */
  3426. + unsigned int mr3en : 1; /* bit 31 Enable Matching Rule 3 */
  3427. + } bits;
  3428. +} GMAC_HASH_ENABLE_REG1_T;
  3429. +
  3430. +/*
  3431. + * GMAC Matching Rule Control Register 0
  3432. + * GMAC0 offset 0x8078
  3433. + * GMAC1 offset 0xC078
  3434. + */
  3435. +typedef union {
  3436. + unsigned int bits32;
  3437. + struct bit_8078 {
  3438. + unsigned int sprx : 8; /* bit 7:0 Support Protocol Register 7:0 */
  3439. + unsigned int reserved2 : 4; /* bit 11:8 */
  3440. + unsigned int tos_traffic : 1; /* bit 12 IPV4 TOS or IPV6 Traffice Class */
  3441. + unsigned int flow_lable : 1; /* bit 13 IPV6 Flow label */
  3442. + unsigned int ip_hdr_len : 1; /* bit 14 IPV4 Header length */
  3443. + unsigned int ip_version : 1; /* bit 15 0: IPV4, 1: IPV6 */
  3444. + unsigned int reserved1 : 3; /* bit 18:16 */
  3445. + unsigned int pppoe : 1; /* bit 19 PPPoE Session ID enable */
  3446. + unsigned int vlan : 1; /* bit 20 VLAN ID enable */
  3447. + unsigned int ether_type : 1; /* bit 21 Ethernet type enable */
  3448. + unsigned int sa : 1; /* bit 22 MAC SA enable */
  3449. + unsigned int da : 1; /* bit 23 MAC DA enable */
  3450. + unsigned int priority : 3; /* bit 26:24 priority if multi-rules matched */
  3451. + unsigned int port : 1; /* bit 27 PORT ID matching enable */
  3452. + unsigned int l7 : 1; /* bit 28 L7 matching enable */
  3453. + unsigned int l4 : 1; /* bit 29 L4 matching enable */
  3454. + unsigned int l3 : 1; /* bit 30 L3 matching enable */
  3455. + unsigned int l2 : 1; /* bit 31 L2 matching enable */
  3456. + } bits;
  3457. +} GMAC_MRxCR0_T;
  3458. +
  3459. +#define MR_L2_BIT BIT(31)
  3460. +#define MR_L3_BIT BIT(30)
  3461. +#define MR_L4_BIT BIT(29)
  3462. +#define MR_L7_BIT BIT(28)
  3463. +#define MR_PORT_BIT BIT(27)
  3464. +#define MR_PRIORITY_BIT BIT(26)
  3465. +#define MR_DA_BIT BIT(23)
  3466. +#define MR_SA_BIT BIT(22)
  3467. +#define MR_ETHER_TYPE_BIT BIT(21)
  3468. +#define MR_VLAN_BIT BIT(20)
  3469. +#define MR_PPPOE_BIT BIT(19)
  3470. +#define MR_IP_VER_BIT BIT(15)
  3471. +#define MR_IP_HDR_LEN_BIT BIT(14)
  3472. +#define MR_FLOW_LABLE_BIT BIT(13)
  3473. +#define MR_TOS_TRAFFIC_BIT BIT(12)
  3474. +#define MR_SPR_BIT(x) BIT(x)
  3475. +#define MR_SPR_BITS 0xff
  3476. +
  3477. +/*
  3478. + * GMAC Matching Rule Control Register 1
  3479. + * GMAC0 offset 0x807C
  3480. + * GMAC1 offset 0xC07C
  3481. + */
  3482. +typedef union {
  3483. + unsigned int bits32;
  3484. + struct bit_807C {
  3485. + unsigned int l4_byte0_15 : 16; /* bit 15: 0 */
  3486. + unsigned int dip_netmask : 7; /* bit 22:16 Dest IP net mask, number of mask bits */
  3487. + unsigned int dip : 1; /* bit 23 Dest IP */
  3488. + unsigned int sip_netmask : 7; /* bit 30:24 Srce IP net mask, number of mask bits */
  3489. + unsigned int sip : 1; /* bit 31 Srce IP */
  3490. + } bits;
  3491. +} GMAC_MRxCR1_T;
  3492. +
  3493. +/*
  3494. + * GMAC Matching Rule Control Register 2
  3495. + * GMAC0 offset 0x8080
  3496. + * GMAC1 offset 0xC080
  3497. + */
  3498. +typedef union {
  3499. + unsigned int bits32;
  3500. + struct bit_8080 {
  3501. + unsigned int l7_byte0_23 : 24; /* bit 23:0 */
  3502. + unsigned int l4_byte16_24 : 8; /* bit 31: 24 */
  3503. + } bits;
  3504. +} GMAC_MRxCR2_T;
  3505. +
  3506. +/*
  3507. + * GMAC Support registers
  3508. + * GMAC0 offset 0x80A8
  3509. + * GMAC1 offset 0xC0A8
  3510. + */
  3511. +typedef union {
  3512. + unsigned int bits32;
  3513. + struct bit_80A8 {
  3514. + unsigned int protocol : 8; /* bit 7:0 Supported protocol */
  3515. + unsigned int swap : 3; /* bit 10:8 Swap */
  3516. + unsigned int reserved : 21; /* bit 31:11 */
  3517. + } bits;
  3518. +} GMAC_SPR_T;
  3519. +
  3520. +/*
  3521. + * GMAC_AHB_WEIGHT registers
  3522. + * GMAC0 offset 0x80C8
  3523. + * GMAC1 offset 0xC0C8
  3524. + */
  3525. +typedef union {
  3526. + unsigned int bits32;
  3527. + struct bit_80C8 {
  3528. + unsigned int hash_weight : 5; /* 4:0 */
  3529. + unsigned int rx_weight : 5; /* 9:5 */
  3530. + unsigned int tx_weight : 5; /* 14:10 */
  3531. + unsigned int pre_req : 5; /* 19:15 Rx Data Pre Request FIFO Threshold */
  3532. + unsigned int tqDV_threshold : 5; /* 24:20 DMA TqCtrl to Start tqDV FIFO Threshold */
  3533. + unsigned int reserved : 7; /* 31:25 */
  3534. + } bits;
  3535. +} GMAC_AHB_WEIGHT_T;
  3536. +
  3537. +/*
  3538. + * the register structure of GMAC
  3539. + */
  3540. +
  3541. +/*
  3542. + * GMAC RX FLTR
  3543. + * GMAC0 Offset 0xA00C
  3544. + * GMAC1 Offset 0xE00C
  3545. + */
  3546. +typedef union {
  3547. + unsigned int bits32;
  3548. + struct bit1_000c {
  3549. + unsigned int unicast : 1; /* enable receive of unicast frames that are sent to STA address */
  3550. + unsigned int multicast : 1; /* enable receive of multicast frames that pass multicast filter */
  3551. + unsigned int broadcast : 1; /* enable receive of broadcast frames */
  3552. + unsigned int promiscuous : 1; /* enable receive of all frames */
  3553. + unsigned int error : 1; /* enable receive of all error frames */
  3554. + unsigned int : 27;
  3555. + } bits;
  3556. +} GMAC_RX_FLTR_T;
  3557. +
  3558. +/*
  3559. + * GMAC Configuration 0
  3560. + * GMAC0 Offset 0xA018
  3561. + * GMAC1 Offset 0xE018
  3562. + */
  3563. +typedef union {
  3564. + unsigned int bits32;
  3565. + struct bit1_0018 {
  3566. + unsigned int dis_tx : 1; /* 0: disable transmit */
  3567. + unsigned int dis_rx : 1; /* 1: disable receive */
  3568. + unsigned int loop_back : 1; /* 2: transmit data loopback enable */
  3569. + unsigned int flow_ctrl : 1; /* 3: flow control also trigged by Rx queues */
  3570. + unsigned int adj_ifg : 4; /* 4-7: adjust IFG from 96+/-56 */
  3571. + unsigned int max_len : 3; /* 8-10 maximum receive frame length allowed */
  3572. + unsigned int dis_bkoff : 1; /* 11: disable back-off function */
  3573. + unsigned int dis_col : 1; /* 12: disable 16 collisions abort function */
  3574. + unsigned int sim_test : 1; /* 13: speed up timers in simulation */
  3575. + unsigned int rx_fc_en : 1; /* 14: RX flow control enable */
  3576. + unsigned int tx_fc_en : 1; /* 15: TX flow control enable */
  3577. + unsigned int rgmii_en : 1; /* 16: RGMII in-band status enable */
  3578. + unsigned int ipv4_rx_chksum : 1; /* 17: IPv4 RX Checksum enable */
  3579. + unsigned int ipv6_rx_chksum : 1; /* 18: IPv6 RX Checksum enable */
  3580. + unsigned int rx_tag_remove : 1; /* 19: Remove Rx VLAN tag */
  3581. + unsigned int rgmm_edge : 1; /* 20 */
  3582. + unsigned int rxc_inv : 1; /* 21 */
  3583. + unsigned int ipv6_exthdr_order : 1; /* 22 */
  3584. + unsigned int rx_err_detect : 1; /* 23 */
  3585. + unsigned int port0_chk_hwq : 1; /* 24 */
  3586. + unsigned int port1_chk_hwq : 1; /* 25 */
  3587. + unsigned int port0_chk_toeq : 1; /* 26 */
  3588. + unsigned int port1_chk_toeq : 1; /* 27 */
  3589. + unsigned int port0_chk_classq : 1; /* 28 */
  3590. + unsigned int port1_chk_classq : 1; /* 29 */
  3591. + unsigned int reserved : 2; /* 31 */
  3592. + } bits;
  3593. +} GMAC_CONFIG0_T;
  3594. +
  3595. +#define CONFIG0_TX_RX_DISABLE (BIT(1)|BIT(0))
  3596. +#define CONFIG0_RX_CHKSUM (BIT(18)|BIT(17))
  3597. +#define CONFIG0_FLOW_RX (BIT(14))
  3598. +#define CONFIG0_FLOW_TX (BIT(15))
  3599. +#define CONFIG0_FLOW_TX_RX (BIT(14)|BIT(15))
  3600. +#define CONFIG0_FLOW_CTL (BIT(14)|BIT(15))
  3601. +
  3602. +#define CONFIG0_MAXLEN_SHIFT 8
  3603. +#define CONFIG0_MAXLEN_MASK (7 << CONFIG0_MAXLEN_SHIFT)
  3604. +#define CONFIG0_MAXLEN_1536 0
  3605. +#define CONFIG0_MAXLEN_1518 1
  3606. +#define CONFIG0_MAXLEN_1522 2
  3607. +#define CONFIG0_MAXLEN_1542 3
  3608. +#define CONFIG0_MAXLEN_9k 4 /* 9212 */
  3609. +#define CONFIG0_MAXLEN_10k 5 /* 10236 */
  3610. +#define CONFIG0_MAXLEN_1518__6 6
  3611. +#define CONFIG0_MAXLEN_1518__7 7
  3612. +
  3613. +/*
  3614. + * GMAC Configuration 1
  3615. + * GMAC0 Offset 0xA01C
  3616. + * GMAC1 Offset 0xE01C
  3617. + */
  3618. +typedef union {
  3619. + unsigned int bits32;
  3620. + struct bit1_001c {
  3621. + unsigned int set_threshold : 8; /* flow control set threshold */
  3622. + unsigned int rel_threshold : 8; /* flow control release threshold */
  3623. + unsigned int reserved : 16;
  3624. + } bits;
  3625. +} GMAC_CONFIG1_T;
  3626. +
  3627. +#define GMAC_FLOWCTRL_SET_MAX 32
  3628. +#define GMAC_FLOWCTRL_SET_MIN 0
  3629. +#define GMAC_FLOWCTRL_RELEASE_MAX 32
  3630. +#define GMAC_FLOWCTRL_RELEASE_MIN 0
  3631. +
  3632. +/*
  3633. + * GMAC Configuration 2
  3634. + * GMAC0 Offset 0xA020
  3635. + * GMAC1 Offset 0xE020
  3636. + */
  3637. +typedef union {
  3638. + unsigned int bits32;
  3639. + struct bit1_0020 {
  3640. + unsigned int set_threshold : 16; /* flow control set threshold */
  3641. + unsigned int rel_threshold : 16; /* flow control release threshold */
  3642. + } bits;
  3643. +} GMAC_CONFIG2_T;
  3644. +
  3645. +/*
  3646. + * GMAC Configuration 3
  3647. + * GMAC0 Offset 0xA024
  3648. + * GMAC1 Offset 0xE024
  3649. + */
  3650. +typedef union {
  3651. + unsigned int bits32;
  3652. + struct bit1_0024 {
  3653. + unsigned int set_threshold : 16; /* flow control set threshold */
  3654. + unsigned int rel_threshold : 16; /* flow control release threshold */
  3655. + } bits;
  3656. +} GMAC_CONFIG3_T;
  3657. +
  3658. +
  3659. +/*
  3660. + * GMAC STATUS
  3661. + * GMAC0 Offset 0xA02C
  3662. + * GMAC1 Offset 0xE02C
  3663. + */
  3664. +typedef union {
  3665. + unsigned int bits32;
  3666. + struct bit1_002c {
  3667. + unsigned int link : 1; /* link status */
  3668. + unsigned int speed : 2; /* link speed(00->2.5M 01->25M 10->125M) */
  3669. + unsigned int duplex : 1; /* duplex mode */
  3670. + unsigned int reserved : 1;
  3671. + unsigned int mii_rmii : 2; /* PHY interface type */
  3672. + unsigned int : 25;
  3673. + } bits;
  3674. +} GMAC_STATUS_T;
  3675. +
  3676. +#define GMAC_SPEED_10 0
  3677. +#define GMAC_SPEED_100 1
  3678. +#define GMAC_SPEED_1000 2
  3679. +
  3680. +#define GMAC_PHY_MII 0
  3681. +#define GMAC_PHY_GMII 1
  3682. +#define GMAC_PHY_RGMII_100_10 2
  3683. +#define GMAC_PHY_RGMII_1000 3
  3684. +
  3685. +/*
  3686. + * Queue Header
  3687. + * (1) TOE Queue Header
  3688. + * (2) Non-TOE Queue Header
  3689. + * (3) Interrupt Queue Header
  3690. + *
  3691. + * memory Layout
  3692. + * TOE Queue Header
  3693. + * 0x60003000 +---------------------------+ 0x0000
  3694. + * | TOE Queue 0 Header |
  3695. + * | 8 * 4 Bytes |
  3696. + * +---------------------------+ 0x0020
  3697. + * | TOE Queue 1 Header |
  3698. + * | 8 * 4 Bytes |
  3699. + * +---------------------------+ 0x0040
  3700. + * | ...... |
  3701. + * | |
  3702. + * +---------------------------+
  3703. + *
  3704. + * Non TOE Queue Header
  3705. + * 0x60002000 +---------------------------+ 0x0000
  3706. + * | Default Queue 0 Header |
  3707. + * | 2 * 4 Bytes |
  3708. + * +---------------------------+ 0x0008
  3709. + * | Default Queue 1 Header |
  3710. + * | 2 * 4 Bytes |
  3711. + * +---------------------------+ 0x0010
  3712. + * | Classification Queue 0 |
  3713. + * | 2 * 4 Bytes |
  3714. + * +---------------------------+
  3715. + * | Classification Queue 1 |
  3716. + * | 2 * 4 Bytes |
  3717. + * +---------------------------+ (n * 8 + 0x10)
  3718. + * | ... |
  3719. + * | 2 * 4 Bytes |
  3720. + * +---------------------------+ (13 * 8 + 0x10)
  3721. + * | Classification Queue 13 |
  3722. + * | 2 * 4 Bytes |
  3723. + * +---------------------------+ 0x80
  3724. + * | Interrupt Queue 0 |
  3725. + * | 2 * 4 Bytes |
  3726. + * +---------------------------+
  3727. + * | Interrupt Queue 1 |
  3728. + * | 2 * 4 Bytes |
  3729. + * +---------------------------+
  3730. + * | Interrupt Queue 2 |
  3731. + * | 2 * 4 Bytes |
  3732. + * +---------------------------+
  3733. + * | Interrupt Queue 3 |
  3734. + * | 2 * 4 Bytes |
  3735. + * +---------------------------+
  3736. + *
  3737. + */
  3738. +#define TOE_QUEUE_HDR_ADDR(n) (TOE_TOE_QUE_HDR_BASE + n * 32)
  3739. +#define TOE_Q_HDR_AREA_END (TOE_QUEUE_HDR_ADDR(TOE_TOE_QUEUE_MAX + 1))
  3740. +#define TOE_DEFAULT_Q_HDR_BASE(x) (TOE_NONTOE_QUE_HDR_BASE + 0x08 * (x))
  3741. +#define TOE_CLASS_Q_HDR_BASE (TOE_NONTOE_QUE_HDR_BASE + 0x10)
  3742. +#define TOE_INTR_Q_HDR_BASE (TOE_NONTOE_QUE_HDR_BASE + 0x80)
  3743. +#define INTERRUPT_QUEUE_HDR_ADDR(n) (TOE_INTR_Q_HDR_BASE + n * 8)
  3744. +#define NONTOE_Q_HDR_AREA_END (INTERRUPT_QUEUE_HDR_ADDR(TOE_INTR_QUEUE_MAX + 1))
  3745. +/*
  3746. + * TOE Queue Header Word 0
  3747. + */
  3748. +typedef union {
  3749. + unsigned int bits32;
  3750. + unsigned int base_size;
  3751. +} TOE_QHDR0_T;
  3752. +
  3753. +#define TOE_QHDR0_BASE_MASK (~0x0f)
  3754. +
  3755. +/*
  3756. + * TOE Queue Header Word 1
  3757. + */
  3758. +typedef union {
  3759. + unsigned int bits32;
  3760. + struct bit_qhdr1 {
  3761. + unsigned int rptr : 16; /* bit 15:0 */
  3762. + unsigned int wptr : 16; /* bit 31:16 */
  3763. + } bits;
  3764. +} TOE_QHDR1_T;
  3765. +
  3766. +/*
  3767. + * TOE Queue Header Word 2
  3768. + */
  3769. +typedef union {
  3770. + unsigned int bits32;
  3771. + struct bit_qhdr2 {
  3772. + unsigned int TotalPktSize : 17; /* bit 16: 0 Total packet size */
  3773. + unsigned int reserved : 7; /* bit 23:17 */
  3774. + unsigned int dack : 1; /* bit 24 1: Duplicated ACK */
  3775. + unsigned int abn : 1; /* bit 25 1: Abnormal case Found */
  3776. + unsigned int tcp_opt : 1; /* bit 26 1: Have TCP option */
  3777. + unsigned int ip_opt : 1; /* bit 27 1: have IPV4 option or IPV6 Extension header */
  3778. + unsigned int sat : 1; /* bit 28 1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold */
  3779. + unsigned int osq : 1; /* bit 29 1: out of sequence */
  3780. + unsigned int ctl : 1; /* bit 30 1: have control flag bits (except ack) */
  3781. + unsigned int usd : 1; /* bit 31 0: if no data assembled yet */
  3782. + } bits;
  3783. +} TOE_QHDR2_T;
  3784. +
  3785. +/*
  3786. + * TOE Queue Header Word 3
  3787. + */
  3788. +typedef union {
  3789. + unsigned int bits32;
  3790. + unsigned int seq_num;
  3791. +} TOE_QHDR3_T;
  3792. +
  3793. +/*
  3794. + * TOE Queue Header Word 4
  3795. + */
  3796. +typedef union {
  3797. + unsigned int bits32;
  3798. + unsigned int ack_num;
  3799. +} TOE_QHDR4_T;
  3800. +
  3801. +/*
  3802. + * TOE Queue Header Word 5
  3803. + */
  3804. +typedef union {
  3805. + unsigned int bits32;
  3806. + struct bit_qhdr5 {
  3807. + unsigned int AckCnt : 16; /* bit 15:0 */
  3808. + unsigned int SeqCnt : 16; /* bit 31:16 */
  3809. + } bits;
  3810. +} TOE_QHDR5_T;
  3811. +
  3812. +/*
  3813. + * TOE Queue Header Word 6
  3814. + */
  3815. +typedef union {
  3816. + unsigned int bits32;
  3817. + struct bit_qhdr6 {
  3818. + unsigned int WinSize : 16; /* bit 15:0 */
  3819. + unsigned int iq_num : 2; /* bit 17:16 */
  3820. + unsigned int MaxPktSize : 14; /* bit 31:18 */
  3821. + } bits;
  3822. +} TOE_QHDR6_T;
  3823. +
  3824. +/*
  3825. + * TOE Queue Header Word 7
  3826. + */
  3827. +typedef union {
  3828. + unsigned int bits32;
  3829. + struct bit_qhdr7 {
  3830. + unsigned int AckThreshold : 16; /* bit 15:0 */
  3831. + unsigned int SeqThreshold : 16; /* bit 31:16 */
  3832. + } bits;
  3833. +} TOE_QHDR7_T;
  3834. +
  3835. +/*
  3836. + * TOE Queue Header
  3837. + */
  3838. +typedef struct {
  3839. + TOE_QHDR0_T word0;
  3840. + TOE_QHDR1_T word1;
  3841. + TOE_QHDR2_T word2;
  3842. + TOE_QHDR3_T word3;
  3843. + TOE_QHDR4_T word4;
  3844. + TOE_QHDR5_T word5;
  3845. + TOE_QHDR6_T word6;
  3846. + TOE_QHDR7_T word7;
  3847. +} TOE_QHDR_T;
  3848. +
  3849. +/*
  3850. + * NONTOE Queue Header Word 0
  3851. + */
  3852. +typedef union {
  3853. + unsigned int bits32;
  3854. + unsigned int base_size;
  3855. +} NONTOE_QHDR0_T;
  3856. +
  3857. +#define NONTOE_QHDR0_BASE_MASK (~0x0f)
  3858. +
  3859. +/*
  3860. + * NONTOE Queue Header Word 1
  3861. + */
  3862. +typedef union {
  3863. + unsigned int bits32;
  3864. + struct bit_nonqhdr1 {
  3865. + unsigned int rptr : 16; /* bit 15:0 */
  3866. + unsigned int wptr : 16; /* bit 31:16 */
  3867. + } bits;
  3868. +} NONTOE_QHDR1_T;
  3869. +
  3870. +/*
  3871. + * Non-TOE Queue Header
  3872. + */
  3873. +typedef struct {
  3874. + NONTOE_QHDR0_T word0;
  3875. + NONTOE_QHDR1_T word1;
  3876. +} NONTOE_QHDR_T;
  3877. +
  3878. +/*
  3879. + * Interrupt Queue Header Word 0
  3880. + */
  3881. +typedef union {
  3882. + unsigned int bits32;
  3883. + struct bit_intrqhdr0 {
  3884. + unsigned int win_size : 16; /* bit 15:0 Descriptor Ring Size */
  3885. + unsigned int wptr : 16; /* bit 31:16 Write Pointer where hw stopped */
  3886. + } bits;
  3887. +} INTR_QHDR0_T;
  3888. +
  3889. +/*
  3890. + * Interrupt Queue Header Word 1
  3891. + */
  3892. +typedef union {
  3893. + unsigned int bits32;
  3894. + struct bit_intrqhdr1 {
  3895. + unsigned int TotalPktSize : 17; /* bit 16: 0 Total packet size */
  3896. + unsigned int tcp_qid : 8; /* bit 24:17 TCP Queue ID */
  3897. + unsigned int dack : 1; /* bit 25 1: Duplicated ACK */
  3898. + unsigned int abn : 1; /* bit 26 1: Abnormal case Found */
  3899. + unsigned int tcp_opt : 1; /* bit 27 1: Have TCP option */
  3900. + unsigned int ip_opt : 1; /* bit 28 1: have IPV4 option or IPV6 Extension header */
  3901. + unsigned int sat : 1; /* bit 29 1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold */
  3902. + unsigned int osq : 1; /* bit 30 1: out of sequence */
  3903. + unsigned int ctl : 1; /* bit 31 1: have control flag bits (except ack) */
  3904. + } bits;
  3905. +} INTR_QHDR1_T;
  3906. +
  3907. +/*
  3908. + * Interrupt Queue Header Word 2
  3909. + */
  3910. +typedef union {
  3911. + unsigned int bits32;
  3912. + unsigned int seq_num;
  3913. +} INTR_QHDR2_T;
  3914. +
  3915. +/*
  3916. + * Interrupt Queue Header Word 3
  3917. + */
  3918. +typedef union {
  3919. + unsigned int bits32;
  3920. + unsigned int ack_num;
  3921. +} INTR_QHDR3_T;
  3922. +
  3923. +/*
  3924. + * Interrupt Queue Header Word 4
  3925. + */
  3926. +typedef union {
  3927. + unsigned int bits32;
  3928. + struct bit_intrqhdr4 {
  3929. + unsigned int AckCnt : 16; /* bit 15:0 Ack# change since last ack# intr. */
  3930. + unsigned int SeqCnt : 16; /* bit 31:16 Seq# change since last seq# intr. */
  3931. + } bits;
  3932. +} INTR_QHDR4_T;
  3933. +
  3934. +/*
  3935. + * Interrupt Queue Header
  3936. + */
  3937. +typedef struct {
  3938. + INTR_QHDR0_T word0;
  3939. + INTR_QHDR1_T word1;
  3940. + INTR_QHDR2_T word2;
  3941. + INTR_QHDR3_T word3;
  3942. + INTR_QHDR4_T word4;
  3943. + unsigned int word5;
  3944. + unsigned int word6;
  3945. + unsigned int word7;
  3946. +} INTR_QHDR_T;
  3947. +
  3948. +#endif /* _GMAC_SL351x_H */