crisv32_ethernet_driver.patch 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094
  1. diff --git a/arch/cris/arch-v32/drivers/Kconfig b/arch/cris/arch-v32/drivers/Kconfig
  2. index e6c523c..5737a5b 100644
  3. --- a/arch/cris/arch-v32/drivers/Kconfig
  4. +++ b/arch/cris/arch-v32/drivers/Kconfig
  5. @@ -8,9 +8,18 @@ config ETRAX_ETHERNET
  6. This option enables the ETRAX FS built-in 10/100Mbit Ethernet
  7. controller.
  8. +config ETRAX_HAVE_PHY
  9. + bool "PHY present"
  10. + default y
  11. + help
  12. + Search and use the first PHY available on the MDIO bus. Fail
  13. + if none is found. Say Y here if you are not in a switched
  14. + environment (single port device).
  15. +
  16. config ETRAX_NO_PHY
  17. bool "PHY not present"
  18. depends on ETRAX_ETHERNET
  19. + default n
  20. help
  21. This option disables all MDIO communication with an ethernet
  22. transceiver connected to the MII interface. This option shall
  23. @@ -18,6 +27,70 @@ config ETRAX_NO_PHY
  24. switch. This option should normally be disabled. If enabled,
  25. speed and duplex will be locked to 100 Mbit and full duplex.
  26. +config ETRAX_PHY_FALLBACK
  27. + bool "Fixed PHY fallback"
  28. + depends on ETRAX_ETHERNET
  29. + default n
  30. + help
  31. + If no PHY is found on the MDIO bus, fall back on a fixed
  32. + 100/Full fixed PHY. Say Y here if you need dynamic PHY
  33. + presence detection (switch connection where some but not
  34. + all ports have integrated PHYs), otherwise say N.
  35. +
  36. +config ETRAX_ETHERNET_IFACE0
  37. + depends on ETRAX_ETHERNET
  38. + bool "Enable network interface 0"
  39. +
  40. +config ETRAX_ETHERNET_IFACE1
  41. + depends on (ETRAX_ETHERNET && ETRAXFS)
  42. + bool "Enable network interface 1 (uses DMA6 and DMA7)"
  43. +
  44. +choice
  45. + prompt "Eth0 led group"
  46. + depends on ETRAX_ETHERNET_IFACE0
  47. + default ETRAX_ETH0_USE_LEDGRP0
  48. +
  49. +config ETRAX_ETH0_USE_LEDGRP0
  50. + bool "Use LED grp 0"
  51. + depends on ETRAX_NBR_LED_GRP_ONE || ETRAX_NBR_LED_GRP_TWO
  52. + help
  53. + Use LED grp 0 for eth0
  54. +
  55. +config ETRAX_ETH0_USE_LEDGRP1
  56. + bool "Use LED grp 1"
  57. + depends on ETRAX_NBR_LED_GRP_TWO
  58. + help
  59. + Use LED grp 1 for eth0
  60. +
  61. +config ETRAX_ETH0_USE_LEDGRPNULL
  62. + bool "Use no LEDs for eth0"
  63. + help
  64. + Use no LEDs for eth0
  65. +endchoice
  66. +
  67. +choice
  68. + prompt "Eth1 led group"
  69. + depends on ETRAX_ETHERNET_IFACE1
  70. + default ETRAX_ETH1_USE_LEDGRP1
  71. +
  72. +config ETRAX_ETH1_USE_LEDGRP0
  73. + bool "Use LED grp 0"
  74. + depends on ETRAX_NBR_LED_GRP_ONE || ETRAX_NBR_LED_GRP_TWO
  75. + help
  76. + Use LED grp 0 for eth1
  77. +
  78. +config ETRAX_ETH1_USE_LEDGRP1
  79. + bool "Use LED grp 1"
  80. + depends on ETRAX_NBR_LED_GRP_TWO
  81. + help
  82. + Use LED grp 1 for eth1
  83. +
  84. +config ETRAX_ETH1_USE_LEDGRPNULL
  85. + bool "Use no LEDs for eth1"
  86. + help
  87. + Use no LEDs for eth1
  88. +endchoice
  89. +
  90. config ETRAXFS_SERIAL
  91. bool "Serial-port support"
  92. depends on ETRAX_ARCH_V32
  93. diff --git a/arch/cris/include/arch-v32/arch/hwregs/eth_defs.h b/arch/cris/include/arch-v32/arch/hwregs/eth_defs.h
  94. index 90fe8a2..37bec9a 100644
  95. --- a/arch/cris/include/arch-v32/arch/hwregs/eth_defs.h
  96. +++ b/arch/cris/include/arch-v32/arch/hwregs/eth_defs.h
  97. @@ -2,69 +2,64 @@
  98. #define __eth_defs_h
  99. /*
  100. - * This file is autogenerated from
  101. - * file: eth.r
  102. - * id: eth_regs.r,v 1.16 2005/05/20 15:41:22 perz Exp
  103. - * last modfied: Mon Jan 9 06:06:41 2006
  104. - *
  105. - * by /n/asic/design/tools/rdesc/rdes2c eth.r
  106. - * id: $Id: eth_defs.h,v 1.7 2006/01/26 13:45:30 karljope Exp $
  107. - * Any changes here will be lost.
  108. - *
  109. - * -*- buffer-read-only: t -*-
  110. + * Note: Previously this was autogenerated code from the hardware
  111. + * implementation. However, to enable the same file to be used
  112. + * for both ARTPEC-3 and ETRAX FS this file is now hand-edited.
  113. + * Be careful.
  114. */
  115. +
  116. /* Main access macros */
  117. #ifndef REG_RD
  118. #define REG_RD( scope, inst, reg ) \
  119. - REG_READ( reg_##scope##_##reg, \
  120. - (inst) + REG_RD_ADDR_##scope##_##reg )
  121. + REG_READ( reg_##scope##_##reg, \
  122. + (inst) + REG_RD_ADDR_##scope##_##reg )
  123. #endif
  124. #ifndef REG_WR
  125. #define REG_WR( scope, inst, reg, val ) \
  126. - REG_WRITE( reg_##scope##_##reg, \
  127. - (inst) + REG_WR_ADDR_##scope##_##reg, (val) )
  128. + REG_WRITE( reg_##scope##_##reg, \
  129. + (inst) + REG_WR_ADDR_##scope##_##reg, (val) )
  130. #endif
  131. #ifndef REG_RD_VECT
  132. #define REG_RD_VECT( scope, inst, reg, index ) \
  133. - REG_READ( reg_##scope##_##reg, \
  134. - (inst) + REG_RD_ADDR_##scope##_##reg + \
  135. - (index) * STRIDE_##scope##_##reg )
  136. + REG_READ( reg_##scope##_##reg, \
  137. + (inst) + REG_RD_ADDR_##scope##_##reg + \
  138. + (index) * STRIDE_##scope##_##reg )
  139. #endif
  140. #ifndef REG_WR_VECT
  141. #define REG_WR_VECT( scope, inst, reg, index, val ) \
  142. - REG_WRITE( reg_##scope##_##reg, \
  143. - (inst) + REG_WR_ADDR_##scope##_##reg + \
  144. - (index) * STRIDE_##scope##_##reg, (val) )
  145. + REG_WRITE( reg_##scope##_##reg, \
  146. + (inst) + REG_WR_ADDR_##scope##_##reg + \
  147. + (index) * STRIDE_##scope##_##reg, (val) )
  148. #endif
  149. #ifndef REG_RD_INT
  150. #define REG_RD_INT( scope, inst, reg ) \
  151. - REG_READ( int, (inst) + REG_RD_ADDR_##scope##_##reg )
  152. + REG_READ( int, (inst) + REG_RD_ADDR_##scope##_##reg )
  153. #endif
  154. #ifndef REG_WR_INT
  155. #define REG_WR_INT( scope, inst, reg, val ) \
  156. - REG_WRITE( int, (inst) + REG_WR_ADDR_##scope##_##reg, (val) )
  157. + REG_WRITE( int, (inst) + REG_WR_ADDR_##scope##_##reg, (val) )
  158. #endif
  159. #ifndef REG_RD_INT_VECT
  160. #define REG_RD_INT_VECT( scope, inst, reg, index ) \
  161. - REG_READ( int, (inst) + REG_RD_ADDR_##scope##_##reg + \
  162. - (index) * STRIDE_##scope##_##reg )
  163. + REG_READ( int, (inst) + REG_RD_ADDR_##scope##_##reg + \
  164. + (index) * STRIDE_##scope##_##reg )
  165. #endif
  166. #ifndef REG_WR_INT_VECT
  167. #define REG_WR_INT_VECT( scope, inst, reg, index, val ) \
  168. - REG_WRITE( int, (inst) + REG_WR_ADDR_##scope##_##reg + \
  169. - (index) * STRIDE_##scope##_##reg, (val) )
  170. + REG_WRITE( int, (inst) + REG_WR_ADDR_##scope##_##reg + \
  171. + (index) * STRIDE_##scope##_##reg, (val) )
  172. #endif
  173. #ifndef REG_TYPE_CONV
  174. #define REG_TYPE_CONV( type, orgtype, val ) \
  175. - ( { union { orgtype o; type n; } r; r.o = val; r.n; } )
  176. + ( { union { orgtype o; type n; } r; r.o = val; r.n; } )
  177. #endif
  178. #ifndef reg_page_size
  179. @@ -73,306 +68,332 @@
  180. #ifndef REG_ADDR
  181. #define REG_ADDR( scope, inst, reg ) \
  182. - ( (inst) + REG_RD_ADDR_##scope##_##reg )
  183. + ( (inst) + REG_RD_ADDR_##scope##_##reg )
  184. #endif
  185. #ifndef REG_ADDR_VECT
  186. #define REG_ADDR_VECT( scope, inst, reg, index ) \
  187. - ( (inst) + REG_RD_ADDR_##scope##_##reg + \
  188. - (index) * STRIDE_##scope##_##reg )
  189. + ( (inst) + REG_RD_ADDR_##scope##_##reg + \
  190. + (index) * STRIDE_##scope##_##reg )
  191. #endif
  192. /* C-code for register scope eth */
  193. /* Register rw_ma0_lo, scope eth, type rw */
  194. typedef struct {
  195. - unsigned int addr : 32;
  196. + unsigned int addr : 32;
  197. } reg_eth_rw_ma0_lo;
  198. #define REG_RD_ADDR_eth_rw_ma0_lo 0
  199. #define REG_WR_ADDR_eth_rw_ma0_lo 0
  200. /* Register rw_ma0_hi, scope eth, type rw */
  201. typedef struct {
  202. - unsigned int addr : 16;
  203. - unsigned int dummy1 : 16;
  204. + unsigned int addr : 16;
  205. + unsigned int dummy1 : 16;
  206. } reg_eth_rw_ma0_hi;
  207. #define REG_RD_ADDR_eth_rw_ma0_hi 4
  208. #define REG_WR_ADDR_eth_rw_ma0_hi 4
  209. /* Register rw_ma1_lo, scope eth, type rw */
  210. typedef struct {
  211. - unsigned int addr : 32;
  212. + unsigned int addr : 32;
  213. } reg_eth_rw_ma1_lo;
  214. #define REG_RD_ADDR_eth_rw_ma1_lo 8
  215. #define REG_WR_ADDR_eth_rw_ma1_lo 8
  216. /* Register rw_ma1_hi, scope eth, type rw */
  217. typedef struct {
  218. - unsigned int addr : 16;
  219. - unsigned int dummy1 : 16;
  220. + unsigned int addr : 16;
  221. + unsigned int dummy1 : 16;
  222. } reg_eth_rw_ma1_hi;
  223. #define REG_RD_ADDR_eth_rw_ma1_hi 12
  224. #define REG_WR_ADDR_eth_rw_ma1_hi 12
  225. /* Register rw_ga_lo, scope eth, type rw */
  226. typedef struct {
  227. - unsigned int tbl : 32;
  228. + unsigned int table : 32;
  229. } reg_eth_rw_ga_lo;
  230. #define REG_RD_ADDR_eth_rw_ga_lo 16
  231. #define REG_WR_ADDR_eth_rw_ga_lo 16
  232. /* Register rw_ga_hi, scope eth, type rw */
  233. typedef struct {
  234. - unsigned int tbl : 32;
  235. + unsigned int table : 32;
  236. } reg_eth_rw_ga_hi;
  237. #define REG_RD_ADDR_eth_rw_ga_hi 20
  238. #define REG_WR_ADDR_eth_rw_ga_hi 20
  239. /* Register rw_gen_ctrl, scope eth, type rw */
  240. typedef struct {
  241. - unsigned int en : 1;
  242. - unsigned int phy : 2;
  243. - unsigned int protocol : 1;
  244. - unsigned int loopback : 1;
  245. - unsigned int flow_ctrl : 1;
  246. - unsigned int gtxclk_out : 1;
  247. - unsigned int phyrst_n : 1;
  248. - unsigned int dummy1 : 24;
  249. + unsigned int en : 1;
  250. + unsigned int phy : 2;
  251. + unsigned int protocol : 1;
  252. + unsigned int loopback : 1;
  253. + unsigned int flow_ctrl : 1;
  254. + unsigned int gtxclk_out : 1;
  255. + unsigned int phyrst_n : 1;
  256. + unsigned int dummy1 : 24;
  257. } reg_eth_rw_gen_ctrl;
  258. #define REG_RD_ADDR_eth_rw_gen_ctrl 24
  259. #define REG_WR_ADDR_eth_rw_gen_ctrl 24
  260. /* Register rw_rec_ctrl, scope eth, type rw */
  261. typedef struct {
  262. - unsigned int ma0 : 1;
  263. - unsigned int ma1 : 1;
  264. - unsigned int individual : 1;
  265. - unsigned int broadcast : 1;
  266. - unsigned int undersize : 1;
  267. - unsigned int oversize : 1;
  268. - unsigned int bad_crc : 1;
  269. - unsigned int duplex : 1;
  270. - unsigned int max_size : 16;
  271. - unsigned int dummy1 : 8;
  272. + unsigned int ma0 : 1;
  273. + unsigned int ma1 : 1;
  274. + unsigned int individual : 1;
  275. + unsigned int broadcast : 1;
  276. + unsigned int undersize : 1;
  277. + unsigned int oversize : 1;
  278. + unsigned int bad_crc : 1;
  279. + unsigned int duplex : 1;
  280. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  281. + unsigned int max_size : 16;
  282. + unsigned int dummy1 : 8;
  283. +#else
  284. + unsigned int max_size : 1;
  285. + unsigned int dummy1 : 23;
  286. +#endif
  287. } reg_eth_rw_rec_ctrl;
  288. #define REG_RD_ADDR_eth_rw_rec_ctrl 28
  289. #define REG_WR_ADDR_eth_rw_rec_ctrl 28
  290. /* Register rw_tr_ctrl, scope eth, type rw */
  291. typedef struct {
  292. - unsigned int crc : 1;
  293. - unsigned int pad : 1;
  294. - unsigned int retry : 1;
  295. - unsigned int ignore_col : 1;
  296. - unsigned int cancel : 1;
  297. - unsigned int hsh_delay : 1;
  298. - unsigned int ignore_crs : 1;
  299. - unsigned int carrier_ext : 1;
  300. - unsigned int dummy1 : 24;
  301. + unsigned int crc : 1;
  302. + unsigned int pad : 1;
  303. + unsigned int retry : 1;
  304. + unsigned int ignore_col : 1;
  305. + unsigned int cancel : 1;
  306. + unsigned int hsh_delay : 1;
  307. + unsigned int ignore_crs : 1;
  308. + unsigned int carrier_ext : 1;
  309. + unsigned int dummy1 : 24;
  310. } reg_eth_rw_tr_ctrl;
  311. #define REG_RD_ADDR_eth_rw_tr_ctrl 32
  312. #define REG_WR_ADDR_eth_rw_tr_ctrl 32
  313. /* Register rw_clr_err, scope eth, type rw */
  314. typedef struct {
  315. - unsigned int clr : 1;
  316. - unsigned int dummy1 : 31;
  317. + unsigned int clr : 1;
  318. + unsigned int dummy1 : 31;
  319. } reg_eth_rw_clr_err;
  320. #define REG_RD_ADDR_eth_rw_clr_err 36
  321. #define REG_WR_ADDR_eth_rw_clr_err 36
  322. /* Register rw_mgm_ctrl, scope eth, type rw */
  323. typedef struct {
  324. - unsigned int mdio : 1;
  325. - unsigned int mdoe : 1;
  326. - unsigned int mdc : 1;
  327. - unsigned int dummy1 : 29;
  328. + unsigned int mdio : 1;
  329. + unsigned int mdoe : 1;
  330. + unsigned int mdc : 1;
  331. + unsigned int phyclk : 1;
  332. + unsigned int txdata : 4;
  333. + unsigned int txen : 1;
  334. + unsigned int dummy1 : 23;
  335. } reg_eth_rw_mgm_ctrl;
  336. #define REG_RD_ADDR_eth_rw_mgm_ctrl 40
  337. #define REG_WR_ADDR_eth_rw_mgm_ctrl 40
  338. /* Register r_stat, scope eth, type r */
  339. typedef struct {
  340. - unsigned int mdio : 1;
  341. - unsigned int exc_col : 1;
  342. - unsigned int urun : 1;
  343. - unsigned int clk_125 : 1;
  344. - unsigned int dummy1 : 28;
  345. + unsigned int mdio : 1;
  346. + unsigned int exc_col : 1;
  347. + unsigned int urun : 1;
  348. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  349. + unsigned int clk_125 : 1;
  350. +#else
  351. + unsigned int phyclk : 1;
  352. +#endif
  353. + unsigned int txdata : 4;
  354. + unsigned int txen : 1;
  355. + unsigned int col : 1;
  356. + unsigned int crs : 1;
  357. + unsigned int txclk : 1;
  358. + unsigned int rxdata : 4;
  359. + unsigned int rxer : 1;
  360. + unsigned int rxdv : 1;
  361. + unsigned int rxclk : 1;
  362. + unsigned int dummy1 : 13;
  363. } reg_eth_r_stat;
  364. #define REG_RD_ADDR_eth_r_stat 44
  365. /* Register rs_rec_cnt, scope eth, type rs */
  366. typedef struct {
  367. - unsigned int crc_err : 8;
  368. - unsigned int align_err : 8;
  369. - unsigned int oversize : 8;
  370. - unsigned int congestion : 8;
  371. + unsigned int crc_err : 8;
  372. + unsigned int align_err : 8;
  373. + unsigned int oversize : 8;
  374. + unsigned int congestion : 8;
  375. } reg_eth_rs_rec_cnt;
  376. #define REG_RD_ADDR_eth_rs_rec_cnt 48
  377. /* Register r_rec_cnt, scope eth, type r */
  378. typedef struct {
  379. - unsigned int crc_err : 8;
  380. - unsigned int align_err : 8;
  381. - unsigned int oversize : 8;
  382. - unsigned int congestion : 8;
  383. + unsigned int crc_err : 8;
  384. + unsigned int align_err : 8;
  385. + unsigned int oversize : 8;
  386. + unsigned int congestion : 8;
  387. } reg_eth_r_rec_cnt;
  388. #define REG_RD_ADDR_eth_r_rec_cnt 52
  389. /* Register rs_tr_cnt, scope eth, type rs */
  390. typedef struct {
  391. - unsigned int single_col : 8;
  392. - unsigned int mult_col : 8;
  393. - unsigned int late_col : 8;
  394. - unsigned int deferred : 8;
  395. + unsigned int single_col : 8;
  396. + unsigned int mult_col : 8;
  397. + unsigned int late_col : 8;
  398. + unsigned int deferred : 8;
  399. } reg_eth_rs_tr_cnt;
  400. #define REG_RD_ADDR_eth_rs_tr_cnt 56
  401. /* Register r_tr_cnt, scope eth, type r */
  402. typedef struct {
  403. - unsigned int single_col : 8;
  404. - unsigned int mult_col : 8;
  405. - unsigned int late_col : 8;
  406. - unsigned int deferred : 8;
  407. + unsigned int single_col : 8;
  408. + unsigned int mult_col : 8;
  409. + unsigned int late_col : 8;
  410. + unsigned int deferred : 8;
  411. } reg_eth_r_tr_cnt;
  412. #define REG_RD_ADDR_eth_r_tr_cnt 60
  413. /* Register rs_phy_cnt, scope eth, type rs */
  414. typedef struct {
  415. - unsigned int carrier_loss : 8;
  416. - unsigned int sqe_err : 8;
  417. - unsigned int dummy1 : 16;
  418. + unsigned int carrier_loss : 8;
  419. + unsigned int sqe_err : 8;
  420. + unsigned int dummy1 : 16;
  421. } reg_eth_rs_phy_cnt;
  422. #define REG_RD_ADDR_eth_rs_phy_cnt 64
  423. /* Register r_phy_cnt, scope eth, type r */
  424. typedef struct {
  425. - unsigned int carrier_loss : 8;
  426. - unsigned int sqe_err : 8;
  427. - unsigned int dummy1 : 16;
  428. + unsigned int carrier_loss : 8;
  429. + unsigned int sqe_err : 8;
  430. + unsigned int dummy1 : 16;
  431. } reg_eth_r_phy_cnt;
  432. #define REG_RD_ADDR_eth_r_phy_cnt 68
  433. /* Register rw_test_ctrl, scope eth, type rw */
  434. typedef struct {
  435. - unsigned int snmp_inc : 1;
  436. - unsigned int snmp : 1;
  437. - unsigned int backoff : 1;
  438. - unsigned int dummy1 : 29;
  439. + unsigned int snmp_inc : 1;
  440. + unsigned int snmp : 1;
  441. + unsigned int backoff : 1;
  442. + unsigned int dummy1 : 29;
  443. } reg_eth_rw_test_ctrl;
  444. #define REG_RD_ADDR_eth_rw_test_ctrl 72
  445. #define REG_WR_ADDR_eth_rw_test_ctrl 72
  446. /* Register rw_intr_mask, scope eth, type rw */
  447. typedef struct {
  448. - unsigned int crc : 1;
  449. - unsigned int align : 1;
  450. - unsigned int oversize : 1;
  451. - unsigned int congestion : 1;
  452. - unsigned int single_col : 1;
  453. - unsigned int mult_col : 1;
  454. - unsigned int late_col : 1;
  455. - unsigned int deferred : 1;
  456. - unsigned int carrier_loss : 1;
  457. - unsigned int sqe_test_err : 1;
  458. - unsigned int orun : 1;
  459. - unsigned int urun : 1;
  460. - unsigned int exc_col : 1;
  461. - unsigned int mdio : 1;
  462. - unsigned int dummy1 : 18;
  463. + unsigned int crc : 1;
  464. + unsigned int align : 1;
  465. + unsigned int oversize : 1;
  466. + unsigned int congestion : 1;
  467. + unsigned int single_col : 1;
  468. + unsigned int mult_col : 1;
  469. + unsigned int late_col : 1;
  470. + unsigned int deferred : 1;
  471. + unsigned int carrier_loss : 1;
  472. + unsigned int sqe_test_err : 1;
  473. + unsigned int orun : 1;
  474. + unsigned int urun : 1;
  475. + unsigned int exc_col : 1;
  476. + unsigned int mdio : 1;
  477. + unsigned int dummy1 : 18;
  478. } reg_eth_rw_intr_mask;
  479. #define REG_RD_ADDR_eth_rw_intr_mask 76
  480. #define REG_WR_ADDR_eth_rw_intr_mask 76
  481. /* Register rw_ack_intr, scope eth, type rw */
  482. typedef struct {
  483. - unsigned int crc : 1;
  484. - unsigned int align : 1;
  485. - unsigned int oversize : 1;
  486. - unsigned int congestion : 1;
  487. - unsigned int single_col : 1;
  488. - unsigned int mult_col : 1;
  489. - unsigned int late_col : 1;
  490. - unsigned int deferred : 1;
  491. - unsigned int carrier_loss : 1;
  492. - unsigned int sqe_test_err : 1;
  493. - unsigned int orun : 1;
  494. - unsigned int urun : 1;
  495. - unsigned int exc_col : 1;
  496. - unsigned int mdio : 1;
  497. - unsigned int dummy1 : 18;
  498. + unsigned int crc : 1;
  499. + unsigned int align : 1;
  500. + unsigned int oversize : 1;
  501. + unsigned int congestion : 1;
  502. + unsigned int single_col : 1;
  503. + unsigned int mult_col : 1;
  504. + unsigned int late_col : 1;
  505. + unsigned int deferred : 1;
  506. + unsigned int carrier_loss : 1;
  507. + unsigned int sqe_test_err : 1;
  508. + unsigned int orun : 1;
  509. + unsigned int urun : 1;
  510. + unsigned int exc_col : 1;
  511. + unsigned int mdio : 1;
  512. + unsigned int dummy1 : 18;
  513. } reg_eth_rw_ack_intr;
  514. #define REG_RD_ADDR_eth_rw_ack_intr 80
  515. #define REG_WR_ADDR_eth_rw_ack_intr 80
  516. /* Register r_intr, scope eth, type r */
  517. typedef struct {
  518. - unsigned int crc : 1;
  519. - unsigned int align : 1;
  520. - unsigned int oversize : 1;
  521. - unsigned int congestion : 1;
  522. - unsigned int single_col : 1;
  523. - unsigned int mult_col : 1;
  524. - unsigned int late_col : 1;
  525. - unsigned int deferred : 1;
  526. - unsigned int carrier_loss : 1;
  527. - unsigned int sqe_test_err : 1;
  528. - unsigned int orun : 1;
  529. - unsigned int urun : 1;
  530. - unsigned int exc_col : 1;
  531. - unsigned int mdio : 1;
  532. - unsigned int dummy1 : 18;
  533. + unsigned int crc : 1;
  534. + unsigned int align : 1;
  535. + unsigned int oversize : 1;
  536. + unsigned int congestion : 1;
  537. + unsigned int single_col : 1;
  538. + unsigned int mult_col : 1;
  539. + unsigned int late_col : 1;
  540. + unsigned int deferred : 1;
  541. + unsigned int carrier_loss : 1;
  542. + unsigned int sqe_test_err : 1;
  543. + unsigned int orun : 1;
  544. + unsigned int urun : 1;
  545. + unsigned int exc_col : 1;
  546. + unsigned int mdio : 1;
  547. + unsigned int dummy1 : 18;
  548. } reg_eth_r_intr;
  549. #define REG_RD_ADDR_eth_r_intr 84
  550. /* Register r_masked_intr, scope eth, type r */
  551. typedef struct {
  552. - unsigned int crc : 1;
  553. - unsigned int align : 1;
  554. - unsigned int oversize : 1;
  555. - unsigned int congestion : 1;
  556. - unsigned int single_col : 1;
  557. - unsigned int mult_col : 1;
  558. - unsigned int late_col : 1;
  559. - unsigned int deferred : 1;
  560. - unsigned int carrier_loss : 1;
  561. - unsigned int sqe_test_err : 1;
  562. - unsigned int orun : 1;
  563. - unsigned int urun : 1;
  564. - unsigned int exc_col : 1;
  565. - unsigned int mdio : 1;
  566. - unsigned int dummy1 : 18;
  567. + unsigned int crc : 1;
  568. + unsigned int align : 1;
  569. + unsigned int oversize : 1;
  570. + unsigned int congestion : 1;
  571. + unsigned int single_col : 1;
  572. + unsigned int mult_col : 1;
  573. + unsigned int late_col : 1;
  574. + unsigned int deferred : 1;
  575. + unsigned int carrier_loss : 1;
  576. + unsigned int sqe_test_err : 1;
  577. + unsigned int orun : 1;
  578. + unsigned int urun : 1;
  579. + unsigned int exc_col : 1;
  580. + unsigned int mdio : 1;
  581. + unsigned int dummy1 : 18;
  582. } reg_eth_r_masked_intr;
  583. #define REG_RD_ADDR_eth_r_masked_intr 88
  584. -
  585. /* Constants */
  586. enum {
  587. - regk_eth_discard = 0x00000000,
  588. - regk_eth_ether = 0x00000000,
  589. - regk_eth_full = 0x00000001,
  590. - regk_eth_gmii = 0x00000003,
  591. - regk_eth_gtxclk = 0x00000001,
  592. - regk_eth_half = 0x00000000,
  593. - regk_eth_hsh = 0x00000001,
  594. - regk_eth_mii = 0x00000001,
  595. - regk_eth_mii_arec = 0x00000002,
  596. - regk_eth_mii_clk = 0x00000000,
  597. - regk_eth_no = 0x00000000,
  598. - regk_eth_phyrst = 0x00000000,
  599. - regk_eth_rec = 0x00000001,
  600. - regk_eth_rw_ga_hi_default = 0x00000000,
  601. - regk_eth_rw_ga_lo_default = 0x00000000,
  602. - regk_eth_rw_gen_ctrl_default = 0x00000000,
  603. - regk_eth_rw_intr_mask_default = 0x00000000,
  604. - regk_eth_rw_ma0_hi_default = 0x00000000,
  605. - regk_eth_rw_ma0_lo_default = 0x00000000,
  606. - regk_eth_rw_ma1_hi_default = 0x00000000,
  607. - regk_eth_rw_ma1_lo_default = 0x00000000,
  608. - regk_eth_rw_mgm_ctrl_default = 0x00000000,
  609. - regk_eth_rw_test_ctrl_default = 0x00000000,
  610. - regk_eth_size1518 = 0x000005ee,
  611. - regk_eth_size1522 = 0x000005f2,
  612. - regk_eth_yes = 0x00000001
  613. + regk_eth_discard = 0x00000000,
  614. + regk_eth_ether = 0x00000000,
  615. + regk_eth_full = 0x00000001,
  616. + regk_eth_gmii = 0x00000003,
  617. + regk_eth_gtxclk = 0x00000001,
  618. + regk_eth_half = 0x00000000,
  619. + regk_eth_hsh = 0x00000001,
  620. + regk_eth_mii = 0x00000001,
  621. + regk_eth_mii_arec = 0x00000002,
  622. + regk_eth_mii_clk = 0x00000000,
  623. + regk_eth_no = 0x00000000,
  624. + regk_eth_phyrst = 0x00000000,
  625. + regk_eth_rec = 0x00000001,
  626. + regk_eth_rw_ga_hi_default = 0x00000000,
  627. + regk_eth_rw_ga_lo_default = 0x00000000,
  628. + regk_eth_rw_gen_ctrl_default = 0x00000000,
  629. + regk_eth_rw_intr_mask_default = 0x00000000,
  630. + regk_eth_rw_ma0_hi_default = 0x00000000,
  631. + regk_eth_rw_ma0_lo_default = 0x00000000,
  632. + regk_eth_rw_ma1_hi_default = 0x00000000,
  633. + regk_eth_rw_ma1_lo_default = 0x00000000,
  634. + regk_eth_rw_mgm_ctrl_default = 0x00000000,
  635. + regk_eth_rw_test_ctrl_default = 0x00000000,
  636. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  637. + regk_eth_size1518 = 0x000005ee,
  638. + regk_eth_size1522 = 0x000005f2,
  639. +#else
  640. + regk_eth_size1518 = 0x00000000,
  641. + regk_eth_size1522 = 0x00000001,
  642. +#endif
  643. + regk_eth_yes = 0x00000001
  644. };
  645. +
  646. #endif /* __eth_defs_h */
  647. diff --git a/drivers/net/cris/Makefile b/drivers/net/cris/Makefile
  648. index b4e8932..39b4d4d 100644
  649. --- a/drivers/net/cris/Makefile
  650. +++ b/drivers/net/cris/Makefile
  651. @@ -1 +1,2 @@
  652. obj-$(CONFIG_ETRAX_ARCH_V10) += eth_v10.o
  653. +obj-$(CONFIG_ETRAX_ARCH_V32) += eth_v32.o
  654. diff --git a/drivers/net/cris/eth_v32.c b/drivers/net/cris/eth_v32.c
  655. new file mode 100644
  656. index 0000000..92c4cae
  657. --- /dev/null
  658. +++ b/drivers/net/cris/eth_v32.c
  659. @@ -0,0 +1,3093 @@
  660. +/*
  661. + * Driver for the ETRAX FS/Artpec-3 network controller.
  662. + *
  663. + * Copyright (c) 2003-2008 Axis Communications AB.
  664. + *
  665. + * TODO:
  666. + * * Decrease the amount of code running with interrupts disabled.
  667. + * * Rework the error handling so that we do not need to touch the tx
  668. + * ring from the error interrupts. When done, we should be able to
  669. + * do tx completition from the NAPI loop without disabling interrupts.
  670. + * * Remove the gigabit code. It's probably never going to be used.
  671. + */
  672. +
  673. +#include <linux/module.h>
  674. +
  675. +#include <linux/kernel.h>
  676. +#include <linux/sched.h>
  677. +#include <linux/delay.h>
  678. +#include <linux/types.h>
  679. +#include <linux/fcntl.h>
  680. +#include <linux/interrupt.h>
  681. +#include <linux/spinlock.h>
  682. +#include <linux/errno.h>
  683. +#include <linux/init.h>
  684. +
  685. +#include <linux/netdevice.h>
  686. +#include <linux/etherdevice.h>
  687. +#include <linux/skbuff.h>
  688. +#include <linux/ethtool.h>
  689. +#include <linux/mii.h>
  690. +
  691. +#include <asm/io.h> /* CRIS_LED_* I/O functions */
  692. +#include <asm/irq.h>
  693. +#include <hwregs/reg_map.h>
  694. +#include <hwregs/reg_rdwr.h>
  695. +#include <hwregs/dma.h>
  696. +#include <hwregs/eth_defs.h>
  697. +#ifdef CONFIG_ETRAXFS
  698. +#include <hwregs/config_defs.h>
  699. +#else
  700. +#include <hwregs/clkgen_defs.h>
  701. +#endif
  702. +#include <hwregs/intr_vect_defs.h>
  703. +#include <hwregs/strmux_defs.h>
  704. +#include <asm/bitops.h>
  705. +#include <asm/ethernet.h>
  706. +#include <mach/dma.h>
  707. +#include <pinmux.h>
  708. +
  709. +#include "eth_v32.h"
  710. +
  711. +#ifndef CONFIG_ETRAXFS
  712. +#define ETH0_INTR_VECT ETH_INTR_VECT
  713. +#define ETH1_INTR_VECT ETH_INTR_VECT
  714. +#define regi_eth0 regi_eth
  715. +#define regi_eth1 regi_
  716. +#endif
  717. +
  718. +#define DEBUG(x)
  719. +#define GET_BIT(bit,val) (((val) >> (bit)) & 0x01)
  720. +
  721. +#if defined(CONFIG_ETRAX_HAVE_PHY) || defined(CONFIG_ETRAX_PHY_FALLBACK)
  722. +#define RESET_PHY 1
  723. +#else
  724. +#define RESET_PHY 0
  725. +#endif
  726. +
  727. +enum {
  728. + HAVE_PHY,
  729. + NO_PHY,
  730. + FALLBACK_PHY,
  731. +};
  732. +#if defined(CONFIG_ETRAX_PHY_FALLBACK)
  733. +#define PHY_MODE (FALLBACK_PHY)
  734. +#elif defined(CONFIG_ETRAX_NO_PHY)
  735. +#define PHY_MODE (NO_PHY)
  736. +#elif defined(CONFIG_ETRAX_HAVE_PHY)
  737. +#define PHY_MODE (HAVE_PHY)
  738. +#else
  739. +#error Unknown PHY behaviour
  740. +#endif
  741. +
  742. +static struct {
  743. + const char str[ETH_GSTRING_LEN];
  744. +} const ethtool_stats_keys[] = {
  745. + { "tx_dma_restarts" },
  746. + { "tx_mac_resets" },
  747. + { "rx_dma_restarts" },
  748. + { "rx_dma_timeouts" },
  749. + { " dropped_rx" }
  750. +};
  751. +
  752. +static void crisv32_eth_check_speed(unsigned long idev);
  753. +static void crisv32_eth_check_duplex(unsigned long idev);
  754. +static void update_rx_stats(struct crisv32_ethernet_local *np);
  755. +static void update_tx_stats(struct crisv32_ethernet_local *np);
  756. +static int crisv32_eth_poll(struct napi_struct *napi, int budget);
  757. +static void crisv32_eth_setup_controller(struct net_device *dev);
  758. +static int crisv32_eth_request_irqdma(struct net_device *dev);
  759. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  760. +static void
  761. +crisv32_eth_restart_rx_dma(struct net_device* dev,
  762. + struct crisv32_ethernet_local *np);
  763. +#endif
  764. +#if 0
  765. +static void crisv32_ethernet_bug(struct net_device *dev);
  766. +#endif
  767. +
  768. +/*
  769. + * The name of the card. Is used for messages and in the requests for
  770. + * io regions, irqs and dma channels.
  771. + */
  772. +#ifdef CONFIG_ETRAXFS
  773. +static const char cardname[] = "ETRAX FS built-in ethernet controller";
  774. +#else
  775. +static const char cardname[] = "ARTPEC-3 built-in ethernet controller";
  776. +#endif
  777. +
  778. +/* Some chipset needs special care. */
  779. +#ifndef CONFIG_ETRAX_NO_PHY
  780. +struct transceiver_ops transceivers[] = {
  781. + {0x1018, broadcom_check_speed, broadcom_check_duplex},
  782. + {0x50EF, broadcom_check_speed, broadcom_check_duplex},
  783. + /* TDK 2120 and TDK 2120C */
  784. + {0xC039, tdk_check_speed, tdk_check_duplex},
  785. + {0x039C, tdk_check_speed, tdk_check_duplex},
  786. + /* Intel LXT972A*/
  787. + {0x04de, intel_check_speed, intel_check_duplex},
  788. + /* National Semiconductor DP83865 */
  789. + {0x0017, national_check_speed, national_check_duplex},
  790. + /* Vitesse VCS8641 */
  791. + {0x01c1, vitesse_check_speed, vitesse_check_duplex},
  792. + /* Davicom DM9161 */
  793. + {0x606E, davicom_check_speed, davicom_check_duplex},
  794. + /* Generic, must be last. */
  795. + {0x0000, generic_check_speed, generic_check_duplex}
  796. +};
  797. +#endif
  798. +
  799. +static struct net_device *crisv32_dev[2];
  800. +static struct crisv32_eth_leds *crisv32_leds[3];
  801. +
  802. +/* Default MAC address for interface 0.
  803. + * The real one will be set later. */
  804. +static struct sockaddr default_mac_iface0 =
  805. + {0, {0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00}};
  806. +
  807. +#ifdef CONFIG_CPU_FREQ
  808. +static int
  809. +crisv32_ethernet_freq_notifier(struct notifier_block *nb, unsigned long val,
  810. + void *data);
  811. +
  812. +static struct notifier_block crisv32_ethernet_freq_notifier_block = {
  813. + .notifier_call = crisv32_ethernet_freq_notifier
  814. +};
  815. +#endif
  816. +
  817. +static void receive_timeout(unsigned long arg);
  818. +static void receive_timeout_work(struct work_struct* work);
  819. +static void transmit_timeout(unsigned long arg);
  820. +
  821. +/*
  822. + * mask in and out tx/rx interrupts.
  823. + */
  824. +static inline void crisv32_disable_tx_ints(struct crisv32_ethernet_local *np)
  825. +{
  826. + reg_dma_rw_intr_mask intr_mask_tx = { .data = regk_dma_no };
  827. + REG_WR(dma, np->dma_out_inst, rw_intr_mask, intr_mask_tx);
  828. +}
  829. +
  830. +static inline void crisv32_enable_tx_ints(struct crisv32_ethernet_local *np)
  831. +{
  832. + reg_dma_rw_intr_mask intr_mask_tx = { .data = regk_dma_yes };
  833. + REG_WR(dma, np->dma_out_inst, rw_intr_mask, intr_mask_tx);
  834. +}
  835. +
  836. +static inline void crisv32_disable_rx_ints(struct crisv32_ethernet_local *np)
  837. +{
  838. + reg_dma_rw_intr_mask intr_mask_rx = { .in_eop = regk_dma_no };
  839. + REG_WR(dma, np->dma_in_inst, rw_intr_mask, intr_mask_rx);
  840. +}
  841. +
  842. +static inline void crisv32_enable_rx_ints(struct crisv32_ethernet_local *np)
  843. +{
  844. + reg_dma_rw_intr_mask intr_mask_rx = { .in_eop = regk_dma_yes };
  845. + REG_WR(dma, np->dma_in_inst, rw_intr_mask, intr_mask_rx);
  846. +}
  847. +
  848. +static inline void crisv32_disable_eth_ints(struct crisv32_ethernet_local *np)
  849. +{
  850. + int intr_mask_nw = 0x0;
  851. + REG_WR_INT(eth, np->eth_inst, rw_intr_mask, intr_mask_nw);
  852. +}
  853. +
  854. +static inline void crisv32_enable_eth_ints(struct crisv32_ethernet_local *np)
  855. +{
  856. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  857. + /* For Artpec-3 we use overrun to workaround voodoo TR 87 */
  858. + int intr_mask_nw = 0x1c00;
  859. +#else
  860. + int intr_mask_nw = 0x1800;
  861. +#endif
  862. + REG_WR_INT(eth, np->eth_inst, rw_intr_mask, intr_mask_nw);
  863. +}
  864. +
  865. +static inline int crisv32_eth_gigabit(struct crisv32_ethernet_local *np)
  866. +{
  867. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  868. + return np->gigabit_mode;
  869. +#else
  870. + return 0;
  871. +#endif
  872. +}
  873. +
  874. +static inline void crisv32_eth_set_gigabit(struct crisv32_ethernet_local *np,
  875. + int g)
  876. +{
  877. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  878. + np->gigabit_mode = g;
  879. +#endif
  880. +}
  881. +
  882. +/* start/stop receiver */
  883. +static inline void crisv32_start_receiver(struct crisv32_ethernet_local *np)
  884. +{
  885. + reg_eth_rw_rec_ctrl rec_ctrl;
  886. +
  887. + rec_ctrl = REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  888. + rec_ctrl.ma0 = regk_eth_yes;
  889. + rec_ctrl.broadcast = regk_eth_rec;
  890. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  891. +}
  892. +
  893. +static inline void crisv32_stop_receiver(struct crisv32_ethernet_local *np)
  894. +{
  895. + reg_eth_rw_rec_ctrl rec_ctrl;
  896. +
  897. + rec_ctrl = REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  898. + rec_ctrl.ma0 = regk_eth_no;
  899. + rec_ctrl.broadcast = regk_eth_discard;
  900. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  901. +}
  902. +
  903. +static inline void crisv32_eth_reset(struct crisv32_ethernet_local *np)
  904. +{
  905. + reg_eth_rw_gen_ctrl gen_ctrl = { 0 };
  906. +
  907. + gen_ctrl = REG_RD(eth, np->eth_inst, rw_gen_ctrl);
  908. + gen_ctrl.en = regk_eth_no;
  909. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  910. + gen_ctrl.en = regk_eth_yes;
  911. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  912. +}
  913. +
  914. +static void crisv32_eth_tx_cancel_frame(struct crisv32_ethernet_local *np)
  915. +{
  916. + reg_eth_rw_tr_ctrl tr_ctrl;
  917. +
  918. + /* Cancel any pending transmits. This should bring us to the
  919. + excessive collisions state but it doesn't always do it. */
  920. + tr_ctrl = REG_RD(eth, np->eth_inst, rw_tr_ctrl);
  921. + tr_ctrl.cancel = 1;
  922. + REG_WR(eth, np->eth_inst, rw_tr_ctrl, tr_ctrl);
  923. + tr_ctrl.cancel = 0;
  924. + REG_WR(eth, np->eth_inst, rw_tr_ctrl, tr_ctrl);
  925. +}
  926. +
  927. +/*
  928. + * Hack to disconnect/reconnect the dma from the ethernet block while we reset
  929. + * things. TODO: verify that we don't need to disconnect out channels and
  930. + * remove that code.
  931. + *
  932. + * ARTPEC-3 has only a single ethernet block so np->eth_inst is always eth0.
  933. + * The strmux values are named slightly different, redefine to avoid #ifdefs
  934. + * in the code blocks. For artpec3 only regk_strmux_eth0 and channel 0/1
  935. + * should be used.
  936. + */
  937. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  938. +#define regk_strmux_eth0 regk_strmux_eth
  939. +#define regk_strmux_eth1 regk_strmux_eth
  940. +#endif
  941. +static inline void
  942. +crisv32_disconnect_eth_tx_dma(struct crisv32_ethernet_local *np)
  943. +{
  944. + reg_strmux_rw_cfg strmux_cfg;
  945. +
  946. + strmux_cfg = REG_RD(strmux, regi_strmux, rw_cfg);
  947. + if (np->eth_inst == regi_eth0)
  948. + strmux_cfg.dma0 = regk_strmux_off;
  949. + else
  950. + strmux_cfg.dma6 = regk_strmux_off;
  951. + REG_WR(strmux, regi_strmux, rw_cfg, strmux_cfg);
  952. +}
  953. +
  954. +static inline void crisv32_connect_eth_tx_dma(struct crisv32_ethernet_local *np)
  955. +{
  956. + reg_strmux_rw_cfg strmux_cfg;
  957. +
  958. + strmux_cfg = REG_RD(strmux, regi_strmux, rw_cfg);
  959. + if (np->eth_inst == regi_eth0)
  960. + strmux_cfg.dma0 = regk_strmux_eth0;
  961. + else
  962. + strmux_cfg.dma6 = regk_strmux_eth1;
  963. + REG_WR(strmux, regi_strmux, rw_cfg, strmux_cfg);
  964. +}
  965. +
  966. +static inline void
  967. +crisv32_disconnect_eth_rx_dma(struct crisv32_ethernet_local *np)
  968. +{
  969. + reg_strmux_rw_cfg strmux_cfg;
  970. +
  971. + strmux_cfg = REG_RD(strmux, regi_strmux, rw_cfg);
  972. + if (np->eth_inst == regi_eth0)
  973. + strmux_cfg.dma1 = regk_strmux_off;
  974. + else
  975. + strmux_cfg.dma7 = regk_strmux_off;
  976. + REG_WR(strmux, regi_strmux, rw_cfg, strmux_cfg);
  977. +}
  978. +
  979. +static inline void crisv32_connect_eth_rx_dma(struct crisv32_ethernet_local *np)
  980. +{
  981. + reg_strmux_rw_cfg strmux_cfg;
  982. +
  983. + strmux_cfg = REG_RD(strmux, regi_strmux, rw_cfg);
  984. + if (np->eth_inst == regi_eth0)
  985. + strmux_cfg.dma1 = regk_strmux_eth0;
  986. + else
  987. + strmux_cfg.dma7 = regk_strmux_eth1;
  988. + REG_WR(strmux, regi_strmux, rw_cfg, strmux_cfg);
  989. +}
  990. +
  991. +static int dma_wait_busy(int inst, int timeout)
  992. +{
  993. + reg_dma_rw_stream_cmd dma_sc;
  994. +
  995. + do {
  996. + dma_sc = REG_RD(dma, inst, rw_stream_cmd);
  997. + } while (timeout-- > 0 && dma_sc.busy);
  998. + return dma_sc.busy;
  999. +}
  1000. +
  1001. +static int __init crisv32_eth_request_irqdma(struct net_device *dev)
  1002. +{
  1003. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1004. +
  1005. + /* Allocate IRQs and DMAs. */
  1006. + if (np->eth_inst == regi_eth0) {
  1007. + if (request_irq(DMA0_INTR_VECT, crisv32tx_eth_interrupt,
  1008. + 0, "Ethernet TX", dev)) {
  1009. + return -EAGAIN;
  1010. + }
  1011. +
  1012. + if (request_irq(DMA1_INTR_VECT, crisv32rx_eth_interrupt,
  1013. + 0, "Ethernet RX", dev))
  1014. + goto err0_1;
  1015. +
  1016. + if (crisv32_request_dma(0, cardname, DMA_VERBOSE_ON_ERROR,
  1017. + 12500000, dma_eth0))
  1018. + goto err0_2;
  1019. +
  1020. + if (crisv32_request_dma(1, cardname, DMA_VERBOSE_ON_ERROR,
  1021. + 12500000, dma_eth0))
  1022. + goto err0_3;
  1023. +
  1024. + if (request_irq(ETH0_INTR_VECT, crisv32nw_eth_interrupt, 0,
  1025. + cardname, dev)) {
  1026. + crisv32_free_dma(1);
  1027. +err0_3:
  1028. + crisv32_free_dma(0);
  1029. +err0_2:
  1030. + free_irq(DMA1_INTR_VECT, dev);
  1031. +err0_1:
  1032. + free_irq(DMA0_INTR_VECT, dev);
  1033. + return -EAGAIN;
  1034. + }
  1035. + } else {
  1036. + if (request_irq(DMA6_INTR_VECT, crisv32tx_eth_interrupt,
  1037. + 0, cardname, dev))
  1038. + return -EAGAIN;
  1039. +
  1040. + if (request_irq(DMA7_INTR_VECT, crisv32rx_eth_interrupt,
  1041. + 0, cardname, dev))
  1042. + goto err1_1;
  1043. +
  1044. + if (crisv32_request_dma(6, cardname, DMA_VERBOSE_ON_ERROR,
  1045. + 0, dma_eth1))
  1046. + goto err1_2;
  1047. +
  1048. + if (crisv32_request_dma(7, cardname, DMA_VERBOSE_ON_ERROR,
  1049. + 0, dma_eth1))
  1050. + goto err1_3;
  1051. +
  1052. + if (request_irq(ETH1_INTR_VECT, crisv32nw_eth_interrupt, 0,
  1053. + cardname, dev)) {
  1054. + crisv32_free_dma(7);
  1055. +err1_3:
  1056. + crisv32_free_dma(6);
  1057. +err1_2:
  1058. + free_irq(DMA7_INTR_VECT, dev);
  1059. +err1_1:
  1060. + free_irq(DMA6_INTR_VECT, dev);
  1061. + return -EAGAIN;
  1062. + }
  1063. + }
  1064. + return 0;
  1065. +}
  1066. +
  1067. +static int __init crisv32_eth_init_phy(struct net_device *dev)
  1068. +{
  1069. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1070. + struct timer_list timer_init = TIMER_INITIALIZER(NULL, 0, 0);
  1071. +
  1072. + if (RESET_PHY) {
  1073. +#ifdef CONFIG_ETRAXFS
  1074. + reg_config_rw_pad_ctrl pad_ctrl;
  1075. + pad_ctrl = REG_RD(config, regi_config, rw_pad_ctrl);
  1076. + pad_ctrl.phyrst_n = 0;
  1077. + REG_WR(config, regi_config, rw_pad_ctrl, pad_ctrl);
  1078. +
  1079. + udelay(500); /* RESET_LEN */
  1080. +
  1081. + pad_ctrl.phyrst_n = 1;
  1082. + REG_WR(config, regi_config, rw_pad_ctrl, pad_ctrl);
  1083. +#else
  1084. + reg_eth_rw_gen_ctrl gen_ctrl = REG_RD(eth, np->eth_inst, rw_gen_ctrl);
  1085. + gen_ctrl.phyrst_n = 0;
  1086. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  1087. +
  1088. + udelay(500); /* RESET_LEN */
  1089. +
  1090. + gen_ctrl.phyrst_n = 1;
  1091. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  1092. +#endif
  1093. +
  1094. + udelay(200); /* RESET_WAIT */
  1095. + }
  1096. +
  1097. + switch (PHY_MODE) {
  1098. + case FALLBACK_PHY:
  1099. + /* Fall back on using fixed iff there is no PHY on */
  1100. + /* the MDIO bus */
  1101. + np->fixed_phy = crisv32_eth_probe_transceiver(dev) != 0;
  1102. + if (np->fixed_phy)
  1103. + printk(KERN_WARNING
  1104. + "eth: No transciever found, falling back "
  1105. + "to fixed phy mode\n");
  1106. + break;
  1107. +
  1108. + case NO_PHY:
  1109. + /* Don't even bother looking for a PHY, always rely */
  1110. + /* on fixed PHY */
  1111. + np->fixed_phy = 1;
  1112. + break;
  1113. +
  1114. + default: /* HAVE_PHY */
  1115. + /* Look for a PHY and abort if there is none, */
  1116. + /* otherwise just carry on */
  1117. + if (crisv32_eth_probe_transceiver(dev)) {
  1118. + printk(KERN_WARNING
  1119. + "eth: No transceiver found, "
  1120. + "removing interface\n");
  1121. + return -ENODEV;
  1122. + }
  1123. + np->fixed_phy = 0;
  1124. + }
  1125. +
  1126. + if (np->fixed_phy) {
  1127. + reg_eth_rw_rec_ctrl rec_ctrl;
  1128. +
  1129. + /* speed */
  1130. + np->current_speed = 100;
  1131. + np->current_speed_selection = 100; /* Auto. */
  1132. +
  1133. + /* duplex */
  1134. + np->full_duplex = 1;
  1135. + np->current_duplex = full;
  1136. +
  1137. + rec_ctrl = REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  1138. + rec_ctrl.duplex = regk_eth_full;
  1139. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  1140. + } else {
  1141. + np->mii_if.supports_gmii = mii_check_gmii_support(&np->mii_if);
  1142. +
  1143. + /* speed */
  1144. + np->current_speed = 10;
  1145. + np->current_speed_selection = 0; /* Auto. */
  1146. + np->speed_timer = timer_init;
  1147. + np->speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
  1148. + np->speed_timer.data = (unsigned long) dev;
  1149. + np->speed_timer.function = crisv32_eth_check_speed;
  1150. +
  1151. + /* duplex */
  1152. + np->full_duplex = 0;
  1153. + np->current_duplex = autoneg;
  1154. + np->duplex_timer = timer_init;
  1155. + np->duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
  1156. + np->duplex_timer.data = (unsigned long) dev;
  1157. + np->duplex_timer.function = crisv32_eth_check_duplex;
  1158. + }
  1159. +
  1160. + return 0;
  1161. +}
  1162. +
  1163. +static void __init crisv32_eth_setup_controller(struct net_device *dev)
  1164. +{
  1165. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1166. + reg_eth_rw_gen_ctrl gen_ctrl;
  1167. +
  1168. + reg_eth_rw_tr_ctrl tr_ctrl = {
  1169. + /* SW retransmits to avoid transmitter bugs. */
  1170. + .retry = regk_eth_no,
  1171. + .pad = regk_eth_yes,
  1172. + .crc = regk_eth_yes
  1173. + };
  1174. +
  1175. + reg_eth_rw_rec_ctrl rec_ctrl = {
  1176. + .ma0 = regk_eth_no, /* enable at open() */
  1177. + .broadcast = regk_eth_no,
  1178. + .max_size = regk_eth_size1522
  1179. + };
  1180. +
  1181. + reg_eth_rw_ga_lo ga_lo = { 0 };
  1182. + reg_eth_rw_ga_hi ga_hi = { 0 };
  1183. +
  1184. + /*
  1185. + * Initialize group address registers to make sure that no
  1186. + * unwanted addresses are matched.
  1187. + */
  1188. + REG_WR(eth, np->eth_inst, rw_ga_lo, ga_lo);
  1189. + REG_WR(eth, np->eth_inst, rw_ga_hi, ga_hi);
  1190. +
  1191. + /* Configure receiver and transmitter */
  1192. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  1193. + REG_WR(eth, np->eth_inst, rw_tr_ctrl, tr_ctrl);
  1194. +
  1195. + /*
  1196. + * Read from rw_gen_ctrl so that we don't override any previous
  1197. + * configuration.
  1198. + */
  1199. + gen_ctrl = REG_RD(eth, np->eth_inst, rw_gen_ctrl);
  1200. + gen_ctrl.phy = regk_eth_mii_clk;
  1201. +#ifdef CONFIG_ETRAXFS
  1202. + /* On ETRAX FS, this bit has reversed meaning */
  1203. + gen_ctrl.flow_ctrl = regk_eth_no;
  1204. +#else
  1205. + gen_ctrl.flow_ctrl = regk_eth_yes;
  1206. +#endif
  1207. +
  1208. + /* Enable ethernet controller with mii clk. */
  1209. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  1210. + gen_ctrl.en = regk_eth_yes;
  1211. + REG_WR(eth, np->eth_inst, rw_gen_ctrl, gen_ctrl);
  1212. +}
  1213. +
  1214. +static void crisv32_eth_reset_rx_ring(struct net_device *dev)
  1215. +{
  1216. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1217. + int i;
  1218. +
  1219. + /* cleanup the rx-ring */
  1220. + for (i = 0; i < NBR_RX_DESC; i++) {
  1221. + struct sk_buff *skb;
  1222. + skb = np->dma_rx_descr_list[i].skb;
  1223. + if (!skb
  1224. + || (np->dma_rx_descr_list[i].descr.buf !=
  1225. + (void *)virt_to_phys(skb->data))) {
  1226. + if (skb)
  1227. + dev_kfree_skb(skb);
  1228. + skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE);
  1229. + np->dma_rx_descr_list[i].skb = skb;
  1230. + np->dma_rx_descr_list[i].descr.buf =
  1231. + (char*)virt_to_phys(skb->data);
  1232. + }
  1233. + if (np->dma_rx_descr_list[i].descr.in_eop)
  1234. + np->rx_restarts_dropped++;
  1235. + np->dma_rx_descr_list[i].descr.after =
  1236. + (char*)virt_to_phys(skb->data
  1237. + + MAX_MEDIA_DATA_SIZE);
  1238. + np->dma_rx_descr_list[i].descr.eol = 0;
  1239. + np->dma_rx_descr_list[i].descr.in_eop = 0;
  1240. + /* Workaround cache bug */
  1241. + flush_dma_descr(&np->dma_rx_descr_list[i].descr, 1);
  1242. + }
  1243. +
  1244. + /* reset rx-ring */
  1245. + np->active_rx_desc = &np->dma_rx_descr_list[0];
  1246. + np->prev_rx_desc = &np->dma_rx_descr_list[NBR_RX_DESC - 1];
  1247. + np->last_rx_desc = np->prev_rx_desc;
  1248. + np->dma_rx_descr_list[NBR_RX_DESC - 1].descr.eol = 1;
  1249. + flush_dma_descr(&np->dma_rx_descr_list[NBR_RX_DESC - 1].descr, 0);
  1250. + /* ready to accept new packets. */
  1251. + np->new_rx_package = 1;
  1252. +
  1253. + /* Fill context descriptors. */
  1254. + np->ctxt_in.next = 0;
  1255. + np->ctxt_in.saved_data =
  1256. + (void *)virt_to_phys(&np->active_rx_desc->descr);
  1257. + np->ctxt_in.saved_data_buf = np->active_rx_desc->descr.buf;
  1258. +}
  1259. +
  1260. +static inline int crisv32_eth_tx_ring_full(struct crisv32_ethernet_local *np)
  1261. +{
  1262. + crisv32_eth_descr *active = np->active_tx_desc;
  1263. +
  1264. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1265. + active = phys_to_virt((unsigned long)active->descr.next);
  1266. +#endif
  1267. + if (active == np->catch_tx_desc)
  1268. + return 1;
  1269. + return 0;
  1270. +}
  1271. +
  1272. +static void crisv32_eth_reset_tx_ring(struct net_device *dev)
  1273. +{
  1274. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1275. +
  1276. + /* free un-handled tx packets */
  1277. + while (np->txpackets || np->catch_tx_desc != np->active_tx_desc) {
  1278. + np->txpackets--;
  1279. + if (np->catch_tx_desc->skb)
  1280. + dev_kfree_skb(np->catch_tx_desc->skb);
  1281. +
  1282. + np->catch_tx_desc->skb = 0;
  1283. + np->catch_tx_desc =
  1284. + phys_to_virt((int)np->catch_tx_desc->descr.next);
  1285. + }
  1286. +
  1287. + WARN_ON(np->txpackets != 0);
  1288. + np->txpackets = 0;
  1289. +
  1290. + /* reset tx-ring */
  1291. + np->dma_tx_descr_list[0].descr.buf =
  1292. + np->dma_tx_descr_list[0].descr.after = 0;
  1293. + np->dma_tx_descr_list[0].descr.eol = 1;
  1294. +
  1295. + np->active_tx_desc = &np->dma_tx_descr_list[0];
  1296. + np->prev_tx_desc = &np->dma_tx_descr_list[NBR_TX_DESC - 1];
  1297. + np->catch_tx_desc = &np->dma_tx_descr_list[0];
  1298. +
  1299. + np->ctxt_out.next = 0;
  1300. + np->ctxt_out.saved_data =
  1301. + (void *)virt_to_phys(&np->dma_tx_descr_list[0].descr);
  1302. +
  1303. +}
  1304. +
  1305. +static void crisv32_eth_reset_rings(struct net_device *dev)
  1306. +{
  1307. + crisv32_eth_reset_tx_ring(dev);
  1308. + crisv32_eth_reset_rx_ring(dev);
  1309. +}
  1310. +
  1311. +/*
  1312. + * Really advance the receive ring. RX interrupts must be off.
  1313. + */
  1314. +static void __crisv32_eth_rx_ring_advance(struct crisv32_ethernet_local *np)
  1315. +{
  1316. + if (np->newbuf)
  1317. + np->active_rx_desc->descr.buf = (void *) np->newbuf;
  1318. + np->active_rx_desc->descr.after =
  1319. + np->active_rx_desc->descr.buf + MAX_MEDIA_DATA_SIZE;
  1320. + np->active_rx_desc->descr.eol = 1;
  1321. + np->active_rx_desc->descr.in_eop = 0;
  1322. + np->active_rx_desc = phys_to_virt((int)np->active_rx_desc->descr.next);
  1323. + barrier();
  1324. + np->prev_rx_desc->descr.eol = 0;
  1325. +
  1326. + /* Workaround cache bug. */
  1327. + flush_dma_descr(&np->prev_rx_desc->descr, 0);
  1328. + np->prev_rx_desc = phys_to_virt((int)np->prev_rx_desc->descr.next);
  1329. + flush_dma_descr(&np->prev_rx_desc->descr, 1);
  1330. +}
  1331. +
  1332. +/*
  1333. + * Advance the receive ring. RX interrupts must be off.
  1334. + */
  1335. +static inline void
  1336. +crisv32_eth_rx_ring_advance(struct crisv32_ethernet_local *np)
  1337. +{
  1338. + /*
  1339. + * When the input DMA reaches eol precaution must be taken, otherwise
  1340. + * the DMA could stop. The problem occurs if the eol flag is re-placed
  1341. + * on the descriptor that the DMA stands on before the DMA proceed to
  1342. + * the next descriptor. This case could, for example, happen if there
  1343. + * is a traffic burst and then the network goes silent. To prevent this
  1344. + * we make sure that we do not set the eol flag on the descriptor that
  1345. + * the DMA stands on.
  1346. + */
  1347. + unsigned long dma_pos;
  1348. +
  1349. + /* Get the current input dma position. */
  1350. + dma_pos = REG_RD_INT(dma, np->dma_in_inst, rw_saved_data);
  1351. +
  1352. + if (virt_to_phys(&np->active_rx_desc->descr) != dma_pos) {
  1353. + crisv32_eth_descr *cur, *nxt;
  1354. +
  1355. + /* Now really advance the ring one step. */
  1356. + __crisv32_eth_rx_ring_advance(np);
  1357. +
  1358. + cur = np->active_rx_desc;
  1359. + nxt = (void *)phys_to_virt((unsigned long)cur->descr.next);
  1360. + flush_dma_descr(&cur->descr, 0);
  1361. + flush_dma_descr(&nxt->descr, 0);
  1362. + if (!cur->descr.in_eop && nxt->descr.in_eop) {
  1363. + /* TODO: Investigate this more. The DMA seems to have
  1364. + skipped a descriptor, possibly due to incoherence
  1365. + between the CPU L1 cache and the DMA updates to the
  1366. + descriptor. */
  1367. + np->newbuf = (unsigned long) np->active_rx_desc->descr.buf;
  1368. + __crisv32_eth_rx_ring_advance(np);
  1369. + }
  1370. + /* flush after peek. */
  1371. + flush_dma_descr(&cur->descr, 0);
  1372. + flush_dma_descr(&nxt->descr, 0);
  1373. + } else {
  1374. + /* delay the advancing of the ring. */
  1375. + np->new_rx_package = 0;
  1376. + }
  1377. +}
  1378. +
  1379. +static void __init crisv32_eth_init_rings(struct net_device *dev)
  1380. +{
  1381. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1382. + int i;
  1383. +
  1384. + /* Initialise receive descriptors for interface. */
  1385. + for (i = 0; i < NBR_RX_DESC; i++) {
  1386. + struct sk_buff *skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE);
  1387. +
  1388. + np->dma_rx_descr_list[i].skb = skb;
  1389. + np->dma_rx_descr_list[i].descr.buf =
  1390. + (char*)virt_to_phys(skb->data);
  1391. + np->dma_rx_descr_list[i].descr.after =
  1392. + (char*)virt_to_phys(skb->data + MAX_MEDIA_DATA_SIZE);
  1393. +
  1394. + np->dma_rx_descr_list[i].descr.eol = 0;
  1395. + np->dma_rx_descr_list[i].descr.in_eop = 0;
  1396. + np->dma_rx_descr_list[i].descr.next =
  1397. + (void *) virt_to_phys(&np->dma_rx_descr_list[i + 1].descr);
  1398. + }
  1399. + /* bend the list into a ring */
  1400. + np->dma_rx_descr_list[NBR_RX_DESC - 1].descr.next =
  1401. + (void *) virt_to_phys(&np->dma_rx_descr_list[0].descr);
  1402. +
  1403. + /* Initialize transmit descriptors. */
  1404. + for (i = 0; i < NBR_TX_DESC; i++) {
  1405. + np->dma_tx_descr_list[i].descr.wait = 1;
  1406. + np->dma_tx_descr_list[i].descr.eol = 0;
  1407. + np->dma_tx_descr_list[i].descr.out_eop = 0;
  1408. + np->dma_tx_descr_list[i].descr.next =
  1409. + (void*)virt_to_phys(&np->dma_tx_descr_list[i+1].descr);
  1410. + }
  1411. + /* bend the list into a ring */
  1412. + np->dma_tx_descr_list[NBR_TX_DESC - 1].descr.next =
  1413. + (void *) virt_to_phys(&np->dma_tx_descr_list[0].descr);
  1414. +
  1415. + crisv32_eth_reset_rings(dev);
  1416. +}
  1417. +
  1418. +static void __init crisv32_init_leds(int ledgrp, struct net_device *dev)
  1419. +{
  1420. + struct timer_list timer_init = TIMER_INITIALIZER(NULL, 0, 0);
  1421. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1422. +
  1423. + /* Use already allocated led grp if initialized */
  1424. + if (crisv32_leds[ledgrp] != NULL) {
  1425. + np->leds = crisv32_leds[ledgrp];
  1426. + return;
  1427. + }
  1428. +
  1429. + crisv32_leds[ledgrp] =
  1430. + kmalloc(sizeof(struct crisv32_eth_leds), GFP_KERNEL);
  1431. +
  1432. + crisv32_leds[ledgrp]->ledgrp = ledgrp;
  1433. + crisv32_leds[ledgrp]->led_active = 0;
  1434. + crisv32_leds[ledgrp]->ifisup[0] = 0;
  1435. + crisv32_leds[ledgrp]->ifisup[1] = 0;
  1436. + /* NOTE: Should this value be set to zero as the jiffies timer
  1437. + can wrap? */
  1438. + crisv32_leds[ledgrp]->led_next_time = jiffies;
  1439. +
  1440. + crisv32_leds[ledgrp]->clear_led_timer = timer_init;
  1441. + crisv32_leds[ledgrp]->clear_led_timer.function =
  1442. + crisv32_clear_network_leds;
  1443. + crisv32_leds[ledgrp]->clear_led_timer.data = (unsigned long) dev;
  1444. +
  1445. + spin_lock_init(&crisv32_leds[ledgrp]->led_lock);
  1446. +
  1447. + np->leds = crisv32_leds[ledgrp];
  1448. +}
  1449. +
  1450. +static int __init crisv32_ethernet_init(void)
  1451. +{
  1452. + struct crisv32_ethernet_local *np;
  1453. + int ret = 0;
  1454. +
  1455. +#ifdef CONFIG_ETRAXFS
  1456. + printk("ETRAX FS 10/100MBit ethernet v0.01 (c)"
  1457. + " 2003 Axis Communications AB\n");
  1458. +#else
  1459. + printk("ARTPEC-3 10/100 MBit ethernet (c)"
  1460. + " 2003-2009 Axis Communications AB\n");
  1461. +#endif
  1462. +
  1463. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1464. + {
  1465. + reg_clkgen_rw_clk_ctrl clk_ctrl = REG_RD(clkgen, regi_clkgen,
  1466. + rw_clk_ctrl);
  1467. + clk_ctrl.eth = clk_ctrl.dma0_1_eth = regk_clkgen_yes;
  1468. + REG_WR(clkgen, regi_clkgen, rw_clk_ctrl, clk_ctrl);
  1469. + }
  1470. +#endif
  1471. +{
  1472. + int iface0 = 0;
  1473. +
  1474. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1475. + if (crisv32_pinmux_alloc_fixed(pinmux_eth))
  1476. + panic("Eth pinmux\n");
  1477. +#endif
  1478. +
  1479. + if (!(crisv32_dev[iface0] = alloc_etherdev(sizeof *np)))
  1480. + return -ENOMEM;
  1481. +
  1482. + ret |= crisv32_ethernet_device_init(crisv32_dev[iface0]);
  1483. +
  1484. +#if defined(CONFIG_ETRAX_ETH0_USE_LEDGRP0)
  1485. + crisv32_init_leds(CRIS_LED_GRP_0,crisv32_dev[iface0]);
  1486. +#elif defined(CONFIG_ETRAX_ETH0_USE_LEDGRP1)
  1487. + crisv32_init_leds(CRIS_LED_GRP_1,crisv32_dev[iface0]);
  1488. +#else
  1489. + crisv32_init_leds(CRIS_LED_GRP_NONE,crisv32_dev[iface0]);
  1490. +#endif
  1491. +
  1492. + np = (struct crisv32_ethernet_local *) netdev_priv(crisv32_dev[iface0]);
  1493. + np->eth_inst = regi_eth0;
  1494. + np->dma_out_inst = regi_dma0;
  1495. + np->dma_in_inst = regi_dma1;
  1496. +
  1497. + np->mii_if.dev = crisv32_dev[iface0];
  1498. + np->mii_if.mdio_read = crisv32_eth_get_mdio_reg;
  1499. + np->mii_if.mdio_write = crisv32_eth_set_mdio_reg;
  1500. + np->mii_if.phy_id_mask = 0x1f;
  1501. + np->mii_if.reg_num_mask = 0x1f;
  1502. +
  1503. + np->use_leds = 1;
  1504. + np->autoneg_normal = 1;
  1505. +
  1506. +
  1507. + register_netdev(crisv32_dev[iface0]);
  1508. +
  1509. + /* Set up default MAC address */
  1510. + memcpy(crisv32_dev[iface0]->dev_addr, default_mac_iface0.sa_data, 6);
  1511. + crisv32_eth_set_mac_address(crisv32_dev[iface0], &default_mac_iface0);
  1512. + if (crisv32_eth_request_irqdma(crisv32_dev[iface0]))
  1513. + printk("%s: eth0 unable to allocate IRQ and DMA resources\n",
  1514. + __func__);
  1515. + np->txpackets = 0;
  1516. + crisv32_eth_init_rings(crisv32_dev[iface0]);
  1517. + crisv32_eth_setup_controller(crisv32_dev[iface0]);
  1518. + ret |= crisv32_eth_init_phy(crisv32_dev[iface0]);
  1519. + if (ret) {
  1520. + unregister_netdev(crisv32_dev[iface0]);
  1521. + return ret;
  1522. + }
  1523. +}
  1524. +
  1525. +#ifdef CONFIG_ETRAX_ETHERNET_IFACE1
  1526. +{
  1527. + int iface1 = 0;
  1528. + /* Default MAC address for interface 1.
  1529. + * The real one will be set later. */
  1530. + static struct sockaddr default_mac_iface1 =
  1531. + {0, {0x00, 0x40, 0x8C, 0xCD, 0x00, 0x01}};
  1532. +
  1533. + if (crisv32_pinmux_alloc_fixed(pinmux_eth1))
  1534. + panic("Eth pinmux\n");
  1535. +
  1536. + /* Increase index to device array if interface 0 is enabled as well.*/
  1537. +#ifdef CONFIG_ETRAX_ETHERNET_IFACE0
  1538. + iface1++;
  1539. +#endif
  1540. + if (!(crisv32_dev[iface1] = alloc_etherdev(sizeof *np)))
  1541. + return -ENOMEM;
  1542. +
  1543. + ret |= crisv32_ethernet_device_init(crisv32_dev[iface1]);
  1544. +
  1545. +#if defined(CONFIG_ETRAX_ETH1_USE_LEDGRP0)
  1546. + crisv32_init_leds(CRIS_LED_GRP_0,crisv32_dev[iface1]);
  1547. +#elif defined(CONFIG_ETRAX_ETH1_USE_LEDGRP1)
  1548. + crisv32_init_leds(CRIS_LED_GRP_1,crisv32_dev[iface1]);
  1549. +#else
  1550. + crisv32_init_leds(CRIS_LED_GRP_NONE,crisv32_dev[iface1]);
  1551. +#endif
  1552. +
  1553. + np = (struct crisv32_ethernet_local *) netdev_priv(crisv32_dev[iface1]);
  1554. + np->eth_inst = regi_eth1;
  1555. + np->dma_out_inst = regi_dma6;
  1556. + np->dma_in_inst = regi_dma7;
  1557. +
  1558. + np->mii_if.dev = crisv32_dev[iface1];
  1559. + np->mii_if.mdio_read = crisv32_eth_get_mdio_reg;
  1560. + np->mii_if.mdio_write = crisv32_eth_set_mdio_reg;
  1561. + np->mii_if.phy_id_mask = 0x1f;
  1562. + np->mii_if.reg_num_mask = 0x1f;
  1563. +
  1564. +
  1565. + register_netdev(crisv32_dev[iface1]);
  1566. +
  1567. + /* Set up default MAC address */
  1568. + memcpy(crisv32_dev[iface1]->dev_addr, default_mac_iface1.sa_data, 6);
  1569. + crisv32_eth_set_mac_address(crisv32_dev[iface1], &default_mac_iface1);
  1570. +
  1571. + if (crisv32_eth_request_irqdma(crisv32_dev[iface1]))
  1572. + printk("%s: eth1 unable to allocate IRQ and DMA resources\n",
  1573. + __func__);
  1574. + np->txpackets = 0;
  1575. + crisv32_eth_init_rings(crisv32_dev[iface1]);
  1576. + crisv32_eth_setup_controller(crisv32_dev[iface1]);
  1577. + ret |= crisv32_eth_init_phy(crisv32_dev[iface1]);
  1578. + if (ret) {
  1579. + unregister_netdev(crisv32_dev[iface1]);
  1580. + return ret;
  1581. + }
  1582. +}
  1583. +#endif /* CONFIG_ETRAX_ETHERNET_IFACE1 */
  1584. +
  1585. +#ifdef CONFIG_CPU_FREQ
  1586. + cpufreq_register_notifier(&crisv32_ethernet_freq_notifier_block,
  1587. + CPUFREQ_TRANSITION_NOTIFIER);
  1588. +#endif
  1589. +
  1590. + return ret;
  1591. +}
  1592. +
  1593. +static struct net_device_ops crisv32_netdev_ops = {
  1594. + .ndo_open = crisv32_eth_open,
  1595. + .ndo_stop = crisv32_eth_close,
  1596. + .ndo_start_xmit = crisv32_eth_send_packet,
  1597. + .ndo_set_rx_mode = crisv32_eth_set_rx_mode,
  1598. + .ndo_validate_addr = eth_validate_addr,
  1599. + .ndo_set_mac_address = crisv32_eth_set_mac_address,
  1600. + .ndo_do_ioctl =crisv32_eth_ioctl,
  1601. + .ndo_get_stats = crisv32_get_stats,
  1602. + .ndo_tx_timeout = crisv32_eth_do_tx_recovery,
  1603. + .ndo_set_config = crisv32_eth_set_config,
  1604. +};
  1605. +
  1606. +static int __init crisv32_ethernet_device_init(struct net_device *dev)
  1607. +{
  1608. + struct crisv32_ethernet_local *np;
  1609. + struct timer_list timer_init = TIMER_INITIALIZER(NULL, 0, 0);
  1610. +
  1611. + dev->base_addr = 0; /* Just to have something to show. */
  1612. +
  1613. + /* we do our own locking */
  1614. + dev->features |= NETIF_F_LLTX;
  1615. +
  1616. + /* We use several IRQs and DMAs so just report 0 here. */
  1617. + dev->irq = 0;
  1618. + dev->dma = 0;
  1619. +
  1620. + /*
  1621. + * Fill in our handlers so the network layer can talk to us in the
  1622. + * future.
  1623. + */
  1624. + dev->netdev_ops = &crisv32_netdev_ops;
  1625. + dev->ethtool_ops = &crisv32_ethtool_ops;
  1626. + dev->watchdog_timeo = HZ * 10;
  1627. +#ifdef CONFIG_NET_POLL_CONTROLLER
  1628. + dev->poll_controller = crisv32_netpoll;
  1629. +#endif
  1630. + np = netdev_priv(dev);
  1631. + np->dev = dev;
  1632. +
  1633. + /*
  1634. + * 8 skbs keeps the system very reponsive even under high load.
  1635. + * At 64 the system locks, pretty much the same way as without NAPI.
  1636. + *
  1637. + * TODO: meassure with 2 interfaces
  1638. + */
  1639. + netif_napi_add(dev, &np->napi, crisv32_eth_poll, 8);
  1640. +
  1641. + spin_lock_init(&np->lock);
  1642. + spin_lock_init(&np->transceiver_lock);
  1643. +
  1644. + np->receive_timer = timer_init;
  1645. + np->receive_timer.data = (unsigned)dev;
  1646. + np->receive_timer.function = receive_timeout;
  1647. +
  1648. + INIT_WORK(&np->receive_work, receive_timeout_work);
  1649. +
  1650. + np->transmit_timer = timer_init;
  1651. + np->transmit_timer.data = (unsigned)dev;
  1652. + np->transmit_timer.function = transmit_timeout;
  1653. +
  1654. + return 0;
  1655. +}
  1656. +
  1657. +static int crisv32_eth_open(struct net_device *dev)
  1658. +{
  1659. + struct sockaddr mac_addr;
  1660. + reg_dma_rw_ack_intr ack_intr = { .data = 1, .in_eop = 1 };
  1661. + reg_eth_rw_clr_err clr_err = {.clr = regk_eth_yes};
  1662. + /*
  1663. + * dont interrupt us at any stat counter thresholds, only at urun
  1664. + * and exc_col.
  1665. + */
  1666. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1667. + /* For Artpec-3 we use overrun to workaround voodoo TR 87 */
  1668. + int intr_mask_nw = 0x1c00;
  1669. +#else
  1670. + int intr_mask_nw = 0x1800;
  1671. +#endif
  1672. + int eth_ack_intr = 0xffff;
  1673. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1674. +
  1675. + spin_lock(&np->lock);
  1676. + crisv32_eth_set_gigabit(np, 0);
  1677. +
  1678. + crisv32_disable_tx_ints(np);
  1679. + crisv32_disable_rx_ints(np);
  1680. +
  1681. + REG_WR(eth, np->eth_inst, rw_clr_err, clr_err);
  1682. + REG_WR_INT(eth, np->eth_inst, rw_ack_intr, eth_ack_intr);
  1683. + REG_WR_INT(eth, np->eth_inst, rw_intr_mask, intr_mask_nw);
  1684. + crisv32_eth_reset_rings(dev);
  1685. +
  1686. + /* Give the hardware an idea of what MAC address we want. */
  1687. + memcpy(mac_addr.sa_data, dev->dev_addr, dev->addr_len);
  1688. + crisv32_eth_set_mac_address(dev, &mac_addr);
  1689. +
  1690. + /* Enable irq and make sure that the irqs are cleared. */
  1691. + REG_WR(dma, np->dma_out_inst, rw_ack_intr, ack_intr);
  1692. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  1693. +
  1694. + crisv32_disconnect_eth_rx_dma(np);
  1695. +
  1696. + /* Prepare input DMA. */
  1697. + DMA_RESET(np->dma_in_inst);
  1698. + DMA_ENABLE(np->dma_in_inst);
  1699. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1700. + DMA_WR_CMD(np->dma_in_inst, regk_dma_set_w_size2);
  1701. +#endif
  1702. + DMA_START_CONTEXT(np->dma_in_inst, virt_to_phys(&np->ctxt_in));
  1703. + DMA_CONTINUE(np->dma_in_inst);
  1704. + crisv32_enable_rx_ints(np);
  1705. + crisv32_start_receiver(np);
  1706. +
  1707. + /* Prepare output DMA. */
  1708. + DMA_RESET(np->dma_out_inst);
  1709. + DMA_ENABLE(np->dma_out_inst);
  1710. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  1711. + DMA_WR_CMD(np->dma_out_inst, regk_dma_set_w_size4);
  1712. +#endif
  1713. + crisv32_connect_eth_rx_dma(np);
  1714. +
  1715. + netif_start_queue(dev);
  1716. + crisv32_enable_tx_ints(np);
  1717. +
  1718. + if (!np->fixed_phy) {
  1719. + /* Start duplex/speed timers */
  1720. + if (!timer_pending(&np->speed_timer))
  1721. + add_timer(&np->speed_timer);
  1722. + if (!timer_pending(&np->duplex_timer))
  1723. + add_timer(&np->duplex_timer);
  1724. + }
  1725. +
  1726. + spin_unlock(&np->lock);
  1727. + /*
  1728. + * We are now ready to accept transmit requests from the queueing
  1729. + * layer of the networking.
  1730. + */
  1731. + np->link = 1;
  1732. + netif_carrier_on(dev);
  1733. + napi_enable(&np->napi);
  1734. +
  1735. + return 0;
  1736. +}
  1737. +
  1738. +static int crisv32_eth_close(struct net_device *dev)
  1739. +{
  1740. + reg_dma_rw_ack_intr ack_intr = {0};
  1741. +
  1742. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1743. + unsigned long flags;
  1744. +
  1745. + del_timer(&np->transmit_timer);
  1746. + spin_lock_irqsave(&np->lock, flags);
  1747. +
  1748. + /* stop the receiver before the DMA channels to avoid overruns. */
  1749. + crisv32_disable_rx_ints(np);
  1750. + napi_disable(&np->napi);
  1751. + crisv32_stop_receiver(np);
  1752. +
  1753. + netif_stop_queue(dev);
  1754. +
  1755. + /* Reset the TX DMA in case it has hung on something. */
  1756. + DMA_RESET(np->dma_in_inst);
  1757. +
  1758. + /* Stop DMA */
  1759. + DMA_STOP(np->dma_in_inst);
  1760. + DMA_STOP(np->dma_out_inst);
  1761. +
  1762. + /* Disable irq and make sure that the irqs are cleared. */
  1763. + crisv32_disable_tx_ints(np);
  1764. + ack_intr.data = 1;
  1765. + REG_WR(dma, np->dma_out_inst, rw_ack_intr, ack_intr);
  1766. +
  1767. + ack_intr.in_eop = 1;
  1768. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  1769. +
  1770. + np->sender_started = 0;
  1771. + spin_unlock_irqrestore(&np->lock, flags);
  1772. +
  1773. + /* Update the statistics. */
  1774. + update_rx_stats(np);
  1775. + update_tx_stats(np);
  1776. +
  1777. + if (!np->fixed_phy) {
  1778. + /* Stop speed/duplex timers */
  1779. + del_timer(&np->speed_timer);
  1780. + del_timer(&np->duplex_timer);
  1781. + }
  1782. +
  1783. + return 0;
  1784. +}
  1785. +
  1786. +static int crisv32_eth_set_mac_address(struct net_device *dev, void *vpntr)
  1787. +{
  1788. + int i;
  1789. + static int first = 1;
  1790. +
  1791. + unsigned char *addr = ((struct sockaddr*)vpntr)->sa_data;
  1792. +
  1793. + reg_eth_rw_ma0_lo ma0_lo =
  1794. + { addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24)};
  1795. +
  1796. + reg_eth_rw_ma0_hi ma0_hi = { addr[4] | (addr[5] << 8) };
  1797. +
  1798. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1799. +
  1800. + /* Remember the address. */
  1801. + memcpy(dev->dev_addr, addr, dev->addr_len);
  1802. +
  1803. + /*
  1804. + * Write the address to the hardware.
  1805. + * Note the way the address is wrapped:
  1806. + * ma0_l0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24);
  1807. + * ma0_hi = a0_4 | (a0_5 << 8);
  1808. + */
  1809. + REG_WR(eth, np->eth_inst, rw_ma0_lo, ma0_lo);
  1810. + REG_WR(eth, np->eth_inst, rw_ma0_hi, ma0_hi);
  1811. +
  1812. + if (first) {
  1813. + printk(KERN_INFO "%s: changed MAC to ", dev->name);
  1814. +
  1815. + for (i = 0; i < 5; i++)
  1816. + printk("%02X:", dev->dev_addr[i]);
  1817. + printk("%02X\n", dev->dev_addr[i]);
  1818. +
  1819. + first = 0;
  1820. + }
  1821. +
  1822. + return 0;
  1823. +}
  1824. +
  1825. +static irqreturn_t crisv32rx_eth_interrupt(int irq, void *dev_id)
  1826. +{
  1827. + struct net_device *dev = (struct net_device *) dev_id;
  1828. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  1829. + reg_dma_r_masked_intr masked_in;
  1830. +
  1831. + masked_in = REG_RD(dma, np->dma_in_inst, r_masked_intr);
  1832. +
  1833. + if (masked_in.in_eop) {
  1834. + reg_dma_rw_ack_intr ack_intr = {0};
  1835. +
  1836. + /*
  1837. + * Ack the rx irq even if we are not prepared to start
  1838. + * polling. This is needed to handle incomming packets
  1839. + * during the stop sequence.
  1840. + */
  1841. + ack_intr.in_eop = 1;
  1842. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  1843. +
  1844. + mod_timer(&np->receive_timer, jiffies + HZ);
  1845. + np->do_rx_recovery = 0;
  1846. +
  1847. + if (napi_schedule_prep(&np->napi)) {
  1848. + crisv32_disable_rx_ints(np);
  1849. + crisv32_disable_tx_ints(np);
  1850. + /* put us onto the poll list */
  1851. + __napi_schedule(&np->napi);
  1852. + }
  1853. + } else {
  1854. + /* Unexpected, ACK it and hope for the best. */
  1855. + reg_dma_rw_ack_intr ack_intr = {
  1856. + .group = 1,
  1857. + .ctxt = 1,
  1858. + .data = 1,
  1859. + .in_eop = 0,
  1860. + .stream_cmd = 1,
  1861. + .dummy1 = ~0
  1862. + };
  1863. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  1864. + }
  1865. +
  1866. + return IRQ_HANDLED;
  1867. +}
  1868. +
  1869. +static inline void crisv32_eth_roll_tx_timer(struct crisv32_ethernet_local *np)
  1870. +{
  1871. + /* If there are more packets in the ring, roll the tx timer. */
  1872. + if (np->txpackets) {
  1873. + /* Eth pause frames may halt us for up to 320ms (100mbit). */
  1874. + unsigned long timeout = jiffies + (HZ / 3) + 1;
  1875. + mod_timer(&np->transmit_timer, timeout);
  1876. + }
  1877. + else
  1878. + del_timer(&np->transmit_timer);
  1879. +}
  1880. +
  1881. +/* Call with np->lock held. */
  1882. +static void _crisv32_tx_ring_advance(struct crisv32_ethernet_local *np,
  1883. + int cleanup)
  1884. +{
  1885. + reg_dma_rw_stat stat;
  1886. + dma_descr_data *dma_pos;
  1887. + struct net_device *dev = np->dev;
  1888. + int eol;
  1889. +
  1890. + /* Get the current output dma position. */
  1891. + dma_pos = phys_to_virt(REG_RD_INT(dma, np->dma_out_inst, rw_data));
  1892. + stat = REG_RD(dma, np->dma_out_inst, rw_stat);
  1893. + eol = stat.list_state == regk_dma_data_at_eol;
  1894. + if (cleanup || eol)
  1895. + dma_pos = &np->active_tx_desc->descr;
  1896. +
  1897. + /* Take care of transmited dma descriptors and report sent packet. */
  1898. + while (np->txpackets && (&np->catch_tx_desc->descr != dma_pos)) {
  1899. + /* Update sent packet statistics. */
  1900. + np->stats.tx_bytes += np->catch_tx_desc->skb->len;
  1901. + np->stats.tx_packets++;
  1902. +
  1903. + dev_kfree_skb_any(np->catch_tx_desc->skb);
  1904. + np->catch_tx_desc->skb = 0;
  1905. + np->txpackets--;
  1906. + np->catch_tx_desc->descr.buf = 0;
  1907. + np->catch_tx_desc =
  1908. + phys_to_virt((int)np->catch_tx_desc->descr.next);
  1909. + np->do_tx_recovery = 0;
  1910. + np->retrans = 0;
  1911. +
  1912. + netif_wake_queue(dev);
  1913. + }
  1914. +}
  1915. +
  1916. +static inline void crisv32_tx_ring_advance(struct crisv32_ethernet_local *np)
  1917. +{
  1918. + unsigned long flags;
  1919. +
  1920. + spin_lock_irqsave(&np->lock, flags);
  1921. + _crisv32_tx_ring_advance(np, 0);
  1922. + crisv32_eth_roll_tx_timer(np);
  1923. + spin_unlock_irqrestore(&np->lock, flags);
  1924. +}
  1925. +
  1926. +static inline int crisv32_tx_complete(struct crisv32_ethernet_local *np)
  1927. +{
  1928. + reg_dma_rw_ack_intr ack_intr = { .data = 1 };
  1929. + reg_dma_r_intr ints;
  1930. + int r = 0;
  1931. +
  1932. + /* We are interested in the unmasked raw interrupt source here. When
  1933. + polling with tx interrupts masked off we still want to do
  1934. + tx completition when the DMA makes progress. */
  1935. + ints = REG_RD(dma, np->dma_out_inst, r_intr);
  1936. + if (ints.data)
  1937. + {
  1938. + /* ack the interrupt, if it was active */
  1939. + REG_WR(dma, np->dma_out_inst, rw_ack_intr, ack_intr);
  1940. + crisv32_tx_ring_advance(np);
  1941. + r = 1;
  1942. + }
  1943. + return r;
  1944. +}
  1945. +
  1946. +static irqreturn_t crisv32tx_eth_interrupt(int irq, void *dev_id)
  1947. +{
  1948. + struct crisv32_ethernet_local *np = netdev_priv(dev_id);
  1949. +
  1950. + crisv32_tx_complete(np);
  1951. + return IRQ_HANDLED;
  1952. +}
  1953. +
  1954. +
  1955. +/* Update receive errors. */
  1956. +static void
  1957. +update_rx_stats(struct crisv32_ethernet_local *np)
  1958. +{
  1959. + reg_eth_rs_rec_cnt r;
  1960. +
  1961. + r = REG_RD(eth, np->eth_inst, rs_rec_cnt);
  1962. +
  1963. + np->stats.rx_over_errors += r.congestion;
  1964. + np->stats.rx_crc_errors += r.crc_err;
  1965. + np->stats.rx_frame_errors += r.align_err;
  1966. + np->stats.rx_length_errors += r.oversize;
  1967. + np->stats.rx_errors += r.crc_err + r.align_err +
  1968. + r.oversize + r.congestion;
  1969. +}
  1970. +
  1971. +/* Update transmit errors. */
  1972. +static void update_tx_stats(struct crisv32_ethernet_local *np)
  1973. +{
  1974. + reg_eth_rs_tr_cnt r;
  1975. + reg_eth_rs_phy_cnt rp;
  1976. +
  1977. + r = REG_RD(eth, np->eth_inst, rs_tr_cnt);
  1978. + rp = REG_RD(eth, np->eth_inst, rs_phy_cnt);
  1979. +
  1980. + /* r.deferred is not good for counting collisions because it also
  1981. + includes frames that have to wait for the interframe gap. That
  1982. + means we get deferred frames even when in full duplex.
  1983. + Here we don't actually count the number of collisions that
  1984. + occured (artpec3 seems to lack such a counter), instead we count
  1985. + the number of frames that collide once or more. */
  1986. + np->stats.collisions += r.mult_col + r.single_col;
  1987. + np->stats.tx_window_errors += r.late_col;
  1988. + np->stats.tx_carrier_errors += rp.carrier_loss;
  1989. +
  1990. + /* Ordinary collisions are not errors, they are just part of
  1991. + ethernet's bus arbitration and congestion control mechanisms.
  1992. + Late collisions are serious errors though. */
  1993. + np->stats.tx_errors += r.late_col;
  1994. +}
  1995. +
  1996. +/* Get current statistics. */
  1997. +static struct net_device_stats *crisv32_get_stats(struct net_device *dev)
  1998. +{
  1999. + unsigned long flags;
  2000. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2001. +
  2002. + spin_lock_irqsave(&np->lock, flags);
  2003. +
  2004. + update_rx_stats(np);
  2005. + update_tx_stats(np);
  2006. +
  2007. + spin_unlock_irqrestore(&np->lock, flags);
  2008. +
  2009. + return &np->stats;
  2010. +}
  2011. +
  2012. +/* Check for network errors. This acknowledge the received interrupt. */
  2013. +static irqreturn_t crisv32nw_eth_interrupt(int irq, void *dev_id)
  2014. +{
  2015. + struct net_device *dev = (struct net_device *) dev_id;
  2016. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2017. + reg_eth_r_masked_intr intr_mask;
  2018. + int ack_intr = 0xffff;
  2019. + reg_eth_rw_clr_err clr_err;
  2020. +
  2021. + intr_mask = REG_RD(eth, np->eth_inst, r_masked_intr);
  2022. +
  2023. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2024. + /* Only apply the workaround if it is not already pending.
  2025. + enable_eth_ints will re-enable the orun interrupt regardless
  2026. + of pending_overrun. */
  2027. + if (intr_mask.orun && !np->pending_overrun) {
  2028. + reg_eth_rw_rec_ctrl rec_ctrl =
  2029. + REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  2030. + np->saved_rec_ctrl = rec_ctrl;
  2031. + np->overrun_set = 1;
  2032. + DMA_STOP(np->dma_in_inst);
  2033. + rec_ctrl.ma0 = regk_eth_no;
  2034. + rec_ctrl.broadcast = regk_eth_no;
  2035. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  2036. + np->saved_ga_lo = REG_RD_INT(eth, np->eth_inst, rw_ga_lo);
  2037. + np->saved_ga_hi = REG_RD_INT(eth, np->eth_inst, rw_ga_hi);
  2038. + REG_WR_INT(eth, np->eth_inst, rw_ga_lo, 0);
  2039. + REG_WR_INT(eth, np->eth_inst, rw_ga_hi, 0);
  2040. + REG_WR_INT(eth, np->eth_inst, rw_intr_mask,
  2041. + REG_RD_INT(eth, np->eth_inst, rw_intr_mask) & 0xfbff);
  2042. + REG_WR_INT(eth, np->eth_inst, rw_ack_intr, 0x400);
  2043. + intr_mask.orun = 0;
  2044. + np->pending_overrun = 1;
  2045. + if (!np->napi_processing)
  2046. + crisv32_eth_restart_rx_dma(np->dev, np);
  2047. +
  2048. + return IRQ_HANDLED;
  2049. + }
  2050. +#endif
  2051. +
  2052. + /*
  2053. + * Check for underrun and/or excessive collisions. Note that the
  2054. + * rw_clr_err register clears both underrun and excessive collision
  2055. + * errors, so there's no need to check them separately.
  2056. + */
  2057. + if (np->sender_started
  2058. + && (intr_mask.urun || intr_mask.exc_col)) {
  2059. + unsigned long flags;
  2060. +
  2061. + /* Underrun are considered to be tx-errors. */
  2062. + np->stats.tx_errors += intr_mask.urun;
  2063. + np->stats.tx_fifo_errors += intr_mask.urun;
  2064. +
  2065. + /*
  2066. + * Protect against the tx-interrupt messing with
  2067. + * the tx-ring.
  2068. + */
  2069. + spin_lock_irqsave(&np->lock, flags);
  2070. +
  2071. + /* DMA should have stopped now, eat from the ring before
  2072. + removing anything due to tx errors. */
  2073. + _crisv32_tx_ring_advance(np, 0);
  2074. +
  2075. + /*
  2076. + * Drop packets after 15 retries.
  2077. + * TODO: Add backoff.
  2078. + */
  2079. + if (np->retrans > 15 && np->txpackets) {
  2080. + dev_kfree_skb_irq(np->catch_tx_desc->skb);
  2081. + np->catch_tx_desc->skb = 0;
  2082. + np->catch_tx_desc->descr.buf = 0;
  2083. + np->catch_tx_desc =
  2084. + phys_to_virt((int)
  2085. + np->catch_tx_desc->descr.next);
  2086. + flush_dma_descr(&np->catch_tx_desc->descr, 0);
  2087. +
  2088. + np->txpackets--;
  2089. + np->retrans = 0;
  2090. + netif_wake_queue(dev);
  2091. + np->stats.tx_dropped++;
  2092. + }
  2093. + np->ctxt_out.next = 0;
  2094. + if (np->txpackets) {
  2095. + np->retrans++;
  2096. + np->ctxt_out.saved_data = (void *)
  2097. + virt_to_phys(&np->catch_tx_desc->descr);
  2098. + np->ctxt_out.saved_data_buf =
  2099. + np->catch_tx_desc->descr.buf;
  2100. + WARN_ON(!np->ctxt_out.saved_data_buf);
  2101. + flush_dma_descr(&np->catch_tx_desc->descr, 0);
  2102. + cris_flush_cache_range(&np->ctxt_out,
  2103. + sizeof np->ctxt_out);
  2104. +
  2105. + /* restart the DMA */
  2106. + DMA_START_CONTEXT(np->dma_out_inst,
  2107. + (int) virt_to_phys(&np->ctxt_out));
  2108. + np->sender_started = 1;
  2109. + }
  2110. + else {
  2111. + /* Load dummy context but do not load the data
  2112. + descriptor nor start the burst. This brings the
  2113. + buggy eth transmitter back in sync with the DMA
  2114. + avoiding malformed frames. */
  2115. + REG_WR(dma, np->dma_out_inst, rw_group_down,
  2116. + (int) virt_to_phys(&np->ctxt_out));
  2117. + DMA_WR_CMD(np->dma_out_inst, regk_dma_load_c);
  2118. + np->sender_started = 0;
  2119. + }
  2120. + crisv32_eth_roll_tx_timer(np);
  2121. + spin_unlock_irqrestore(&np->lock, flags);
  2122. + }
  2123. +
  2124. + ack_intr = *(u32 *)&intr_mask;
  2125. + REG_WR_INT(eth, np->eth_inst, rw_ack_intr, ack_intr);
  2126. + clr_err.clr = 1;
  2127. + REG_WR(eth, np->eth_inst, rw_clr_err, clr_err);
  2128. +
  2129. + update_rx_stats(np);
  2130. + update_tx_stats(np);
  2131. +
  2132. + return IRQ_HANDLED;
  2133. +}
  2134. +
  2135. +/* We have a good packet(s), get it/them out of the buffers. */
  2136. +static int crisv32_eth_receive_packet(struct net_device *dev)
  2137. +{
  2138. + int length;
  2139. + struct sk_buff *skb;
  2140. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2141. + struct sk_buff *tmp;
  2142. + unsigned long flags;
  2143. +
  2144. + DEBUG(printk("crisv32_receive_packet\n"));
  2145. +
  2146. + /* Roll the rx bug timer. */
  2147. + mod_timer(&np->receive_timer, jiffies + HZ);
  2148. +
  2149. + /* Activate LED */
  2150. + spin_lock_irqsave(&np->leds->led_lock, flags);
  2151. + if (!np->leds->led_active && time_after(jiffies,
  2152. + np->leds->led_next_time)) {
  2153. + /* light the network leds depending on the current speed. */
  2154. + crisv32_set_network_leds(CRIS_LED_ACTIVITY, dev);
  2155. +
  2156. + /* Set the earliest time we may clear the LED */
  2157. + np->leds->led_next_time = jiffies + NET_FLASH_TIME;
  2158. + np->leds->led_active = 1;
  2159. + np->leds->clear_led_timer.data = (unsigned long) dev;
  2160. + mod_timer(&np->leds->clear_led_timer, jiffies + HZ/10);
  2161. + }
  2162. + spin_unlock_irqrestore(&np->leds->led_lock, flags);
  2163. +
  2164. + /* Discard CRC (4 bytes). */
  2165. + length = (np->active_rx_desc->descr.after) -
  2166. + (np->active_rx_desc->descr.buf) - 4;
  2167. +
  2168. + tmp = dev_alloc_skb(MAX_MEDIA_DATA_SIZE);
  2169. + if (!tmp) {
  2170. + np->stats.rx_errors++;
  2171. + printk(KERN_NOTICE "%s: memory squeeze,"
  2172. + " dropping packet.",
  2173. + dev->name);
  2174. + return 0;
  2175. + }
  2176. + skb = np->active_rx_desc->skb;
  2177. + np->active_rx_desc->skb = tmp;
  2178. + skb_put(skb, length);
  2179. +
  2180. + np->newbuf = virt_to_phys(np->active_rx_desc->skb->data);
  2181. +
  2182. + skb->dev = dev;
  2183. + skb->protocol = eth_type_trans(skb, dev);
  2184. + skb->ip_summed = CHECKSUM_NONE;
  2185. +
  2186. + np->stats.multicast += skb->pkt_type == PACKET_MULTICAST;
  2187. + /* Send the packet to the upper layer. */
  2188. + netif_receive_skb(skb);
  2189. + np->last_rx_desc =
  2190. + phys_to_virt((int)
  2191. + np->last_rx_desc->descr.next);
  2192. +
  2193. + /* Forward rotate the receive ring. */
  2194. + crisv32_eth_rx_ring_advance(np);
  2195. + return length;
  2196. +}
  2197. +
  2198. +/* Must be called with the np-lock held. */
  2199. +static void
  2200. +__crisv32_eth_restart_rx_dma(struct net_device* dev,
  2201. + struct crisv32_ethernet_local *np)
  2202. +{
  2203. + reg_dma_rw_ack_intr ack_intr = {0};
  2204. + reg_dma_rw_stream_cmd dma_sc = {0};
  2205. + reg_dma_rw_stat stat;
  2206. + int resets = 0;
  2207. + reg_eth_rw_intr_mask eth_intr_mask;
  2208. +
  2209. + np->rx_dma_restarts++;
  2210. +
  2211. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2212. + if (np->pending_overrun) {
  2213. + np->pending_overrun = 0;
  2214. + REG_WR_INT(eth, np->eth_inst, rw_ga_lo, np->saved_ga_lo);
  2215. + REG_WR_INT(eth, np->eth_inst, rw_ga_hi, np->saved_ga_hi);
  2216. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, np->saved_rec_ctrl);
  2217. + REG_WR_INT(eth, np->eth_inst, rw_intr_mask,
  2218. + REG_RD_INT(eth, regi_eth, rw_intr_mask) | 0x400);
  2219. + DMA_CONTINUE(np->dma_in_inst);
  2220. + }
  2221. +#endif
  2222. + /* Bring down the receiver. */
  2223. + crisv32_disable_rx_ints(np);
  2224. + crisv32_disconnect_eth_rx_dma(np);
  2225. +
  2226. + /* Stop DMA and ack possible ints. */
  2227. + DMA_STOP(np->dma_in_inst);
  2228. + ack_intr.in_eop = 1;
  2229. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  2230. +
  2231. + crisv32_stop_receiver(np);
  2232. +
  2233. + /* Disable overrun interrupts while receive is shut off. */
  2234. + eth_intr_mask = REG_RD(eth, np->eth_inst, rw_intr_mask);
  2235. + eth_intr_mask.orun = regk_eth_no;
  2236. + REG_WR(eth, np->eth_inst, rw_intr_mask, eth_intr_mask);
  2237. + /* ACK overrun. */
  2238. + REG_WR_INT(eth, np->eth_inst, rw_ack_intr, 0x400);
  2239. +
  2240. + crisv32_eth_reset_rx_ring(dev);
  2241. + reset:
  2242. + /* TODO: if nr resets grows to high we should reboot. */
  2243. + if (resets++ > 0)
  2244. + printk("reset DMA %d.\n", resets);
  2245. +
  2246. + DMA_RESET(np->dma_in_inst);
  2247. + /* Wait for the channel to reset. */
  2248. + do {
  2249. + stat = REG_RD(dma, np->dma_in_inst, rw_stat);
  2250. + } while (stat.mode != regk_dma_rst);
  2251. +
  2252. + /* Now bring the rx path back up. */
  2253. + DMA_ENABLE(np->dma_in_inst);
  2254. + if (dma_wait_busy(np->dma_in_inst, 100))
  2255. + goto reset;
  2256. +
  2257. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2258. +// DMA_WR_CMD(np->dma_in_inst, regk_dma_set_w_size2);
  2259. + dma_sc.cmd = (regk_dma_set_w_size2);
  2260. + REG_WR(dma, np->dma_in_inst, rw_stream_cmd, dma_sc);
  2261. + if (dma_wait_busy(np->dma_in_inst, 100))
  2262. + goto reset;
  2263. +#endif
  2264. +
  2265. +// DMA_START_CONTEXT(np->dma_in_inst, virt_to_phys(&np->ctxt_in));
  2266. + REG_WR_INT(dma, np->dma_in_inst, rw_group_down, (int)&np->ctxt_in);
  2267. +
  2268. +// DMA_WR_CMD(np->dma_in_inst, regk_dma_load_c);
  2269. + dma_sc.cmd = (regk_dma_load_c);
  2270. + REG_WR(dma, np->dma_in_inst, rw_stream_cmd, dma_sc);
  2271. + if (dma_wait_busy(np->dma_in_inst, 100))
  2272. + goto reset;
  2273. +
  2274. +// DMA_WR_CMD(np->dma_in_inst, regk_dma_load_d | regk_dma_burst);
  2275. + dma_sc.cmd = (regk_dma_load_d | regk_dma_burst);
  2276. + REG_WR(dma, np->dma_in_inst, rw_stream_cmd, dma_sc);
  2277. +
  2278. + if (dma_wait_busy(np->dma_in_inst, 100))
  2279. + goto reset;
  2280. +
  2281. + /* Now things get critical again. Don't give us any interrupts until
  2282. + the following sequence is complete. */
  2283. + DMA_CONTINUE(np->dma_in_inst);
  2284. + np->overrun_set = 0;
  2285. + crisv32_enable_rx_ints(np);
  2286. + crisv32_start_receiver(np);
  2287. +
  2288. + /* Reenable overrun interrupts when receive is started again. */
  2289. + eth_intr_mask = REG_RD(eth, np->eth_inst, rw_intr_mask);
  2290. + eth_intr_mask.orun = regk_eth_yes;
  2291. + REG_WR(eth, np->eth_inst, rw_intr_mask, eth_intr_mask);
  2292. +
  2293. + crisv32_connect_eth_rx_dma(np);
  2294. +}
  2295. +
  2296. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2297. +static void
  2298. +crisv32_eth_restart_rx_dma(struct net_device* dev,
  2299. + struct crisv32_ethernet_local *np)
  2300. +{
  2301. + unsigned long flags;
  2302. +
  2303. + spin_lock_irqsave(&np->lock, flags);
  2304. + __crisv32_eth_restart_rx_dma(dev, np);
  2305. + spin_unlock_irqrestore(&np->lock, flags);
  2306. +}
  2307. +#endif
  2308. +
  2309. +/*
  2310. + * Is there work to do in the rx-path?
  2311. + */
  2312. +static inline int crisv32_has_rx_work(struct crisv32_ethernet_local *np,
  2313. + dma_descr_data *active)
  2314. +{
  2315. + int mw;
  2316. + mw = (active->in_eop && np->new_rx_package);
  2317. + return mw;
  2318. +}
  2319. +
  2320. +static void crisv32_eth_do_rx_recovery(struct net_device* dev,
  2321. + struct crisv32_ethernet_local *np)
  2322. +{
  2323. + unsigned long flags;
  2324. + static int r = 0;
  2325. +
  2326. + r++;
  2327. +
  2328. + /* Bring down the receiver. */
  2329. + spin_lock_irqsave(&np->lock, flags);
  2330. + if (!np->do_rx_recovery)
  2331. + goto done;
  2332. +
  2333. + napi_disable(&np->napi);
  2334. +
  2335. + np->rx_dma_timeouts++;
  2336. +
  2337. + __crisv32_eth_restart_rx_dma(dev, np);
  2338. +
  2339. + np->do_rx_recovery = 0;
  2340. +
  2341. + napi_enable(&np->napi);
  2342. + done:
  2343. + spin_unlock_irqrestore(&np->lock, flags);
  2344. +
  2345. + WARN_ON(r != 1);
  2346. + r--;
  2347. +}
  2348. +
  2349. +static void receive_timeout_work(struct work_struct* work)
  2350. +{
  2351. + struct dma_descr_data* descr;
  2352. + struct dma_descr_data* descr2;
  2353. + struct net_device* dev = crisv32_dev[0];
  2354. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2355. + reg_eth_r_intr intr_mask;
  2356. +
  2357. + descr = &np->active_rx_desc->descr;
  2358. + descr2 = phys_to_virt(REG_RD_INT(dma, np->dma_in_inst, rw_data));
  2359. +
  2360. + intr_mask = REG_RD(eth, np->eth_inst, r_intr);
  2361. +
  2362. + if (!np->overrun_set
  2363. + && !intr_mask.orun
  2364. + && !descr->in_eop
  2365. + && !descr2->in_eop)
  2366. + return;
  2367. +
  2368. + crisv32_eth_do_rx_recovery(dev, np);
  2369. +}
  2370. +
  2371. +static void receive_timeout(unsigned long arg)
  2372. +{
  2373. + struct net_device* dev = (struct net_device*)arg;
  2374. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2375. +
  2376. + np->do_rx_recovery++;
  2377. + schedule_work(&np->receive_work);
  2378. + mod_timer(&np->receive_timer, jiffies + 1*HZ);
  2379. +}
  2380. +
  2381. +static void transmit_timeout(unsigned long arg)
  2382. +{
  2383. + struct net_device* dev = (struct net_device*)arg;
  2384. + crisv32_eth_do_tx_recovery(dev);
  2385. +}
  2386. +
  2387. +/*
  2388. + * NAPI poll
  2389. + *
  2390. + * We are allowed to pull up to budget number of frames from the rx ring.
  2391. + * If we are done, remove us from the poll list and re-enable rx interrupts.
  2392. + * Always return number of pulled frames from the rx ring.
  2393. + */
  2394. +static int crisv32_eth_poll(struct napi_struct *napi, int budget)
  2395. +{
  2396. + struct crisv32_ethernet_local *np;
  2397. + int work_done = 0;
  2398. + int morework;
  2399. + int rx_bytes = 0;
  2400. + reg_dma_rw_ack_intr ack_intr = {0};
  2401. +
  2402. + np = container_of(napi, struct crisv32_ethernet_local, napi);
  2403. + crisv32_disable_eth_ints(np);
  2404. + np->napi_processing = 1;
  2405. + ack_intr.in_eop = 1;
  2406. +
  2407. + if (np->new_rx_package == 0) {
  2408. + /*
  2409. + * In the previous round we pulled a packet from the ring but
  2410. + * we didn't advance the ring due to hw DMA bug. Try to do it
  2411. + * now.
  2412. + */
  2413. + np->new_rx_package = 1;
  2414. + crisv32_eth_rx_ring_advance(np);
  2415. + }
  2416. +
  2417. + morework = crisv32_has_rx_work(np, &np->active_rx_desc->descr);
  2418. +
  2419. + /* See if tx needs attention. */
  2420. + crisv32_tx_complete(np);
  2421. +
  2422. + while (morework)
  2423. + {
  2424. + rx_bytes += crisv32_eth_receive_packet(np->dev);
  2425. + work_done++;
  2426. +
  2427. + /* Ack irq and restart rx dma */
  2428. + REG_WR(dma, np->dma_in_inst, rw_ack_intr, ack_intr);
  2429. + DMA_CONTINUE_DATA(np->dma_in_inst);
  2430. +
  2431. + if (unlikely(work_done >= budget))
  2432. + break;
  2433. +
  2434. + /* See if tx needs attention. */
  2435. + crisv32_tx_complete(np);
  2436. +
  2437. + morework = crisv32_has_rx_work(np, &np->active_rx_desc->descr);
  2438. + }
  2439. + crisv32_enable_eth_ints(np);
  2440. +
  2441. + if (!morework) {
  2442. + np->napi_processing = 0;
  2443. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2444. + if (np->pending_overrun) {
  2445. + crisv32_eth_restart_rx_dma(np->dev, np);
  2446. + }
  2447. +#endif
  2448. + if (irqs_disabled())
  2449. + printk("WARNING: %s irqs disabled!\n", __func__);
  2450. +
  2451. + if (work_done < budget) {
  2452. + /* first mark as done, then enable irq's */
  2453. + napi_complete(napi);
  2454. + crisv32_enable_rx_ints(np);
  2455. + crisv32_enable_tx_ints(np);
  2456. + }
  2457. + }
  2458. + np->napi_processing = 0;
  2459. +
  2460. + np->stats.rx_bytes += rx_bytes;
  2461. + np->stats.rx_packets += work_done;
  2462. + update_rx_stats(np);
  2463. + return work_done;
  2464. +}
  2465. +
  2466. +/*
  2467. + * This function (i.e. hard_start_xmit) is protected from concurent calls by a
  2468. + * spinlock (xmit_lock) in the net_device structure.
  2469. + */
  2470. +static int
  2471. +crisv32_eth_send_packet(struct sk_buff *skb, struct net_device *dev)
  2472. +{
  2473. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2474. + unsigned char *buf = skb->data;
  2475. + unsigned long flags;
  2476. +
  2477. + /*
  2478. + * Need to disable irq to avoid updating pointer in interrupt while
  2479. + * sending packets.
  2480. + */
  2481. + spin_lock_irqsave(&np->lock, flags);
  2482. +
  2483. + np->active_tx_desc->skb = skb;
  2484. + crisv32_eth_hw_send_packet(buf, skb->len, np);
  2485. +
  2486. + dev->trans_start = jiffies;
  2487. +
  2488. + /* Stop queue if full. */
  2489. + if (crisv32_eth_tx_ring_full(np))
  2490. + netif_stop_queue(dev);
  2491. +
  2492. + np->txpackets++;
  2493. + crisv32_eth_roll_tx_timer(np);
  2494. + spin_unlock_irqrestore(&np->lock, flags);
  2495. +
  2496. + spin_lock_irqsave(&np->leds->led_lock, flags);
  2497. + if (!np->leds->led_active && time_after(jiffies,
  2498. + np->leds->led_next_time)) {
  2499. + /* light the network leds depending on the current speed. */
  2500. + crisv32_set_network_leds(CRIS_LED_ACTIVITY, dev);
  2501. +
  2502. + /* Set the earliest time we may clear the LED */
  2503. + np->leds->led_next_time = jiffies + NET_FLASH_TIME;
  2504. + np->leds->led_active = 1;
  2505. + np->leds->clear_led_timer.data = (unsigned long) dev;
  2506. + mod_timer(&np->leds->clear_led_timer, jiffies + HZ/10);
  2507. + }
  2508. + spin_unlock_irqrestore(&np->leds->led_lock, flags);
  2509. +
  2510. + return 0;
  2511. +}
  2512. +
  2513. +
  2514. +static void
  2515. +crisv32_eth_hw_send_packet(unsigned char *buf, int length, void *priv)
  2516. +{
  2517. + struct crisv32_ethernet_local *np =
  2518. + (struct crisv32_ethernet_local *) priv;
  2519. +
  2520. + /* Configure the tx dma descriptor. */
  2521. + np->active_tx_desc->descr.buf = (unsigned char *)virt_to_phys(buf);
  2522. +
  2523. + np->active_tx_desc->descr.after = np->active_tx_desc->descr.buf +
  2524. + length;
  2525. + np->active_tx_desc->descr.intr = 1;
  2526. + np->active_tx_desc->descr.out_eop = 1;
  2527. +
  2528. + /* Move eol. */
  2529. + np->active_tx_desc->descr.eol = 1;
  2530. + flush_dma_descr(&np->active_tx_desc->descr, 1);
  2531. +
  2532. + if (np->sender_started)
  2533. + WARN_ON(!np->prev_tx_desc->descr.eol);
  2534. + np->prev_tx_desc->descr.eol = 0;
  2535. + flush_dma_descr(&np->prev_tx_desc->descr, 0);
  2536. +
  2537. + /* Update pointers. */
  2538. + np->prev_tx_desc = np->active_tx_desc;
  2539. + np->active_tx_desc = phys_to_virt((int)np->active_tx_desc->descr.next);
  2540. +
  2541. + /* Start DMA. */
  2542. + crisv32_start_dma_out(np);
  2543. +}
  2544. +
  2545. +static void crisv32_start_dma_out(struct crisv32_ethernet_local *np)
  2546. +{
  2547. + if (!np->sender_started) {
  2548. + /* Start DMA for the first time. */
  2549. + np->ctxt_out.saved_data =
  2550. + (void *)virt_to_phys(&np->prev_tx_desc->descr);
  2551. + np->ctxt_out.saved_data_buf = np->prev_tx_desc->descr.buf;
  2552. + WARN_ON(!np->ctxt_out.saved_data_buf);
  2553. +
  2554. + cris_flush_cache_range(&np->ctxt_out, sizeof np->ctxt_out);
  2555. + REG_WR(dma, np->dma_out_inst, rw_group_down,
  2556. + (int) virt_to_phys(&np->ctxt_out));
  2557. + DMA_WR_CMD(np->dma_out_inst, regk_dma_load_c);
  2558. + DMA_WR_CMD(np->dma_out_inst, regk_dma_load_d | regk_dma_burst);
  2559. + np->sender_started = 1;
  2560. + } else {
  2561. + DMA_CONTINUE_DATA(np->dma_out_inst);
  2562. + }
  2563. +}
  2564. +
  2565. +/*
  2566. + * Bring the transmitter back to life.
  2567. + */
  2568. +static void
  2569. +crisv32_eth_do_tx_recovery(struct net_device *dev)
  2570. +{
  2571. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2572. + reg_eth_rw_clr_err clr_err;
  2573. + reg_dma_rw_stat stat = {0};
  2574. + unsigned long flags;
  2575. + /* ACK urun and exc_col. */
  2576. + int ack_intr = 0x1800;
  2577. + int do_full;
  2578. +
  2579. + /* Give the tx recovery some time without link state polling. */
  2580. + if (!np->fixed_phy)
  2581. + mod_timer(&np->speed_timer, jiffies + 4 * HZ);
  2582. +
  2583. + np->tx_dma_restarts++;
  2584. +
  2585. + spin_lock_irqsave(&np->lock, flags);
  2586. +
  2587. + do_full = 1;
  2588. + update_tx_stats(np);
  2589. +
  2590. + /* Cancel ongoing frame. */
  2591. + crisv32_eth_tx_cancel_frame(np);
  2592. +
  2593. + /* In case TR 125 just hit us. */
  2594. + DMA_WR_CMD(np->dma_out_inst, regk_dma_ack_pkt);
  2595. + dma_wait_busy(np->dma_out_inst, 100);
  2596. +
  2597. + /* At this point, the transmit block should be idle or waiting for us
  2598. + to clear the excessive collision error. Let's reset the DMA. */
  2599. + DMA_STOP(np->dma_out_inst);
  2600. +
  2601. + crisv32_disconnect_eth_tx_dma(np);
  2602. +
  2603. + /* Eat from the tx ring. */
  2604. + _crisv32_tx_ring_advance(np, 1);
  2605. + np->do_tx_recovery++;
  2606. +
  2607. + DMA_RESET(np->dma_out_inst);
  2608. + do {
  2609. + stat = REG_RD(dma, np->dma_out_inst, rw_stat);
  2610. + } while (stat.mode != regk_dma_rst);
  2611. +
  2612. + /* Next packet will restart output DMA. */
  2613. + np->sender_started = 0;
  2614. +
  2615. + crisv32_enable_tx_ints(np);
  2616. +
  2617. + DMA_ENABLE(np->dma_out_inst);
  2618. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  2619. + DMA_WR_CMD(np->dma_out_inst, regk_dma_set_w_size4);
  2620. +#endif
  2621. + DMA_CONTINUE(np->dma_out_inst);
  2622. +
  2623. + /* Clear pending errors. */
  2624. + REG_WR_INT(eth, np->eth_inst, rw_ack_intr, ack_intr);
  2625. + clr_err.clr = 1;
  2626. + REG_WR(eth, np->eth_inst, rw_clr_err, clr_err);
  2627. +
  2628. + /* Do a full reset of the MAC block. */
  2629. + if (do_full) {
  2630. + np->tx_mac_resets++;
  2631. + crisv32_eth_reset(np);
  2632. + }
  2633. +
  2634. + crisv32_connect_eth_tx_dma(np);
  2635. +
  2636. + if (np->txpackets) {
  2637. + WARN_ON(!np->catch_tx_desc->skb);
  2638. + np->catch_tx_desc->descr.intr = 1;
  2639. + np->catch_tx_desc->descr.out_eop = 1;
  2640. +
  2641. + /* Start DMA for the first time. */
  2642. + np->ctxt_out.saved_data =
  2643. + (void *)virt_to_phys(&np->catch_tx_desc->descr);
  2644. + np->ctxt_out.saved_data_buf = np->catch_tx_desc->descr.buf;
  2645. + WARN_ON(!np->ctxt_out.saved_data_buf);
  2646. + flush_dma_descr(&np->catch_tx_desc->descr, 0);
  2647. + cris_flush_cache_range(&np->ctxt_out, sizeof np->ctxt_out);
  2648. +
  2649. + REG_WR(dma, np->dma_out_inst, rw_group_down,
  2650. + (int) virt_to_phys(&np->ctxt_out));
  2651. + DMA_WR_CMD(np->dma_out_inst, regk_dma_load_c);
  2652. + DMA_WR_CMD(np->dma_out_inst, regk_dma_load_d | regk_dma_burst);
  2653. + crisv32_eth_roll_tx_timer(np);
  2654. + np->sender_started = 1;
  2655. + }
  2656. +
  2657. + if (np->txpackets && crisv32_eth_tx_ring_full(np))
  2658. + netif_stop_queue(dev);
  2659. + else
  2660. + netif_wake_queue(dev);
  2661. +
  2662. + spin_unlock_irqrestore(&np->lock, flags);
  2663. +}
  2664. +
  2665. +/*
  2666. + * Set or clear the multicast filter for this adaptor.
  2667. + * num_addrs == -1 Promiscuous mode, receive all packets
  2668. + * num_addrs == 0 Normal mode, clear multicast list
  2669. + * num_addrs > 0 Multicast mode, receive normal and MC packets,
  2670. + * and do best-effort filtering.
  2671. + */
  2672. +static void crisv32_eth_set_rx_mode(struct net_device *dev)
  2673. +{
  2674. + int num_addr = netdev_mc_count(dev);
  2675. + unsigned long int lo_bits;
  2676. + unsigned long int hi_bits;
  2677. + reg_eth_rw_rec_ctrl rec_ctrl = {0};
  2678. + reg_eth_rw_ga_lo ga_lo = {0};
  2679. + reg_eth_rw_ga_hi ga_hi = {0};
  2680. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2681. +
  2682. + if (dev->flags & IFF_PROMISC) {
  2683. + /* Promiscuous mode. */
  2684. + lo_bits = 0xfffffffful;
  2685. + hi_bits = 0xfffffffful;
  2686. +
  2687. + /* Enable individual receive. */
  2688. + rec_ctrl = (reg_eth_rw_rec_ctrl) REG_RD(eth, np->eth_inst,
  2689. + rw_rec_ctrl);
  2690. + rec_ctrl.individual = regk_eth_yes;
  2691. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  2692. + } else if (dev->flags & IFF_ALLMULTI) {
  2693. + /* Enable all multicasts. */
  2694. + lo_bits = 0xfffffffful;
  2695. + hi_bits = 0xfffffffful;
  2696. +
  2697. + /* Disable individual receive */
  2698. + rec_ctrl =
  2699. + (reg_eth_rw_rec_ctrl) REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  2700. + rec_ctrl.individual = regk_eth_no;
  2701. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  2702. + } else if (num_addr == 0) {
  2703. + /* Normal, clear the mc list. */
  2704. + lo_bits = 0x00000000ul;
  2705. + hi_bits = 0x00000000ul;
  2706. +
  2707. + /* Disable individual receive */
  2708. + rec_ctrl =
  2709. + (reg_eth_rw_rec_ctrl) REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  2710. + rec_ctrl.individual = regk_eth_no;
  2711. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  2712. + } else {
  2713. + /* MC mode, receive normal and MC packets. */
  2714. + char hash_ix;
  2715. + struct netdev_hw_addr *ha;
  2716. + char *baddr;
  2717. + lo_bits = 0x00000000ul;
  2718. + hi_bits = 0x00000000ul;
  2719. +
  2720. + netdev_for_each_mc_addr(ha, dev) {
  2721. + /* Calculate the hash index for the GA registers. */
  2722. + hash_ix = 0;
  2723. + baddr = ha->addr;
  2724. + hash_ix ^= (*baddr) & 0x3f;
  2725. + hash_ix ^= ((*baddr) >> 6) & 0x03;
  2726. + ++baddr;
  2727. + hash_ix ^= ((*baddr) << 2) & 0x03c;
  2728. + hash_ix ^= ((*baddr) >> 4) & 0xf;
  2729. + ++baddr;
  2730. + hash_ix ^= ((*baddr) << 4) & 0x30;
  2731. + hash_ix ^= ((*baddr) >> 2) & 0x3f;
  2732. + ++baddr;
  2733. + hash_ix ^= (*baddr) & 0x3f;
  2734. + hash_ix ^= ((*baddr) >> 6) & 0x03;
  2735. + ++baddr;
  2736. + hash_ix ^= ((*baddr) << 2) & 0x03c;
  2737. + hash_ix ^= ((*baddr) >> 4) & 0xf;
  2738. + ++baddr;
  2739. + hash_ix ^= ((*baddr) << 4) & 0x30;
  2740. + hash_ix ^= ((*baddr) >> 2) & 0x3f;
  2741. +
  2742. + hash_ix &= 0x3f;
  2743. +
  2744. + if (hash_ix > 32)
  2745. + hi_bits |= (1 << (hash_ix - 32));
  2746. + else
  2747. + lo_bits |= (1 << hash_ix);
  2748. + }
  2749. +
  2750. + /* Disable individual receive. */
  2751. + rec_ctrl =
  2752. + (reg_eth_rw_rec_ctrl) REG_RD(eth, np->eth_inst, rw_rec_ctrl);
  2753. + rec_ctrl.individual = regk_eth_no;
  2754. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  2755. + }
  2756. +
  2757. + ga_lo.table = (unsigned int) lo_bits;
  2758. + ga_hi.table = (unsigned int) hi_bits;
  2759. +
  2760. + REG_WR(eth, np->eth_inst, rw_ga_lo, ga_lo);
  2761. + REG_WR(eth, np->eth_inst, rw_ga_hi, ga_hi);
  2762. +}
  2763. +
  2764. +static int
  2765. +crisv32_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2766. +{
  2767. + struct mii_ioctl_data *data = if_mii(ifr);
  2768. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2769. + int old_autoneg;
  2770. + int rc = 0;
  2771. +
  2772. + spin_lock(&np->lock); /* Preempt protection */
  2773. + switch (cmd) {
  2774. + case SET_ETH_ENABLE_LEDS:
  2775. + np->use_leds = 1;
  2776. + break;
  2777. + case SET_ETH_DISABLE_LEDS:
  2778. + np->use_leds = 0;
  2779. + break;
  2780. + case SET_ETH_AUTONEG:
  2781. + old_autoneg = np->autoneg_normal;
  2782. + np->autoneg_normal = *(int*)data;
  2783. + if (np->autoneg_normal != old_autoneg)
  2784. + crisv32_eth_negotiate(dev);
  2785. + break;
  2786. + default:
  2787. + rc = generic_mii_ioctl(&np->mii_if,
  2788. + if_mii(ifr), cmd, NULL);
  2789. + break;
  2790. + }
  2791. + spin_unlock(&np->lock);
  2792. + return rc;
  2793. +}
  2794. +
  2795. +static int crisv32_eth_get_settings(struct net_device *dev,
  2796. + struct ethtool_cmd *cmd)
  2797. +{
  2798. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2799. + int err;
  2800. +
  2801. + spin_lock_irq(&np->lock);
  2802. + err = mii_ethtool_gset(&np->mii_if, cmd);
  2803. + spin_unlock_irq(&np->lock);
  2804. +
  2805. + /* The PHY may support 1000baseT, but the EtraxFS does not. */
  2806. + cmd->supported &= ~(SUPPORTED_1000baseT_Half
  2807. + | SUPPORTED_1000baseT_Full);
  2808. + return err;
  2809. +}
  2810. +
  2811. +static int crisv32_eth_set_settings(struct net_device *dev,
  2812. + struct ethtool_cmd *ecmd)
  2813. +{
  2814. + if (ecmd->autoneg == AUTONEG_ENABLE) {
  2815. + crisv32_eth_set_duplex(dev, autoneg);
  2816. + crisv32_eth_set_speed(dev, 0);
  2817. + } else {
  2818. + crisv32_eth_set_duplex(dev, ecmd->duplex);
  2819. + crisv32_eth_set_speed(dev, ecmd->speed);
  2820. + }
  2821. +
  2822. + return 0;
  2823. +}
  2824. +
  2825. +static void crisv32_eth_get_drvinfo(struct net_device *dev,
  2826. + struct ethtool_drvinfo *info)
  2827. +{
  2828. +#ifdef CONFIG_ETRAXFS
  2829. + strncpy(info->driver, "ETRAX FS", sizeof(info->driver) - 1);
  2830. +#else
  2831. + strncpy(info->driver, "ARTPEC-3", sizeof(info->driver) - 1);
  2832. +#endif
  2833. + strncpy(info->version, "$Revision: 1.197 $", sizeof(info->version) - 1);
  2834. + strncpy(info->fw_version, "N/A", sizeof(info->fw_version) - 1);
  2835. + strncpy(info->bus_info, "N/A", sizeof(info->bus_info) - 1);
  2836. +}
  2837. +
  2838. +static int crisv32_eth_get_ethtool_sset_count(struct net_device *dev,
  2839. + int stringset)
  2840. +{
  2841. + if (stringset != ETH_SS_STATS)
  2842. + return -EINVAL;
  2843. +
  2844. + return ARRAY_SIZE(ethtool_stats_keys);
  2845. +}
  2846. +
  2847. +static void crisv32_eth_get_ethtool_stats(struct net_device *dev,
  2848. + struct ethtool_stats *stats,
  2849. + u64 *data)
  2850. +{
  2851. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2852. +
  2853. + data[0] = np->tx_dma_restarts;
  2854. + data[1] = np->tx_mac_resets;
  2855. + data[2] = np->rx_dma_restarts;
  2856. + data[3] = np->rx_dma_timeouts;
  2857. + data[4] = np->rx_restarts_dropped;
  2858. +}
  2859. +
  2860. +static void crisv32_eth_get_strings(struct net_device *dev,
  2861. + u32 stringset, u8 *data)
  2862. +{
  2863. + switch (stringset) {
  2864. + case ETH_SS_STATS:
  2865. + memcpy(data, &ethtool_stats_keys,
  2866. + sizeof(ethtool_stats_keys));
  2867. + break;
  2868. + default:
  2869. + WARN_ON(1);
  2870. + break;
  2871. + }
  2872. +}
  2873. +
  2874. +static int crisv32_eth_nway_reset(struct net_device *dev)
  2875. +{
  2876. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2877. +
  2878. + if (np->current_duplex == autoneg && np->current_speed_selection == 0)
  2879. + crisv32_eth_negotiate(dev);
  2880. + return 0;
  2881. +}
  2882. +/* The FS/A3 ethernet block has 23 32-bit config registers. */
  2883. +/* plus 2 dma_descr_context */
  2884. +/* plus 2 sets of ring pointers (active, prev, last) */
  2885. +/* plus 2 sets of DMA registers 40*4 bytes = 0xA0 */
  2886. +#define ETRAX_ETH_REGDUMP_LEN (23 * 4 + 2 * sizeof (dma_descr_context) + 2*3*4 + 2*0xA0)
  2887. +static int crisv32_eth_get_regs_len(struct net_device *dev)
  2888. +{
  2889. + return ETRAX_ETH_REGDUMP_LEN;
  2890. +}
  2891. +
  2892. +static void crisv32_eth_get_regs(struct net_device *dev,
  2893. + struct ethtool_regs *regs, void *_p)
  2894. +{
  2895. + u32 *p = _p;
  2896. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2897. + int i;
  2898. +
  2899. + /* Let's call this major version 0, minor version 1 with some
  2900. + * undecided field separation in the version data. Previously
  2901. + * only the eth regs were dumped (version=0: maj 0, min 0).*/
  2902. + regs->version = 1;
  2903. + memset(p, 0, ETRAX_ETH_REGDUMP_LEN);
  2904. +
  2905. +#define GET_REG32_LOOP(base, len) \
  2906. + do { \
  2907. + for (i = 0; i < len; i += 4) \
  2908. + *(p)++ = REG_READ(u32, (base) + i); \
  2909. + } while (0)
  2910. +
  2911. + GET_REG32_LOOP(np->eth_inst, 0x30);
  2912. + /* Do not dump registers with read side effects. */
  2913. + GET_REG32_LOOP(np->eth_inst + 0x34, 1);
  2914. + GET_REG32_LOOP(np->eth_inst + 0x3c, 1);
  2915. + GET_REG32_LOOP(np->eth_inst + 0x44, 0x5c - 0x44);
  2916. +
  2917. +
  2918. + memcpy(p, &np->ctxt_out, sizeof (dma_descr_context));
  2919. + p += sizeof (dma_descr_context)/4;
  2920. + *(p++) = (u32) np->active_tx_desc;
  2921. + *(p++) = (u32) np->prev_tx_desc;
  2922. + *(p++) = (u32) np->catch_tx_desc;
  2923. +
  2924. + GET_REG32_LOOP(np->dma_out_inst, 0xa0);
  2925. +
  2926. + memcpy(p, &np->ctxt_in, sizeof (dma_descr_context));
  2927. + p += sizeof (dma_descr_context)/4;
  2928. + *(p++) = (u32)np->active_rx_desc;
  2929. + *(p++) = (u32)np->prev_rx_desc;
  2930. + *(p++) = (u32)np->last_rx_desc;
  2931. +
  2932. + GET_REG32_LOOP(np->dma_in_inst, 0xa0);
  2933. +#undef GET_REG32_LOOP
  2934. +}
  2935. +
  2936. +static struct ethtool_ops crisv32_ethtool_ops = {
  2937. + .get_settings = crisv32_eth_get_settings,
  2938. + .set_settings = crisv32_eth_set_settings,
  2939. + .get_drvinfo = crisv32_eth_get_drvinfo,
  2940. + .get_regs_len = crisv32_eth_get_regs_len,
  2941. + .get_regs = crisv32_eth_get_regs,
  2942. + .nway_reset = crisv32_eth_nway_reset,
  2943. + .get_link = ethtool_op_get_link,
  2944. + .get_strings = crisv32_eth_get_strings,
  2945. + .get_ethtool_stats = crisv32_eth_get_ethtool_stats,
  2946. + .get_sset_count = crisv32_eth_get_ethtool_sset_count
  2947. +};
  2948. +
  2949. +/* Is this function really needed? Use ethtool instead? */
  2950. +static int crisv32_eth_set_config(struct net_device *dev, struct ifmap *map)
  2951. +{
  2952. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2953. +
  2954. + spin_lock(&np->lock); /* Preempt protection */
  2955. +
  2956. + switch (map->port) {
  2957. + case IF_PORT_UNKNOWN:
  2958. + /* Use autoneg */
  2959. + crisv32_eth_set_speed(dev, 0);
  2960. + crisv32_eth_set_duplex(dev, autoneg);
  2961. + break;
  2962. + case IF_PORT_10BASET:
  2963. + crisv32_eth_set_speed(dev, 10);
  2964. + crisv32_eth_set_duplex(dev, autoneg);
  2965. + break;
  2966. + case IF_PORT_100BASET:
  2967. + case IF_PORT_100BASETX:
  2968. + crisv32_eth_set_speed(dev, 100);
  2969. + crisv32_eth_set_duplex(dev, autoneg);
  2970. + break;
  2971. + case IF_PORT_100BASEFX:
  2972. + case IF_PORT_10BASE2:
  2973. + case IF_PORT_AUI:
  2974. + spin_unlock(&np->lock);
  2975. + return -EOPNOTSUPP;
  2976. + break;
  2977. + default:
  2978. + printk(KERN_ERR "%s: Invalid media selected",
  2979. + dev->name);
  2980. + spin_unlock(&np->lock);
  2981. + return -EINVAL;
  2982. + }
  2983. + spin_unlock(&np->lock);
  2984. + return 0;
  2985. +}
  2986. +
  2987. +static void crisv32_eth_negotiate(struct net_device *dev)
  2988. +{
  2989. + unsigned short data;
  2990. + unsigned short ctrl1000;
  2991. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  2992. +
  2993. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE);
  2994. + ctrl1000 = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  2995. + MII_CTRL1000);
  2996. +
  2997. + /* Make all capabilities available */
  2998. + data |= ADVERTISE_10HALF | ADVERTISE_10FULL |
  2999. + ADVERTISE_100HALF | ADVERTISE_100FULL;
  3000. + ctrl1000 |= ADVERTISE_1000HALF | ADVERTISE_1000FULL;
  3001. +
  3002. + /* Remove the speed capabilities that we that do not want */
  3003. + switch (np->current_speed_selection) {
  3004. + case 10 :
  3005. + data &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL);
  3006. + ctrl1000 &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
  3007. + break;
  3008. + case 100 :
  3009. + data &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL);
  3010. + ctrl1000 &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
  3011. + break;
  3012. + case 1000 :
  3013. + data &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
  3014. + ADVERTISE_100HALF | ADVERTISE_100FULL);
  3015. + break;
  3016. + }
  3017. +
  3018. + /* Remove the duplex capabilites that we do not want */
  3019. + if (np->current_duplex == full) {
  3020. + data &= ~(ADVERTISE_10HALF | ADVERTISE_100HALF);
  3021. + ctrl1000 &= ~(ADVERTISE_1000HALF);
  3022. + }
  3023. + else if (np->current_duplex == half) {
  3024. + data &= ~(ADVERTISE_10FULL | ADVERTISE_100FULL);
  3025. + ctrl1000 &= ~(ADVERTISE_1000FULL);
  3026. + }
  3027. +
  3028. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE, data);
  3029. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  3030. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id,
  3031. + MII_CTRL1000, ctrl1000);
  3032. +#endif
  3033. +
  3034. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  3035. + if (np->autoneg_normal) {
  3036. + /* Renegotiate with link partner */
  3037. + data |= BMCR_ANENABLE | BMCR_ANRESTART;
  3038. + } else {
  3039. + /* Don't negitiate speed or duplex */
  3040. + data &= ~(BMCR_ANENABLE | BMCR_ANRESTART);
  3041. +
  3042. + /* Set speed and duplex static */
  3043. + if (np->current_speed_selection == 10) {
  3044. + data &= ~(BMCR_SPEED100 | BMCR_SPEED1000);
  3045. + }
  3046. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  3047. + else if (np->current_speed_selection == 1000) {
  3048. + data &= ~BMCR_SPEED100;
  3049. + data |= BMCR_SPEED1000;
  3050. + }
  3051. +#endif
  3052. + else {
  3053. + data |= BMCR_SPEED100;
  3054. + data &= ~BMCR_SPEED1000;
  3055. + }
  3056. +
  3057. + if (np->current_duplex != full) {
  3058. + data &= ~BMCR_FULLDPLX;
  3059. + } else {
  3060. + data |= BMCR_FULLDPLX;
  3061. + }
  3062. + }
  3063. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR, data);
  3064. +}
  3065. +
  3066. +static void crisv32_eth_check_speed(unsigned long idev)
  3067. +{
  3068. +#ifndef CONFIG_ETRAX_NO_PHY
  3069. + static int led_initiated = 0;
  3070. + struct net_device *dev = (struct net_device *) idev;
  3071. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3072. +
  3073. + unsigned long data;
  3074. + int old_speed;
  3075. + unsigned long flags;
  3076. +
  3077. + BUG_ON(!np);
  3078. + BUG_ON(!np->transceiver);
  3079. +
  3080. + spin_lock(&np->transceiver_lock);
  3081. +
  3082. + old_speed = np->current_speed;
  3083. +
  3084. + /* Do a fake read. This is needed for DM9161, otherwise the link will
  3085. + * go up and down all the time.
  3086. + */
  3087. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMSR);
  3088. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMSR);
  3089. +
  3090. + if (!(data & BMSR_LSTATUS))
  3091. + np->current_speed = 0;
  3092. + else
  3093. + np->transceiver->check_speed(dev);
  3094. +
  3095. + spin_lock_irqsave(&np->leds->led_lock, flags);
  3096. + if ((old_speed != np->current_speed) || !led_initiated) {
  3097. + led_initiated = 1;
  3098. + np->leds->clear_led_timer.data = (unsigned long) dev;
  3099. + if (np->current_speed) {
  3100. + if (!np->link)
  3101. + netif_carrier_on(dev);
  3102. + crisv32_set_network_leds(CRIS_LED_LINK, dev);
  3103. + np->link = 1;
  3104. + } else {
  3105. + if (np->link)
  3106. + netif_carrier_off(dev);
  3107. + crisv32_set_network_leds(CRIS_LED_NOLINK, dev);
  3108. + np->link = 0;
  3109. + }
  3110. + }
  3111. + spin_unlock_irqrestore(&np->leds->led_lock, flags);
  3112. +
  3113. + /* Reinitialize the timer. */
  3114. + np->speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
  3115. + add_timer(&np->speed_timer);
  3116. +
  3117. + spin_unlock(&np->transceiver_lock);
  3118. +#endif
  3119. +}
  3120. +
  3121. +static void crisv32_eth_set_speed(struct net_device *dev, unsigned long speed)
  3122. +{
  3123. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3124. +
  3125. + spin_lock(&np->transceiver_lock);
  3126. + if (np->current_speed_selection != speed) {
  3127. + np->current_speed_selection = speed;
  3128. + crisv32_eth_negotiate(dev);
  3129. + }
  3130. + spin_unlock(&np->transceiver_lock);
  3131. +}
  3132. +
  3133. +static void crisv32_eth_check_duplex(unsigned long idev)
  3134. +{
  3135. +#ifndef CONFIG_ETRAX_NO_PHY
  3136. + struct net_device *dev = (struct net_device *) idev;
  3137. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3138. + reg_eth_rw_rec_ctrl rec_ctrl;
  3139. + int old_duplex = np->full_duplex;
  3140. +
  3141. + np->transceiver->check_duplex(dev);
  3142. +
  3143. + if (old_duplex != np->full_duplex) {
  3144. + /* Duplex changed. */
  3145. + rec_ctrl = (reg_eth_rw_rec_ctrl) REG_RD(eth, np->eth_inst,
  3146. + rw_rec_ctrl);
  3147. + rec_ctrl.duplex = np->full_duplex;
  3148. + REG_WR(eth, np->eth_inst, rw_rec_ctrl, rec_ctrl);
  3149. + }
  3150. +
  3151. + /* Reinitialize the timer. */
  3152. + np->duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
  3153. + add_timer(&np->duplex_timer);
  3154. +#endif
  3155. +}
  3156. +
  3157. +static void
  3158. +crisv32_eth_set_duplex(struct net_device *dev, enum duplex new_duplex)
  3159. +{
  3160. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3161. + spin_lock(&np->transceiver_lock);
  3162. + if (np->current_duplex != new_duplex) {
  3163. + np->current_duplex = new_duplex;
  3164. + crisv32_eth_negotiate(dev);
  3165. + }
  3166. + spin_unlock(&np->transceiver_lock);
  3167. +}
  3168. +
  3169. +static int crisv32_eth_probe_transceiver(struct net_device *dev)
  3170. +{
  3171. +#ifndef CONFIG_ETRAX_NO_PHY
  3172. + unsigned int phyid_high;
  3173. + unsigned int phyid_low;
  3174. + unsigned int oui;
  3175. + struct transceiver_ops *ops = NULL;
  3176. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3177. +
  3178. + /* Probe MDIO physical address. */
  3179. + for (np->mii_if.phy_id = 0;
  3180. + np->mii_if.phy_id <= 31; np->mii_if.phy_id++) {
  3181. + if (crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMSR)
  3182. + != 0xffff)
  3183. + break;
  3184. + }
  3185. +
  3186. + if (np->mii_if.phy_id == 32)
  3187. + return -ENODEV;
  3188. +
  3189. + /* Get manufacturer. */
  3190. + phyid_high = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3191. + MII_PHYSID1);
  3192. + phyid_low = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3193. + MII_PHYSID2);
  3194. +
  3195. + oui = (phyid_high << 6) | (phyid_low >> 10);
  3196. +
  3197. + for (ops = &transceivers[0]; ops->oui; ops++) {
  3198. + if (ops->oui == oui)
  3199. + break;
  3200. + }
  3201. +
  3202. + np->transceiver = ops;
  3203. +
  3204. + if (oui == DM9161_OUI) {
  3205. + /* Do not bypass the scrambler/descrambler, this is needed
  3206. + * to make 10Mbit work.
  3207. + */
  3208. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id,
  3209. + MII_DM9161_SCR,MII_DM9161_SCR_INIT);
  3210. + /* Clear 10BTCSR to default */
  3211. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id,
  3212. + MII_DM9161_10BTCSR,
  3213. + MII_DM9161_10BTCSR_INIT);
  3214. + }
  3215. + return 0;
  3216. +#else
  3217. + return -ENODEV;
  3218. +#endif
  3219. +}
  3220. +
  3221. +#ifndef CONFIG_ETRAX_NO_PHY
  3222. +static void generic_check_speed(struct net_device *dev)
  3223. +{
  3224. + unsigned long data;
  3225. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3226. +
  3227. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE);
  3228. + if ((data & ADVERTISE_100FULL) ||
  3229. + (data & ADVERTISE_100HALF))
  3230. + np->current_speed = 100;
  3231. + else
  3232. + np->current_speed = 10;
  3233. +}
  3234. +
  3235. +static void generic_check_duplex(struct net_device *dev)
  3236. +{
  3237. + unsigned long data;
  3238. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3239. +
  3240. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE);
  3241. + if ((data & ADVERTISE_10FULL) ||
  3242. + (data & ADVERTISE_100FULL))
  3243. + np->full_duplex = 1;
  3244. + else
  3245. + np->full_duplex = 0;
  3246. +}
  3247. +
  3248. +static void broadcom_check_speed(struct net_device *dev)
  3249. +{
  3250. + unsigned long data;
  3251. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3252. +
  3253. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3254. + MDIO_AUX_CTRL_STATUS_REG);
  3255. + np->current_speed = (data & MDIO_BC_SPEED ? 100 : 10);
  3256. +}
  3257. +
  3258. +static void broadcom_check_duplex(struct net_device *dev)
  3259. +{
  3260. + unsigned long data;
  3261. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3262. +
  3263. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3264. + MDIO_AUX_CTRL_STATUS_REG);
  3265. + np->full_duplex = (data & MDIO_BC_FULL_DUPLEX_IND) ? 1 : 0;
  3266. +}
  3267. +
  3268. +static void tdk_check_speed(struct net_device *dev)
  3269. +{
  3270. + unsigned long data;
  3271. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3272. +
  3273. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3274. + MDIO_TDK_DIAGNOSTIC_REG);
  3275. + np->current_speed = (data & MDIO_TDK_DIAGNOSTIC_RATE ? 100 : 10);
  3276. +}
  3277. +
  3278. +static void tdk_check_duplex(struct net_device *dev)
  3279. +{
  3280. + unsigned long data;
  3281. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3282. +
  3283. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3284. + MDIO_TDK_DIAGNOSTIC_REG);
  3285. + np->full_duplex = (data & MDIO_TDK_DIAGNOSTIC_DPLX) ? 1 : 0;
  3286. +
  3287. +}
  3288. +
  3289. +static void intel_check_speed(struct net_device *dev)
  3290. +{
  3291. + unsigned long data;
  3292. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3293. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3294. + MDIO_INT_STATUS_REG_2);
  3295. + np->current_speed = (data & MDIO_INT_SPEED ? 100 : 10);
  3296. +}
  3297. +
  3298. +static void intel_check_duplex(struct net_device *dev)
  3299. +{
  3300. + unsigned long data;
  3301. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3302. +
  3303. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3304. + MDIO_INT_STATUS_REG_2);
  3305. + np->full_duplex = (data & MDIO_INT_FULL_DUPLEX_IND) ? 1 : 0;
  3306. +}
  3307. +
  3308. +static void national_check_speed(struct net_device *dev)
  3309. +{
  3310. + unsigned long data;
  3311. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3312. +
  3313. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3314. + MDIO_NAT_LINK_AN_REG);
  3315. + if (data & MDIO_NAT_1000)
  3316. + np->current_speed = 1000;
  3317. + else if (data & MDIO_NAT_100)
  3318. + np->current_speed = 100;
  3319. + else
  3320. + np->current_speed = 10;
  3321. +}
  3322. +
  3323. +static void national_check_duplex(struct net_device *dev)
  3324. +{
  3325. + unsigned long data;
  3326. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3327. +
  3328. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3329. + MDIO_NAT_LINK_AN_REG);
  3330. + if (data & MDIO_NAT_FULL_DUPLEX_IND)
  3331. + np->full_duplex = 1;
  3332. + else
  3333. + np->full_duplex = 0;
  3334. +}
  3335. +
  3336. +static void vitesse_check_speed(struct net_device *dev)
  3337. +{
  3338. + unsigned long data;
  3339. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3340. +
  3341. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3342. + MDIO_VIT_AUX_STAT);
  3343. + if ((data & 0x18) == MDIO_VIT_1000)
  3344. + np->current_speed = 1000;
  3345. + else if ((data & 0x18) == MDIO_VIT_100)
  3346. + np->current_speed = 100;
  3347. + else
  3348. + np->current_speed = 10;
  3349. +}
  3350. +
  3351. +static void vitesse_check_duplex(struct net_device *dev)
  3352. +{
  3353. + unsigned long data;
  3354. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3355. +
  3356. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3357. + MDIO_VIT_AUX_STAT);
  3358. + if (data & 0x20)
  3359. + np->full_duplex = 1;
  3360. + else
  3361. + np->full_duplex = 0;
  3362. +}
  3363. +
  3364. +static void davicom_check_speed(struct net_device *dev)
  3365. +{
  3366. + unsigned long data;
  3367. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3368. +
  3369. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  3370. + np->current_speed = (data & BMCR_SPEED100) ? 100 : 10;
  3371. +}
  3372. +
  3373. +static void davicom_check_duplex(struct net_device *dev)
  3374. +{
  3375. + unsigned long data;
  3376. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3377. +
  3378. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  3379. + np->full_duplex = (data & BMCR_FULLDPLX) ? 1 : 0;
  3380. +}
  3381. +#endif
  3382. +
  3383. +#if 0
  3384. +static void crisv32_eth_reset_tranceiver(struct net_device *dev)
  3385. +{
  3386. + int i;
  3387. + unsigned short cmd;
  3388. + unsigned short data;
  3389. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3390. +
  3391. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  3392. +
  3393. + cmd = (MDIO_START << 14)
  3394. + | (MDIO_WRITE << 12)
  3395. + | (np->mii_if.phy_id << 7)
  3396. + | (MII_BMCR << 2);
  3397. +
  3398. + crisv32_eth_send_mdio_cmd(dev, cmd, 1);
  3399. +
  3400. + data |= 0x8000;
  3401. +
  3402. + /* Magic value is number of bits. */
  3403. + for (i = 15; i >= 0; i--)
  3404. + crisv32_eth_send_mdio_bit(dev, GET_BIT(i, data));
  3405. +}
  3406. +#endif
  3407. +
  3408. +static int
  3409. +crisv32_eth_get_mdio_reg(struct net_device *dev, int phyid, int reg_num)
  3410. +{
  3411. + int i;
  3412. + unsigned short cmd; /* Data to be sent on MDIO port. */
  3413. + unsigned short data; /* Data read from MDIO. */
  3414. +
  3415. +#ifdef CONFIG_ETRAX_NO_PHY
  3416. + return 0;
  3417. +#endif
  3418. +
  3419. + /* Start of frame, OP Code, Physical Address, Register Address. */
  3420. + cmd = (MDIO_START << 14)
  3421. + | (MDIO_READ << 12)
  3422. + | (phyid << 7)
  3423. + | (reg_num << 2);
  3424. +
  3425. + crisv32_eth_send_mdio_cmd(dev, cmd, 0);
  3426. +
  3427. + data = 0;
  3428. +
  3429. + /* Receive data. Magic value is number of bits. */
  3430. + for (i = 15; i >= 0; i--)
  3431. + data |= (crisv32_eth_receive_mdio_bit(dev) << i);
  3432. +
  3433. + return data;
  3434. +}
  3435. +
  3436. +static void
  3437. +crisv32_eth_set_mdio_reg(struct net_device *dev, int phyid, int reg, int value)
  3438. +{
  3439. + int bitCounter;
  3440. + unsigned short cmd;
  3441. +
  3442. +#ifdef CONFIG_ETRAX_NO_PHY
  3443. + return;
  3444. +#endif
  3445. + cmd = (MDIO_START << 14)
  3446. + | (MDIO_WRITE << 12)
  3447. + | (phyid << 7)
  3448. + | (reg << 2);
  3449. +
  3450. + crisv32_eth_send_mdio_cmd(dev, cmd, 1);
  3451. +
  3452. + /* Data... */
  3453. + for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
  3454. + crisv32_eth_send_mdio_bit(dev, GET_BIT(bitCounter, value));
  3455. + }
  3456. +}
  3457. +
  3458. +static void
  3459. +crisv32_eth_send_mdio_cmd(struct net_device *dev, unsigned short cmd,
  3460. + int write_cmd)
  3461. +{
  3462. + int i;
  3463. + unsigned char data = 0x2;
  3464. +
  3465. + /* Preamble. Magic value is number of bits. */
  3466. + for (i = 31; i >= 0; i--)
  3467. + crisv32_eth_send_mdio_bit(dev, GET_BIT(i, MDIO_PREAMBLE));
  3468. +
  3469. + for (i = 15; i >= 2; i--)
  3470. + crisv32_eth_send_mdio_bit(dev, GET_BIT(i, cmd));
  3471. +
  3472. + /* Turnaround. */
  3473. + for (i = 1; i >= 0; i--)
  3474. + if (write_cmd)
  3475. + crisv32_eth_send_mdio_bit(dev, GET_BIT(i, data));
  3476. + else
  3477. + crisv32_eth_receive_mdio_bit(dev);
  3478. +}
  3479. +
  3480. +static void crisv32_eth_send_mdio_bit(struct net_device *dev, unsigned char bit)
  3481. +{
  3482. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3483. +
  3484. + reg_eth_rw_mgm_ctrl mgm_ctrl = {
  3485. + .mdoe = regk_eth_yes,
  3486. + .mdio = bit & 1
  3487. + };
  3488. +
  3489. + REG_WR(eth, np->eth_inst, rw_mgm_ctrl, mgm_ctrl);
  3490. +
  3491. + udelay(1);
  3492. +
  3493. + mgm_ctrl.mdc = 1;
  3494. + REG_WR(eth, np->eth_inst, rw_mgm_ctrl, mgm_ctrl);
  3495. +
  3496. + udelay(1);
  3497. +}
  3498. +
  3499. +static unsigned char crisv32_eth_receive_mdio_bit(struct net_device *dev)
  3500. +{
  3501. + reg_eth_r_stat stat;
  3502. + reg_eth_rw_mgm_ctrl mgm_ctrl = {0};
  3503. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3504. +
  3505. + REG_WR(eth, np->eth_inst, rw_mgm_ctrl, mgm_ctrl);
  3506. + stat = REG_RD(eth, np->eth_inst, r_stat);
  3507. +
  3508. + udelay(1);
  3509. +
  3510. + mgm_ctrl.mdc = 1;
  3511. + REG_WR(eth, np->eth_inst, rw_mgm_ctrl, mgm_ctrl);
  3512. +
  3513. + udelay(1);
  3514. + return stat.mdio;
  3515. +}
  3516. +
  3517. +static void crisv32_clear_network_leds(unsigned long priv)
  3518. +{
  3519. + struct net_device *dev = (struct net_device *)priv;
  3520. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3521. + unsigned long flags;
  3522. +
  3523. + spin_lock_irqsave(&np->leds->led_lock, flags);
  3524. + if (np->leds->led_active && time_after(jiffies,
  3525. + np->leds->led_next_time)) {
  3526. + crisv32_set_network_leds(CRIS_LED_NOACTIVITY, dev);
  3527. +
  3528. + /* Set the earliest time we may set the LED */
  3529. + np->leds->led_next_time = jiffies + NET_FLASH_PAUSE;
  3530. + np->leds->led_active = 0;
  3531. + }
  3532. + spin_unlock_irqrestore(&np->leds->led_lock, flags);
  3533. +}
  3534. +
  3535. +static void crisv32_set_network_leds(int active, struct net_device *dev)
  3536. +{
  3537. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3538. + int light_leds = 0;
  3539. +
  3540. + if (np->leds->ledgrp == CRIS_LED_GRP_NONE)
  3541. + return;
  3542. +
  3543. + if (!np->use_leds)
  3544. + return;
  3545. +
  3546. + if (active == CRIS_LED_NOLINK) {
  3547. + if (dev == crisv32_dev[0])
  3548. + np->leds->ifisup[0] = 0;
  3549. + else
  3550. + np->leds->ifisup[1] = 0;
  3551. + }
  3552. + else if (active == CRIS_LED_LINK) {
  3553. + if (dev == crisv32_dev[0])
  3554. + np->leds->ifisup[0] = 1;
  3555. + else
  3556. + np->leds->ifisup[1] = 1;
  3557. +#if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
  3558. + light_leds = 1;
  3559. + } else {
  3560. + light_leds = (active == CRIS_LED_NOACTIVITY);
  3561. +#elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
  3562. + light_leds = 0;
  3563. + } else {
  3564. + light_leds = (active == CRIS_LED_ACTIVITY);
  3565. +#else
  3566. +#error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
  3567. +#endif
  3568. + }
  3569. +
  3570. + if (!np->current_speed) {
  3571. + /* Set link down if none of the interfaces that use this led
  3572. + group is up */
  3573. + if ((np->leds->ifisup[0] + np->leds->ifisup[1]) == 0) {
  3574. +#if defined(CONFIG_ETRAX_NETWORK_RED_ON_NO_CONNECTION)
  3575. + /* Make LED red, link is down */
  3576. + NET_LED_SET(np->leds->ledgrp, CRIS_LED_RED);
  3577. +#else
  3578. + NET_LED_SET(np->leds->ledgrp, CRIS_LED_OFF);
  3579. +#endif
  3580. + }
  3581. + } else if (light_leds) {
  3582. + if (np->current_speed == 10)
  3583. + NET_LED_SET(np->leds->ledgrp, CRIS_LED_ORANGE);
  3584. + else
  3585. + NET_LED_SET(np->leds->ledgrp, CRIS_LED_GREEN);
  3586. + } else
  3587. + NET_LED_SET(np->leds->ledgrp, CRIS_LED_OFF);
  3588. +}
  3589. +
  3590. +#ifdef CONFIG_NET_POLL_CONTROLLER
  3591. +static void crisv32_netpoll(struct net_device *netdev)
  3592. +{
  3593. + crisv32rx_eth_interrupt(DMA0_INTR_VECT, netdev);
  3594. +}
  3595. +#endif
  3596. +
  3597. +#ifdef CONFIG_CPU_FREQ
  3598. +static int crisv32_ethernet_freq_notifier(struct notifier_block *nb,
  3599. + unsigned long val, void *data)
  3600. +{
  3601. + struct cpufreq_freqs *freqs = data;
  3602. + int i;
  3603. + if (val != CPUFREQ_POSTCHANGE)
  3604. + return 0;
  3605. +
  3606. + for (i = 0; i < 2; i++) {
  3607. + struct net_device *dev = crisv32_dev[i];
  3608. + unsigned short data;
  3609. + if (dev == NULL)
  3610. + continue;
  3611. +
  3612. + data = crisv32_eth_get_mdio_reg(dev, np->mii_if.phy_id,
  3613. + MII_BMCR);
  3614. + if (freqs->new == 200000)
  3615. + data &= ~BMCR_PDOWN;
  3616. + else
  3617. + data |= BMCR_PDOWN;
  3618. + crisv32_eth_set_mdio_reg(dev, np->mii_if.phy_id,
  3619. + MII_BMCR, data);
  3620. + }
  3621. + return 0;
  3622. +}
  3623. +#endif
  3624. +
  3625. +#if 0
  3626. +/*
  3627. + * Must be called with the np->lock held.
  3628. + */
  3629. +static void crisv32_ethernet_bug(struct net_device *dev)
  3630. +{
  3631. + struct crisv32_ethernet_local *np = netdev_priv(dev);
  3632. + dma_descr_data *dma_pos;
  3633. + dma_descr_data *in_dma_pos;
  3634. + reg_dma_rw_stat stat = {0};
  3635. + reg_dma_rw_stat in_stat = {0};
  3636. + int i;
  3637. +
  3638. + /* Get the current output dma position. */
  3639. + stat = REG_RD(dma, np->dma_out_inst, rw_stat);
  3640. +
  3641. + dma_pos = phys_to_virt(REG_RD_INT(dma, np->dma_out_inst, rw_data));
  3642. + in_dma_pos = phys_to_virt(REG_RD_INT(dma, np->dma_in_inst, rw_data));
  3643. + in_stat = REG_RD(dma, np->dma_in_inst, rw_stat);
  3644. +
  3645. + printk("%s:\n"
  3646. + "stat.list_state=%x\n"
  3647. + "stat.mode=%x\n"
  3648. + "stat.stream_cmd_src=%x\n"
  3649. + "dma_pos=%x\n"
  3650. + "tx catch=%x active=%x\n"
  3651. + "packets=%d queue=%d sender_started=%d\n"
  3652. + "intr_vect.r_vect=%x\n"
  3653. + "dma.r_masked_intr=%x dma.rw_ack_intr=%x "
  3654. + "dma.r_intr=%x dma.rw_intr_masked=%x\n"
  3655. + "eth.r_stat=%x\n",
  3656. + __func__,
  3657. + stat.list_state, stat.mode, stat.stream_cmd_src,
  3658. + (unsigned int)dma_pos,
  3659. + (unsigned int)&np->catch_tx_desc->descr,
  3660. + (unsigned int)&np->active_tx_desc->descr,
  3661. + np->txpackets,
  3662. + netif_queue_stopped(dev), np->sender_started,
  3663. + REG_RD_INT(intr_vect, regi_irq, r_vect),
  3664. + REG_RD_INT(dma, np->dma_out_inst, r_masked_intr),
  3665. + REG_RD_INT(dma, np->dma_out_inst, rw_ack_intr),
  3666. + REG_RD_INT(dma, np->dma_out_inst, r_intr),
  3667. + REG_RD_INT(dma, np->dma_out_inst, rw_intr_mask),
  3668. + REG_RD_INT(eth, np->eth_inst, r_stat));
  3669. +
  3670. + printk("in_stat.list_state=%x\n"
  3671. + "in_stat.mode=%x\n"
  3672. + "in_stat.stream_cmd_src=%x\n"
  3673. + "in_dma_pos=%x\n"
  3674. + "rx last=%x prev=%x active=%x\n",
  3675. + in_stat.list_state, in_stat.mode, in_stat.stream_cmd_src,
  3676. + (unsigned int)in_dma_pos,
  3677. + (unsigned int)&np->last_rx_desc->descr,
  3678. + (unsigned int)&np->prev_rx_desc->descr,
  3679. + (unsigned int)&np->active_rx_desc->descr);
  3680. +
  3681. +#if 0
  3682. + printk("rx-descriptors:\n");
  3683. + for (i = 0; i < NBR_RX_DESC; i++) {
  3684. + printk("rxdesc[%d]=0x%x\n", i, (unsigned int)
  3685. + virt_to_phys(&np->dma_rx_descr_list[i].descr));
  3686. + printk("rxdesc[%d].skb=0x%x\n", i,
  3687. + (unsigned int)np->dma_rx_descr_list[i].skb);
  3688. + printk("rxdesc[%d].buf=0x%x\n", i,
  3689. + (unsigned int)np->dma_rx_descr_list[i].descr.buf);
  3690. + printk("rxdesc[%d].after=0x%x\n", i,
  3691. + (unsigned int)np->dma_rx_descr_list[i].descr.after);
  3692. + printk("rxdesc[%d].intr=%x\n", i,
  3693. + np->dma_rx_descr_list[i].descr.intr);
  3694. + printk("rxdesc[%d].eol=%x\n", i,
  3695. + np->dma_rx_descr_list[i].descr.eol);
  3696. + printk("rxdesc[%d].out_eop=%x\n", i,
  3697. + np->dma_rx_descr_list[i].descr.out_eop);
  3698. + printk("rxdesc[%d].in_eop=%x\n", i,
  3699. + np->dma_rx_descr_list[i].descr.in_eop);
  3700. + printk("rxdesc[%d].wait=%x\n", i,
  3701. + np->dma_rx_descr_list[i].descr.wait);
  3702. + }
  3703. +#endif
  3704. +
  3705. +#if 1
  3706. + printk("tx-descriptors:\n");
  3707. + for (i = 0; i < NBR_TX_DESC; i++) {
  3708. + printk("txdesc[%d]=0x%x\n", i, (unsigned int)
  3709. + virt_to_phys(&np->dma_tx_descr_list[i].descr));
  3710. + printk("txdesc[%d].skb=0x%x\n", i,
  3711. + (unsigned int)np->dma_tx_descr_list[i].skb);
  3712. + printk("txdesc[%d].buf=0x%x\n", i,
  3713. + (unsigned int)np->dma_tx_descr_list[i].descr.buf);
  3714. + printk("txdesc[%d].after=0x%x\n", i,
  3715. + (unsigned int)np->dma_tx_descr_list[i].descr.after);
  3716. + printk("txdesc[%d].intr=%x\n", i,
  3717. + np->dma_tx_descr_list[i].descr.intr);
  3718. + printk("txdesc[%d].eol=%x\n", i,
  3719. + np->dma_tx_descr_list[i].descr.eol);
  3720. + printk("txdesc[%d].out_eop=%x\n", i,
  3721. + np->dma_tx_descr_list[i].descr.out_eop);
  3722. + printk("txdesc[%d].in_eop=%x\n", i,
  3723. + np->dma_tx_descr_list[i].descr.in_eop);
  3724. + printk("txdesc[%d].wait=%x\n", i,
  3725. + np->dma_tx_descr_list[i].descr.wait);
  3726. + }
  3727. +#endif
  3728. +}
  3729. +#endif
  3730. +
  3731. +static int __init crisv32_boot_setup(char *str)
  3732. +{
  3733. + struct sockaddr sa = {0};
  3734. + int i;
  3735. +
  3736. + /* Parse the colon separated Ethernet station address */
  3737. + for (i = 0; i < ETH_ALEN; i++) {
  3738. + unsigned int tmp;
  3739. + if (sscanf(str + 3*i, "%2x", &tmp) != 1) {
  3740. + printk(KERN_WARNING "Malformed station address");
  3741. + return 0;
  3742. + }
  3743. + sa.sa_data[i] = (char)tmp;
  3744. + }
  3745. +
  3746. + default_mac_iface0 = sa;
  3747. + return 1;
  3748. +}
  3749. +
  3750. +__setup("crisv32_eth=", crisv32_boot_setup);
  3751. +
  3752. +module_init(crisv32_ethernet_init);
  3753. diff --git a/drivers/net/cris/eth_v32.h b/drivers/net/cris/eth_v32.h
  3754. new file mode 100644
  3755. index 0000000..b6b0c7c
  3756. --- /dev/null
  3757. +++ b/drivers/net/cris/eth_v32.h
  3758. @@ -0,0 +1,297 @@
  3759. +/*
  3760. + * Definitions for ETRAX FS ethernet driver.
  3761. + *
  3762. + * Copyright (C) 2003, 2004, 2005 Axis Communications.
  3763. + */
  3764. +
  3765. +#ifndef _ETRAX_ETHERNET_H_
  3766. +#define _ETRAX_ETHERNET_H_
  3767. +
  3768. +#include <hwregs/dma.h>
  3769. +
  3770. +#define MAX_MEDIA_DATA_SIZE 1522 /* Max packet size. */
  3771. +
  3772. +#define NBR_RX_DESC 128 /* Number of RX descriptors. */
  3773. +#define NBR_TX_DESC 16 /* Number of TX descriptors. */
  3774. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  3775. +#define NBR_INTMEM_RX_DESC 16 /* Number of RX descriptors in int. mem.
  3776. + * when running in gigabit mode.
  3777. + * Should be less then NBR_RX_DESC
  3778. + */
  3779. +#define NBR_INTMEM_TX_BUF 4 /* Number of TX buffers in int. mem
  3780. + * when running in gigabit mode.
  3781. + * Should be less than NBR_TX_DESC
  3782. + */
  3783. +#endif
  3784. +
  3785. +/* Large packets are sent directly to upper layers while small packets
  3786. + * are copied (to reduce memory waste). The following constant
  3787. + * decides the breakpoint.
  3788. + */
  3789. +#define RX_COPYBREAK (256)
  3790. +
  3791. +#define ETHER_HEAD_LEN (14)
  3792. +
  3793. +/*
  3794. + * MDIO constants.
  3795. + */
  3796. +#define MDIO_START 0x1
  3797. +#define MDIO_READ 0x2
  3798. +#define MDIO_WRITE 0x1
  3799. +#define MDIO_PREAMBLE 0xfffffffful
  3800. +
  3801. +/* Broadcom specific */
  3802. +#define MDIO_AUX_CTRL_STATUS_REG 0x18
  3803. +#define MDIO_BC_FULL_DUPLEX_IND 0x1
  3804. +#define MDIO_BC_SPEED 0x2
  3805. +
  3806. +/* TDK specific */
  3807. +#define MDIO_TDK_DIAGNOSTIC_REG 18
  3808. +#define MDIO_TDK_DIAGNOSTIC_RATE 0x400
  3809. +#define MDIO_TDK_DIAGNOSTIC_DPLX 0x800
  3810. +
  3811. +/*Intel LXT972A specific*/
  3812. +#define MDIO_INT_STATUS_REG_2 0x0011
  3813. +#define MDIO_INT_FULL_DUPLEX_IND ( 0x0001 << 9 )
  3814. +#define MDIO_INT_SPEED ( 0x0001 << 14 )
  3815. +
  3816. +/*National Semiconductor DP83865 specific*/
  3817. +#define MDIO_NAT_LINK_AN_REG 0x11
  3818. +#define MDIO_NAT_1000 (0x0001 << 4)
  3819. +#define MDIO_NAT_100 (0x0001 << 3)
  3820. +#define MDIO_NAT_FULL_DUPLEX_IND (0x0001 << 1)
  3821. +
  3822. +/* Vitesse VCS8641 specific */
  3823. +#define MDIO_VIT_AUX_STAT 0x1c
  3824. +#define MDIO_VIT_1000 (0x2 << 3)
  3825. +#define MDIO_VIT_100 (0x1 << 3)
  3826. +#define MDIO_VIT_10 0
  3827. +#define MDIO_VIT_FD (0x1 << 5)
  3828. +
  3829. +/* Davicom DM9161 specific */
  3830. +#define DM9161_OUI 0x606E
  3831. +#define MII_DM9161_SCR 0x10
  3832. +#define MII_DM9161_SCR_INIT 0x0610
  3833. +#define MII_DM9161_SCR_RMII 0x0100
  3834. +#define MII_DM9161_10BTCSR 0x12
  3835. +#define MII_DM9161_10BTCSR_INIT 0x7800
  3836. +
  3837. +/* Network flash constants */
  3838. +#define NET_FLASH_TIME (HZ/50) /* 20 ms */
  3839. +#define NET_FLASH_PAUSE (HZ/100) /* 10 ms */
  3840. +#define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 seconds. */
  3841. +#define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 seconds. */
  3842. +
  3843. +/* Duplex settings. */
  3844. +enum duplex {
  3845. + half,
  3846. + full,
  3847. + autoneg
  3848. +};
  3849. +
  3850. +/* Some transceivers requires special handling. */
  3851. +struct transceiver_ops {
  3852. + unsigned int oui;
  3853. + void (*check_speed) (struct net_device * dev);
  3854. + void (*check_duplex) (struct net_device * dev);
  3855. +};
  3856. +
  3857. +typedef struct crisv32_eth_descr {
  3858. + dma_descr_data descr __attribute__ ((__aligned__(32)));
  3859. + struct sk_buff *skb;
  3860. + unsigned char *linearized_packet;
  3861. +} crisv32_eth_descr;
  3862. +
  3863. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  3864. +struct tx_buffer_list {
  3865. + struct tx_buffer_list *next;
  3866. + unsigned char *buf;
  3867. + char free;
  3868. +};
  3869. +#endif
  3870. +
  3871. +/* LED stuff */
  3872. +#define CRIS_LED_GRP_0 0
  3873. +#define CRIS_LED_GRP_1 1
  3874. +#define CRIS_LED_GRP_NONE 2
  3875. +
  3876. +#define CRIS_LED_ACTIVITY 0
  3877. +#define CRIS_LED_NOACTIVITY 1
  3878. +#define CRIS_LED_LINK 2
  3879. +#define CRIS_LED_NOLINK 3
  3880. +
  3881. +struct crisv32_eth_leds {
  3882. + unsigned int ledgrp;
  3883. + int led_active;
  3884. + unsigned long led_next_time;
  3885. + struct timer_list clear_led_timer;
  3886. + spinlock_t led_lock; /* Protect LED state */
  3887. + int ifisup[2];
  3888. +};
  3889. +
  3890. +#define NET_LED_SET(x,y) \
  3891. + do { \
  3892. + if (x == 0) CRIS_LED_NETWORK_GRP0_SET(y); \
  3893. + if (x == 1) CRIS_LED_NETWORK_GRP1_SET(y); \
  3894. + } while (0)
  3895. +
  3896. +/* Information that need to be kept for each device. */
  3897. +struct crisv32_ethernet_local {
  3898. + /* FIXME: These align attributes don't really help. If they are really
  3899. + * needed alignment has to be enforced at runtime, these objects
  3900. + * are dynamically allocated. */
  3901. + dma_descr_context ctxt_in __attribute__ ((__aligned__(32)));
  3902. + dma_descr_context ctxt_out __attribute__ ((__aligned__(32)));
  3903. +
  3904. + crisv32_eth_descr dma_rx_descr_list[NBR_RX_DESC];
  3905. + crisv32_eth_descr dma_tx_descr_list[NBR_TX_DESC];
  3906. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  3907. + struct tx_buffer_list tx_intmem_buf_list[NBR_INTMEM_TX_BUF];
  3908. + struct tx_buffer_list *intmem_tx_buf_active;
  3909. + struct tx_buffer_list *intmem_tx_buf_catch;
  3910. + int gigabit_mode;
  3911. +#endif
  3912. + /* Transmit data path. */
  3913. + int dma_out_inst;
  3914. + int sender_started;
  3915. +
  3916. + /* TX-ring state. */
  3917. + crisv32_eth_descr *active_tx_desc;
  3918. + crisv32_eth_descr *prev_tx_desc;
  3919. + crisv32_eth_descr *catch_tx_desc;
  3920. + int txpackets;
  3921. + int retrans;
  3922. + int do_tx_recovery;
  3923. + struct timer_list transmit_timer;
  3924. +
  3925. + /* Receive data path. */
  3926. + struct napi_struct napi;
  3927. + int dma_in_inst;
  3928. +
  3929. + /* RX-ring state. */
  3930. + crisv32_eth_descr *active_rx_desc;
  3931. + crisv32_eth_descr *prev_rx_desc;
  3932. + crisv32_eth_descr *last_rx_desc;
  3933. +
  3934. + unsigned long newbuf;
  3935. + u8 new_rx_package;
  3936. + u8 pending_overrun;
  3937. + u8 overrun_set;
  3938. + u8 link;
  3939. + int napi_processing;
  3940. + struct timer_list receive_timer;
  3941. + struct work_struct receive_work;
  3942. + reg_eth_rw_rec_ctrl saved_rec_ctrl;
  3943. + int saved_ga_lo;
  3944. + int saved_ga_hi;
  3945. + int do_rx_recovery;
  3946. +
  3947. + /* Control paths. */
  3948. + spinlock_t lock;
  3949. + struct net_device *dev;
  3950. + int eth_inst;
  3951. +
  3952. + /* Toggle network LEDs usage at runtime */
  3953. + int use_leds;
  3954. + struct crisv32_eth_leds *leds;
  3955. +
  3956. + /* PHY control. */
  3957. + int fixed_phy;
  3958. + spinlock_t transceiver_lock; /* Protect transceiver state. */
  3959. + struct transceiver_ops *transceiver;
  3960. + struct mii_if_info mii_if;
  3961. +
  3962. + /* Specifies if we should do autonegotiation or not.
  3963. + * TODO: This ad-hoc hack should be removed. Ethtool already supports
  3964. + * this kind of control.
  3965. + */
  3966. + int autoneg_normal;
  3967. +
  3968. + struct timer_list duplex_timer;
  3969. + int full_duplex;
  3970. + enum duplex current_duplex;
  3971. +
  3972. + struct timer_list speed_timer;
  3973. + int current_speed; /* Speed read from tranceiver */
  3974. + int current_speed_selection; /* Speed selected by user */
  3975. +
  3976. + /* Statistics. */
  3977. + u64 tx_dma_restarts;
  3978. + u64 tx_mac_resets;
  3979. + u64 rx_dma_restarts;
  3980. + u64 rx_dma_timeouts;
  3981. + u64 rx_restarts_dropped;
  3982. +
  3983. + struct net_device_stats stats;
  3984. +};
  3985. +
  3986. +/* Function prototypes. */
  3987. +static int crisv32_ethernet_init(void);
  3988. +static int crisv32_ethernet_device_init(struct net_device *dev);
  3989. +static int crisv32_eth_open(struct net_device *dev);
  3990. +static int crisv32_eth_close(struct net_device *dev);
  3991. +static int crisv32_eth_set_mac_address(struct net_device *dev, void *vpntr);
  3992. +static irqreturn_t crisv32rx_eth_interrupt(int irq, void *dev_id);
  3993. +static irqreturn_t crisv32tx_eth_interrupt(int irq, void *dev_id);
  3994. +static irqreturn_t crisv32nw_eth_interrupt(int irq, void *dev_id);
  3995. +static int crisv32_eth_send_packet(struct sk_buff *skb, struct net_device *dev);
  3996. +static void crisv32_eth_hw_send_packet(unsigned char *buf, int length,
  3997. + void *priv);
  3998. +static void crisv32_eth_do_tx_recovery(struct net_device *dev);
  3999. +static void crisv32_eth_set_rx_mode(struct net_device *dev);
  4000. +static int crisv32_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
  4001. + int cmd);
  4002. +static int crisv32_eth_set_config(struct net_device *dev, struct ifmap *map);
  4003. +#ifdef CONFIG_CRIS_MACH_ARTPEC3
  4004. +static void crisv32_eth_switch_intmem_usage(struct net_device *dev);
  4005. +#endif
  4006. +static void crisv32_eth_negotiate(struct net_device *dev);
  4007. +static void crisv32_eth_set_speed(struct net_device *dev, unsigned long speed);
  4008. +#ifndef CONFIG_ETRAX_NO_PHY
  4009. +static void crisv32_eth_check_duplex(unsigned long idev);
  4010. +static void crisv32_eth_check_speed(unsigned long idev);
  4011. +#endif
  4012. +
  4013. +static void crisv32_eth_set_duplex(struct net_device *dev, enum duplex);
  4014. +static int crisv32_eth_probe_transceiver(struct net_device *dev);
  4015. +
  4016. +static struct ethtool_ops crisv32_ethtool_ops;
  4017. +
  4018. +#ifndef CONFIG_ETRAX_NO_PHY
  4019. +static void generic_check_speed(struct net_device *dev);
  4020. +static void generic_check_duplex(struct net_device *dev);
  4021. +static void broadcom_check_speed(struct net_device *dev);
  4022. +static void broadcom_check_duplex(struct net_device *dev);
  4023. +static void tdk_check_speed(struct net_device *dev);
  4024. +static void tdk_check_duplex(struct net_device *dev);
  4025. +static void intel_check_speed(struct net_device *dev);
  4026. +static void intel_check_duplex(struct net_device *dev);
  4027. +static void national_check_speed(struct net_device *dev);
  4028. +static void national_check_duplex(struct net_device *dev);
  4029. +static void vitesse_check_speed(struct net_device *dev);
  4030. +static void vitesse_check_duplex(struct net_device *dev);
  4031. +static void davicom_check_speed(struct net_device *dev);
  4032. +static void davicom_check_duplex(struct net_device *dev);
  4033. +#endif
  4034. +
  4035. +#ifdef CONFIG_NET_POLL_CONTROLLER
  4036. +static void crisv32_netpoll(struct net_device *dev);
  4037. +#endif
  4038. +
  4039. +static void crisv32_clear_network_leds(unsigned long dummy);
  4040. +static void crisv32_set_network_leds(int active, struct net_device *dev);
  4041. +
  4042. +static int crisv32_eth_get_mdio_reg(struct net_device *dev,
  4043. + int phyid, int reg_num);
  4044. +static void crisv32_eth_set_mdio_reg(struct net_device *dev,
  4045. + int phyid, int reg_num, int val);
  4046. +static void crisv32_eth_send_mdio_cmd(struct net_device *dev,
  4047. + unsigned short cmd, int write_cmd);
  4048. +static void crisv32_eth_send_mdio_bit(struct net_device *dev,
  4049. + unsigned char bit);
  4050. +static unsigned char crisv32_eth_receive_mdio_bit(struct net_device *dev);
  4051. +
  4052. +static struct net_device_stats *crisv32_get_stats(struct net_device *dev);
  4053. +static void crisv32_start_dma_out(struct crisv32_ethernet_local *np);
  4054. +
  4055. +#endif /* _ETRAX_ETHERNET_H_ */