sh_eth.c 66 KB

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