sh_eth.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795
  1. /*
  2. * SuperH Ethernet device driver
  3. *
  4. * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
  5. * Copyright (C) 2008-2013 Renesas Solutions Corp.
  6. * Copyright (C) 2013 Cogent Embedded, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * The full GNU General Public License is included in this distribution in
  21. * the file called "COPYING".
  22. */
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/delay.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/mdio-bitbang.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/phy.h>
  35. #include <linux/cache.h>
  36. #include <linux/io.h>
  37. #include <linux/pm_runtime.h>
  38. #include <linux/slab.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/clk.h>
  42. #include <linux/sh_eth.h>
  43. #include "sh_eth.h"
  44. #define SH_ETH_DEF_MSG_ENABLE \
  45. (NETIF_MSG_LINK | \
  46. NETIF_MSG_TIMER | \
  47. NETIF_MSG_RX_ERR| \
  48. NETIF_MSG_TX_ERR)
  49. static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
  50. [EDSR] = 0x0000,
  51. [EDMR] = 0x0400,
  52. [EDTRR] = 0x0408,
  53. [EDRRR] = 0x0410,
  54. [EESR] = 0x0428,
  55. [EESIPR] = 0x0430,
  56. [TDLAR] = 0x0010,
  57. [TDFAR] = 0x0014,
  58. [TDFXR] = 0x0018,
  59. [TDFFR] = 0x001c,
  60. [RDLAR] = 0x0030,
  61. [RDFAR] = 0x0034,
  62. [RDFXR] = 0x0038,
  63. [RDFFR] = 0x003c,
  64. [TRSCER] = 0x0438,
  65. [RMFCR] = 0x0440,
  66. [TFTR] = 0x0448,
  67. [FDR] = 0x0450,
  68. [RMCR] = 0x0458,
  69. [RPADIR] = 0x0460,
  70. [FCFTR] = 0x0468,
  71. [CSMR] = 0x04E4,
  72. [ECMR] = 0x0500,
  73. [ECSR] = 0x0510,
  74. [ECSIPR] = 0x0518,
  75. [PIR] = 0x0520,
  76. [PSR] = 0x0528,
  77. [PIPR] = 0x052c,
  78. [RFLR] = 0x0508,
  79. [APR] = 0x0554,
  80. [MPR] = 0x0558,
  81. [PFTCR] = 0x055c,
  82. [PFRCR] = 0x0560,
  83. [TPAUSER] = 0x0564,
  84. [GECMR] = 0x05b0,
  85. [BCULR] = 0x05b4,
  86. [MAHR] = 0x05c0,
  87. [MALR] = 0x05c8,
  88. [TROCR] = 0x0700,
  89. [CDCR] = 0x0708,
  90. [LCCR] = 0x0710,
  91. [CEFCR] = 0x0740,
  92. [FRECR] = 0x0748,
  93. [TSFRCR] = 0x0750,
  94. [TLFRCR] = 0x0758,
  95. [RFCR] = 0x0760,
  96. [CERCR] = 0x0768,
  97. [CEECR] = 0x0770,
  98. [MAFCR] = 0x0778,
  99. [RMII_MII] = 0x0790,
  100. [ARSTR] = 0x0000,
  101. [TSU_CTRST] = 0x0004,
  102. [TSU_FWEN0] = 0x0010,
  103. [TSU_FWEN1] = 0x0014,
  104. [TSU_FCM] = 0x0018,
  105. [TSU_BSYSL0] = 0x0020,
  106. [TSU_BSYSL1] = 0x0024,
  107. [TSU_PRISL0] = 0x0028,
  108. [TSU_PRISL1] = 0x002c,
  109. [TSU_FWSL0] = 0x0030,
  110. [TSU_FWSL1] = 0x0034,
  111. [TSU_FWSLC] = 0x0038,
  112. [TSU_QTAG0] = 0x0040,
  113. [TSU_QTAG1] = 0x0044,
  114. [TSU_FWSR] = 0x0050,
  115. [TSU_FWINMK] = 0x0054,
  116. [TSU_ADQT0] = 0x0048,
  117. [TSU_ADQT1] = 0x004c,
  118. [TSU_VTAG0] = 0x0058,
  119. [TSU_VTAG1] = 0x005c,
  120. [TSU_ADSBSY] = 0x0060,
  121. [TSU_TEN] = 0x0064,
  122. [TSU_POST1] = 0x0070,
  123. [TSU_POST2] = 0x0074,
  124. [TSU_POST3] = 0x0078,
  125. [TSU_POST4] = 0x007c,
  126. [TSU_ADRH0] = 0x0100,
  127. [TSU_ADRL0] = 0x0104,
  128. [TSU_ADRH31] = 0x01f8,
  129. [TSU_ADRL31] = 0x01fc,
  130. [TXNLCR0] = 0x0080,
  131. [TXALCR0] = 0x0084,
  132. [RXNLCR0] = 0x0088,
  133. [RXALCR0] = 0x008c,
  134. [FWNLCR0] = 0x0090,
  135. [FWALCR0] = 0x0094,
  136. [TXNLCR1] = 0x00a0,
  137. [TXALCR1] = 0x00a0,
  138. [RXNLCR1] = 0x00a8,
  139. [RXALCR1] = 0x00ac,
  140. [FWNLCR1] = 0x00b0,
  141. [FWALCR1] = 0x00b4,
  142. };
  143. static const u16 sh_eth_offset_fast_rcar[SH_ETH_MAX_REGISTER_OFFSET] = {
  144. [ECMR] = 0x0300,
  145. [RFLR] = 0x0308,
  146. [ECSR] = 0x0310,
  147. [ECSIPR] = 0x0318,
  148. [PIR] = 0x0320,
  149. [PSR] = 0x0328,
  150. [RDMLR] = 0x0340,
  151. [IPGR] = 0x0350,
  152. [APR] = 0x0354,
  153. [MPR] = 0x0358,
  154. [RFCF] = 0x0360,
  155. [TPAUSER] = 0x0364,
  156. [TPAUSECR] = 0x0368,
  157. [MAHR] = 0x03c0,
  158. [MALR] = 0x03c8,
  159. [TROCR] = 0x03d0,
  160. [CDCR] = 0x03d4,
  161. [LCCR] = 0x03d8,
  162. [CNDCR] = 0x03dc,
  163. [CEFCR] = 0x03e4,
  164. [FRECR] = 0x03e8,
  165. [TSFRCR] = 0x03ec,
  166. [TLFRCR] = 0x03f0,
  167. [RFCR] = 0x03f4,
  168. [MAFCR] = 0x03f8,
  169. [EDMR] = 0x0200,
  170. [EDTRR] = 0x0208,
  171. [EDRRR] = 0x0210,
  172. [TDLAR] = 0x0218,
  173. [RDLAR] = 0x0220,
  174. [EESR] = 0x0228,
  175. [EESIPR] = 0x0230,
  176. [TRSCER] = 0x0238,
  177. [RMFCR] = 0x0240,
  178. [TFTR] = 0x0248,
  179. [FDR] = 0x0250,
  180. [RMCR] = 0x0258,
  181. [TFUCR] = 0x0264,
  182. [RFOCR] = 0x0268,
  183. [RMIIMODE] = 0x026c,
  184. [FCFTR] = 0x0270,
  185. [TRIMD] = 0x027c,
  186. };
  187. static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = {
  188. [ECMR] = 0x0100,
  189. [RFLR] = 0x0108,
  190. [ECSR] = 0x0110,
  191. [ECSIPR] = 0x0118,
  192. [PIR] = 0x0120,
  193. [PSR] = 0x0128,
  194. [RDMLR] = 0x0140,
  195. [IPGR] = 0x0150,
  196. [APR] = 0x0154,
  197. [MPR] = 0x0158,
  198. [TPAUSER] = 0x0164,
  199. [RFCF] = 0x0160,
  200. [TPAUSECR] = 0x0168,
  201. [BCFRR] = 0x016c,
  202. [MAHR] = 0x01c0,
  203. [MALR] = 0x01c8,
  204. [TROCR] = 0x01d0,
  205. [CDCR] = 0x01d4,
  206. [LCCR] = 0x01d8,
  207. [CNDCR] = 0x01dc,
  208. [CEFCR] = 0x01e4,
  209. [FRECR] = 0x01e8,
  210. [TSFRCR] = 0x01ec,
  211. [TLFRCR] = 0x01f0,
  212. [RFCR] = 0x01f4,
  213. [MAFCR] = 0x01f8,
  214. [RTRATE] = 0x01fc,
  215. [EDMR] = 0x0000,
  216. [EDTRR] = 0x0008,
  217. [EDRRR] = 0x0010,
  218. [TDLAR] = 0x0018,
  219. [RDLAR] = 0x0020,
  220. [EESR] = 0x0028,
  221. [EESIPR] = 0x0030,
  222. [TRSCER] = 0x0038,
  223. [RMFCR] = 0x0040,
  224. [TFTR] = 0x0048,
  225. [FDR] = 0x0050,
  226. [RMCR] = 0x0058,
  227. [TFUCR] = 0x0064,
  228. [RFOCR] = 0x0068,
  229. [FCFTR] = 0x0070,
  230. [RPADIR] = 0x0078,
  231. [TRIMD] = 0x007c,
  232. [RBWAR] = 0x00c8,
  233. [RDFAR] = 0x00cc,
  234. [TBRAR] = 0x00d4,
  235. [TDFAR] = 0x00d8,
  236. };
  237. static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = {
  238. [ECMR] = 0x0160,
  239. [ECSR] = 0x0164,
  240. [ECSIPR] = 0x0168,
  241. [PIR] = 0x016c,
  242. [MAHR] = 0x0170,
  243. [MALR] = 0x0174,
  244. [RFLR] = 0x0178,
  245. [PSR] = 0x017c,
  246. [TROCR] = 0x0180,
  247. [CDCR] = 0x0184,
  248. [LCCR] = 0x0188,
  249. [CNDCR] = 0x018c,
  250. [CEFCR] = 0x0194,
  251. [FRECR] = 0x0198,
  252. [TSFRCR] = 0x019c,
  253. [TLFRCR] = 0x01a0,
  254. [RFCR] = 0x01a4,
  255. [MAFCR] = 0x01a8,
  256. [IPGR] = 0x01b4,
  257. [APR] = 0x01b8,
  258. [MPR] = 0x01bc,
  259. [TPAUSER] = 0x01c4,
  260. [BCFR] = 0x01cc,
  261. [ARSTR] = 0x0000,
  262. [TSU_CTRST] = 0x0004,
  263. [TSU_FWEN0] = 0x0010,
  264. [TSU_FWEN1] = 0x0014,
  265. [TSU_FCM] = 0x0018,
  266. [TSU_BSYSL0] = 0x0020,
  267. [TSU_BSYSL1] = 0x0024,
  268. [TSU_PRISL0] = 0x0028,
  269. [TSU_PRISL1] = 0x002c,
  270. [TSU_FWSL0] = 0x0030,
  271. [TSU_FWSL1] = 0x0034,
  272. [TSU_FWSLC] = 0x0038,
  273. [TSU_QTAGM0] = 0x0040,
  274. [TSU_QTAGM1] = 0x0044,
  275. [TSU_ADQT0] = 0x0048,
  276. [TSU_ADQT1] = 0x004c,
  277. [TSU_FWSR] = 0x0050,
  278. [TSU_FWINMK] = 0x0054,
  279. [TSU_ADSBSY] = 0x0060,
  280. [TSU_TEN] = 0x0064,
  281. [TSU_POST1] = 0x0070,
  282. [TSU_POST2] = 0x0074,
  283. [TSU_POST3] = 0x0078,
  284. [TSU_POST4] = 0x007c,
  285. [TXNLCR0] = 0x0080,
  286. [TXALCR0] = 0x0084,
  287. [RXNLCR0] = 0x0088,
  288. [RXALCR0] = 0x008c,
  289. [FWNLCR0] = 0x0090,
  290. [FWALCR0] = 0x0094,
  291. [TXNLCR1] = 0x00a0,
  292. [TXALCR1] = 0x00a0,
  293. [RXNLCR1] = 0x00a8,
  294. [RXALCR1] = 0x00ac,
  295. [FWNLCR1] = 0x00b0,
  296. [FWALCR1] = 0x00b4,
  297. [TSU_ADRH0] = 0x0100,
  298. [TSU_ADRL0] = 0x0104,
  299. [TSU_ADRL31] = 0x01fc,
  300. };
  301. static int sh_eth_is_gether(struct sh_eth_private *mdp)
  302. {
  303. if (mdp->reg_offset == sh_eth_offset_gigabit)
  304. return 1;
  305. else
  306. return 0;
  307. }
  308. static void sh_eth_select_mii(struct net_device *ndev)
  309. {
  310. u32 value = 0x0;
  311. struct sh_eth_private *mdp = netdev_priv(ndev);
  312. switch (mdp->phy_interface) {
  313. case PHY_INTERFACE_MODE_GMII:
  314. value = 0x2;
  315. break;
  316. case PHY_INTERFACE_MODE_MII:
  317. value = 0x1;
  318. break;
  319. case PHY_INTERFACE_MODE_RMII:
  320. value = 0x0;
  321. break;
  322. default:
  323. pr_warn("PHY interface mode was not setup. Set to MII.\n");
  324. value = 0x1;
  325. break;
  326. }
  327. sh_eth_write(ndev, value, RMII_MII);
  328. }
  329. static void sh_eth_set_duplex(struct net_device *ndev)
  330. {
  331. struct sh_eth_private *mdp = netdev_priv(ndev);
  332. if (mdp->duplex) /* Full */
  333. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_DM, ECMR);
  334. else /* Half */
  335. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_DM, ECMR);
  336. }
  337. /* There is CPU dependent code */
  338. static void sh_eth_set_rate_r8a777x(struct net_device *ndev)
  339. {
  340. struct sh_eth_private *mdp = netdev_priv(ndev);
  341. switch (mdp->speed) {
  342. case 10: /* 10BASE */
  343. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_ELB, ECMR);
  344. break;
  345. case 100:/* 100BASE */
  346. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_ELB, ECMR);
  347. break;
  348. default:
  349. break;
  350. }
  351. }
  352. /* R8A7778/9 */
  353. static struct sh_eth_cpu_data r8a777x_data = {
  354. .set_duplex = sh_eth_set_duplex,
  355. .set_rate = sh_eth_set_rate_r8a777x,
  356. .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
  357. .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
  358. .eesipr_value = 0x01ff009f,
  359. .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
  360. .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
  361. EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
  362. EESR_ECI,
  363. .apr = 1,
  364. .mpr = 1,
  365. .tpauser = 1,
  366. .hw_swap = 1,
  367. };
  368. /* R8A7790 */
  369. static struct sh_eth_cpu_data r8a7790_data = {
  370. .set_duplex = sh_eth_set_duplex,
  371. .set_rate = sh_eth_set_rate_r8a777x,
  372. .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
  373. .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
  374. .eesipr_value = 0x01ff009f,
  375. .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
  376. .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE |
  377. EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI,
  378. .apr = 1,
  379. .mpr = 1,
  380. .tpauser = 1,
  381. .hw_swap = 1,
  382. .rmiimode = 1,
  383. };
  384. static void sh_eth_set_rate_sh7724(struct net_device *ndev)
  385. {
  386. struct sh_eth_private *mdp = netdev_priv(ndev);
  387. switch (mdp->speed) {
  388. case 10: /* 10BASE */
  389. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) & ~ECMR_RTM, ECMR);
  390. break;
  391. case 100:/* 100BASE */
  392. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) | ECMR_RTM, ECMR);
  393. break;
  394. default:
  395. break;
  396. }
  397. }
  398. /* SH7724 */
  399. static struct sh_eth_cpu_data sh7724_data = {
  400. .set_duplex = sh_eth_set_duplex,
  401. .set_rate = sh_eth_set_rate_sh7724,
  402. .ecsr_value = ECSR_PSRTO | ECSR_LCHNG | ECSR_ICD,
  403. .ecsipr_value = ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | ECSIPR_ICDIP,
  404. .eesipr_value = 0x01ff009f,
  405. .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
  406. .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
  407. EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
  408. EESR_ECI,
  409. .apr = 1,
  410. .mpr = 1,
  411. .tpauser = 1,
  412. .hw_swap = 1,
  413. .rpadir = 1,
  414. .rpadir_value = 0x00020000, /* NET_IP_ALIGN assumed to be 2 */
  415. };
  416. static void sh_eth_set_rate_sh7757(struct net_device *ndev)
  417. {
  418. struct sh_eth_private *mdp = netdev_priv(ndev);
  419. switch (mdp->speed) {
  420. case 10: /* 10BASE */
  421. sh_eth_write(ndev, 0, RTRATE);
  422. break;
  423. case 100:/* 100BASE */
  424. sh_eth_write(ndev, 1, RTRATE);
  425. break;
  426. default:
  427. break;
  428. }
  429. }
  430. /* SH7757 */
  431. static struct sh_eth_cpu_data sh7757_data = {
  432. .set_duplex = sh_eth_set_duplex,
  433. .set_rate = sh_eth_set_rate_sh7757,
  434. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  435. .rmcr_value = 0x00000001,
  436. .tx_check = EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO,
  437. .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
  438. EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
  439. EESR_ECI,
  440. .irq_flags = IRQF_SHARED,
  441. .apr = 1,
  442. .mpr = 1,
  443. .tpauser = 1,
  444. .hw_swap = 1,
  445. .no_ade = 1,
  446. .rpadir = 1,
  447. .rpadir_value = 2 << 16,
  448. };
  449. #define SH_GIGA_ETH_BASE 0xfee00000UL
  450. #define GIGA_MALR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c8)
  451. #define GIGA_MAHR(port) (SH_GIGA_ETH_BASE + 0x800 * (port) + 0x05c0)
  452. static void sh_eth_chip_reset_giga(struct net_device *ndev)
  453. {
  454. int i;
  455. unsigned long mahr[2], malr[2];
  456. /* save MAHR and MALR */
  457. for (i = 0; i < 2; i++) {
  458. malr[i] = ioread32((void *)GIGA_MALR(i));
  459. mahr[i] = ioread32((void *)GIGA_MAHR(i));
  460. }
  461. /* reset device */
  462. iowrite32(ARSTR_ARSTR, (void *)(SH_GIGA_ETH_BASE + 0x1800));
  463. mdelay(1);
  464. /* restore MAHR and MALR */
  465. for (i = 0; i < 2; i++) {
  466. iowrite32(malr[i], (void *)GIGA_MALR(i));
  467. iowrite32(mahr[i], (void *)GIGA_MAHR(i));
  468. }
  469. }
  470. static void sh_eth_set_rate_giga(struct net_device *ndev)
  471. {
  472. struct sh_eth_private *mdp = netdev_priv(ndev);
  473. switch (mdp->speed) {
  474. case 10: /* 10BASE */
  475. sh_eth_write(ndev, 0x00000000, GECMR);
  476. break;
  477. case 100:/* 100BASE */
  478. sh_eth_write(ndev, 0x00000010, GECMR);
  479. break;
  480. case 1000: /* 1000BASE */
  481. sh_eth_write(ndev, 0x00000020, GECMR);
  482. break;
  483. default:
  484. break;
  485. }
  486. }
  487. /* SH7757(GETHERC) */
  488. static struct sh_eth_cpu_data sh7757_data_giga = {
  489. .chip_reset = sh_eth_chip_reset_giga,
  490. .set_duplex = sh_eth_set_duplex,
  491. .set_rate = sh_eth_set_rate_giga,
  492. .ecsr_value = ECSR_ICD | ECSR_MPD,
  493. .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
  494. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  495. .tx_check = EESR_TC1 | EESR_FTC,
  496. .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
  497. EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
  498. EESR_TDE | EESR_ECI,
  499. .fdr_value = 0x0000072f,
  500. .rmcr_value = 0x00000001,
  501. .irq_flags = IRQF_SHARED,
  502. .apr = 1,
  503. .mpr = 1,
  504. .tpauser = 1,
  505. .bculr = 1,
  506. .hw_swap = 1,
  507. .rpadir = 1,
  508. .rpadir_value = 2 << 16,
  509. .no_trimd = 1,
  510. .no_ade = 1,
  511. .tsu = 1,
  512. };
  513. static void sh_eth_chip_reset(struct net_device *ndev)
  514. {
  515. struct sh_eth_private *mdp = netdev_priv(ndev);
  516. /* reset device */
  517. sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR);
  518. mdelay(1);
  519. }
  520. static void sh_eth_set_rate_gether(struct net_device *ndev)
  521. {
  522. struct sh_eth_private *mdp = netdev_priv(ndev);
  523. switch (mdp->speed) {
  524. case 10: /* 10BASE */
  525. sh_eth_write(ndev, GECMR_10, GECMR);
  526. break;
  527. case 100:/* 100BASE */
  528. sh_eth_write(ndev, GECMR_100, GECMR);
  529. break;
  530. case 1000: /* 1000BASE */
  531. sh_eth_write(ndev, GECMR_1000, GECMR);
  532. break;
  533. default:
  534. break;
  535. }
  536. }
  537. /* SH7734 */
  538. static struct sh_eth_cpu_data sh7734_data = {
  539. .chip_reset = sh_eth_chip_reset,
  540. .set_duplex = sh_eth_set_duplex,
  541. .set_rate = sh_eth_set_rate_gether,
  542. .ecsr_value = ECSR_ICD | ECSR_MPD,
  543. .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
  544. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  545. .tx_check = EESR_TC1 | EESR_FTC,
  546. .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
  547. EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
  548. EESR_TDE | EESR_ECI,
  549. .apr = 1,
  550. .mpr = 1,
  551. .tpauser = 1,
  552. .bculr = 1,
  553. .hw_swap = 1,
  554. .no_trimd = 1,
  555. .no_ade = 1,
  556. .tsu = 1,
  557. .hw_crc = 1,
  558. .select_mii = 1,
  559. };
  560. /* SH7763 */
  561. static struct sh_eth_cpu_data sh7763_data = {
  562. .chip_reset = sh_eth_chip_reset,
  563. .set_duplex = sh_eth_set_duplex,
  564. .set_rate = sh_eth_set_rate_gether,
  565. .ecsr_value = ECSR_ICD | ECSR_MPD,
  566. .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
  567. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  568. .tx_check = EESR_TC1 | EESR_FTC,
  569. .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | \
  570. EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | \
  571. EESR_ECI,
  572. .apr = 1,
  573. .mpr = 1,
  574. .tpauser = 1,
  575. .bculr = 1,
  576. .hw_swap = 1,
  577. .no_trimd = 1,
  578. .no_ade = 1,
  579. .tsu = 1,
  580. .irq_flags = IRQF_SHARED,
  581. };
  582. static void sh_eth_chip_reset_r8a7740(struct net_device *ndev)
  583. {
  584. struct sh_eth_private *mdp = netdev_priv(ndev);
  585. /* reset device */
  586. sh_eth_tsu_write(mdp, ARSTR_ARSTR, ARSTR);
  587. mdelay(1);
  588. sh_eth_select_mii(ndev);
  589. }
  590. /* R8A7740 */
  591. static struct sh_eth_cpu_data r8a7740_data = {
  592. .chip_reset = sh_eth_chip_reset_r8a7740,
  593. .set_duplex = sh_eth_set_duplex,
  594. .set_rate = sh_eth_set_rate_gether,
  595. .ecsr_value = ECSR_ICD | ECSR_MPD,
  596. .ecsipr_value = ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP,
  597. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  598. .tx_check = EESR_TC1 | EESR_FTC,
  599. .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
  600. EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
  601. EESR_TDE | EESR_ECI,
  602. .apr = 1,
  603. .mpr = 1,
  604. .tpauser = 1,
  605. .bculr = 1,
  606. .hw_swap = 1,
  607. .no_trimd = 1,
  608. .no_ade = 1,
  609. .tsu = 1,
  610. .select_mii = 1,
  611. .shift_rd0 = 1,
  612. };
  613. static struct sh_eth_cpu_data sh7619_data = {
  614. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  615. .apr = 1,
  616. .mpr = 1,
  617. .tpauser = 1,
  618. .hw_swap = 1,
  619. };
  620. static struct sh_eth_cpu_data sh771x_data = {
  621. .eesipr_value = DMAC_M_RFRMER | DMAC_M_ECI | 0x003fffff,
  622. .tsu = 1,
  623. };
  624. static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd)
  625. {
  626. if (!cd->ecsr_value)
  627. cd->ecsr_value = DEFAULT_ECSR_INIT;
  628. if (!cd->ecsipr_value)
  629. cd->ecsipr_value = DEFAULT_ECSIPR_INIT;
  630. if (!cd->fcftr_value)
  631. cd->fcftr_value = DEFAULT_FIFO_F_D_RFF | \
  632. DEFAULT_FIFO_F_D_RFD;
  633. if (!cd->fdr_value)
  634. cd->fdr_value = DEFAULT_FDR_INIT;
  635. if (!cd->rmcr_value)
  636. cd->rmcr_value = DEFAULT_RMCR_VALUE;
  637. if (!cd->tx_check)
  638. cd->tx_check = DEFAULT_TX_CHECK;
  639. if (!cd->eesr_err_check)
  640. cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK;
  641. }
  642. static int sh_eth_check_reset(struct net_device *ndev)
  643. {
  644. int ret = 0;
  645. int cnt = 100;
  646. while (cnt > 0) {
  647. if (!(sh_eth_read(ndev, EDMR) & 0x3))
  648. break;
  649. mdelay(1);
  650. cnt--;
  651. }
  652. if (cnt <= 0) {
  653. pr_err("Device reset failed\n");
  654. ret = -ETIMEDOUT;
  655. }
  656. return ret;
  657. }
  658. static int sh_eth_reset(struct net_device *ndev)
  659. {
  660. struct sh_eth_private *mdp = netdev_priv(ndev);
  661. int ret = 0;
  662. if (sh_eth_is_gether(mdp)) {
  663. sh_eth_write(ndev, EDSR_ENALL, EDSR);
  664. sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_GETHER,
  665. EDMR);
  666. ret = sh_eth_check_reset(ndev);
  667. if (ret)
  668. goto out;
  669. /* Table Init */
  670. sh_eth_write(ndev, 0x0, TDLAR);
  671. sh_eth_write(ndev, 0x0, TDFAR);
  672. sh_eth_write(ndev, 0x0, TDFXR);
  673. sh_eth_write(ndev, 0x0, TDFFR);
  674. sh_eth_write(ndev, 0x0, RDLAR);
  675. sh_eth_write(ndev, 0x0, RDFAR);
  676. sh_eth_write(ndev, 0x0, RDFXR);
  677. sh_eth_write(ndev, 0x0, RDFFR);
  678. /* Reset HW CRC register */
  679. if (mdp->cd->hw_crc)
  680. sh_eth_write(ndev, 0x0, CSMR);
  681. /* Select MII mode */
  682. if (mdp->cd->select_mii)
  683. sh_eth_select_mii(ndev);
  684. } else {
  685. sh_eth_write(ndev, sh_eth_read(ndev, EDMR) | EDMR_SRST_ETHER,
  686. EDMR);
  687. mdelay(3);
  688. sh_eth_write(ndev, sh_eth_read(ndev, EDMR) & ~EDMR_SRST_ETHER,
  689. EDMR);
  690. }
  691. out:
  692. return ret;
  693. }
  694. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
  695. static void sh_eth_set_receive_align(struct sk_buff *skb)
  696. {
  697. int reserve;
  698. reserve = SH4_SKB_RX_ALIGN - ((u32)skb->data & (SH4_SKB_RX_ALIGN - 1));
  699. if (reserve)
  700. skb_reserve(skb, reserve);
  701. }
  702. #else
  703. static void sh_eth_set_receive_align(struct sk_buff *skb)
  704. {
  705. skb_reserve(skb, SH2_SH3_SKB_RX_ALIGN);
  706. }
  707. #endif
  708. /* CPU <-> EDMAC endian convert */
  709. static inline __u32 cpu_to_edmac(struct sh_eth_private *mdp, u32 x)
  710. {
  711. switch (mdp->edmac_endian) {
  712. case EDMAC_LITTLE_ENDIAN:
  713. return cpu_to_le32(x);
  714. case EDMAC_BIG_ENDIAN:
  715. return cpu_to_be32(x);
  716. }
  717. return x;
  718. }
  719. static inline __u32 edmac_to_cpu(struct sh_eth_private *mdp, u32 x)
  720. {
  721. switch (mdp->edmac_endian) {
  722. case EDMAC_LITTLE_ENDIAN:
  723. return le32_to_cpu(x);
  724. case EDMAC_BIG_ENDIAN:
  725. return be32_to_cpu(x);
  726. }
  727. return x;
  728. }
  729. /*
  730. * Program the hardware MAC address from dev->dev_addr.
  731. */
  732. static void update_mac_address(struct net_device *ndev)
  733. {
  734. sh_eth_write(ndev,
  735. (ndev->dev_addr[0] << 24) | (ndev->dev_addr[1] << 16) |
  736. (ndev->dev_addr[2] << 8) | (ndev->dev_addr[3]), MAHR);
  737. sh_eth_write(ndev,
  738. (ndev->dev_addr[4] << 8) | (ndev->dev_addr[5]), MALR);
  739. }
  740. /*
  741. * Get MAC address from SuperH MAC address register
  742. *
  743. * SuperH's Ethernet device doesn't have 'ROM' to MAC address.
  744. * This driver get MAC address that use by bootloader(U-boot or sh-ipl+g).
  745. * When you want use this device, you must set MAC address in bootloader.
  746. *
  747. */
  748. static void read_mac_address(struct net_device *ndev, unsigned char *mac)
  749. {
  750. if (mac[0] || mac[1] || mac[2] || mac[3] || mac[4] || mac[5]) {
  751. memcpy(ndev->dev_addr, mac, 6);
  752. } else {
  753. ndev->dev_addr[0] = (sh_eth_read(ndev, MAHR) >> 24);
  754. ndev->dev_addr[1] = (sh_eth_read(ndev, MAHR) >> 16) & 0xFF;
  755. ndev->dev_addr[2] = (sh_eth_read(ndev, MAHR) >> 8) & 0xFF;
  756. ndev->dev_addr[3] = (sh_eth_read(ndev, MAHR) & 0xFF);
  757. ndev->dev_addr[4] = (sh_eth_read(ndev, MALR) >> 8) & 0xFF;
  758. ndev->dev_addr[5] = (sh_eth_read(ndev, MALR) & 0xFF);
  759. }
  760. }
  761. static unsigned long sh_eth_get_edtrr_trns(struct sh_eth_private *mdp)
  762. {
  763. if (sh_eth_is_gether(mdp))
  764. return EDTRR_TRNS_GETHER;
  765. else
  766. return EDTRR_TRNS_ETHER;
  767. }
  768. struct bb_info {
  769. void (*set_gate)(void *addr);
  770. struct mdiobb_ctrl ctrl;
  771. void *addr;
  772. u32 mmd_msk;/* MMD */
  773. u32 mdo_msk;
  774. u32 mdi_msk;
  775. u32 mdc_msk;
  776. };
  777. /* PHY bit set */
  778. static void bb_set(void *addr, u32 msk)
  779. {
  780. iowrite32(ioread32(addr) | msk, addr);
  781. }
  782. /* PHY bit clear */
  783. static void bb_clr(void *addr, u32 msk)
  784. {
  785. iowrite32((ioread32(addr) & ~msk), addr);
  786. }
  787. /* PHY bit read */
  788. static int bb_read(void *addr, u32 msk)
  789. {
  790. return (ioread32(addr) & msk) != 0;
  791. }
  792. /* Data I/O pin control */
  793. static void sh_mmd_ctrl(struct mdiobb_ctrl *ctrl, int bit)
  794. {
  795. struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
  796. if (bitbang->set_gate)
  797. bitbang->set_gate(bitbang->addr);
  798. if (bit)
  799. bb_set(bitbang->addr, bitbang->mmd_msk);
  800. else
  801. bb_clr(bitbang->addr, bitbang->mmd_msk);
  802. }
  803. /* Set bit data*/
  804. static void sh_set_mdio(struct mdiobb_ctrl *ctrl, int bit)
  805. {
  806. struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
  807. if (bitbang->set_gate)
  808. bitbang->set_gate(bitbang->addr);
  809. if (bit)
  810. bb_set(bitbang->addr, bitbang->mdo_msk);
  811. else
  812. bb_clr(bitbang->addr, bitbang->mdo_msk);
  813. }
  814. /* Get bit data*/
  815. static int sh_get_mdio(struct mdiobb_ctrl *ctrl)
  816. {
  817. struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
  818. if (bitbang->set_gate)
  819. bitbang->set_gate(bitbang->addr);
  820. return bb_read(bitbang->addr, bitbang->mdi_msk);
  821. }
  822. /* MDC pin control */
  823. static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
  824. {
  825. struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
  826. if (bitbang->set_gate)
  827. bitbang->set_gate(bitbang->addr);
  828. if (bit)
  829. bb_set(bitbang->addr, bitbang->mdc_msk);
  830. else
  831. bb_clr(bitbang->addr, bitbang->mdc_msk);
  832. }
  833. /* mdio bus control struct */
  834. static struct mdiobb_ops bb_ops = {
  835. .owner = THIS_MODULE,
  836. .set_mdc = sh_mdc_ctrl,
  837. .set_mdio_dir = sh_mmd_ctrl,
  838. .set_mdio_data = sh_set_mdio,
  839. .get_mdio_data = sh_get_mdio,
  840. };
  841. /* free skb and descriptor buffer */
  842. static void sh_eth_ring_free(struct net_device *ndev)
  843. {
  844. struct sh_eth_private *mdp = netdev_priv(ndev);
  845. int i;
  846. /* Free Rx skb ringbuffer */
  847. if (mdp->rx_skbuff) {
  848. for (i = 0; i < mdp->num_rx_ring; i++) {
  849. if (mdp->rx_skbuff[i])
  850. dev_kfree_skb(mdp->rx_skbuff[i]);
  851. }
  852. }
  853. kfree(mdp->rx_skbuff);
  854. mdp->rx_skbuff = NULL;
  855. /* Free Tx skb ringbuffer */
  856. if (mdp->tx_skbuff) {
  857. for (i = 0; i < mdp->num_tx_ring; i++) {
  858. if (mdp->tx_skbuff[i])
  859. dev_kfree_skb(mdp->tx_skbuff[i]);
  860. }
  861. }
  862. kfree(mdp->tx_skbuff);
  863. mdp->tx_skbuff = NULL;
  864. }
  865. /* format skb and descriptor buffer */
  866. static void sh_eth_ring_format(struct net_device *ndev)
  867. {
  868. struct sh_eth_private *mdp = netdev_priv(ndev);
  869. int i;
  870. struct sk_buff *skb;
  871. struct sh_eth_rxdesc *rxdesc = NULL;
  872. struct sh_eth_txdesc *txdesc = NULL;
  873. int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring;
  874. int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring;
  875. mdp->cur_rx = mdp->cur_tx = 0;
  876. mdp->dirty_rx = mdp->dirty_tx = 0;
  877. memset(mdp->rx_ring, 0, rx_ringsize);
  878. /* build Rx ring buffer */
  879. for (i = 0; i < mdp->num_rx_ring; i++) {
  880. /* skb */
  881. mdp->rx_skbuff[i] = NULL;
  882. skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz);
  883. mdp->rx_skbuff[i] = skb;
  884. if (skb == NULL)
  885. break;
  886. dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
  887. DMA_FROM_DEVICE);
  888. sh_eth_set_receive_align(skb);
  889. /* RX descriptor */
  890. rxdesc = &mdp->rx_ring[i];
  891. rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
  892. rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP);
  893. /* The size of the buffer is 16 byte boundary. */
  894. rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
  895. /* Rx descriptor address set */
  896. if (i == 0) {
  897. sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR);
  898. if (sh_eth_is_gether(mdp))
  899. sh_eth_write(ndev, mdp->rx_desc_dma, RDFAR);
  900. }
  901. }
  902. mdp->dirty_rx = (u32) (i - mdp->num_rx_ring);
  903. /* Mark the last entry as wrapping the ring. */
  904. rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL);
  905. memset(mdp->tx_ring, 0, tx_ringsize);
  906. /* build Tx ring buffer */
  907. for (i = 0; i < mdp->num_tx_ring; i++) {
  908. mdp->tx_skbuff[i] = NULL;
  909. txdesc = &mdp->tx_ring[i];
  910. txdesc->status = cpu_to_edmac(mdp, TD_TFP);
  911. txdesc->buffer_length = 0;
  912. if (i == 0) {
  913. /* Tx descriptor address set */
  914. sh_eth_write(ndev, mdp->tx_desc_dma, TDLAR);
  915. if (sh_eth_is_gether(mdp))
  916. sh_eth_write(ndev, mdp->tx_desc_dma, TDFAR);
  917. }
  918. }
  919. txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
  920. }
  921. /* Get skb and descriptor buffer */
  922. static int sh_eth_ring_init(struct net_device *ndev)
  923. {
  924. struct sh_eth_private *mdp = netdev_priv(ndev);
  925. int rx_ringsize, tx_ringsize, ret = 0;
  926. /*
  927. * +26 gets the maximum ethernet encapsulation, +7 & ~7 because the
  928. * card needs room to do 8 byte alignment, +2 so we can reserve
  929. * the first 2 bytes, and +16 gets room for the status word from the
  930. * card.
  931. */
  932. mdp->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ :
  933. (((ndev->mtu + 26 + 7) & ~7) + 2 + 16));
  934. if (mdp->cd->rpadir)
  935. mdp->rx_buf_sz += NET_IP_ALIGN;
  936. /* Allocate RX and TX skb rings */
  937. mdp->rx_skbuff = kmalloc_array(mdp->num_rx_ring,
  938. sizeof(*mdp->rx_skbuff), GFP_KERNEL);
  939. if (!mdp->rx_skbuff) {
  940. ret = -ENOMEM;
  941. return ret;
  942. }
  943. mdp->tx_skbuff = kmalloc_array(mdp->num_tx_ring,
  944. sizeof(*mdp->tx_skbuff), GFP_KERNEL);
  945. if (!mdp->tx_skbuff) {
  946. ret = -ENOMEM;
  947. goto skb_ring_free;
  948. }
  949. /* Allocate all Rx descriptors. */
  950. rx_ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
  951. mdp->rx_ring = dma_alloc_coherent(NULL, rx_ringsize, &mdp->rx_desc_dma,
  952. GFP_KERNEL);
  953. if (!mdp->rx_ring) {
  954. ret = -ENOMEM;
  955. goto desc_ring_free;
  956. }
  957. mdp->dirty_rx = 0;
  958. /* Allocate all Tx descriptors. */
  959. tx_ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
  960. mdp->tx_ring = dma_alloc_coherent(NULL, tx_ringsize, &mdp->tx_desc_dma,
  961. GFP_KERNEL);
  962. if (!mdp->tx_ring) {
  963. ret = -ENOMEM;
  964. goto desc_ring_free;
  965. }
  966. return ret;
  967. desc_ring_free:
  968. /* free DMA buffer */
  969. dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma);
  970. skb_ring_free:
  971. /* Free Rx and Tx skb ring buffer */
  972. sh_eth_ring_free(ndev);
  973. mdp->tx_ring = NULL;
  974. mdp->rx_ring = NULL;
  975. return ret;
  976. }
  977. static void sh_eth_free_dma_buffer(struct sh_eth_private *mdp)
  978. {
  979. int ringsize;
  980. if (mdp->rx_ring) {
  981. ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
  982. dma_free_coherent(NULL, ringsize, mdp->rx_ring,
  983. mdp->rx_desc_dma);
  984. mdp->rx_ring = NULL;
  985. }
  986. if (mdp->tx_ring) {
  987. ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
  988. dma_free_coherent(NULL, ringsize, mdp->tx_ring,
  989. mdp->tx_desc_dma);
  990. mdp->tx_ring = NULL;
  991. }
  992. }
  993. static int sh_eth_dev_init(struct net_device *ndev, bool start)
  994. {
  995. int ret = 0;
  996. struct sh_eth_private *mdp = netdev_priv(ndev);
  997. u32 val;
  998. /* Soft Reset */
  999. ret = sh_eth_reset(ndev);
  1000. if (ret)
  1001. goto out;
  1002. if (mdp->cd->rmiimode)
  1003. sh_eth_write(ndev, 0x1, RMIIMODE);
  1004. /* Descriptor format */
  1005. sh_eth_ring_format(ndev);
  1006. if (mdp->cd->rpadir)
  1007. sh_eth_write(ndev, mdp->cd->rpadir_value, RPADIR);
  1008. /* all sh_eth int mask */
  1009. sh_eth_write(ndev, 0, EESIPR);
  1010. #if defined(__LITTLE_ENDIAN)
  1011. if (mdp->cd->hw_swap)
  1012. sh_eth_write(ndev, EDMR_EL, EDMR);
  1013. else
  1014. #endif
  1015. sh_eth_write(ndev, 0, EDMR);
  1016. /* FIFO size set */
  1017. sh_eth_write(ndev, mdp->cd->fdr_value, FDR);
  1018. sh_eth_write(ndev, 0, TFTR);
  1019. /* Frame recv control */
  1020. sh_eth_write(ndev, mdp->cd->rmcr_value, RMCR);
  1021. sh_eth_write(ndev, DESC_I_RINT8 | DESC_I_RINT5 | DESC_I_TINT2, TRSCER);
  1022. if (mdp->cd->bculr)
  1023. sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */
  1024. sh_eth_write(ndev, mdp->cd->fcftr_value, FCFTR);
  1025. if (!mdp->cd->no_trimd)
  1026. sh_eth_write(ndev, 0, TRIMD);
  1027. /* Recv frame limit set register */
  1028. sh_eth_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN,
  1029. RFLR);
  1030. sh_eth_write(ndev, sh_eth_read(ndev, EESR), EESR);
  1031. if (start)
  1032. sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
  1033. /* PAUSE Prohibition */
  1034. val = (sh_eth_read(ndev, ECMR) & ECMR_DM) |
  1035. ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
  1036. sh_eth_write(ndev, val, ECMR);
  1037. if (mdp->cd->set_rate)
  1038. mdp->cd->set_rate(ndev);
  1039. /* E-MAC Status Register clear */
  1040. sh_eth_write(ndev, mdp->cd->ecsr_value, ECSR);
  1041. /* E-MAC Interrupt Enable register */
  1042. if (start)
  1043. sh_eth_write(ndev, mdp->cd->ecsipr_value, ECSIPR);
  1044. /* Set MAC address */
  1045. update_mac_address(ndev);
  1046. /* mask reset */
  1047. if (mdp->cd->apr)
  1048. sh_eth_write(ndev, APR_AP, APR);
  1049. if (mdp->cd->mpr)
  1050. sh_eth_write(ndev, MPR_MP, MPR);
  1051. if (mdp->cd->tpauser)
  1052. sh_eth_write(ndev, TPAUSER_UNLIMITED, TPAUSER);
  1053. if (start) {
  1054. /* Setting the Rx mode will start the Rx process. */
  1055. sh_eth_write(ndev, EDRRR_R, EDRRR);
  1056. netif_start_queue(ndev);
  1057. }
  1058. out:
  1059. return ret;
  1060. }
  1061. /* free Tx skb function */
  1062. static int sh_eth_txfree(struct net_device *ndev)
  1063. {
  1064. struct sh_eth_private *mdp = netdev_priv(ndev);
  1065. struct sh_eth_txdesc *txdesc;
  1066. int freeNum = 0;
  1067. int entry = 0;
  1068. for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
  1069. entry = mdp->dirty_tx % mdp->num_tx_ring;
  1070. txdesc = &mdp->tx_ring[entry];
  1071. if (txdesc->status & cpu_to_edmac(mdp, TD_TACT))
  1072. break;
  1073. /* Free the original skb. */
  1074. if (mdp->tx_skbuff[entry]) {
  1075. dma_unmap_single(&ndev->dev, txdesc->addr,
  1076. txdesc->buffer_length, DMA_TO_DEVICE);
  1077. dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
  1078. mdp->tx_skbuff[entry] = NULL;
  1079. freeNum++;
  1080. }
  1081. txdesc->status = cpu_to_edmac(mdp, TD_TFP);
  1082. if (entry >= mdp->num_tx_ring - 1)
  1083. txdesc->status |= cpu_to_edmac(mdp, TD_TDLE);
  1084. ndev->stats.tx_packets++;
  1085. ndev->stats.tx_bytes += txdesc->buffer_length;
  1086. }
  1087. return freeNum;
  1088. }
  1089. /* Packet receive function */
  1090. static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
  1091. {
  1092. struct sh_eth_private *mdp = netdev_priv(ndev);
  1093. struct sh_eth_rxdesc *rxdesc;
  1094. int entry = mdp->cur_rx % mdp->num_rx_ring;
  1095. int boguscnt = (mdp->dirty_rx + mdp->num_rx_ring) - mdp->cur_rx;
  1096. struct sk_buff *skb;
  1097. int exceeded = 0;
  1098. u16 pkt_len = 0;
  1099. u32 desc_status;
  1100. rxdesc = &mdp->rx_ring[entry];
  1101. while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) {
  1102. desc_status = edmac_to_cpu(mdp, rxdesc->status);
  1103. pkt_len = rxdesc->frame_length;
  1104. if (--boguscnt < 0)
  1105. break;
  1106. if (*quota <= 0) {
  1107. exceeded = 1;
  1108. break;
  1109. }
  1110. (*quota)--;
  1111. if (!(desc_status & RDFEND))
  1112. ndev->stats.rx_length_errors++;
  1113. /*
  1114. * In case of almost all GETHER/ETHERs, the Receive Frame State
  1115. * (RFS) bits in the Receive Descriptor 0 are from bit 9 to
  1116. * bit 0. However, in case of the R8A7740's GETHER, the RFS
  1117. * bits are from bit 25 to bit 16. So, the driver needs right
  1118. * shifting by 16.
  1119. */
  1120. if (mdp->cd->shift_rd0)
  1121. desc_status >>= 16;
  1122. if (desc_status & (RD_RFS1 | RD_RFS2 | RD_RFS3 | RD_RFS4 |
  1123. RD_RFS5 | RD_RFS6 | RD_RFS10)) {
  1124. ndev->stats.rx_errors++;
  1125. if (desc_status & RD_RFS1)
  1126. ndev->stats.rx_crc_errors++;
  1127. if (desc_status & RD_RFS2)
  1128. ndev->stats.rx_frame_errors++;
  1129. if (desc_status & RD_RFS3)
  1130. ndev->stats.rx_length_errors++;
  1131. if (desc_status & RD_RFS4)
  1132. ndev->stats.rx_length_errors++;
  1133. if (desc_status & RD_RFS6)
  1134. ndev->stats.rx_missed_errors++;
  1135. if (desc_status & RD_RFS10)
  1136. ndev->stats.rx_over_errors++;
  1137. } else {
  1138. if (!mdp->cd->hw_swap)
  1139. sh_eth_soft_swap(
  1140. phys_to_virt(ALIGN(rxdesc->addr, 4)),
  1141. pkt_len + 2);
  1142. skb = mdp->rx_skbuff[entry];
  1143. mdp->rx_skbuff[entry] = NULL;
  1144. if (mdp->cd->rpadir)
  1145. skb_reserve(skb, NET_IP_ALIGN);
  1146. skb_put(skb, pkt_len);
  1147. skb->protocol = eth_type_trans(skb, ndev);
  1148. netif_rx(skb);
  1149. ndev->stats.rx_packets++;
  1150. ndev->stats.rx_bytes += pkt_len;
  1151. }
  1152. rxdesc->status |= cpu_to_edmac(mdp, RD_RACT);
  1153. entry = (++mdp->cur_rx) % mdp->num_rx_ring;
  1154. rxdesc = &mdp->rx_ring[entry];
  1155. }
  1156. /* Refill the Rx ring buffers. */
  1157. for (; mdp->cur_rx - mdp->dirty_rx > 0; mdp->dirty_rx++) {
  1158. entry = mdp->dirty_rx % mdp->num_rx_ring;
  1159. rxdesc = &mdp->rx_ring[entry];
  1160. /* The size of the buffer is 16 byte boundary. */
  1161. rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
  1162. if (mdp->rx_skbuff[entry] == NULL) {
  1163. skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz);
  1164. mdp->rx_skbuff[entry] = skb;
  1165. if (skb == NULL)
  1166. break; /* Better luck next round. */
  1167. dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
  1168. DMA_FROM_DEVICE);
  1169. sh_eth_set_receive_align(skb);
  1170. skb_checksum_none_assert(skb);
  1171. rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
  1172. }
  1173. if (entry >= mdp->num_rx_ring - 1)
  1174. rxdesc->status |=
  1175. cpu_to_edmac(mdp, RD_RACT | RD_RFP | RD_RDEL);
  1176. else
  1177. rxdesc->status |=
  1178. cpu_to_edmac(mdp, RD_RACT | RD_RFP);
  1179. }
  1180. /* Restart Rx engine if stopped. */
  1181. /* If we don't need to check status, don't. -KDU */
  1182. if (!(sh_eth_read(ndev, EDRRR) & EDRRR_R)) {
  1183. /* fix the values for the next receiving if RDE is set */
  1184. if (intr_status & EESR_RDE)
  1185. mdp->cur_rx = mdp->dirty_rx =
  1186. (sh_eth_read(ndev, RDFAR) -
  1187. sh_eth_read(ndev, RDLAR)) >> 4;
  1188. sh_eth_write(ndev, EDRRR_R, EDRRR);
  1189. }
  1190. return exceeded;
  1191. }
  1192. static void sh_eth_rcv_snd_disable(struct net_device *ndev)
  1193. {
  1194. /* disable tx and rx */
  1195. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) &
  1196. ~(ECMR_RE | ECMR_TE), ECMR);
  1197. }
  1198. static void sh_eth_rcv_snd_enable(struct net_device *ndev)
  1199. {
  1200. /* enable tx and rx */
  1201. sh_eth_write(ndev, sh_eth_read(ndev, ECMR) |
  1202. (ECMR_RE | ECMR_TE), ECMR);
  1203. }
  1204. /* error control function */
  1205. static void sh_eth_error(struct net_device *ndev, int intr_status)
  1206. {
  1207. struct sh_eth_private *mdp = netdev_priv(ndev);
  1208. u32 felic_stat;
  1209. u32 link_stat;
  1210. u32 mask;
  1211. if (intr_status & EESR_ECI) {
  1212. felic_stat = sh_eth_read(ndev, ECSR);
  1213. sh_eth_write(ndev, felic_stat, ECSR); /* clear int */
  1214. if (felic_stat & ECSR_ICD)
  1215. ndev->stats.tx_carrier_errors++;
  1216. if (felic_stat & ECSR_LCHNG) {
  1217. /* Link Changed */
  1218. if (mdp->cd->no_psr || mdp->no_ether_link) {
  1219. goto ignore_link;
  1220. } else {
  1221. link_stat = (sh_eth_read(ndev, PSR));
  1222. if (mdp->ether_link_active_low)
  1223. link_stat = ~link_stat;
  1224. }
  1225. if (!(link_stat & PHY_ST_LINK))
  1226. sh_eth_rcv_snd_disable(ndev);
  1227. else {
  1228. /* Link Up */
  1229. sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) &
  1230. ~DMAC_M_ECI, EESIPR);
  1231. /*clear int */
  1232. sh_eth_write(ndev, sh_eth_read(ndev, ECSR),
  1233. ECSR);
  1234. sh_eth_write(ndev, sh_eth_read(ndev, EESIPR) |
  1235. DMAC_M_ECI, EESIPR);
  1236. /* enable tx and rx */
  1237. sh_eth_rcv_snd_enable(ndev);
  1238. }
  1239. }
  1240. }
  1241. ignore_link:
  1242. if (intr_status & EESR_TWB) {
  1243. /* Unused write back interrupt */
  1244. if (intr_status & EESR_TABT) { /* Transmit Abort int */
  1245. ndev->stats.tx_aborted_errors++;
  1246. if (netif_msg_tx_err(mdp))
  1247. dev_err(&ndev->dev, "Transmit Abort\n");
  1248. }
  1249. }
  1250. if (intr_status & EESR_RABT) {
  1251. /* Receive Abort int */
  1252. if (intr_status & EESR_RFRMER) {
  1253. /* Receive Frame Overflow int */
  1254. ndev->stats.rx_frame_errors++;
  1255. if (netif_msg_rx_err(mdp))
  1256. dev_err(&ndev->dev, "Receive Abort\n");
  1257. }
  1258. }
  1259. if (intr_status & EESR_TDE) {
  1260. /* Transmit Descriptor Empty int */
  1261. ndev->stats.tx_fifo_errors++;
  1262. if (netif_msg_tx_err(mdp))
  1263. dev_err(&ndev->dev, "Transmit Descriptor Empty\n");
  1264. }
  1265. if (intr_status & EESR_TFE) {
  1266. /* FIFO under flow */
  1267. ndev->stats.tx_fifo_errors++;
  1268. if (netif_msg_tx_err(mdp))
  1269. dev_err(&ndev->dev, "Transmit FIFO Under flow\n");
  1270. }
  1271. if (intr_status & EESR_RDE) {
  1272. /* Receive Descriptor Empty int */
  1273. ndev->stats.rx_over_errors++;
  1274. if (netif_msg_rx_err(mdp))
  1275. dev_err(&ndev->dev, "Receive Descriptor Empty\n");
  1276. }
  1277. if (intr_status & EESR_RFE) {
  1278. /* Receive FIFO Overflow int */
  1279. ndev->stats.rx_fifo_errors++;
  1280. if (netif_msg_rx_err(mdp))
  1281. dev_err(&ndev->dev, "Receive FIFO Overflow\n");
  1282. }
  1283. if (!mdp->cd->no_ade && (intr_status & EESR_ADE)) {
  1284. /* Address Error */
  1285. ndev->stats.tx_fifo_errors++;
  1286. if (netif_msg_tx_err(mdp))
  1287. dev_err(&ndev->dev, "Address Error\n");
  1288. }
  1289. mask = EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE;
  1290. if (mdp->cd->no_ade)
  1291. mask &= ~EESR_ADE;
  1292. if (intr_status & mask) {
  1293. /* Tx error */
  1294. u32 edtrr = sh_eth_read(ndev, EDTRR);
  1295. /* dmesg */
  1296. dev_err(&ndev->dev, "TX error. status=%8.8x cur_tx=%8.8x ",
  1297. intr_status, mdp->cur_tx);
  1298. dev_err(&ndev->dev, "dirty_tx=%8.8x state=%8.8x EDTRR=%8.8x.\n",
  1299. mdp->dirty_tx, (u32) ndev->state, edtrr);
  1300. /* dirty buffer free */
  1301. sh_eth_txfree(ndev);
  1302. /* SH7712 BUG */
  1303. if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) {
  1304. /* tx dma start */
  1305. sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR);
  1306. }
  1307. /* wakeup */
  1308. netif_wake_queue(ndev);
  1309. }
  1310. }
  1311. static irqreturn_t sh_eth_interrupt(int irq, void *netdev)
  1312. {
  1313. struct net_device *ndev = netdev;
  1314. struct sh_eth_private *mdp = netdev_priv(ndev);
  1315. struct sh_eth_cpu_data *cd = mdp->cd;
  1316. irqreturn_t ret = IRQ_NONE;
  1317. unsigned long intr_status, intr_enable;
  1318. spin_lock(&mdp->lock);
  1319. /* Get interrupt status */
  1320. intr_status = sh_eth_read(ndev, EESR);
  1321. /* Mask it with the interrupt mask, forcing ECI interrupt to be always
  1322. * enabled since it's the one that comes thru regardless of the mask,
  1323. * and we need to fully handle it in sh_eth_error() in order to quench
  1324. * it as it doesn't get cleared by just writing 1 to the ECI bit...
  1325. */
  1326. intr_enable = sh_eth_read(ndev, EESIPR);
  1327. intr_status &= intr_enable | DMAC_M_ECI;
  1328. if (intr_status & (EESR_RX_CHECK | cd->tx_check | cd->eesr_err_check))
  1329. ret = IRQ_HANDLED;
  1330. else
  1331. goto other_irq;
  1332. if (intr_status & EESR_RX_CHECK) {
  1333. if (napi_schedule_prep(&mdp->napi)) {
  1334. /* Mask Rx interrupts */
  1335. sh_eth_write(ndev, intr_enable & ~EESR_RX_CHECK,
  1336. EESIPR);
  1337. __napi_schedule(&mdp->napi);
  1338. } else {
  1339. dev_warn(&ndev->dev,
  1340. "ignoring interrupt, status 0x%08lx, mask 0x%08lx.\n",
  1341. intr_status, intr_enable);
  1342. }
  1343. }
  1344. /* Tx Check */
  1345. if (intr_status & cd->tx_check) {
  1346. /* Clear Tx interrupts */
  1347. sh_eth_write(ndev, intr_status & cd->tx_check, EESR);
  1348. sh_eth_txfree(ndev);
  1349. netif_wake_queue(ndev);
  1350. }
  1351. if (intr_status & cd->eesr_err_check) {
  1352. /* Clear error interrupts */
  1353. sh_eth_write(ndev, intr_status & cd->eesr_err_check, EESR);
  1354. sh_eth_error(ndev, intr_status);
  1355. }
  1356. other_irq:
  1357. spin_unlock(&mdp->lock);
  1358. return ret;
  1359. }
  1360. static int sh_eth_poll(struct napi_struct *napi, int budget)
  1361. {
  1362. struct sh_eth_private *mdp = container_of(napi, struct sh_eth_private,
  1363. napi);
  1364. struct net_device *ndev = napi->dev;
  1365. int quota = budget;
  1366. unsigned long intr_status;
  1367. for (;;) {
  1368. intr_status = sh_eth_read(ndev, EESR);
  1369. if (!(intr_status & EESR_RX_CHECK))
  1370. break;
  1371. /* Clear Rx interrupts */
  1372. sh_eth_write(ndev, intr_status & EESR_RX_CHECK, EESR);
  1373. if (sh_eth_rx(ndev, intr_status, &quota))
  1374. goto out;
  1375. }
  1376. napi_complete(napi);
  1377. /* Reenable Rx interrupts */
  1378. sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
  1379. out:
  1380. return budget - quota;
  1381. }
  1382. /* PHY state control function */
  1383. static void sh_eth_adjust_link(struct net_device *ndev)
  1384. {
  1385. struct sh_eth_private *mdp = netdev_priv(ndev);
  1386. struct phy_device *phydev = mdp->phydev;
  1387. int new_state = 0;
  1388. if (phydev->link) {
  1389. if (phydev->duplex != mdp->duplex) {
  1390. new_state = 1;
  1391. mdp->duplex = phydev->duplex;
  1392. if (mdp->cd->set_duplex)
  1393. mdp->cd->set_duplex(ndev);
  1394. }
  1395. if (phydev->speed != mdp->speed) {
  1396. new_state = 1;
  1397. mdp->speed = phydev->speed;
  1398. if (mdp->cd->set_rate)
  1399. mdp->cd->set_rate(ndev);
  1400. }
  1401. if (!mdp->link) {
  1402. sh_eth_write(ndev,
  1403. (sh_eth_read(ndev, ECMR) & ~ECMR_TXF), ECMR);
  1404. new_state = 1;
  1405. mdp->link = phydev->link;
  1406. if (mdp->cd->no_psr || mdp->no_ether_link)
  1407. sh_eth_rcv_snd_enable(ndev);
  1408. }
  1409. } else if (mdp->link) {
  1410. new_state = 1;
  1411. mdp->link = 0;
  1412. mdp->speed = 0;
  1413. mdp->duplex = -1;
  1414. if (mdp->cd->no_psr || mdp->no_ether_link)
  1415. sh_eth_rcv_snd_disable(ndev);
  1416. }
  1417. if (new_state && netif_msg_link(mdp))
  1418. phy_print_status(phydev);
  1419. }
  1420. /* PHY init function */
  1421. static int sh_eth_phy_init(struct net_device *ndev)
  1422. {
  1423. struct sh_eth_private *mdp = netdev_priv(ndev);
  1424. char phy_id[MII_BUS_ID_SIZE + 3];
  1425. struct phy_device *phydev = NULL;
  1426. snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
  1427. mdp->mii_bus->id , mdp->phy_id);
  1428. mdp->link = 0;
  1429. mdp->speed = 0;
  1430. mdp->duplex = -1;
  1431. /* Try connect to PHY */
  1432. phydev = phy_connect(ndev, phy_id, sh_eth_adjust_link,
  1433. mdp->phy_interface);
  1434. if (IS_ERR(phydev)) {
  1435. dev_err(&ndev->dev, "phy_connect failed\n");
  1436. return PTR_ERR(phydev);
  1437. }
  1438. dev_info(&ndev->dev, "attached phy %i to driver %s\n",
  1439. phydev->addr, phydev->drv->name);
  1440. mdp->phydev = phydev;
  1441. return 0;
  1442. }
  1443. /* PHY control start function */
  1444. static int sh_eth_phy_start(struct net_device *ndev)
  1445. {
  1446. struct sh_eth_private *mdp = netdev_priv(ndev);
  1447. int ret;
  1448. ret = sh_eth_phy_init(ndev);
  1449. if (ret)
  1450. return ret;
  1451. /* reset phy - this also wakes it from PDOWN */
  1452. phy_write(mdp->phydev, MII_BMCR, BMCR_RESET);
  1453. phy_start(mdp->phydev);
  1454. return 0;
  1455. }
  1456. static int sh_eth_get_settings(struct net_device *ndev,
  1457. struct ethtool_cmd *ecmd)
  1458. {
  1459. struct sh_eth_private *mdp = netdev_priv(ndev);
  1460. unsigned long flags;
  1461. int ret;
  1462. spin_lock_irqsave(&mdp->lock, flags);
  1463. ret = phy_ethtool_gset(mdp->phydev, ecmd);
  1464. spin_unlock_irqrestore(&mdp->lock, flags);
  1465. return ret;
  1466. }
  1467. static int sh_eth_set_settings(struct net_device *ndev,
  1468. struct ethtool_cmd *ecmd)
  1469. {
  1470. struct sh_eth_private *mdp = netdev_priv(ndev);
  1471. unsigned long flags;
  1472. int ret;
  1473. spin_lock_irqsave(&mdp->lock, flags);
  1474. /* disable tx and rx */
  1475. sh_eth_rcv_snd_disable(ndev);
  1476. ret = phy_ethtool_sset(mdp->phydev, ecmd);
  1477. if (ret)
  1478. goto error_exit;
  1479. if (ecmd->duplex == DUPLEX_FULL)
  1480. mdp->duplex = 1;
  1481. else
  1482. mdp->duplex = 0;
  1483. if (mdp->cd->set_duplex)
  1484. mdp->cd->set_duplex(ndev);
  1485. error_exit:
  1486. mdelay(1);
  1487. /* enable tx and rx */
  1488. sh_eth_rcv_snd_enable(ndev);
  1489. spin_unlock_irqrestore(&mdp->lock, flags);
  1490. return ret;
  1491. }
  1492. static int sh_eth_nway_reset(struct net_device *ndev)
  1493. {
  1494. struct sh_eth_private *mdp = netdev_priv(ndev);
  1495. unsigned long flags;
  1496. int ret;
  1497. spin_lock_irqsave(&mdp->lock, flags);
  1498. ret = phy_start_aneg(mdp->phydev);
  1499. spin_unlock_irqrestore(&mdp->lock, flags);
  1500. return ret;
  1501. }
  1502. static u32 sh_eth_get_msglevel(struct net_device *ndev)
  1503. {
  1504. struct sh_eth_private *mdp = netdev_priv(ndev);
  1505. return mdp->msg_enable;
  1506. }
  1507. static void sh_eth_set_msglevel(struct net_device *ndev, u32 value)
  1508. {
  1509. struct sh_eth_private *mdp = netdev_priv(ndev);
  1510. mdp->msg_enable = value;
  1511. }
  1512. static const char sh_eth_gstrings_stats[][ETH_GSTRING_LEN] = {
  1513. "rx_current", "tx_current",
  1514. "rx_dirty", "tx_dirty",
  1515. };
  1516. #define SH_ETH_STATS_LEN ARRAY_SIZE(sh_eth_gstrings_stats)
  1517. static int sh_eth_get_sset_count(struct net_device *netdev, int sset)
  1518. {
  1519. switch (sset) {
  1520. case ETH_SS_STATS:
  1521. return SH_ETH_STATS_LEN;
  1522. default:
  1523. return -EOPNOTSUPP;
  1524. }
  1525. }
  1526. static void sh_eth_get_ethtool_stats(struct net_device *ndev,
  1527. struct ethtool_stats *stats, u64 *data)
  1528. {
  1529. struct sh_eth_private *mdp = netdev_priv(ndev);
  1530. int i = 0;
  1531. /* device-specific stats */
  1532. data[i++] = mdp->cur_rx;
  1533. data[i++] = mdp->cur_tx;
  1534. data[i++] = mdp->dirty_rx;
  1535. data[i++] = mdp->dirty_tx;
  1536. }
  1537. static void sh_eth_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
  1538. {
  1539. switch (stringset) {
  1540. case ETH_SS_STATS:
  1541. memcpy(data, *sh_eth_gstrings_stats,
  1542. sizeof(sh_eth_gstrings_stats));
  1543. break;
  1544. }
  1545. }
  1546. static void sh_eth_get_ringparam(struct net_device *ndev,
  1547. struct ethtool_ringparam *ring)
  1548. {
  1549. struct sh_eth_private *mdp = netdev_priv(ndev);
  1550. ring->rx_max_pending = RX_RING_MAX;
  1551. ring->tx_max_pending = TX_RING_MAX;
  1552. ring->rx_pending = mdp->num_rx_ring;
  1553. ring->tx_pending = mdp->num_tx_ring;
  1554. }
  1555. static int sh_eth_set_ringparam(struct net_device *ndev,
  1556. struct ethtool_ringparam *ring)
  1557. {
  1558. struct sh_eth_private *mdp = netdev_priv(ndev);
  1559. int ret;
  1560. if (ring->tx_pending > TX_RING_MAX ||
  1561. ring->rx_pending > RX_RING_MAX ||
  1562. ring->tx_pending < TX_RING_MIN ||
  1563. ring->rx_pending < RX_RING_MIN)
  1564. return -EINVAL;
  1565. if (ring->rx_mini_pending || ring->rx_jumbo_pending)
  1566. return -EINVAL;
  1567. if (netif_running(ndev)) {
  1568. netif_tx_disable(ndev);
  1569. /* Disable interrupts by clearing the interrupt mask. */
  1570. sh_eth_write(ndev, 0x0000, EESIPR);
  1571. /* Stop the chip's Tx and Rx processes. */
  1572. sh_eth_write(ndev, 0, EDTRR);
  1573. sh_eth_write(ndev, 0, EDRRR);
  1574. synchronize_irq(ndev->irq);
  1575. }
  1576. /* Free all the skbuffs in the Rx queue. */
  1577. sh_eth_ring_free(ndev);
  1578. /* Free DMA buffer */
  1579. sh_eth_free_dma_buffer(mdp);
  1580. /* Set new parameters */
  1581. mdp->num_rx_ring = ring->rx_pending;
  1582. mdp->num_tx_ring = ring->tx_pending;
  1583. ret = sh_eth_ring_init(ndev);
  1584. if (ret < 0) {
  1585. dev_err(&ndev->dev, "%s: sh_eth_ring_init failed.\n", __func__);
  1586. return ret;
  1587. }
  1588. ret = sh_eth_dev_init(ndev, false);
  1589. if (ret < 0) {
  1590. dev_err(&ndev->dev, "%s: sh_eth_dev_init failed.\n", __func__);
  1591. return ret;
  1592. }
  1593. if (netif_running(ndev)) {
  1594. sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
  1595. /* Setting the Rx mode will start the Rx process. */
  1596. sh_eth_write(ndev, EDRRR_R, EDRRR);
  1597. netif_wake_queue(ndev);
  1598. }
  1599. return 0;
  1600. }
  1601. static const struct ethtool_ops sh_eth_ethtool_ops = {
  1602. .get_settings = sh_eth_get_settings,
  1603. .set_settings = sh_eth_set_settings,
  1604. .nway_reset = sh_eth_nway_reset,
  1605. .get_msglevel = sh_eth_get_msglevel,
  1606. .set_msglevel = sh_eth_set_msglevel,
  1607. .get_link = ethtool_op_get_link,
  1608. .get_strings = sh_eth_get_strings,
  1609. .get_ethtool_stats = sh_eth_get_ethtool_stats,
  1610. .get_sset_count = sh_eth_get_sset_count,
  1611. .get_ringparam = sh_eth_get_ringparam,
  1612. .set_ringparam = sh_eth_set_ringparam,
  1613. };
  1614. /* network device open function */
  1615. static int sh_eth_open(struct net_device *ndev)
  1616. {
  1617. int ret = 0;
  1618. struct sh_eth_private *mdp = netdev_priv(ndev);
  1619. pm_runtime_get_sync(&mdp->pdev->dev);
  1620. ret = request_irq(ndev->irq, sh_eth_interrupt,
  1621. mdp->cd->irq_flags, ndev->name, ndev);
  1622. if (ret) {
  1623. dev_err(&ndev->dev, "Can not assign IRQ number\n");
  1624. return ret;
  1625. }
  1626. /* Descriptor set */
  1627. ret = sh_eth_ring_init(ndev);
  1628. if (ret)
  1629. goto out_free_irq;
  1630. /* device init */
  1631. ret = sh_eth_dev_init(ndev, true);
  1632. if (ret)
  1633. goto out_free_irq;
  1634. /* PHY control start*/
  1635. ret = sh_eth_phy_start(ndev);
  1636. if (ret)
  1637. goto out_free_irq;
  1638. napi_enable(&mdp->napi);
  1639. return ret;
  1640. out_free_irq:
  1641. free_irq(ndev->irq, ndev);
  1642. pm_runtime_put_sync(&mdp->pdev->dev);
  1643. return ret;
  1644. }
  1645. /* Timeout function */
  1646. static void sh_eth_tx_timeout(struct net_device *ndev)
  1647. {
  1648. struct sh_eth_private *mdp = netdev_priv(ndev);
  1649. struct sh_eth_rxdesc *rxdesc;
  1650. int i;
  1651. netif_stop_queue(ndev);
  1652. if (netif_msg_timer(mdp))
  1653. dev_err(&ndev->dev, "%s: transmit timed out, status %8.8x,"
  1654. " resetting...\n", ndev->name, (int)sh_eth_read(ndev, EESR));
  1655. /* tx_errors count up */
  1656. ndev->stats.tx_errors++;
  1657. /* Free all the skbuffs in the Rx queue. */
  1658. for (i = 0; i < mdp->num_rx_ring; i++) {
  1659. rxdesc = &mdp->rx_ring[i];
  1660. rxdesc->status = 0;
  1661. rxdesc->addr = 0xBADF00D0;
  1662. if (mdp->rx_skbuff[i])
  1663. dev_kfree_skb(mdp->rx_skbuff[i]);
  1664. mdp->rx_skbuff[i] = NULL;
  1665. }
  1666. for (i = 0; i < mdp->num_tx_ring; i++) {
  1667. if (mdp->tx_skbuff[i])
  1668. dev_kfree_skb(mdp->tx_skbuff[i]);
  1669. mdp->tx_skbuff[i] = NULL;
  1670. }
  1671. /* device init */
  1672. sh_eth_dev_init(ndev, true);
  1673. }
  1674. /* Packet transmit function */
  1675. static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  1676. {
  1677. struct sh_eth_private *mdp = netdev_priv(ndev);
  1678. struct sh_eth_txdesc *txdesc;
  1679. u32 entry;
  1680. unsigned long flags;
  1681. spin_lock_irqsave(&mdp->lock, flags);
  1682. if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) {
  1683. if (!sh_eth_txfree(ndev)) {
  1684. if (netif_msg_tx_queued(mdp))
  1685. dev_warn(&ndev->dev, "TxFD exhausted.\n");
  1686. netif_stop_queue(ndev);
  1687. spin_unlock_irqrestore(&mdp->lock, flags);
  1688. return NETDEV_TX_BUSY;
  1689. }
  1690. }
  1691. spin_unlock_irqrestore(&mdp->lock, flags);
  1692. entry = mdp->cur_tx % mdp->num_tx_ring;
  1693. mdp->tx_skbuff[entry] = skb;
  1694. txdesc = &mdp->tx_ring[entry];
  1695. /* soft swap. */
  1696. if (!mdp->cd->hw_swap)
  1697. sh_eth_soft_swap(phys_to_virt(ALIGN(txdesc->addr, 4)),
  1698. skb->len + 2);
  1699. txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len,
  1700. DMA_TO_DEVICE);
  1701. if (skb->len < ETHERSMALL)
  1702. txdesc->buffer_length = ETHERSMALL;
  1703. else
  1704. txdesc->buffer_length = skb->len;
  1705. if (entry >= mdp->num_tx_ring - 1)
  1706. txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE);
  1707. else
  1708. txdesc->status |= cpu_to_edmac(mdp, TD_TACT);
  1709. mdp->cur_tx++;
  1710. if (!(sh_eth_read(ndev, EDTRR) & sh_eth_get_edtrr_trns(mdp)))
  1711. sh_eth_write(ndev, sh_eth_get_edtrr_trns(mdp), EDTRR);
  1712. return NETDEV_TX_OK;
  1713. }
  1714. /* device close function */
  1715. static int sh_eth_close(struct net_device *ndev)
  1716. {
  1717. struct sh_eth_private *mdp = netdev_priv(ndev);
  1718. napi_disable(&mdp->napi);
  1719. netif_stop_queue(ndev);
  1720. /* Disable interrupts by clearing the interrupt mask. */
  1721. sh_eth_write(ndev, 0x0000, EESIPR);
  1722. /* Stop the chip's Tx and Rx processes. */
  1723. sh_eth_write(ndev, 0, EDTRR);
  1724. sh_eth_write(ndev, 0, EDRRR);
  1725. /* PHY Disconnect */
  1726. if (mdp->phydev) {
  1727. phy_stop(mdp->phydev);
  1728. phy_disconnect(mdp->phydev);
  1729. }
  1730. free_irq(ndev->irq, ndev);
  1731. /* Free all the skbuffs in the Rx queue. */
  1732. sh_eth_ring_free(ndev);
  1733. /* free DMA buffer */
  1734. sh_eth_free_dma_buffer(mdp);
  1735. pm_runtime_put_sync(&mdp->pdev->dev);
  1736. return 0;
  1737. }
  1738. static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
  1739. {
  1740. struct sh_eth_private *mdp = netdev_priv(ndev);
  1741. pm_runtime_get_sync(&mdp->pdev->dev);
  1742. ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
  1743. sh_eth_write(ndev, 0, TROCR); /* (write clear) */
  1744. ndev->stats.collisions += sh_eth_read(ndev, CDCR);
  1745. sh_eth_write(ndev, 0, CDCR); /* (write clear) */
  1746. ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
  1747. sh_eth_write(ndev, 0, LCCR); /* (write clear) */
  1748. if (sh_eth_is_gether(mdp)) {
  1749. ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
  1750. sh_eth_write(ndev, 0, CERCR); /* (write clear) */
  1751. ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
  1752. sh_eth_write(ndev, 0, CEECR); /* (write clear) */
  1753. } else {
  1754. ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
  1755. sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
  1756. }
  1757. pm_runtime_put_sync(&mdp->pdev->dev);
  1758. return &ndev->stats;
  1759. }
  1760. /* ioctl to device function */
  1761. static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq,
  1762. int cmd)
  1763. {
  1764. struct sh_eth_private *mdp = netdev_priv(ndev);
  1765. struct phy_device *phydev = mdp->phydev;
  1766. if (!netif_running(ndev))
  1767. return -EINVAL;
  1768. if (!phydev)
  1769. return -ENODEV;
  1770. return phy_mii_ioctl(phydev, rq, cmd);
  1771. }
  1772. /* For TSU_POSTn. Please refer to the manual about this (strange) bitfields */
  1773. static void *sh_eth_tsu_get_post_reg_offset(struct sh_eth_private *mdp,
  1774. int entry)
  1775. {
  1776. return sh_eth_tsu_get_offset(mdp, TSU_POST1) + (entry / 8 * 4);
  1777. }
  1778. static u32 sh_eth_tsu_get_post_mask(int entry)
  1779. {
  1780. return 0x0f << (28 - ((entry % 8) * 4));
  1781. }
  1782. static u32 sh_eth_tsu_get_post_bit(struct sh_eth_private *mdp, int entry)
  1783. {
  1784. return (0x08 >> (mdp->port << 1)) << (28 - ((entry % 8) * 4));
  1785. }
  1786. static void sh_eth_tsu_enable_cam_entry_post(struct net_device *ndev,
  1787. int entry)
  1788. {
  1789. struct sh_eth_private *mdp = netdev_priv(ndev);
  1790. u32 tmp;
  1791. void *reg_offset;
  1792. reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry);
  1793. tmp = ioread32(reg_offset);
  1794. iowrite32(tmp | sh_eth_tsu_get_post_bit(mdp, entry), reg_offset);
  1795. }
  1796. static bool sh_eth_tsu_disable_cam_entry_post(struct net_device *ndev,
  1797. int entry)
  1798. {
  1799. struct sh_eth_private *mdp = netdev_priv(ndev);
  1800. u32 post_mask, ref_mask, tmp;
  1801. void *reg_offset;
  1802. reg_offset = sh_eth_tsu_get_post_reg_offset(mdp, entry);
  1803. post_mask = sh_eth_tsu_get_post_mask(entry);
  1804. ref_mask = sh_eth_tsu_get_post_bit(mdp, entry) & ~post_mask;
  1805. tmp = ioread32(reg_offset);
  1806. iowrite32(tmp & ~post_mask, reg_offset);
  1807. /* If other port enables, the function returns "true" */
  1808. return tmp & ref_mask;
  1809. }
  1810. static int sh_eth_tsu_busy(struct net_device *ndev)
  1811. {
  1812. int timeout = SH_ETH_TSU_TIMEOUT_MS * 100;
  1813. struct sh_eth_private *mdp = netdev_priv(ndev);
  1814. while ((sh_eth_tsu_read(mdp, TSU_ADSBSY) & TSU_ADSBSY_0)) {
  1815. udelay(10);
  1816. timeout--;
  1817. if (timeout <= 0) {
  1818. dev_err(&ndev->dev, "%s: timeout\n", __func__);
  1819. return -ETIMEDOUT;
  1820. }
  1821. }
  1822. return 0;
  1823. }
  1824. static int sh_eth_tsu_write_entry(struct net_device *ndev, void *reg,
  1825. const u8 *addr)
  1826. {
  1827. u32 val;
  1828. val = addr[0] << 24 | addr[1] << 16 | addr[2] << 8 | addr[3];
  1829. iowrite32(val, reg);
  1830. if (sh_eth_tsu_busy(ndev) < 0)
  1831. return -EBUSY;
  1832. val = addr[4] << 8 | addr[5];
  1833. iowrite32(val, reg + 4);
  1834. if (sh_eth_tsu_busy(ndev) < 0)
  1835. return -EBUSY;
  1836. return 0;
  1837. }
  1838. static void sh_eth_tsu_read_entry(void *reg, u8 *addr)
  1839. {
  1840. u32 val;
  1841. val = ioread32(reg);
  1842. addr[0] = (val >> 24) & 0xff;
  1843. addr[1] = (val >> 16) & 0xff;
  1844. addr[2] = (val >> 8) & 0xff;
  1845. addr[3] = val & 0xff;
  1846. val = ioread32(reg + 4);
  1847. addr[4] = (val >> 8) & 0xff;
  1848. addr[5] = val & 0xff;
  1849. }
  1850. static int sh_eth_tsu_find_entry(struct net_device *ndev, const u8 *addr)
  1851. {
  1852. struct sh_eth_private *mdp = netdev_priv(ndev);
  1853. void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
  1854. int i;
  1855. u8 c_addr[ETH_ALEN];
  1856. for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) {
  1857. sh_eth_tsu_read_entry(reg_offset, c_addr);
  1858. if (memcmp(addr, c_addr, ETH_ALEN) == 0)
  1859. return i;
  1860. }
  1861. return -ENOENT;
  1862. }
  1863. static int sh_eth_tsu_find_empty(struct net_device *ndev)
  1864. {
  1865. u8 blank[ETH_ALEN];
  1866. int entry;
  1867. memset(blank, 0, sizeof(blank));
  1868. entry = sh_eth_tsu_find_entry(ndev, blank);
  1869. return (entry < 0) ? -ENOMEM : entry;
  1870. }
  1871. static int sh_eth_tsu_disable_cam_entry_table(struct net_device *ndev,
  1872. int entry)
  1873. {
  1874. struct sh_eth_private *mdp = netdev_priv(ndev);
  1875. void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
  1876. int ret;
  1877. u8 blank[ETH_ALEN];
  1878. sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) &
  1879. ~(1 << (31 - entry)), TSU_TEN);
  1880. memset(blank, 0, sizeof(blank));
  1881. ret = sh_eth_tsu_write_entry(ndev, reg_offset + entry * 8, blank);
  1882. if (ret < 0)
  1883. return ret;
  1884. return 0;
  1885. }
  1886. static int sh_eth_tsu_add_entry(struct net_device *ndev, const u8 *addr)
  1887. {
  1888. struct sh_eth_private *mdp = netdev_priv(ndev);
  1889. void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
  1890. int i, ret;
  1891. if (!mdp->cd->tsu)
  1892. return 0;
  1893. i = sh_eth_tsu_find_entry(ndev, addr);
  1894. if (i < 0) {
  1895. /* No entry found, create one */
  1896. i = sh_eth_tsu_find_empty(ndev);
  1897. if (i < 0)
  1898. return -ENOMEM;
  1899. ret = sh_eth_tsu_write_entry(ndev, reg_offset + i * 8, addr);
  1900. if (ret < 0)
  1901. return ret;
  1902. /* Enable the entry */
  1903. sh_eth_tsu_write(mdp, sh_eth_tsu_read(mdp, TSU_TEN) |
  1904. (1 << (31 - i)), TSU_TEN);
  1905. }
  1906. /* Entry found or created, enable POST */
  1907. sh_eth_tsu_enable_cam_entry_post(ndev, i);
  1908. return 0;
  1909. }
  1910. static int sh_eth_tsu_del_entry(struct net_device *ndev, const u8 *addr)
  1911. {
  1912. struct sh_eth_private *mdp = netdev_priv(ndev);
  1913. int i, ret;
  1914. if (!mdp->cd->tsu)
  1915. return 0;
  1916. i = sh_eth_tsu_find_entry(ndev, addr);
  1917. if (i) {
  1918. /* Entry found */
  1919. if (sh_eth_tsu_disable_cam_entry_post(ndev, i))
  1920. goto done;
  1921. /* Disable the entry if both ports was disabled */
  1922. ret = sh_eth_tsu_disable_cam_entry_table(ndev, i);
  1923. if (ret < 0)
  1924. return ret;
  1925. }
  1926. done:
  1927. return 0;
  1928. }
  1929. static int sh_eth_tsu_purge_all(struct net_device *ndev)
  1930. {
  1931. struct sh_eth_private *mdp = netdev_priv(ndev);
  1932. int i, ret;
  1933. if (unlikely(!mdp->cd->tsu))
  1934. return 0;
  1935. for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++) {
  1936. if (sh_eth_tsu_disable_cam_entry_post(ndev, i))
  1937. continue;
  1938. /* Disable the entry if both ports was disabled */
  1939. ret = sh_eth_tsu_disable_cam_entry_table(ndev, i);
  1940. if (ret < 0)
  1941. return ret;
  1942. }
  1943. return 0;
  1944. }
  1945. static void sh_eth_tsu_purge_mcast(struct net_device *ndev)
  1946. {
  1947. struct sh_eth_private *mdp = netdev_priv(ndev);
  1948. u8 addr[ETH_ALEN];
  1949. void *reg_offset = sh_eth_tsu_get_offset(mdp, TSU_ADRH0);
  1950. int i;
  1951. if (unlikely(!mdp->cd->tsu))
  1952. return;
  1953. for (i = 0; i < SH_ETH_TSU_CAM_ENTRIES; i++, reg_offset += 8) {
  1954. sh_eth_tsu_read_entry(reg_offset, addr);
  1955. if (is_multicast_ether_addr(addr))
  1956. sh_eth_tsu_del_entry(ndev, addr);
  1957. }
  1958. }
  1959. /* Multicast reception directions set */
  1960. static void sh_eth_set_multicast_list(struct net_device *ndev)
  1961. {
  1962. struct sh_eth_private *mdp = netdev_priv(ndev);
  1963. u32 ecmr_bits;
  1964. int mcast_all = 0;
  1965. unsigned long flags;
  1966. spin_lock_irqsave(&mdp->lock, flags);
  1967. /*
  1968. * Initial condition is MCT = 1, PRM = 0.
  1969. * Depending on ndev->flags, set PRM or clear MCT
  1970. */
  1971. ecmr_bits = (sh_eth_read(ndev, ECMR) & ~ECMR_PRM) | ECMR_MCT;
  1972. if (!(ndev->flags & IFF_MULTICAST)) {
  1973. sh_eth_tsu_purge_mcast(ndev);
  1974. mcast_all = 1;
  1975. }
  1976. if (ndev->flags & IFF_ALLMULTI) {
  1977. sh_eth_tsu_purge_mcast(ndev);
  1978. ecmr_bits &= ~ECMR_MCT;
  1979. mcast_all = 1;
  1980. }
  1981. if (ndev->flags & IFF_PROMISC) {
  1982. sh_eth_tsu_purge_all(ndev);
  1983. ecmr_bits = (ecmr_bits & ~ECMR_MCT) | ECMR_PRM;
  1984. } else if (mdp->cd->tsu) {
  1985. struct netdev_hw_addr *ha;
  1986. netdev_for_each_mc_addr(ha, ndev) {
  1987. if (mcast_all && is_multicast_ether_addr(ha->addr))
  1988. continue;
  1989. if (sh_eth_tsu_add_entry(ndev, ha->addr) < 0) {
  1990. if (!mcast_all) {
  1991. sh_eth_tsu_purge_mcast(ndev);
  1992. ecmr_bits &= ~ECMR_MCT;
  1993. mcast_all = 1;
  1994. }
  1995. }
  1996. }
  1997. } else {
  1998. /* Normal, unicast/broadcast-only mode. */
  1999. ecmr_bits = (ecmr_bits & ~ECMR_PRM) | ECMR_MCT;
  2000. }
  2001. /* update the ethernet mode */
  2002. sh_eth_write(ndev, ecmr_bits, ECMR);
  2003. spin_unlock_irqrestore(&mdp->lock, flags);
  2004. }
  2005. static int sh_eth_get_vtag_index(struct sh_eth_private *mdp)
  2006. {
  2007. if (!mdp->port)
  2008. return TSU_VTAG0;
  2009. else
  2010. return TSU_VTAG1;
  2011. }
  2012. static int sh_eth_vlan_rx_add_vid(struct net_device *ndev,
  2013. __be16 proto, u16 vid)
  2014. {
  2015. struct sh_eth_private *mdp = netdev_priv(ndev);
  2016. int vtag_reg_index = sh_eth_get_vtag_index(mdp);
  2017. if (unlikely(!mdp->cd->tsu))
  2018. return -EPERM;
  2019. /* No filtering if vid = 0 */
  2020. if (!vid)
  2021. return 0;
  2022. mdp->vlan_num_ids++;
  2023. /*
  2024. * The controller has one VLAN tag HW filter. So, if the filter is
  2025. * already enabled, the driver disables it and the filte
  2026. */
  2027. if (mdp->vlan_num_ids > 1) {
  2028. /* disable VLAN filter */
  2029. sh_eth_tsu_write(mdp, 0, vtag_reg_index);
  2030. return 0;
  2031. }
  2032. sh_eth_tsu_write(mdp, TSU_VTAG_ENABLE | (vid & TSU_VTAG_VID_MASK),
  2033. vtag_reg_index);
  2034. return 0;
  2035. }
  2036. static int sh_eth_vlan_rx_kill_vid(struct net_device *ndev,
  2037. __be16 proto, u16 vid)
  2038. {
  2039. struct sh_eth_private *mdp = netdev_priv(ndev);
  2040. int vtag_reg_index = sh_eth_get_vtag_index(mdp);
  2041. if (unlikely(!mdp->cd->tsu))
  2042. return -EPERM;
  2043. /* No filtering if vid = 0 */
  2044. if (!vid)
  2045. return 0;
  2046. mdp->vlan_num_ids--;
  2047. sh_eth_tsu_write(mdp, 0, vtag_reg_index);
  2048. return 0;
  2049. }
  2050. /* SuperH's TSU register init function */
  2051. static void sh_eth_tsu_init(struct sh_eth_private *mdp)
  2052. {
  2053. sh_eth_tsu_write(mdp, 0, TSU_FWEN0); /* Disable forward(0->1) */
  2054. sh_eth_tsu_write(mdp, 0, TSU_FWEN1); /* Disable forward(1->0) */
  2055. sh_eth_tsu_write(mdp, 0, TSU_FCM); /* forward fifo 3k-3k */
  2056. sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL0);
  2057. sh_eth_tsu_write(mdp, 0xc, TSU_BSYSL1);
  2058. sh_eth_tsu_write(mdp, 0, TSU_PRISL0);
  2059. sh_eth_tsu_write(mdp, 0, TSU_PRISL1);
  2060. sh_eth_tsu_write(mdp, 0, TSU_FWSL0);
  2061. sh_eth_tsu_write(mdp, 0, TSU_FWSL1);
  2062. sh_eth_tsu_write(mdp, TSU_FWSLC_POSTENU | TSU_FWSLC_POSTENL, TSU_FWSLC);
  2063. if (sh_eth_is_gether(mdp)) {
  2064. sh_eth_tsu_write(mdp, 0, TSU_QTAG0); /* Disable QTAG(0->1) */
  2065. sh_eth_tsu_write(mdp, 0, TSU_QTAG1); /* Disable QTAG(1->0) */
  2066. } else {
  2067. sh_eth_tsu_write(mdp, 0, TSU_QTAGM0); /* Disable QTAG(0->1) */
  2068. sh_eth_tsu_write(mdp, 0, TSU_QTAGM1); /* Disable QTAG(1->0) */
  2069. }
  2070. sh_eth_tsu_write(mdp, 0, TSU_FWSR); /* all interrupt status clear */
  2071. sh_eth_tsu_write(mdp, 0, TSU_FWINMK); /* Disable all interrupt */
  2072. sh_eth_tsu_write(mdp, 0, TSU_TEN); /* Disable all CAM entry */
  2073. sh_eth_tsu_write(mdp, 0, TSU_POST1); /* Disable CAM entry [ 0- 7] */
  2074. sh_eth_tsu_write(mdp, 0, TSU_POST2); /* Disable CAM entry [ 8-15] */
  2075. sh_eth_tsu_write(mdp, 0, TSU_POST3); /* Disable CAM entry [16-23] */
  2076. sh_eth_tsu_write(mdp, 0, TSU_POST4); /* Disable CAM entry [24-31] */
  2077. }
  2078. /* MDIO bus release function */
  2079. static int sh_mdio_release(struct net_device *ndev)
  2080. {
  2081. struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
  2082. /* unregister mdio bus */
  2083. mdiobus_unregister(bus);
  2084. /* remove mdio bus info from net_device */
  2085. dev_set_drvdata(&ndev->dev, NULL);
  2086. /* free bitbang info */
  2087. free_mdio_bitbang(bus);
  2088. return 0;
  2089. }
  2090. /* MDIO bus init function */
  2091. static int sh_mdio_init(struct net_device *ndev, int id,
  2092. struct sh_eth_plat_data *pd)
  2093. {
  2094. int ret, i;
  2095. struct bb_info *bitbang;
  2096. struct sh_eth_private *mdp = netdev_priv(ndev);
  2097. /* create bit control struct for PHY */
  2098. bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info),
  2099. GFP_KERNEL);
  2100. if (!bitbang) {
  2101. ret = -ENOMEM;
  2102. goto out;
  2103. }
  2104. /* bitbang init */
  2105. bitbang->addr = mdp->addr + mdp->reg_offset[PIR];
  2106. bitbang->set_gate = pd->set_mdio_gate;
  2107. bitbang->mdi_msk = PIR_MDI;
  2108. bitbang->mdo_msk = PIR_MDO;
  2109. bitbang->mmd_msk = PIR_MMD;
  2110. bitbang->mdc_msk = PIR_MDC;
  2111. bitbang->ctrl.ops = &bb_ops;
  2112. /* MII controller setting */
  2113. mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
  2114. if (!mdp->mii_bus) {
  2115. ret = -ENOMEM;
  2116. goto out;
  2117. }
  2118. /* Hook up MII support for ethtool */
  2119. mdp->mii_bus->name = "sh_mii";
  2120. mdp->mii_bus->parent = &ndev->dev;
  2121. snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
  2122. mdp->pdev->name, id);
  2123. /* PHY IRQ */
  2124. mdp->mii_bus->irq = devm_kzalloc(&ndev->dev,
  2125. sizeof(int) * PHY_MAX_ADDR,
  2126. GFP_KERNEL);
  2127. if (!mdp->mii_bus->irq) {
  2128. ret = -ENOMEM;
  2129. goto out_free_bus;
  2130. }
  2131. for (i = 0; i < PHY_MAX_ADDR; i++)
  2132. mdp->mii_bus->irq[i] = PHY_POLL;
  2133. /* register mdio bus */
  2134. ret = mdiobus_register(mdp->mii_bus);
  2135. if (ret)
  2136. goto out_free_bus;
  2137. dev_set_drvdata(&ndev->dev, mdp->mii_bus);
  2138. return 0;
  2139. out_free_bus:
  2140. free_mdio_bitbang(mdp->mii_bus);
  2141. out:
  2142. return ret;
  2143. }
  2144. static const u16 *sh_eth_get_register_offset(int register_type)
  2145. {
  2146. const u16 *reg_offset = NULL;
  2147. switch (register_type) {
  2148. case SH_ETH_REG_GIGABIT:
  2149. reg_offset = sh_eth_offset_gigabit;
  2150. break;
  2151. case SH_ETH_REG_FAST_RCAR:
  2152. reg_offset = sh_eth_offset_fast_rcar;
  2153. break;
  2154. case SH_ETH_REG_FAST_SH4:
  2155. reg_offset = sh_eth_offset_fast_sh4;
  2156. break;
  2157. case SH_ETH_REG_FAST_SH3_SH2:
  2158. reg_offset = sh_eth_offset_fast_sh3_sh2;
  2159. break;
  2160. default:
  2161. pr_err("Unknown register type (%d)\n", register_type);
  2162. break;
  2163. }
  2164. return reg_offset;
  2165. }
  2166. static const struct net_device_ops sh_eth_netdev_ops = {
  2167. .ndo_open = sh_eth_open,
  2168. .ndo_stop = sh_eth_close,
  2169. .ndo_start_xmit = sh_eth_start_xmit,
  2170. .ndo_get_stats = sh_eth_get_stats,
  2171. .ndo_tx_timeout = sh_eth_tx_timeout,
  2172. .ndo_do_ioctl = sh_eth_do_ioctl,
  2173. .ndo_validate_addr = eth_validate_addr,
  2174. .ndo_set_mac_address = eth_mac_addr,
  2175. .ndo_change_mtu = eth_change_mtu,
  2176. };
  2177. static const struct net_device_ops sh_eth_netdev_ops_tsu = {
  2178. .ndo_open = sh_eth_open,
  2179. .ndo_stop = sh_eth_close,
  2180. .ndo_start_xmit = sh_eth_start_xmit,
  2181. .ndo_get_stats = sh_eth_get_stats,
  2182. .ndo_set_rx_mode = sh_eth_set_multicast_list,
  2183. .ndo_vlan_rx_add_vid = sh_eth_vlan_rx_add_vid,
  2184. .ndo_vlan_rx_kill_vid = sh_eth_vlan_rx_kill_vid,
  2185. .ndo_tx_timeout = sh_eth_tx_timeout,
  2186. .ndo_do_ioctl = sh_eth_do_ioctl,
  2187. .ndo_validate_addr = eth_validate_addr,
  2188. .ndo_set_mac_address = eth_mac_addr,
  2189. .ndo_change_mtu = eth_change_mtu,
  2190. };
  2191. static int sh_eth_drv_probe(struct platform_device *pdev)
  2192. {
  2193. int ret, devno = 0;
  2194. struct resource *res;
  2195. struct net_device *ndev = NULL;
  2196. struct sh_eth_private *mdp = NULL;
  2197. struct sh_eth_plat_data *pd = pdev->dev.platform_data;
  2198. const struct platform_device_id *id = platform_get_device_id(pdev);
  2199. /* get base addr */
  2200. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2201. if (unlikely(res == NULL)) {
  2202. dev_err(&pdev->dev, "invalid resource\n");
  2203. ret = -EINVAL;
  2204. goto out;
  2205. }
  2206. ndev = alloc_etherdev(sizeof(struct sh_eth_private));
  2207. if (!ndev) {
  2208. ret = -ENOMEM;
  2209. goto out;
  2210. }
  2211. /* The sh Ether-specific entries in the device structure. */
  2212. ndev->base_addr = res->start;
  2213. devno = pdev->id;
  2214. if (devno < 0)
  2215. devno = 0;
  2216. ndev->dma = -1;
  2217. ret = platform_get_irq(pdev, 0);
  2218. if (ret < 0) {
  2219. ret = -ENODEV;
  2220. goto out_release;
  2221. }
  2222. ndev->irq = ret;
  2223. SET_NETDEV_DEV(ndev, &pdev->dev);
  2224. /* Fill in the fields of the device structure with ethernet values. */
  2225. ether_setup(ndev);
  2226. mdp = netdev_priv(ndev);
  2227. mdp->num_tx_ring = TX_RING_SIZE;
  2228. mdp->num_rx_ring = RX_RING_SIZE;
  2229. mdp->addr = devm_ioremap_resource(&pdev->dev, res);
  2230. if (IS_ERR(mdp->addr)) {
  2231. ret = PTR_ERR(mdp->addr);
  2232. goto out_release;
  2233. }
  2234. spin_lock_init(&mdp->lock);
  2235. mdp->pdev = pdev;
  2236. pm_runtime_enable(&pdev->dev);
  2237. pm_runtime_resume(&pdev->dev);
  2238. /* get PHY ID */
  2239. mdp->phy_id = pd->phy;
  2240. mdp->phy_interface = pd->phy_interface;
  2241. /* EDMAC endian */
  2242. mdp->edmac_endian = pd->edmac_endian;
  2243. mdp->no_ether_link = pd->no_ether_link;
  2244. mdp->ether_link_active_low = pd->ether_link_active_low;
  2245. mdp->reg_offset = sh_eth_get_register_offset(pd->register_type);
  2246. /* set cpu data */
  2247. mdp->cd = (struct sh_eth_cpu_data *)id->driver_data;
  2248. sh_eth_set_default_cpu_data(mdp->cd);
  2249. /* set function */
  2250. if (mdp->cd->tsu)
  2251. ndev->netdev_ops = &sh_eth_netdev_ops_tsu;
  2252. else
  2253. ndev->netdev_ops = &sh_eth_netdev_ops;
  2254. SET_ETHTOOL_OPS(ndev, &sh_eth_ethtool_ops);
  2255. ndev->watchdog_timeo = TX_TIMEOUT;
  2256. /* debug message level */
  2257. mdp->msg_enable = SH_ETH_DEF_MSG_ENABLE;
  2258. /* read and set MAC address */
  2259. read_mac_address(ndev, pd->mac_addr);
  2260. if (!is_valid_ether_addr(ndev->dev_addr)) {
  2261. dev_warn(&pdev->dev,
  2262. "no valid MAC address supplied, using a random one.\n");
  2263. eth_hw_addr_random(ndev);
  2264. }
  2265. /* ioremap the TSU registers */
  2266. if (mdp->cd->tsu) {
  2267. struct resource *rtsu;
  2268. rtsu = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  2269. mdp->tsu_addr = devm_ioremap_resource(&pdev->dev, rtsu);
  2270. if (IS_ERR(mdp->tsu_addr)) {
  2271. ret = PTR_ERR(mdp->tsu_addr);
  2272. goto out_release;
  2273. }
  2274. mdp->port = devno % 2;
  2275. ndev->features = NETIF_F_HW_VLAN_CTAG_FILTER;
  2276. }
  2277. /* initialize first or needed device */
  2278. if (!devno || pd->needs_init) {
  2279. if (mdp->cd->chip_reset)
  2280. mdp->cd->chip_reset(ndev);
  2281. if (mdp->cd->tsu) {
  2282. /* TSU init (Init only)*/
  2283. sh_eth_tsu_init(mdp);
  2284. }
  2285. }
  2286. netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64);
  2287. /* network device register */
  2288. ret = register_netdev(ndev);
  2289. if (ret)
  2290. goto out_napi_del;
  2291. /* mdio bus init */
  2292. ret = sh_mdio_init(ndev, pdev->id, pd);
  2293. if (ret)
  2294. goto out_unregister;
  2295. /* print device information */
  2296. pr_info("Base address at 0x%x, %pM, IRQ %d.\n",
  2297. (u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
  2298. platform_set_drvdata(pdev, ndev);
  2299. return ret;
  2300. out_unregister:
  2301. unregister_netdev(ndev);
  2302. out_napi_del:
  2303. netif_napi_del(&mdp->napi);
  2304. out_release:
  2305. /* net_dev free */
  2306. if (ndev)
  2307. free_netdev(ndev);
  2308. out:
  2309. return ret;
  2310. }
  2311. static int sh_eth_drv_remove(struct platform_device *pdev)
  2312. {
  2313. struct net_device *ndev = platform_get_drvdata(pdev);
  2314. struct sh_eth_private *mdp = netdev_priv(ndev);
  2315. sh_mdio_release(ndev);
  2316. unregister_netdev(ndev);
  2317. netif_napi_del(&mdp->napi);
  2318. pm_runtime_disable(&pdev->dev);
  2319. free_netdev(ndev);
  2320. return 0;
  2321. }
  2322. #ifdef CONFIG_PM
  2323. static int sh_eth_runtime_nop(struct device *dev)
  2324. {
  2325. /*
  2326. * Runtime PM callback shared between ->runtime_suspend()
  2327. * and ->runtime_resume(). Simply returns success.
  2328. *
  2329. * This driver re-initializes all registers after
  2330. * pm_runtime_get_sync() anyway so there is no need
  2331. * to save and restore registers here.
  2332. */
  2333. return 0;
  2334. }
  2335. static const struct dev_pm_ops sh_eth_dev_pm_ops = {
  2336. .runtime_suspend = sh_eth_runtime_nop,
  2337. .runtime_resume = sh_eth_runtime_nop,
  2338. };
  2339. #define SH_ETH_PM_OPS (&sh_eth_dev_pm_ops)
  2340. #else
  2341. #define SH_ETH_PM_OPS NULL
  2342. #endif
  2343. static struct platform_device_id sh_eth_id_table[] = {
  2344. { "sh7619-ether", (kernel_ulong_t)&sh7619_data },
  2345. { "sh771x-ether", (kernel_ulong_t)&sh771x_data },
  2346. { "sh7724-ether", (kernel_ulong_t)&sh7724_data },
  2347. { "sh7734-gether", (kernel_ulong_t)&sh7734_data },
  2348. { "sh7757-ether", (kernel_ulong_t)&sh7757_data },
  2349. { "sh7757-gether", (kernel_ulong_t)&sh7757_data_giga },
  2350. { "sh7763-gether", (kernel_ulong_t)&sh7763_data },
  2351. { "r8a7740-gether", (kernel_ulong_t)&r8a7740_data },
  2352. { "r8a777x-ether", (kernel_ulong_t)&r8a777x_data },
  2353. { "r8a7790-ether", (kernel_ulong_t)&r8a7790_data },
  2354. { }
  2355. };
  2356. MODULE_DEVICE_TABLE(platform, sh_eth_id_table);
  2357. static struct platform_driver sh_eth_driver = {
  2358. .probe = sh_eth_drv_probe,
  2359. .remove = sh_eth_drv_remove,
  2360. .id_table = sh_eth_id_table,
  2361. .driver = {
  2362. .name = CARDNAME,
  2363. .pm = SH_ETH_PM_OPS,
  2364. },
  2365. };
  2366. module_platform_driver(sh_eth_driver);
  2367. MODULE_AUTHOR("Nobuhiro Iwamatsu, Yoshihiro Shimoda");
  2368. MODULE_DESCRIPTION("Renesas SuperH Ethernet driver");
  2369. MODULE_LICENSE("GPL v2");