bcm63xx_enet.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  1. /*
  2. * Driver for BCM963xx builtin Ethernet mac
  3. *
  4. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/module.h>
  23. #include <linux/clk.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/slab.h>
  26. #include <linux/delay.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/crc32.h>
  29. #include <linux/err.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/if_vlan.h>
  33. #include <bcm63xx_dev_enet.h>
  34. #include "bcm63xx_enet.h"
  35. static char bcm_enet_driver_name[] = "bcm63xx_enet";
  36. static char bcm_enet_driver_version[] = "1.0";
  37. static int copybreak __read_mostly = 128;
  38. module_param(copybreak, int, 0);
  39. MODULE_PARM_DESC(copybreak, "Receive copy threshold");
  40. /* io registers memory shared between all devices */
  41. static void __iomem *bcm_enet_shared_base[3];
  42. /*
  43. * io helpers to access mac registers
  44. */
  45. static inline u32 enet_readl(struct bcm_enet_priv *priv, u32 off)
  46. {
  47. return bcm_readl(priv->base + off);
  48. }
  49. static inline void enet_writel(struct bcm_enet_priv *priv,
  50. u32 val, u32 off)
  51. {
  52. bcm_writel(val, priv->base + off);
  53. }
  54. /*
  55. * io helpers to access switch registers
  56. */
  57. static inline u32 enetsw_readl(struct bcm_enet_priv *priv, u32 off)
  58. {
  59. return bcm_readl(priv->base + off);
  60. }
  61. static inline void enetsw_writel(struct bcm_enet_priv *priv,
  62. u32 val, u32 off)
  63. {
  64. bcm_writel(val, priv->base + off);
  65. }
  66. static inline u16 enetsw_readw(struct bcm_enet_priv *priv, u32 off)
  67. {
  68. return bcm_readw(priv->base + off);
  69. }
  70. static inline void enetsw_writew(struct bcm_enet_priv *priv,
  71. u16 val, u32 off)
  72. {
  73. bcm_writew(val, priv->base + off);
  74. }
  75. static inline u8 enetsw_readb(struct bcm_enet_priv *priv, u32 off)
  76. {
  77. return bcm_readb(priv->base + off);
  78. }
  79. static inline void enetsw_writeb(struct bcm_enet_priv *priv,
  80. u8 val, u32 off)
  81. {
  82. bcm_writeb(val, priv->base + off);
  83. }
  84. /* io helpers to access shared registers */
  85. static inline u32 enet_dma_readl(struct bcm_enet_priv *priv, u32 off)
  86. {
  87. return bcm_readl(bcm_enet_shared_base[0] + off);
  88. }
  89. static inline void enet_dma_writel(struct bcm_enet_priv *priv,
  90. u32 val, u32 off)
  91. {
  92. bcm_writel(val, bcm_enet_shared_base[0] + off);
  93. }
  94. static inline u32 enet_dmac_readl(struct bcm_enet_priv *priv, u32 off, int chan)
  95. {
  96. return bcm_readl(bcm_enet_shared_base[1] +
  97. bcm63xx_enetdmacreg(off) + chan * priv->dma_chan_width);
  98. }
  99. static inline void enet_dmac_writel(struct bcm_enet_priv *priv,
  100. u32 val, u32 off, int chan)
  101. {
  102. bcm_writel(val, bcm_enet_shared_base[1] +
  103. bcm63xx_enetdmacreg(off) + chan * priv->dma_chan_width);
  104. }
  105. static inline u32 enet_dmas_readl(struct bcm_enet_priv *priv, u32 off, int chan)
  106. {
  107. return bcm_readl(bcm_enet_shared_base[2] + off + chan * priv->dma_chan_width);
  108. }
  109. static inline void enet_dmas_writel(struct bcm_enet_priv *priv,
  110. u32 val, u32 off, int chan)
  111. {
  112. bcm_writel(val, bcm_enet_shared_base[2] + off + chan * priv->dma_chan_width);
  113. }
  114. /*
  115. * write given data into mii register and wait for transfer to end
  116. * with timeout (average measured transfer time is 25us)
  117. */
  118. static int do_mdio_op(struct bcm_enet_priv *priv, unsigned int data)
  119. {
  120. int limit;
  121. /* make sure mii interrupt status is cleared */
  122. enet_writel(priv, ENET_IR_MII, ENET_IR_REG);
  123. enet_writel(priv, data, ENET_MIIDATA_REG);
  124. wmb();
  125. /* busy wait on mii interrupt bit, with timeout */
  126. limit = 1000;
  127. do {
  128. if (enet_readl(priv, ENET_IR_REG) & ENET_IR_MII)
  129. break;
  130. udelay(1);
  131. } while (limit-- > 0);
  132. return (limit < 0) ? 1 : 0;
  133. }
  134. /*
  135. * MII internal read callback
  136. */
  137. static int bcm_enet_mdio_read(struct bcm_enet_priv *priv, int mii_id,
  138. int regnum)
  139. {
  140. u32 tmp, val;
  141. tmp = regnum << ENET_MIIDATA_REG_SHIFT;
  142. tmp |= 0x2 << ENET_MIIDATA_TA_SHIFT;
  143. tmp |= mii_id << ENET_MIIDATA_PHYID_SHIFT;
  144. tmp |= ENET_MIIDATA_OP_READ_MASK;
  145. if (do_mdio_op(priv, tmp))
  146. return -1;
  147. val = enet_readl(priv, ENET_MIIDATA_REG);
  148. val &= 0xffff;
  149. return val;
  150. }
  151. /*
  152. * MII internal write callback
  153. */
  154. static int bcm_enet_mdio_write(struct bcm_enet_priv *priv, int mii_id,
  155. int regnum, u16 value)
  156. {
  157. u32 tmp;
  158. tmp = (value & 0xffff) << ENET_MIIDATA_DATA_SHIFT;
  159. tmp |= 0x2 << ENET_MIIDATA_TA_SHIFT;
  160. tmp |= regnum << ENET_MIIDATA_REG_SHIFT;
  161. tmp |= mii_id << ENET_MIIDATA_PHYID_SHIFT;
  162. tmp |= ENET_MIIDATA_OP_WRITE_MASK;
  163. (void)do_mdio_op(priv, tmp);
  164. return 0;
  165. }
  166. /*
  167. * MII read callback from phylib
  168. */
  169. static int bcm_enet_mdio_read_phylib(struct mii_bus *bus, int mii_id,
  170. int regnum)
  171. {
  172. return bcm_enet_mdio_read(bus->priv, mii_id, regnum);
  173. }
  174. /*
  175. * MII write callback from phylib
  176. */
  177. static int bcm_enet_mdio_write_phylib(struct mii_bus *bus, int mii_id,
  178. int regnum, u16 value)
  179. {
  180. return bcm_enet_mdio_write(bus->priv, mii_id, regnum, value);
  181. }
  182. /*
  183. * MII read callback from mii core
  184. */
  185. static int bcm_enet_mdio_read_mii(struct net_device *dev, int mii_id,
  186. int regnum)
  187. {
  188. return bcm_enet_mdio_read(netdev_priv(dev), mii_id, regnum);
  189. }
  190. /*
  191. * MII write callback from mii core
  192. */
  193. static void bcm_enet_mdio_write_mii(struct net_device *dev, int mii_id,
  194. int regnum, int value)
  195. {
  196. bcm_enet_mdio_write(netdev_priv(dev), mii_id, regnum, value);
  197. }
  198. /*
  199. * refill rx queue
  200. */
  201. static int bcm_enet_refill_rx(struct net_device *dev)
  202. {
  203. struct bcm_enet_priv *priv;
  204. priv = netdev_priv(dev);
  205. while (priv->rx_desc_count < priv->rx_ring_size) {
  206. struct bcm_enet_desc *desc;
  207. struct sk_buff *skb;
  208. dma_addr_t p;
  209. int desc_idx;
  210. u32 len_stat;
  211. desc_idx = priv->rx_dirty_desc;
  212. desc = &priv->rx_desc_cpu[desc_idx];
  213. if (!priv->rx_skb[desc_idx]) {
  214. skb = netdev_alloc_skb(dev, priv->rx_skb_size);
  215. if (!skb)
  216. break;
  217. priv->rx_skb[desc_idx] = skb;
  218. p = dma_map_single(&priv->pdev->dev, skb->data,
  219. priv->rx_skb_size,
  220. DMA_FROM_DEVICE);
  221. desc->address = p;
  222. }
  223. len_stat = priv->rx_skb_size << DMADESC_LENGTH_SHIFT;
  224. len_stat |= DMADESC_OWNER_MASK;
  225. if (priv->rx_dirty_desc == priv->rx_ring_size - 1) {
  226. len_stat |= (DMADESC_WRAP_MASK >> priv->dma_desc_shift);
  227. priv->rx_dirty_desc = 0;
  228. } else {
  229. priv->rx_dirty_desc++;
  230. }
  231. wmb();
  232. desc->len_stat = len_stat;
  233. priv->rx_desc_count++;
  234. /* tell dma engine we allocated one buffer */
  235. if (priv->dma_has_sram)
  236. enet_dma_writel(priv, 1, ENETDMA_BUFALLOC_REG(priv->rx_chan));
  237. else
  238. enet_dmac_writel(priv, 1, ENETDMAC_BUFALLOC, priv->rx_chan);
  239. }
  240. /* If rx ring is still empty, set a timer to try allocating
  241. * again at a later time. */
  242. if (priv->rx_desc_count == 0 && netif_running(dev)) {
  243. dev_warn(&priv->pdev->dev, "unable to refill rx ring\n");
  244. priv->rx_timeout.expires = jiffies + HZ;
  245. add_timer(&priv->rx_timeout);
  246. }
  247. return 0;
  248. }
  249. /*
  250. * timer callback to defer refill rx queue in case we're OOM
  251. */
  252. static void bcm_enet_refill_rx_timer(struct timer_list *t)
  253. {
  254. struct bcm_enet_priv *priv = from_timer(priv, t, rx_timeout);
  255. struct net_device *dev = priv->net_dev;
  256. spin_lock(&priv->rx_lock);
  257. bcm_enet_refill_rx(dev);
  258. spin_unlock(&priv->rx_lock);
  259. }
  260. /*
  261. * extract packet from rx queue
  262. */
  263. static int bcm_enet_receive_queue(struct net_device *dev, int budget)
  264. {
  265. struct bcm_enet_priv *priv;
  266. struct device *kdev;
  267. int processed;
  268. priv = netdev_priv(dev);
  269. kdev = &priv->pdev->dev;
  270. processed = 0;
  271. /* don't scan ring further than number of refilled
  272. * descriptor */
  273. if (budget > priv->rx_desc_count)
  274. budget = priv->rx_desc_count;
  275. do {
  276. struct bcm_enet_desc *desc;
  277. struct sk_buff *skb;
  278. int desc_idx;
  279. u32 len_stat;
  280. unsigned int len;
  281. desc_idx = priv->rx_curr_desc;
  282. desc = &priv->rx_desc_cpu[desc_idx];
  283. /* make sure we actually read the descriptor status at
  284. * each loop */
  285. rmb();
  286. len_stat = desc->len_stat;
  287. /* break if dma ownership belongs to hw */
  288. if (len_stat & DMADESC_OWNER_MASK)
  289. break;
  290. processed++;
  291. priv->rx_curr_desc++;
  292. if (priv->rx_curr_desc == priv->rx_ring_size)
  293. priv->rx_curr_desc = 0;
  294. priv->rx_desc_count--;
  295. /* if the packet does not have start of packet _and_
  296. * end of packet flag set, then just recycle it */
  297. if ((len_stat & (DMADESC_ESOP_MASK >> priv->dma_desc_shift)) !=
  298. (DMADESC_ESOP_MASK >> priv->dma_desc_shift)) {
  299. dev->stats.rx_dropped++;
  300. continue;
  301. }
  302. /* recycle packet if it's marked as bad */
  303. if (!priv->enet_is_sw &&
  304. unlikely(len_stat & DMADESC_ERR_MASK)) {
  305. dev->stats.rx_errors++;
  306. if (len_stat & DMADESC_OVSIZE_MASK)
  307. dev->stats.rx_length_errors++;
  308. if (len_stat & DMADESC_CRC_MASK)
  309. dev->stats.rx_crc_errors++;
  310. if (len_stat & DMADESC_UNDER_MASK)
  311. dev->stats.rx_frame_errors++;
  312. if (len_stat & DMADESC_OV_MASK)
  313. dev->stats.rx_fifo_errors++;
  314. continue;
  315. }
  316. /* valid packet */
  317. skb = priv->rx_skb[desc_idx];
  318. len = (len_stat & DMADESC_LENGTH_MASK) >> DMADESC_LENGTH_SHIFT;
  319. /* don't include FCS */
  320. len -= 4;
  321. if (len < copybreak) {
  322. struct sk_buff *nskb;
  323. nskb = napi_alloc_skb(&priv->napi, len);
  324. if (!nskb) {
  325. /* forget packet, just rearm desc */
  326. dev->stats.rx_dropped++;
  327. continue;
  328. }
  329. dma_sync_single_for_cpu(kdev, desc->address,
  330. len, DMA_FROM_DEVICE);
  331. memcpy(nskb->data, skb->data, len);
  332. dma_sync_single_for_device(kdev, desc->address,
  333. len, DMA_FROM_DEVICE);
  334. skb = nskb;
  335. } else {
  336. dma_unmap_single(&priv->pdev->dev, desc->address,
  337. priv->rx_skb_size, DMA_FROM_DEVICE);
  338. priv->rx_skb[desc_idx] = NULL;
  339. }
  340. skb_put(skb, len);
  341. skb->protocol = eth_type_trans(skb, dev);
  342. dev->stats.rx_packets++;
  343. dev->stats.rx_bytes += len;
  344. netif_receive_skb(skb);
  345. } while (--budget > 0);
  346. if (processed || !priv->rx_desc_count) {
  347. bcm_enet_refill_rx(dev);
  348. /* kick rx dma */
  349. enet_dmac_writel(priv, priv->dma_chan_en_mask,
  350. ENETDMAC_CHANCFG, priv->rx_chan);
  351. }
  352. return processed;
  353. }
  354. /*
  355. * try to or force reclaim of transmitted buffers
  356. */
  357. static int bcm_enet_tx_reclaim(struct net_device *dev, int force)
  358. {
  359. struct bcm_enet_priv *priv;
  360. int released;
  361. priv = netdev_priv(dev);
  362. released = 0;
  363. while (priv->tx_desc_count < priv->tx_ring_size) {
  364. struct bcm_enet_desc *desc;
  365. struct sk_buff *skb;
  366. /* We run in a bh and fight against start_xmit, which
  367. * is called with bh disabled */
  368. spin_lock(&priv->tx_lock);
  369. desc = &priv->tx_desc_cpu[priv->tx_dirty_desc];
  370. if (!force && (desc->len_stat & DMADESC_OWNER_MASK)) {
  371. spin_unlock(&priv->tx_lock);
  372. break;
  373. }
  374. /* ensure other field of the descriptor were not read
  375. * before we checked ownership */
  376. rmb();
  377. skb = priv->tx_skb[priv->tx_dirty_desc];
  378. priv->tx_skb[priv->tx_dirty_desc] = NULL;
  379. dma_unmap_single(&priv->pdev->dev, desc->address, skb->len,
  380. DMA_TO_DEVICE);
  381. priv->tx_dirty_desc++;
  382. if (priv->tx_dirty_desc == priv->tx_ring_size)
  383. priv->tx_dirty_desc = 0;
  384. priv->tx_desc_count++;
  385. spin_unlock(&priv->tx_lock);
  386. if (desc->len_stat & DMADESC_UNDER_MASK)
  387. dev->stats.tx_errors++;
  388. dev_kfree_skb(skb);
  389. released++;
  390. }
  391. if (netif_queue_stopped(dev) && released)
  392. netif_wake_queue(dev);
  393. return released;
  394. }
  395. /*
  396. * poll func, called by network core
  397. */
  398. static int bcm_enet_poll(struct napi_struct *napi, int budget)
  399. {
  400. struct bcm_enet_priv *priv;
  401. struct net_device *dev;
  402. int rx_work_done;
  403. priv = container_of(napi, struct bcm_enet_priv, napi);
  404. dev = priv->net_dev;
  405. /* ack interrupts */
  406. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  407. ENETDMAC_IR, priv->rx_chan);
  408. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  409. ENETDMAC_IR, priv->tx_chan);
  410. /* reclaim sent skb */
  411. bcm_enet_tx_reclaim(dev, 0);
  412. spin_lock(&priv->rx_lock);
  413. rx_work_done = bcm_enet_receive_queue(dev, budget);
  414. spin_unlock(&priv->rx_lock);
  415. if (rx_work_done >= budget) {
  416. /* rx queue is not yet empty/clean */
  417. return rx_work_done;
  418. }
  419. /* no more packet in rx/tx queue, remove device from poll
  420. * queue */
  421. napi_complete_done(napi, rx_work_done);
  422. /* restore rx/tx interrupt */
  423. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  424. ENETDMAC_IRMASK, priv->rx_chan);
  425. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  426. ENETDMAC_IRMASK, priv->tx_chan);
  427. return rx_work_done;
  428. }
  429. /*
  430. * mac interrupt handler
  431. */
  432. static irqreturn_t bcm_enet_isr_mac(int irq, void *dev_id)
  433. {
  434. struct net_device *dev;
  435. struct bcm_enet_priv *priv;
  436. u32 stat;
  437. dev = dev_id;
  438. priv = netdev_priv(dev);
  439. stat = enet_readl(priv, ENET_IR_REG);
  440. if (!(stat & ENET_IR_MIB))
  441. return IRQ_NONE;
  442. /* clear & mask interrupt */
  443. enet_writel(priv, ENET_IR_MIB, ENET_IR_REG);
  444. enet_writel(priv, 0, ENET_IRMASK_REG);
  445. /* read mib registers in workqueue */
  446. schedule_work(&priv->mib_update_task);
  447. return IRQ_HANDLED;
  448. }
  449. /*
  450. * rx/tx dma interrupt handler
  451. */
  452. static irqreturn_t bcm_enet_isr_dma(int irq, void *dev_id)
  453. {
  454. struct net_device *dev;
  455. struct bcm_enet_priv *priv;
  456. dev = dev_id;
  457. priv = netdev_priv(dev);
  458. /* mask rx/tx interrupts */
  459. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->rx_chan);
  460. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->tx_chan);
  461. napi_schedule(&priv->napi);
  462. return IRQ_HANDLED;
  463. }
  464. /*
  465. * tx request callback
  466. */
  467. static netdev_tx_t
  468. bcm_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  469. {
  470. struct bcm_enet_priv *priv;
  471. struct bcm_enet_desc *desc;
  472. u32 len_stat;
  473. netdev_tx_t ret;
  474. priv = netdev_priv(dev);
  475. /* lock against tx reclaim */
  476. spin_lock(&priv->tx_lock);
  477. /* make sure the tx hw queue is not full, should not happen
  478. * since we stop queue before it's the case */
  479. if (unlikely(!priv->tx_desc_count)) {
  480. netif_stop_queue(dev);
  481. dev_err(&priv->pdev->dev, "xmit called with no tx desc "
  482. "available?\n");
  483. ret = NETDEV_TX_BUSY;
  484. goto out_unlock;
  485. }
  486. /* pad small packets sent on a switch device */
  487. if (priv->enet_is_sw && skb->len < 64) {
  488. int needed = 64 - skb->len;
  489. char *data;
  490. if (unlikely(skb_tailroom(skb) < needed)) {
  491. struct sk_buff *nskb;
  492. nskb = skb_copy_expand(skb, 0, needed, GFP_ATOMIC);
  493. if (!nskb) {
  494. ret = NETDEV_TX_BUSY;
  495. goto out_unlock;
  496. }
  497. dev_kfree_skb(skb);
  498. skb = nskb;
  499. }
  500. data = skb_put_zero(skb, needed);
  501. }
  502. /* point to the next available desc */
  503. desc = &priv->tx_desc_cpu[priv->tx_curr_desc];
  504. priv->tx_skb[priv->tx_curr_desc] = skb;
  505. /* fill descriptor */
  506. desc->address = dma_map_single(&priv->pdev->dev, skb->data, skb->len,
  507. DMA_TO_DEVICE);
  508. len_stat = (skb->len << DMADESC_LENGTH_SHIFT) & DMADESC_LENGTH_MASK;
  509. len_stat |= (DMADESC_ESOP_MASK >> priv->dma_desc_shift) |
  510. DMADESC_APPEND_CRC |
  511. DMADESC_OWNER_MASK;
  512. priv->tx_curr_desc++;
  513. if (priv->tx_curr_desc == priv->tx_ring_size) {
  514. priv->tx_curr_desc = 0;
  515. len_stat |= (DMADESC_WRAP_MASK >> priv->dma_desc_shift);
  516. }
  517. priv->tx_desc_count--;
  518. /* dma might be already polling, make sure we update desc
  519. * fields in correct order */
  520. wmb();
  521. desc->len_stat = len_stat;
  522. wmb();
  523. /* kick tx dma */
  524. enet_dmac_writel(priv, priv->dma_chan_en_mask,
  525. ENETDMAC_CHANCFG, priv->tx_chan);
  526. /* stop queue if no more desc available */
  527. if (!priv->tx_desc_count)
  528. netif_stop_queue(dev);
  529. dev->stats.tx_bytes += skb->len;
  530. dev->stats.tx_packets++;
  531. ret = NETDEV_TX_OK;
  532. out_unlock:
  533. spin_unlock(&priv->tx_lock);
  534. return ret;
  535. }
  536. /*
  537. * Change the interface's mac address.
  538. */
  539. static int bcm_enet_set_mac_address(struct net_device *dev, void *p)
  540. {
  541. struct bcm_enet_priv *priv;
  542. struct sockaddr *addr = p;
  543. u32 val;
  544. priv = netdev_priv(dev);
  545. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  546. /* use perfect match register 0 to store my mac address */
  547. val = (dev->dev_addr[2] << 24) | (dev->dev_addr[3] << 16) |
  548. (dev->dev_addr[4] << 8) | dev->dev_addr[5];
  549. enet_writel(priv, val, ENET_PML_REG(0));
  550. val = (dev->dev_addr[0] << 8 | dev->dev_addr[1]);
  551. val |= ENET_PMH_DATAVALID_MASK;
  552. enet_writel(priv, val, ENET_PMH_REG(0));
  553. return 0;
  554. }
  555. /*
  556. * Change rx mode (promiscuous/allmulti) and update multicast list
  557. */
  558. static void bcm_enet_set_multicast_list(struct net_device *dev)
  559. {
  560. struct bcm_enet_priv *priv;
  561. struct netdev_hw_addr *ha;
  562. u32 val;
  563. int i;
  564. priv = netdev_priv(dev);
  565. val = enet_readl(priv, ENET_RXCFG_REG);
  566. if (dev->flags & IFF_PROMISC)
  567. val |= ENET_RXCFG_PROMISC_MASK;
  568. else
  569. val &= ~ENET_RXCFG_PROMISC_MASK;
  570. /* only 3 perfect match registers left, first one is used for
  571. * own mac address */
  572. if ((dev->flags & IFF_ALLMULTI) || netdev_mc_count(dev) > 3)
  573. val |= ENET_RXCFG_ALLMCAST_MASK;
  574. else
  575. val &= ~ENET_RXCFG_ALLMCAST_MASK;
  576. /* no need to set perfect match registers if we catch all
  577. * multicast */
  578. if (val & ENET_RXCFG_ALLMCAST_MASK) {
  579. enet_writel(priv, val, ENET_RXCFG_REG);
  580. return;
  581. }
  582. i = 0;
  583. netdev_for_each_mc_addr(ha, dev) {
  584. u8 *dmi_addr;
  585. u32 tmp;
  586. if (i == 3)
  587. break;
  588. /* update perfect match registers */
  589. dmi_addr = ha->addr;
  590. tmp = (dmi_addr[2] << 24) | (dmi_addr[3] << 16) |
  591. (dmi_addr[4] << 8) | dmi_addr[5];
  592. enet_writel(priv, tmp, ENET_PML_REG(i + 1));
  593. tmp = (dmi_addr[0] << 8 | dmi_addr[1]);
  594. tmp |= ENET_PMH_DATAVALID_MASK;
  595. enet_writel(priv, tmp, ENET_PMH_REG(i++ + 1));
  596. }
  597. for (; i < 3; i++) {
  598. enet_writel(priv, 0, ENET_PML_REG(i + 1));
  599. enet_writel(priv, 0, ENET_PMH_REG(i + 1));
  600. }
  601. enet_writel(priv, val, ENET_RXCFG_REG);
  602. }
  603. /*
  604. * set mac duplex parameters
  605. */
  606. static void bcm_enet_set_duplex(struct bcm_enet_priv *priv, int fullduplex)
  607. {
  608. u32 val;
  609. val = enet_readl(priv, ENET_TXCTL_REG);
  610. if (fullduplex)
  611. val |= ENET_TXCTL_FD_MASK;
  612. else
  613. val &= ~ENET_TXCTL_FD_MASK;
  614. enet_writel(priv, val, ENET_TXCTL_REG);
  615. }
  616. /*
  617. * set mac flow control parameters
  618. */
  619. static void bcm_enet_set_flow(struct bcm_enet_priv *priv, int rx_en, int tx_en)
  620. {
  621. u32 val;
  622. /* rx flow control (pause frame handling) */
  623. val = enet_readl(priv, ENET_RXCFG_REG);
  624. if (rx_en)
  625. val |= ENET_RXCFG_ENFLOW_MASK;
  626. else
  627. val &= ~ENET_RXCFG_ENFLOW_MASK;
  628. enet_writel(priv, val, ENET_RXCFG_REG);
  629. if (!priv->dma_has_sram)
  630. return;
  631. /* tx flow control (pause frame generation) */
  632. val = enet_dma_readl(priv, ENETDMA_CFG_REG);
  633. if (tx_en)
  634. val |= ENETDMA_CFG_FLOWCH_MASK(priv->rx_chan);
  635. else
  636. val &= ~ENETDMA_CFG_FLOWCH_MASK(priv->rx_chan);
  637. enet_dma_writel(priv, val, ENETDMA_CFG_REG);
  638. }
  639. /*
  640. * link changed callback (from phylib)
  641. */
  642. static void bcm_enet_adjust_phy_link(struct net_device *dev)
  643. {
  644. struct bcm_enet_priv *priv;
  645. struct phy_device *phydev;
  646. int status_changed;
  647. priv = netdev_priv(dev);
  648. phydev = dev->phydev;
  649. status_changed = 0;
  650. if (priv->old_link != phydev->link) {
  651. status_changed = 1;
  652. priv->old_link = phydev->link;
  653. }
  654. /* reflect duplex change in mac configuration */
  655. if (phydev->link && phydev->duplex != priv->old_duplex) {
  656. bcm_enet_set_duplex(priv,
  657. (phydev->duplex == DUPLEX_FULL) ? 1 : 0);
  658. status_changed = 1;
  659. priv->old_duplex = phydev->duplex;
  660. }
  661. /* enable flow control if remote advertise it (trust phylib to
  662. * check that duplex is full */
  663. if (phydev->link && phydev->pause != priv->old_pause) {
  664. int rx_pause_en, tx_pause_en;
  665. if (phydev->pause) {
  666. /* pause was advertised by lpa and us */
  667. rx_pause_en = 1;
  668. tx_pause_en = 1;
  669. } else if (!priv->pause_auto) {
  670. /* pause setting overridden by user */
  671. rx_pause_en = priv->pause_rx;
  672. tx_pause_en = priv->pause_tx;
  673. } else {
  674. rx_pause_en = 0;
  675. tx_pause_en = 0;
  676. }
  677. bcm_enet_set_flow(priv, rx_pause_en, tx_pause_en);
  678. status_changed = 1;
  679. priv->old_pause = phydev->pause;
  680. }
  681. if (status_changed) {
  682. pr_info("%s: link %s", dev->name, phydev->link ?
  683. "UP" : "DOWN");
  684. if (phydev->link)
  685. pr_cont(" - %d/%s - flow control %s", phydev->speed,
  686. DUPLEX_FULL == phydev->duplex ? "full" : "half",
  687. phydev->pause == 1 ? "rx&tx" : "off");
  688. pr_cont("\n");
  689. }
  690. }
  691. /*
  692. * link changed callback (if phylib is not used)
  693. */
  694. static void bcm_enet_adjust_link(struct net_device *dev)
  695. {
  696. struct bcm_enet_priv *priv;
  697. priv = netdev_priv(dev);
  698. bcm_enet_set_duplex(priv, priv->force_duplex_full);
  699. bcm_enet_set_flow(priv, priv->pause_rx, priv->pause_tx);
  700. netif_carrier_on(dev);
  701. pr_info("%s: link forced UP - %d/%s - flow control %s/%s\n",
  702. dev->name,
  703. priv->force_speed_100 ? 100 : 10,
  704. priv->force_duplex_full ? "full" : "half",
  705. priv->pause_rx ? "rx" : "off",
  706. priv->pause_tx ? "tx" : "off");
  707. }
  708. /*
  709. * open callback, allocate dma rings & buffers and start rx operation
  710. */
  711. static int bcm_enet_open(struct net_device *dev)
  712. {
  713. struct bcm_enet_priv *priv;
  714. struct sockaddr addr;
  715. struct device *kdev;
  716. struct phy_device *phydev;
  717. int i, ret;
  718. unsigned int size;
  719. char phy_id[MII_BUS_ID_SIZE + 3];
  720. void *p;
  721. u32 val;
  722. priv = netdev_priv(dev);
  723. kdev = &priv->pdev->dev;
  724. if (priv->has_phy) {
  725. /* connect to PHY */
  726. snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
  727. priv->mii_bus->id, priv->phy_id);
  728. phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
  729. PHY_INTERFACE_MODE_MII);
  730. if (IS_ERR(phydev)) {
  731. dev_err(kdev, "could not attach to PHY\n");
  732. return PTR_ERR(phydev);
  733. }
  734. /* mask with MAC supported features */
  735. phydev->supported &= (SUPPORTED_10baseT_Half |
  736. SUPPORTED_10baseT_Full |
  737. SUPPORTED_100baseT_Half |
  738. SUPPORTED_100baseT_Full |
  739. SUPPORTED_Autoneg |
  740. SUPPORTED_Pause |
  741. SUPPORTED_MII);
  742. phydev->advertising = phydev->supported;
  743. if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
  744. phydev->advertising |= SUPPORTED_Pause;
  745. else
  746. phydev->advertising &= ~SUPPORTED_Pause;
  747. phy_attached_info(phydev);
  748. priv->old_link = 0;
  749. priv->old_duplex = -1;
  750. priv->old_pause = -1;
  751. } else {
  752. phydev = NULL;
  753. }
  754. /* mask all interrupts and request them */
  755. enet_writel(priv, 0, ENET_IRMASK_REG);
  756. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->rx_chan);
  757. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->tx_chan);
  758. ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
  759. if (ret)
  760. goto out_phy_disconnect;
  761. ret = request_irq(priv->irq_rx, bcm_enet_isr_dma, 0,
  762. dev->name, dev);
  763. if (ret)
  764. goto out_freeirq;
  765. ret = request_irq(priv->irq_tx, bcm_enet_isr_dma,
  766. 0, dev->name, dev);
  767. if (ret)
  768. goto out_freeirq_rx;
  769. /* initialize perfect match registers */
  770. for (i = 0; i < 4; i++) {
  771. enet_writel(priv, 0, ENET_PML_REG(i));
  772. enet_writel(priv, 0, ENET_PMH_REG(i));
  773. }
  774. /* write device mac address */
  775. memcpy(addr.sa_data, dev->dev_addr, ETH_ALEN);
  776. bcm_enet_set_mac_address(dev, &addr);
  777. /* allocate rx dma ring */
  778. size = priv->rx_ring_size * sizeof(struct bcm_enet_desc);
  779. p = dma_zalloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
  780. if (!p) {
  781. ret = -ENOMEM;
  782. goto out_freeirq_tx;
  783. }
  784. priv->rx_desc_alloc_size = size;
  785. priv->rx_desc_cpu = p;
  786. /* allocate tx dma ring */
  787. size = priv->tx_ring_size * sizeof(struct bcm_enet_desc);
  788. p = dma_zalloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
  789. if (!p) {
  790. ret = -ENOMEM;
  791. goto out_free_rx_ring;
  792. }
  793. priv->tx_desc_alloc_size = size;
  794. priv->tx_desc_cpu = p;
  795. priv->tx_skb = kcalloc(priv->tx_ring_size, sizeof(struct sk_buff *),
  796. GFP_KERNEL);
  797. if (!priv->tx_skb) {
  798. ret = -ENOMEM;
  799. goto out_free_tx_ring;
  800. }
  801. priv->tx_desc_count = priv->tx_ring_size;
  802. priv->tx_dirty_desc = 0;
  803. priv->tx_curr_desc = 0;
  804. spin_lock_init(&priv->tx_lock);
  805. /* init & fill rx ring with skbs */
  806. priv->rx_skb = kcalloc(priv->rx_ring_size, sizeof(struct sk_buff *),
  807. GFP_KERNEL);
  808. if (!priv->rx_skb) {
  809. ret = -ENOMEM;
  810. goto out_free_tx_skb;
  811. }
  812. priv->rx_desc_count = 0;
  813. priv->rx_dirty_desc = 0;
  814. priv->rx_curr_desc = 0;
  815. /* initialize flow control buffer allocation */
  816. if (priv->dma_has_sram)
  817. enet_dma_writel(priv, ENETDMA_BUFALLOC_FORCE_MASK | 0,
  818. ENETDMA_BUFALLOC_REG(priv->rx_chan));
  819. else
  820. enet_dmac_writel(priv, ENETDMA_BUFALLOC_FORCE_MASK | 0,
  821. ENETDMAC_BUFALLOC, priv->rx_chan);
  822. if (bcm_enet_refill_rx(dev)) {
  823. dev_err(kdev, "cannot allocate rx skb queue\n");
  824. ret = -ENOMEM;
  825. goto out;
  826. }
  827. /* write rx & tx ring addresses */
  828. if (priv->dma_has_sram) {
  829. enet_dmas_writel(priv, priv->rx_desc_dma,
  830. ENETDMAS_RSTART_REG, priv->rx_chan);
  831. enet_dmas_writel(priv, priv->tx_desc_dma,
  832. ENETDMAS_RSTART_REG, priv->tx_chan);
  833. } else {
  834. enet_dmac_writel(priv, priv->rx_desc_dma,
  835. ENETDMAC_RSTART, priv->rx_chan);
  836. enet_dmac_writel(priv, priv->tx_desc_dma,
  837. ENETDMAC_RSTART, priv->tx_chan);
  838. }
  839. /* clear remaining state ram for rx & tx channel */
  840. if (priv->dma_has_sram) {
  841. enet_dmas_writel(priv, 0, ENETDMAS_SRAM2_REG, priv->rx_chan);
  842. enet_dmas_writel(priv, 0, ENETDMAS_SRAM2_REG, priv->tx_chan);
  843. enet_dmas_writel(priv, 0, ENETDMAS_SRAM3_REG, priv->rx_chan);
  844. enet_dmas_writel(priv, 0, ENETDMAS_SRAM3_REG, priv->tx_chan);
  845. enet_dmas_writel(priv, 0, ENETDMAS_SRAM4_REG, priv->rx_chan);
  846. enet_dmas_writel(priv, 0, ENETDMAS_SRAM4_REG, priv->tx_chan);
  847. } else {
  848. enet_dmac_writel(priv, 0, ENETDMAC_FC, priv->rx_chan);
  849. enet_dmac_writel(priv, 0, ENETDMAC_FC, priv->tx_chan);
  850. }
  851. /* set max rx/tx length */
  852. enet_writel(priv, priv->hw_mtu, ENET_RXMAXLEN_REG);
  853. enet_writel(priv, priv->hw_mtu, ENET_TXMAXLEN_REG);
  854. /* set dma maximum burst len */
  855. enet_dmac_writel(priv, priv->dma_maxburst,
  856. ENETDMAC_MAXBURST, priv->rx_chan);
  857. enet_dmac_writel(priv, priv->dma_maxburst,
  858. ENETDMAC_MAXBURST, priv->tx_chan);
  859. /* set correct transmit fifo watermark */
  860. enet_writel(priv, BCMENET_TX_FIFO_TRESH, ENET_TXWMARK_REG);
  861. /* set flow control low/high threshold to 1/3 / 2/3 */
  862. if (priv->dma_has_sram) {
  863. val = priv->rx_ring_size / 3;
  864. enet_dma_writel(priv, val, ENETDMA_FLOWCL_REG(priv->rx_chan));
  865. val = (priv->rx_ring_size * 2) / 3;
  866. enet_dma_writel(priv, val, ENETDMA_FLOWCH_REG(priv->rx_chan));
  867. } else {
  868. enet_dmac_writel(priv, 5, ENETDMAC_FC, priv->rx_chan);
  869. enet_dmac_writel(priv, priv->rx_ring_size, ENETDMAC_LEN, priv->rx_chan);
  870. enet_dmac_writel(priv, priv->tx_ring_size, ENETDMAC_LEN, priv->tx_chan);
  871. }
  872. /* all set, enable mac and interrupts, start dma engine and
  873. * kick rx dma channel */
  874. wmb();
  875. val = enet_readl(priv, ENET_CTL_REG);
  876. val |= ENET_CTL_ENABLE_MASK;
  877. enet_writel(priv, val, ENET_CTL_REG);
  878. if (priv->dma_has_sram)
  879. enet_dma_writel(priv, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG);
  880. enet_dmac_writel(priv, priv->dma_chan_en_mask,
  881. ENETDMAC_CHANCFG, priv->rx_chan);
  882. /* watch "mib counters about to overflow" interrupt */
  883. enet_writel(priv, ENET_IR_MIB, ENET_IR_REG);
  884. enet_writel(priv, ENET_IR_MIB, ENET_IRMASK_REG);
  885. /* watch "packet transferred" interrupt in rx and tx */
  886. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  887. ENETDMAC_IR, priv->rx_chan);
  888. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  889. ENETDMAC_IR, priv->tx_chan);
  890. /* make sure we enable napi before rx interrupt */
  891. napi_enable(&priv->napi);
  892. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  893. ENETDMAC_IRMASK, priv->rx_chan);
  894. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  895. ENETDMAC_IRMASK, priv->tx_chan);
  896. if (phydev)
  897. phy_start(phydev);
  898. else
  899. bcm_enet_adjust_link(dev);
  900. netif_start_queue(dev);
  901. return 0;
  902. out:
  903. for (i = 0; i < priv->rx_ring_size; i++) {
  904. struct bcm_enet_desc *desc;
  905. if (!priv->rx_skb[i])
  906. continue;
  907. desc = &priv->rx_desc_cpu[i];
  908. dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
  909. DMA_FROM_DEVICE);
  910. kfree_skb(priv->rx_skb[i]);
  911. }
  912. kfree(priv->rx_skb);
  913. out_free_tx_skb:
  914. kfree(priv->tx_skb);
  915. out_free_tx_ring:
  916. dma_free_coherent(kdev, priv->tx_desc_alloc_size,
  917. priv->tx_desc_cpu, priv->tx_desc_dma);
  918. out_free_rx_ring:
  919. dma_free_coherent(kdev, priv->rx_desc_alloc_size,
  920. priv->rx_desc_cpu, priv->rx_desc_dma);
  921. out_freeirq_tx:
  922. free_irq(priv->irq_tx, dev);
  923. out_freeirq_rx:
  924. free_irq(priv->irq_rx, dev);
  925. out_freeirq:
  926. free_irq(dev->irq, dev);
  927. out_phy_disconnect:
  928. if (phydev)
  929. phy_disconnect(phydev);
  930. return ret;
  931. }
  932. /*
  933. * disable mac
  934. */
  935. static void bcm_enet_disable_mac(struct bcm_enet_priv *priv)
  936. {
  937. int limit;
  938. u32 val;
  939. val = enet_readl(priv, ENET_CTL_REG);
  940. val |= ENET_CTL_DISABLE_MASK;
  941. enet_writel(priv, val, ENET_CTL_REG);
  942. limit = 1000;
  943. do {
  944. u32 val;
  945. val = enet_readl(priv, ENET_CTL_REG);
  946. if (!(val & ENET_CTL_DISABLE_MASK))
  947. break;
  948. udelay(1);
  949. } while (limit--);
  950. }
  951. /*
  952. * disable dma in given channel
  953. */
  954. static void bcm_enet_disable_dma(struct bcm_enet_priv *priv, int chan)
  955. {
  956. int limit;
  957. enet_dmac_writel(priv, 0, ENETDMAC_CHANCFG, chan);
  958. limit = 1000;
  959. do {
  960. u32 val;
  961. val = enet_dmac_readl(priv, ENETDMAC_CHANCFG, chan);
  962. if (!(val & ENETDMAC_CHANCFG_EN_MASK))
  963. break;
  964. udelay(1);
  965. } while (limit--);
  966. }
  967. /*
  968. * stop callback
  969. */
  970. static int bcm_enet_stop(struct net_device *dev)
  971. {
  972. struct bcm_enet_priv *priv;
  973. struct device *kdev;
  974. int i;
  975. priv = netdev_priv(dev);
  976. kdev = &priv->pdev->dev;
  977. netif_stop_queue(dev);
  978. napi_disable(&priv->napi);
  979. if (priv->has_phy)
  980. phy_stop(dev->phydev);
  981. del_timer_sync(&priv->rx_timeout);
  982. /* mask all interrupts */
  983. enet_writel(priv, 0, ENET_IRMASK_REG);
  984. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->rx_chan);
  985. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->tx_chan);
  986. /* make sure no mib update is scheduled */
  987. cancel_work_sync(&priv->mib_update_task);
  988. /* disable dma & mac */
  989. bcm_enet_disable_dma(priv, priv->tx_chan);
  990. bcm_enet_disable_dma(priv, priv->rx_chan);
  991. bcm_enet_disable_mac(priv);
  992. /* force reclaim of all tx buffers */
  993. bcm_enet_tx_reclaim(dev, 1);
  994. /* free the rx skb ring */
  995. for (i = 0; i < priv->rx_ring_size; i++) {
  996. struct bcm_enet_desc *desc;
  997. if (!priv->rx_skb[i])
  998. continue;
  999. desc = &priv->rx_desc_cpu[i];
  1000. dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
  1001. DMA_FROM_DEVICE);
  1002. kfree_skb(priv->rx_skb[i]);
  1003. }
  1004. /* free remaining allocated memory */
  1005. kfree(priv->rx_skb);
  1006. kfree(priv->tx_skb);
  1007. dma_free_coherent(kdev, priv->rx_desc_alloc_size,
  1008. priv->rx_desc_cpu, priv->rx_desc_dma);
  1009. dma_free_coherent(kdev, priv->tx_desc_alloc_size,
  1010. priv->tx_desc_cpu, priv->tx_desc_dma);
  1011. free_irq(priv->irq_tx, dev);
  1012. free_irq(priv->irq_rx, dev);
  1013. free_irq(dev->irq, dev);
  1014. /* release phy */
  1015. if (priv->has_phy)
  1016. phy_disconnect(dev->phydev);
  1017. return 0;
  1018. }
  1019. /*
  1020. * ethtool callbacks
  1021. */
  1022. struct bcm_enet_stats {
  1023. char stat_string[ETH_GSTRING_LEN];
  1024. int sizeof_stat;
  1025. int stat_offset;
  1026. int mib_reg;
  1027. };
  1028. #define GEN_STAT(m) sizeof(((struct bcm_enet_priv *)0)->m), \
  1029. offsetof(struct bcm_enet_priv, m)
  1030. #define DEV_STAT(m) sizeof(((struct net_device_stats *)0)->m), \
  1031. offsetof(struct net_device_stats, m)
  1032. static const struct bcm_enet_stats bcm_enet_gstrings_stats[] = {
  1033. { "rx_packets", DEV_STAT(rx_packets), -1 },
  1034. { "tx_packets", DEV_STAT(tx_packets), -1 },
  1035. { "rx_bytes", DEV_STAT(rx_bytes), -1 },
  1036. { "tx_bytes", DEV_STAT(tx_bytes), -1 },
  1037. { "rx_errors", DEV_STAT(rx_errors), -1 },
  1038. { "tx_errors", DEV_STAT(tx_errors), -1 },
  1039. { "rx_dropped", DEV_STAT(rx_dropped), -1 },
  1040. { "tx_dropped", DEV_STAT(tx_dropped), -1 },
  1041. { "rx_good_octets", GEN_STAT(mib.rx_gd_octets), ETH_MIB_RX_GD_OCTETS},
  1042. { "rx_good_pkts", GEN_STAT(mib.rx_gd_pkts), ETH_MIB_RX_GD_PKTS },
  1043. { "rx_broadcast", GEN_STAT(mib.rx_brdcast), ETH_MIB_RX_BRDCAST },
  1044. { "rx_multicast", GEN_STAT(mib.rx_mult), ETH_MIB_RX_MULT },
  1045. { "rx_64_octets", GEN_STAT(mib.rx_64), ETH_MIB_RX_64 },
  1046. { "rx_65_127_oct", GEN_STAT(mib.rx_65_127), ETH_MIB_RX_65_127 },
  1047. { "rx_128_255_oct", GEN_STAT(mib.rx_128_255), ETH_MIB_RX_128_255 },
  1048. { "rx_256_511_oct", GEN_STAT(mib.rx_256_511), ETH_MIB_RX_256_511 },
  1049. { "rx_512_1023_oct", GEN_STAT(mib.rx_512_1023), ETH_MIB_RX_512_1023 },
  1050. { "rx_1024_max_oct", GEN_STAT(mib.rx_1024_max), ETH_MIB_RX_1024_MAX },
  1051. { "rx_jabber", GEN_STAT(mib.rx_jab), ETH_MIB_RX_JAB },
  1052. { "rx_oversize", GEN_STAT(mib.rx_ovr), ETH_MIB_RX_OVR },
  1053. { "rx_fragment", GEN_STAT(mib.rx_frag), ETH_MIB_RX_FRAG },
  1054. { "rx_dropped", GEN_STAT(mib.rx_drop), ETH_MIB_RX_DROP },
  1055. { "rx_crc_align", GEN_STAT(mib.rx_crc_align), ETH_MIB_RX_CRC_ALIGN },
  1056. { "rx_undersize", GEN_STAT(mib.rx_und), ETH_MIB_RX_UND },
  1057. { "rx_crc", GEN_STAT(mib.rx_crc), ETH_MIB_RX_CRC },
  1058. { "rx_align", GEN_STAT(mib.rx_align), ETH_MIB_RX_ALIGN },
  1059. { "rx_symbol_error", GEN_STAT(mib.rx_sym), ETH_MIB_RX_SYM },
  1060. { "rx_pause", GEN_STAT(mib.rx_pause), ETH_MIB_RX_PAUSE },
  1061. { "rx_control", GEN_STAT(mib.rx_cntrl), ETH_MIB_RX_CNTRL },
  1062. { "tx_good_octets", GEN_STAT(mib.tx_gd_octets), ETH_MIB_TX_GD_OCTETS },
  1063. { "tx_good_pkts", GEN_STAT(mib.tx_gd_pkts), ETH_MIB_TX_GD_PKTS },
  1064. { "tx_broadcast", GEN_STAT(mib.tx_brdcast), ETH_MIB_TX_BRDCAST },
  1065. { "tx_multicast", GEN_STAT(mib.tx_mult), ETH_MIB_TX_MULT },
  1066. { "tx_64_oct", GEN_STAT(mib.tx_64), ETH_MIB_TX_64 },
  1067. { "tx_65_127_oct", GEN_STAT(mib.tx_65_127), ETH_MIB_TX_65_127 },
  1068. { "tx_128_255_oct", GEN_STAT(mib.tx_128_255), ETH_MIB_TX_128_255 },
  1069. { "tx_256_511_oct", GEN_STAT(mib.tx_256_511), ETH_MIB_TX_256_511 },
  1070. { "tx_512_1023_oct", GEN_STAT(mib.tx_512_1023), ETH_MIB_TX_512_1023},
  1071. { "tx_1024_max_oct", GEN_STAT(mib.tx_1024_max), ETH_MIB_TX_1024_MAX },
  1072. { "tx_jabber", GEN_STAT(mib.tx_jab), ETH_MIB_TX_JAB },
  1073. { "tx_oversize", GEN_STAT(mib.tx_ovr), ETH_MIB_TX_OVR },
  1074. { "tx_fragment", GEN_STAT(mib.tx_frag), ETH_MIB_TX_FRAG },
  1075. { "tx_underrun", GEN_STAT(mib.tx_underrun), ETH_MIB_TX_UNDERRUN },
  1076. { "tx_collisions", GEN_STAT(mib.tx_col), ETH_MIB_TX_COL },
  1077. { "tx_single_collision", GEN_STAT(mib.tx_1_col), ETH_MIB_TX_1_COL },
  1078. { "tx_multiple_collision", GEN_STAT(mib.tx_m_col), ETH_MIB_TX_M_COL },
  1079. { "tx_excess_collision", GEN_STAT(mib.tx_ex_col), ETH_MIB_TX_EX_COL },
  1080. { "tx_late_collision", GEN_STAT(mib.tx_late), ETH_MIB_TX_LATE },
  1081. { "tx_deferred", GEN_STAT(mib.tx_def), ETH_MIB_TX_DEF },
  1082. { "tx_carrier_sense", GEN_STAT(mib.tx_crs), ETH_MIB_TX_CRS },
  1083. { "tx_pause", GEN_STAT(mib.tx_pause), ETH_MIB_TX_PAUSE },
  1084. };
  1085. #define BCM_ENET_STATS_LEN ARRAY_SIZE(bcm_enet_gstrings_stats)
  1086. static const u32 unused_mib_regs[] = {
  1087. ETH_MIB_TX_ALL_OCTETS,
  1088. ETH_MIB_TX_ALL_PKTS,
  1089. ETH_MIB_RX_ALL_OCTETS,
  1090. ETH_MIB_RX_ALL_PKTS,
  1091. };
  1092. static void bcm_enet_get_drvinfo(struct net_device *netdev,
  1093. struct ethtool_drvinfo *drvinfo)
  1094. {
  1095. strlcpy(drvinfo->driver, bcm_enet_driver_name, sizeof(drvinfo->driver));
  1096. strlcpy(drvinfo->version, bcm_enet_driver_version,
  1097. sizeof(drvinfo->version));
  1098. strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  1099. strlcpy(drvinfo->bus_info, "bcm63xx", sizeof(drvinfo->bus_info));
  1100. }
  1101. static int bcm_enet_get_sset_count(struct net_device *netdev,
  1102. int string_set)
  1103. {
  1104. switch (string_set) {
  1105. case ETH_SS_STATS:
  1106. return BCM_ENET_STATS_LEN;
  1107. default:
  1108. return -EINVAL;
  1109. }
  1110. }
  1111. static void bcm_enet_get_strings(struct net_device *netdev,
  1112. u32 stringset, u8 *data)
  1113. {
  1114. int i;
  1115. switch (stringset) {
  1116. case ETH_SS_STATS:
  1117. for (i = 0; i < BCM_ENET_STATS_LEN; i++) {
  1118. memcpy(data + i * ETH_GSTRING_LEN,
  1119. bcm_enet_gstrings_stats[i].stat_string,
  1120. ETH_GSTRING_LEN);
  1121. }
  1122. break;
  1123. }
  1124. }
  1125. static void update_mib_counters(struct bcm_enet_priv *priv)
  1126. {
  1127. int i;
  1128. for (i = 0; i < BCM_ENET_STATS_LEN; i++) {
  1129. const struct bcm_enet_stats *s;
  1130. u32 val;
  1131. char *p;
  1132. s = &bcm_enet_gstrings_stats[i];
  1133. if (s->mib_reg == -1)
  1134. continue;
  1135. val = enet_readl(priv, ENET_MIB_REG(s->mib_reg));
  1136. p = (char *)priv + s->stat_offset;
  1137. if (s->sizeof_stat == sizeof(u64))
  1138. *(u64 *)p += val;
  1139. else
  1140. *(u32 *)p += val;
  1141. }
  1142. /* also empty unused mib counters to make sure mib counter
  1143. * overflow interrupt is cleared */
  1144. for (i = 0; i < ARRAY_SIZE(unused_mib_regs); i++)
  1145. (void)enet_readl(priv, ENET_MIB_REG(unused_mib_regs[i]));
  1146. }
  1147. static void bcm_enet_update_mib_counters_defer(struct work_struct *t)
  1148. {
  1149. struct bcm_enet_priv *priv;
  1150. priv = container_of(t, struct bcm_enet_priv, mib_update_task);
  1151. mutex_lock(&priv->mib_update_lock);
  1152. update_mib_counters(priv);
  1153. mutex_unlock(&priv->mib_update_lock);
  1154. /* reenable mib interrupt */
  1155. if (netif_running(priv->net_dev))
  1156. enet_writel(priv, ENET_IR_MIB, ENET_IRMASK_REG);
  1157. }
  1158. static void bcm_enet_get_ethtool_stats(struct net_device *netdev,
  1159. struct ethtool_stats *stats,
  1160. u64 *data)
  1161. {
  1162. struct bcm_enet_priv *priv;
  1163. int i;
  1164. priv = netdev_priv(netdev);
  1165. mutex_lock(&priv->mib_update_lock);
  1166. update_mib_counters(priv);
  1167. for (i = 0; i < BCM_ENET_STATS_LEN; i++) {
  1168. const struct bcm_enet_stats *s;
  1169. char *p;
  1170. s = &bcm_enet_gstrings_stats[i];
  1171. if (s->mib_reg == -1)
  1172. p = (char *)&netdev->stats;
  1173. else
  1174. p = (char *)priv;
  1175. p += s->stat_offset;
  1176. data[i] = (s->sizeof_stat == sizeof(u64)) ?
  1177. *(u64 *)p : *(u32 *)p;
  1178. }
  1179. mutex_unlock(&priv->mib_update_lock);
  1180. }
  1181. static int bcm_enet_nway_reset(struct net_device *dev)
  1182. {
  1183. struct bcm_enet_priv *priv;
  1184. priv = netdev_priv(dev);
  1185. if (priv->has_phy)
  1186. return phy_ethtool_nway_reset(dev);
  1187. return -EOPNOTSUPP;
  1188. }
  1189. static int bcm_enet_get_link_ksettings(struct net_device *dev,
  1190. struct ethtool_link_ksettings *cmd)
  1191. {
  1192. struct bcm_enet_priv *priv;
  1193. u32 supported, advertising;
  1194. priv = netdev_priv(dev);
  1195. if (priv->has_phy) {
  1196. if (!dev->phydev)
  1197. return -ENODEV;
  1198. phy_ethtool_ksettings_get(dev->phydev, cmd);
  1199. return 0;
  1200. } else {
  1201. cmd->base.autoneg = 0;
  1202. cmd->base.speed = (priv->force_speed_100) ?
  1203. SPEED_100 : SPEED_10;
  1204. cmd->base.duplex = (priv->force_duplex_full) ?
  1205. DUPLEX_FULL : DUPLEX_HALF;
  1206. supported = ADVERTISED_10baseT_Half |
  1207. ADVERTISED_10baseT_Full |
  1208. ADVERTISED_100baseT_Half |
  1209. ADVERTISED_100baseT_Full;
  1210. advertising = 0;
  1211. ethtool_convert_legacy_u32_to_link_mode(
  1212. cmd->link_modes.supported, supported);
  1213. ethtool_convert_legacy_u32_to_link_mode(
  1214. cmd->link_modes.advertising, advertising);
  1215. cmd->base.port = PORT_MII;
  1216. }
  1217. return 0;
  1218. }
  1219. static int bcm_enet_set_link_ksettings(struct net_device *dev,
  1220. const struct ethtool_link_ksettings *cmd)
  1221. {
  1222. struct bcm_enet_priv *priv;
  1223. priv = netdev_priv(dev);
  1224. if (priv->has_phy) {
  1225. if (!dev->phydev)
  1226. return -ENODEV;
  1227. return phy_ethtool_ksettings_set(dev->phydev, cmd);
  1228. } else {
  1229. if (cmd->base.autoneg ||
  1230. (cmd->base.speed != SPEED_100 &&
  1231. cmd->base.speed != SPEED_10) ||
  1232. cmd->base.port != PORT_MII)
  1233. return -EINVAL;
  1234. priv->force_speed_100 =
  1235. (cmd->base.speed == SPEED_100) ? 1 : 0;
  1236. priv->force_duplex_full =
  1237. (cmd->base.duplex == DUPLEX_FULL) ? 1 : 0;
  1238. if (netif_running(dev))
  1239. bcm_enet_adjust_link(dev);
  1240. return 0;
  1241. }
  1242. }
  1243. static void bcm_enet_get_ringparam(struct net_device *dev,
  1244. struct ethtool_ringparam *ering)
  1245. {
  1246. struct bcm_enet_priv *priv;
  1247. priv = netdev_priv(dev);
  1248. /* rx/tx ring is actually only limited by memory */
  1249. ering->rx_max_pending = 8192;
  1250. ering->tx_max_pending = 8192;
  1251. ering->rx_pending = priv->rx_ring_size;
  1252. ering->tx_pending = priv->tx_ring_size;
  1253. }
  1254. static int bcm_enet_set_ringparam(struct net_device *dev,
  1255. struct ethtool_ringparam *ering)
  1256. {
  1257. struct bcm_enet_priv *priv;
  1258. int was_running;
  1259. priv = netdev_priv(dev);
  1260. was_running = 0;
  1261. if (netif_running(dev)) {
  1262. bcm_enet_stop(dev);
  1263. was_running = 1;
  1264. }
  1265. priv->rx_ring_size = ering->rx_pending;
  1266. priv->tx_ring_size = ering->tx_pending;
  1267. if (was_running) {
  1268. int err;
  1269. err = bcm_enet_open(dev);
  1270. if (err)
  1271. dev_close(dev);
  1272. else
  1273. bcm_enet_set_multicast_list(dev);
  1274. }
  1275. return 0;
  1276. }
  1277. static void bcm_enet_get_pauseparam(struct net_device *dev,
  1278. struct ethtool_pauseparam *ecmd)
  1279. {
  1280. struct bcm_enet_priv *priv;
  1281. priv = netdev_priv(dev);
  1282. ecmd->autoneg = priv->pause_auto;
  1283. ecmd->rx_pause = priv->pause_rx;
  1284. ecmd->tx_pause = priv->pause_tx;
  1285. }
  1286. static int bcm_enet_set_pauseparam(struct net_device *dev,
  1287. struct ethtool_pauseparam *ecmd)
  1288. {
  1289. struct bcm_enet_priv *priv;
  1290. priv = netdev_priv(dev);
  1291. if (priv->has_phy) {
  1292. if (ecmd->autoneg && (ecmd->rx_pause != ecmd->tx_pause)) {
  1293. /* asymetric pause mode not supported,
  1294. * actually possible but integrated PHY has RO
  1295. * asym_pause bit */
  1296. return -EINVAL;
  1297. }
  1298. } else {
  1299. /* no pause autoneg on direct mii connection */
  1300. if (ecmd->autoneg)
  1301. return -EINVAL;
  1302. }
  1303. priv->pause_auto = ecmd->autoneg;
  1304. priv->pause_rx = ecmd->rx_pause;
  1305. priv->pause_tx = ecmd->tx_pause;
  1306. return 0;
  1307. }
  1308. static const struct ethtool_ops bcm_enet_ethtool_ops = {
  1309. .get_strings = bcm_enet_get_strings,
  1310. .get_sset_count = bcm_enet_get_sset_count,
  1311. .get_ethtool_stats = bcm_enet_get_ethtool_stats,
  1312. .nway_reset = bcm_enet_nway_reset,
  1313. .get_drvinfo = bcm_enet_get_drvinfo,
  1314. .get_link = ethtool_op_get_link,
  1315. .get_ringparam = bcm_enet_get_ringparam,
  1316. .set_ringparam = bcm_enet_set_ringparam,
  1317. .get_pauseparam = bcm_enet_get_pauseparam,
  1318. .set_pauseparam = bcm_enet_set_pauseparam,
  1319. .get_link_ksettings = bcm_enet_get_link_ksettings,
  1320. .set_link_ksettings = bcm_enet_set_link_ksettings,
  1321. };
  1322. static int bcm_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1323. {
  1324. struct bcm_enet_priv *priv;
  1325. priv = netdev_priv(dev);
  1326. if (priv->has_phy) {
  1327. if (!dev->phydev)
  1328. return -ENODEV;
  1329. return phy_mii_ioctl(dev->phydev, rq, cmd);
  1330. } else {
  1331. struct mii_if_info mii;
  1332. mii.dev = dev;
  1333. mii.mdio_read = bcm_enet_mdio_read_mii;
  1334. mii.mdio_write = bcm_enet_mdio_write_mii;
  1335. mii.phy_id = 0;
  1336. mii.phy_id_mask = 0x3f;
  1337. mii.reg_num_mask = 0x1f;
  1338. return generic_mii_ioctl(&mii, if_mii(rq), cmd, NULL);
  1339. }
  1340. }
  1341. /*
  1342. * adjust mtu, can't be called while device is running
  1343. */
  1344. static int bcm_enet_change_mtu(struct net_device *dev, int new_mtu)
  1345. {
  1346. struct bcm_enet_priv *priv = netdev_priv(dev);
  1347. int actual_mtu = new_mtu;
  1348. if (netif_running(dev))
  1349. return -EBUSY;
  1350. /* add ethernet header + vlan tag size */
  1351. actual_mtu += VLAN_ETH_HLEN;
  1352. /*
  1353. * setup maximum size before we get overflow mark in
  1354. * descriptor, note that this will not prevent reception of
  1355. * big frames, they will be split into multiple buffers
  1356. * anyway
  1357. */
  1358. priv->hw_mtu = actual_mtu;
  1359. /*
  1360. * align rx buffer size to dma burst len, account FCS since
  1361. * it's appended
  1362. */
  1363. priv->rx_skb_size = ALIGN(actual_mtu + ETH_FCS_LEN,
  1364. priv->dma_maxburst * 4);
  1365. dev->mtu = new_mtu;
  1366. return 0;
  1367. }
  1368. /*
  1369. * preinit hardware to allow mii operation while device is down
  1370. */
  1371. static void bcm_enet_hw_preinit(struct bcm_enet_priv *priv)
  1372. {
  1373. u32 val;
  1374. int limit;
  1375. /* make sure mac is disabled */
  1376. bcm_enet_disable_mac(priv);
  1377. /* soft reset mac */
  1378. val = ENET_CTL_SRESET_MASK;
  1379. enet_writel(priv, val, ENET_CTL_REG);
  1380. wmb();
  1381. limit = 1000;
  1382. do {
  1383. val = enet_readl(priv, ENET_CTL_REG);
  1384. if (!(val & ENET_CTL_SRESET_MASK))
  1385. break;
  1386. udelay(1);
  1387. } while (limit--);
  1388. /* select correct mii interface */
  1389. val = enet_readl(priv, ENET_CTL_REG);
  1390. if (priv->use_external_mii)
  1391. val |= ENET_CTL_EPHYSEL_MASK;
  1392. else
  1393. val &= ~ENET_CTL_EPHYSEL_MASK;
  1394. enet_writel(priv, val, ENET_CTL_REG);
  1395. /* turn on mdc clock */
  1396. enet_writel(priv, (0x1f << ENET_MIISC_MDCFREQDIV_SHIFT) |
  1397. ENET_MIISC_PREAMBLEEN_MASK, ENET_MIISC_REG);
  1398. /* set mib counters to self-clear when read */
  1399. val = enet_readl(priv, ENET_MIBCTL_REG);
  1400. val |= ENET_MIBCTL_RDCLEAR_MASK;
  1401. enet_writel(priv, val, ENET_MIBCTL_REG);
  1402. }
  1403. static const struct net_device_ops bcm_enet_ops = {
  1404. .ndo_open = bcm_enet_open,
  1405. .ndo_stop = bcm_enet_stop,
  1406. .ndo_start_xmit = bcm_enet_start_xmit,
  1407. .ndo_set_mac_address = bcm_enet_set_mac_address,
  1408. .ndo_set_rx_mode = bcm_enet_set_multicast_list,
  1409. .ndo_do_ioctl = bcm_enet_ioctl,
  1410. .ndo_change_mtu = bcm_enet_change_mtu,
  1411. };
  1412. /*
  1413. * allocate netdevice, request register memory and register device.
  1414. */
  1415. static int bcm_enet_probe(struct platform_device *pdev)
  1416. {
  1417. struct bcm_enet_priv *priv;
  1418. struct net_device *dev;
  1419. struct bcm63xx_enet_platform_data *pd;
  1420. struct resource *res_mem, *res_irq, *res_irq_rx, *res_irq_tx;
  1421. struct mii_bus *bus;
  1422. int i, ret;
  1423. if (!bcm_enet_shared_base[0])
  1424. return -EPROBE_DEFER;
  1425. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1426. res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
  1427. res_irq_tx = platform_get_resource(pdev, IORESOURCE_IRQ, 2);
  1428. if (!res_irq || !res_irq_rx || !res_irq_tx)
  1429. return -ENODEV;
  1430. ret = 0;
  1431. dev = alloc_etherdev(sizeof(*priv));
  1432. if (!dev)
  1433. return -ENOMEM;
  1434. priv = netdev_priv(dev);
  1435. priv->enet_is_sw = false;
  1436. priv->dma_maxburst = BCMENET_DMA_MAXBURST;
  1437. ret = bcm_enet_change_mtu(dev, dev->mtu);
  1438. if (ret)
  1439. goto out;
  1440. res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1441. priv->base = devm_ioremap_resource(&pdev->dev, res_mem);
  1442. if (IS_ERR(priv->base)) {
  1443. ret = PTR_ERR(priv->base);
  1444. goto out;
  1445. }
  1446. dev->irq = priv->irq = res_irq->start;
  1447. priv->irq_rx = res_irq_rx->start;
  1448. priv->irq_tx = res_irq_tx->start;
  1449. priv->mac_clk = devm_clk_get(&pdev->dev, "enet");
  1450. if (IS_ERR(priv->mac_clk)) {
  1451. ret = PTR_ERR(priv->mac_clk);
  1452. goto out;
  1453. }
  1454. ret = clk_prepare_enable(priv->mac_clk);
  1455. if (ret)
  1456. goto out;
  1457. /* initialize default and fetch platform data */
  1458. priv->rx_ring_size = BCMENET_DEF_RX_DESC;
  1459. priv->tx_ring_size = BCMENET_DEF_TX_DESC;
  1460. pd = dev_get_platdata(&pdev->dev);
  1461. if (pd) {
  1462. memcpy(dev->dev_addr, pd->mac_addr, ETH_ALEN);
  1463. priv->has_phy = pd->has_phy;
  1464. priv->phy_id = pd->phy_id;
  1465. priv->has_phy_interrupt = pd->has_phy_interrupt;
  1466. priv->phy_interrupt = pd->phy_interrupt;
  1467. priv->use_external_mii = !pd->use_internal_phy;
  1468. priv->pause_auto = pd->pause_auto;
  1469. priv->pause_rx = pd->pause_rx;
  1470. priv->pause_tx = pd->pause_tx;
  1471. priv->force_duplex_full = pd->force_duplex_full;
  1472. priv->force_speed_100 = pd->force_speed_100;
  1473. priv->dma_chan_en_mask = pd->dma_chan_en_mask;
  1474. priv->dma_chan_int_mask = pd->dma_chan_int_mask;
  1475. priv->dma_chan_width = pd->dma_chan_width;
  1476. priv->dma_has_sram = pd->dma_has_sram;
  1477. priv->dma_desc_shift = pd->dma_desc_shift;
  1478. priv->rx_chan = pd->rx_chan;
  1479. priv->tx_chan = pd->tx_chan;
  1480. }
  1481. if (priv->has_phy && !priv->use_external_mii) {
  1482. /* using internal PHY, enable clock */
  1483. priv->phy_clk = devm_clk_get(&pdev->dev, "ephy");
  1484. if (IS_ERR(priv->phy_clk)) {
  1485. ret = PTR_ERR(priv->phy_clk);
  1486. priv->phy_clk = NULL;
  1487. goto out_disable_clk_mac;
  1488. }
  1489. ret = clk_prepare_enable(priv->phy_clk);
  1490. if (ret)
  1491. goto out_disable_clk_mac;
  1492. }
  1493. /* do minimal hardware init to be able to probe mii bus */
  1494. bcm_enet_hw_preinit(priv);
  1495. /* MII bus registration */
  1496. if (priv->has_phy) {
  1497. priv->mii_bus = mdiobus_alloc();
  1498. if (!priv->mii_bus) {
  1499. ret = -ENOMEM;
  1500. goto out_uninit_hw;
  1501. }
  1502. bus = priv->mii_bus;
  1503. bus->name = "bcm63xx_enet MII bus";
  1504. bus->parent = &pdev->dev;
  1505. bus->priv = priv;
  1506. bus->read = bcm_enet_mdio_read_phylib;
  1507. bus->write = bcm_enet_mdio_write_phylib;
  1508. sprintf(bus->id, "%s-%d", pdev->name, pdev->id);
  1509. /* only probe bus where we think the PHY is, because
  1510. * the mdio read operation return 0 instead of 0xffff
  1511. * if a slave is not present on hw */
  1512. bus->phy_mask = ~(1 << priv->phy_id);
  1513. if (priv->has_phy_interrupt)
  1514. bus->irq[priv->phy_id] = priv->phy_interrupt;
  1515. ret = mdiobus_register(bus);
  1516. if (ret) {
  1517. dev_err(&pdev->dev, "unable to register mdio bus\n");
  1518. goto out_free_mdio;
  1519. }
  1520. } else {
  1521. /* run platform code to initialize PHY device */
  1522. if (pd && pd->mii_config &&
  1523. pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
  1524. bcm_enet_mdio_write_mii)) {
  1525. dev_err(&pdev->dev, "unable to configure mdio bus\n");
  1526. goto out_uninit_hw;
  1527. }
  1528. }
  1529. spin_lock_init(&priv->rx_lock);
  1530. /* init rx timeout (used for oom) */
  1531. timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
  1532. /* init the mib update lock&work */
  1533. mutex_init(&priv->mib_update_lock);
  1534. INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
  1535. /* zero mib counters */
  1536. for (i = 0; i < ENET_MIB_REG_COUNT; i++)
  1537. enet_writel(priv, 0, ENET_MIB_REG(i));
  1538. /* register netdevice */
  1539. dev->netdev_ops = &bcm_enet_ops;
  1540. netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
  1541. dev->ethtool_ops = &bcm_enet_ethtool_ops;
  1542. /* MTU range: 46 - 2028 */
  1543. dev->min_mtu = ETH_ZLEN - ETH_HLEN;
  1544. dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
  1545. SET_NETDEV_DEV(dev, &pdev->dev);
  1546. ret = register_netdev(dev);
  1547. if (ret)
  1548. goto out_unregister_mdio;
  1549. netif_carrier_off(dev);
  1550. platform_set_drvdata(pdev, dev);
  1551. priv->pdev = pdev;
  1552. priv->net_dev = dev;
  1553. return 0;
  1554. out_unregister_mdio:
  1555. if (priv->mii_bus)
  1556. mdiobus_unregister(priv->mii_bus);
  1557. out_free_mdio:
  1558. if (priv->mii_bus)
  1559. mdiobus_free(priv->mii_bus);
  1560. out_uninit_hw:
  1561. /* turn off mdc clock */
  1562. enet_writel(priv, 0, ENET_MIISC_REG);
  1563. clk_disable_unprepare(priv->phy_clk);
  1564. out_disable_clk_mac:
  1565. clk_disable_unprepare(priv->mac_clk);
  1566. out:
  1567. free_netdev(dev);
  1568. return ret;
  1569. }
  1570. /*
  1571. * exit func, stops hardware and unregisters netdevice
  1572. */
  1573. static int bcm_enet_remove(struct platform_device *pdev)
  1574. {
  1575. struct bcm_enet_priv *priv;
  1576. struct net_device *dev;
  1577. /* stop netdevice */
  1578. dev = platform_get_drvdata(pdev);
  1579. priv = netdev_priv(dev);
  1580. unregister_netdev(dev);
  1581. /* turn off mdc clock */
  1582. enet_writel(priv, 0, ENET_MIISC_REG);
  1583. if (priv->has_phy) {
  1584. mdiobus_unregister(priv->mii_bus);
  1585. mdiobus_free(priv->mii_bus);
  1586. } else {
  1587. struct bcm63xx_enet_platform_data *pd;
  1588. pd = dev_get_platdata(&pdev->dev);
  1589. if (pd && pd->mii_config)
  1590. pd->mii_config(dev, 0, bcm_enet_mdio_read_mii,
  1591. bcm_enet_mdio_write_mii);
  1592. }
  1593. /* disable hw block clocks */
  1594. clk_disable_unprepare(priv->phy_clk);
  1595. clk_disable_unprepare(priv->mac_clk);
  1596. free_netdev(dev);
  1597. return 0;
  1598. }
  1599. struct platform_driver bcm63xx_enet_driver = {
  1600. .probe = bcm_enet_probe,
  1601. .remove = bcm_enet_remove,
  1602. .driver = {
  1603. .name = "bcm63xx_enet",
  1604. .owner = THIS_MODULE,
  1605. },
  1606. };
  1607. /*
  1608. * switch mii access callbacks
  1609. */
  1610. static int bcmenet_sw_mdio_read(struct bcm_enet_priv *priv,
  1611. int ext, int phy_id, int location)
  1612. {
  1613. u32 reg;
  1614. int ret;
  1615. spin_lock_bh(&priv->enetsw_mdio_lock);
  1616. enetsw_writel(priv, 0, ENETSW_MDIOC_REG);
  1617. reg = ENETSW_MDIOC_RD_MASK |
  1618. (phy_id << ENETSW_MDIOC_PHYID_SHIFT) |
  1619. (location << ENETSW_MDIOC_REG_SHIFT);
  1620. if (ext)
  1621. reg |= ENETSW_MDIOC_EXT_MASK;
  1622. enetsw_writel(priv, reg, ENETSW_MDIOC_REG);
  1623. udelay(50);
  1624. ret = enetsw_readw(priv, ENETSW_MDIOD_REG);
  1625. spin_unlock_bh(&priv->enetsw_mdio_lock);
  1626. return ret;
  1627. }
  1628. static void bcmenet_sw_mdio_write(struct bcm_enet_priv *priv,
  1629. int ext, int phy_id, int location,
  1630. uint16_t data)
  1631. {
  1632. u32 reg;
  1633. spin_lock_bh(&priv->enetsw_mdio_lock);
  1634. enetsw_writel(priv, 0, ENETSW_MDIOC_REG);
  1635. reg = ENETSW_MDIOC_WR_MASK |
  1636. (phy_id << ENETSW_MDIOC_PHYID_SHIFT) |
  1637. (location << ENETSW_MDIOC_REG_SHIFT);
  1638. if (ext)
  1639. reg |= ENETSW_MDIOC_EXT_MASK;
  1640. reg |= data;
  1641. enetsw_writel(priv, reg, ENETSW_MDIOC_REG);
  1642. udelay(50);
  1643. spin_unlock_bh(&priv->enetsw_mdio_lock);
  1644. }
  1645. static inline int bcm_enet_port_is_rgmii(int portid)
  1646. {
  1647. return portid >= ENETSW_RGMII_PORT0;
  1648. }
  1649. /*
  1650. * enet sw PHY polling
  1651. */
  1652. static void swphy_poll_timer(struct timer_list *t)
  1653. {
  1654. struct bcm_enet_priv *priv = from_timer(priv, t, swphy_poll);
  1655. unsigned int i;
  1656. for (i = 0; i < priv->num_ports; i++) {
  1657. struct bcm63xx_enetsw_port *port;
  1658. int val, j, up, advertise, lpa, speed, duplex, media;
  1659. int external_phy = bcm_enet_port_is_rgmii(i);
  1660. u8 override;
  1661. port = &priv->used_ports[i];
  1662. if (!port->used)
  1663. continue;
  1664. if (port->bypass_link)
  1665. continue;
  1666. /* dummy read to clear */
  1667. for (j = 0; j < 2; j++)
  1668. val = bcmenet_sw_mdio_read(priv, external_phy,
  1669. port->phy_id, MII_BMSR);
  1670. if (val == 0xffff)
  1671. continue;
  1672. up = (val & BMSR_LSTATUS) ? 1 : 0;
  1673. if (!(up ^ priv->sw_port_link[i]))
  1674. continue;
  1675. priv->sw_port_link[i] = up;
  1676. /* link changed */
  1677. if (!up) {
  1678. dev_info(&priv->pdev->dev, "link DOWN on %s\n",
  1679. port->name);
  1680. enetsw_writeb(priv, ENETSW_PORTOV_ENABLE_MASK,
  1681. ENETSW_PORTOV_REG(i));
  1682. enetsw_writeb(priv, ENETSW_PTCTRL_RXDIS_MASK |
  1683. ENETSW_PTCTRL_TXDIS_MASK,
  1684. ENETSW_PTCTRL_REG(i));
  1685. continue;
  1686. }
  1687. advertise = bcmenet_sw_mdio_read(priv, external_phy,
  1688. port->phy_id, MII_ADVERTISE);
  1689. lpa = bcmenet_sw_mdio_read(priv, external_phy, port->phy_id,
  1690. MII_LPA);
  1691. /* figure out media and duplex from advertise and LPA values */
  1692. media = mii_nway_result(lpa & advertise);
  1693. duplex = (media & ADVERTISE_FULL) ? 1 : 0;
  1694. if (media & (ADVERTISE_100FULL | ADVERTISE_100HALF))
  1695. speed = 100;
  1696. else
  1697. speed = 10;
  1698. if (val & BMSR_ESTATEN) {
  1699. advertise = bcmenet_sw_mdio_read(priv, external_phy,
  1700. port->phy_id, MII_CTRL1000);
  1701. lpa = bcmenet_sw_mdio_read(priv, external_phy,
  1702. port->phy_id, MII_STAT1000);
  1703. if (advertise & (ADVERTISE_1000FULL | ADVERTISE_1000HALF)
  1704. && lpa & (LPA_1000FULL | LPA_1000HALF)) {
  1705. speed = 1000;
  1706. duplex = (lpa & LPA_1000FULL);
  1707. }
  1708. }
  1709. dev_info(&priv->pdev->dev,
  1710. "link UP on %s, %dMbps, %s-duplex\n",
  1711. port->name, speed, duplex ? "full" : "half");
  1712. override = ENETSW_PORTOV_ENABLE_MASK |
  1713. ENETSW_PORTOV_LINKUP_MASK;
  1714. if (speed == 1000)
  1715. override |= ENETSW_IMPOV_1000_MASK;
  1716. else if (speed == 100)
  1717. override |= ENETSW_IMPOV_100_MASK;
  1718. if (duplex)
  1719. override |= ENETSW_IMPOV_FDX_MASK;
  1720. enetsw_writeb(priv, override, ENETSW_PORTOV_REG(i));
  1721. enetsw_writeb(priv, 0, ENETSW_PTCTRL_REG(i));
  1722. }
  1723. priv->swphy_poll.expires = jiffies + HZ;
  1724. add_timer(&priv->swphy_poll);
  1725. }
  1726. /*
  1727. * open callback, allocate dma rings & buffers and start rx operation
  1728. */
  1729. static int bcm_enetsw_open(struct net_device *dev)
  1730. {
  1731. struct bcm_enet_priv *priv;
  1732. struct device *kdev;
  1733. int i, ret;
  1734. unsigned int size;
  1735. void *p;
  1736. u32 val;
  1737. priv = netdev_priv(dev);
  1738. kdev = &priv->pdev->dev;
  1739. /* mask all interrupts and request them */
  1740. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->rx_chan);
  1741. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->tx_chan);
  1742. ret = request_irq(priv->irq_rx, bcm_enet_isr_dma,
  1743. 0, dev->name, dev);
  1744. if (ret)
  1745. goto out_freeirq;
  1746. if (priv->irq_tx != -1) {
  1747. ret = request_irq(priv->irq_tx, bcm_enet_isr_dma,
  1748. 0, dev->name, dev);
  1749. if (ret)
  1750. goto out_freeirq_rx;
  1751. }
  1752. /* allocate rx dma ring */
  1753. size = priv->rx_ring_size * sizeof(struct bcm_enet_desc);
  1754. p = dma_zalloc_coherent(kdev, size, &priv->rx_desc_dma, GFP_KERNEL);
  1755. if (!p) {
  1756. dev_err(kdev, "cannot allocate rx ring %u\n", size);
  1757. ret = -ENOMEM;
  1758. goto out_freeirq_tx;
  1759. }
  1760. priv->rx_desc_alloc_size = size;
  1761. priv->rx_desc_cpu = p;
  1762. /* allocate tx dma ring */
  1763. size = priv->tx_ring_size * sizeof(struct bcm_enet_desc);
  1764. p = dma_zalloc_coherent(kdev, size, &priv->tx_desc_dma, GFP_KERNEL);
  1765. if (!p) {
  1766. dev_err(kdev, "cannot allocate tx ring\n");
  1767. ret = -ENOMEM;
  1768. goto out_free_rx_ring;
  1769. }
  1770. priv->tx_desc_alloc_size = size;
  1771. priv->tx_desc_cpu = p;
  1772. priv->tx_skb = kcalloc(priv->tx_ring_size, sizeof(struct sk_buff *),
  1773. GFP_KERNEL);
  1774. if (!priv->tx_skb) {
  1775. dev_err(kdev, "cannot allocate rx skb queue\n");
  1776. ret = -ENOMEM;
  1777. goto out_free_tx_ring;
  1778. }
  1779. priv->tx_desc_count = priv->tx_ring_size;
  1780. priv->tx_dirty_desc = 0;
  1781. priv->tx_curr_desc = 0;
  1782. spin_lock_init(&priv->tx_lock);
  1783. /* init & fill rx ring with skbs */
  1784. priv->rx_skb = kcalloc(priv->rx_ring_size, sizeof(struct sk_buff *),
  1785. GFP_KERNEL);
  1786. if (!priv->rx_skb) {
  1787. dev_err(kdev, "cannot allocate rx skb queue\n");
  1788. ret = -ENOMEM;
  1789. goto out_free_tx_skb;
  1790. }
  1791. priv->rx_desc_count = 0;
  1792. priv->rx_dirty_desc = 0;
  1793. priv->rx_curr_desc = 0;
  1794. /* disable all ports */
  1795. for (i = 0; i < priv->num_ports; i++) {
  1796. enetsw_writeb(priv, ENETSW_PORTOV_ENABLE_MASK,
  1797. ENETSW_PORTOV_REG(i));
  1798. enetsw_writeb(priv, ENETSW_PTCTRL_RXDIS_MASK |
  1799. ENETSW_PTCTRL_TXDIS_MASK,
  1800. ENETSW_PTCTRL_REG(i));
  1801. priv->sw_port_link[i] = 0;
  1802. }
  1803. /* reset mib */
  1804. val = enetsw_readb(priv, ENETSW_GMCR_REG);
  1805. val |= ENETSW_GMCR_RST_MIB_MASK;
  1806. enetsw_writeb(priv, val, ENETSW_GMCR_REG);
  1807. mdelay(1);
  1808. val &= ~ENETSW_GMCR_RST_MIB_MASK;
  1809. enetsw_writeb(priv, val, ENETSW_GMCR_REG);
  1810. mdelay(1);
  1811. /* force CPU port state */
  1812. val = enetsw_readb(priv, ENETSW_IMPOV_REG);
  1813. val |= ENETSW_IMPOV_FORCE_MASK | ENETSW_IMPOV_LINKUP_MASK;
  1814. enetsw_writeb(priv, val, ENETSW_IMPOV_REG);
  1815. /* enable switch forward engine */
  1816. val = enetsw_readb(priv, ENETSW_SWMODE_REG);
  1817. val |= ENETSW_SWMODE_FWD_EN_MASK;
  1818. enetsw_writeb(priv, val, ENETSW_SWMODE_REG);
  1819. /* enable jumbo on all ports */
  1820. enetsw_writel(priv, 0x1ff, ENETSW_JMBCTL_PORT_REG);
  1821. enetsw_writew(priv, 9728, ENETSW_JMBCTL_MAXSIZE_REG);
  1822. /* initialize flow control buffer allocation */
  1823. enet_dma_writel(priv, ENETDMA_BUFALLOC_FORCE_MASK | 0,
  1824. ENETDMA_BUFALLOC_REG(priv->rx_chan));
  1825. if (bcm_enet_refill_rx(dev)) {
  1826. dev_err(kdev, "cannot allocate rx skb queue\n");
  1827. ret = -ENOMEM;
  1828. goto out;
  1829. }
  1830. /* write rx & tx ring addresses */
  1831. enet_dmas_writel(priv, priv->rx_desc_dma,
  1832. ENETDMAS_RSTART_REG, priv->rx_chan);
  1833. enet_dmas_writel(priv, priv->tx_desc_dma,
  1834. ENETDMAS_RSTART_REG, priv->tx_chan);
  1835. /* clear remaining state ram for rx & tx channel */
  1836. enet_dmas_writel(priv, 0, ENETDMAS_SRAM2_REG, priv->rx_chan);
  1837. enet_dmas_writel(priv, 0, ENETDMAS_SRAM2_REG, priv->tx_chan);
  1838. enet_dmas_writel(priv, 0, ENETDMAS_SRAM3_REG, priv->rx_chan);
  1839. enet_dmas_writel(priv, 0, ENETDMAS_SRAM3_REG, priv->tx_chan);
  1840. enet_dmas_writel(priv, 0, ENETDMAS_SRAM4_REG, priv->rx_chan);
  1841. enet_dmas_writel(priv, 0, ENETDMAS_SRAM4_REG, priv->tx_chan);
  1842. /* set dma maximum burst len */
  1843. enet_dmac_writel(priv, priv->dma_maxburst,
  1844. ENETDMAC_MAXBURST, priv->rx_chan);
  1845. enet_dmac_writel(priv, priv->dma_maxburst,
  1846. ENETDMAC_MAXBURST, priv->tx_chan);
  1847. /* set flow control low/high threshold to 1/3 / 2/3 */
  1848. val = priv->rx_ring_size / 3;
  1849. enet_dma_writel(priv, val, ENETDMA_FLOWCL_REG(priv->rx_chan));
  1850. val = (priv->rx_ring_size * 2) / 3;
  1851. enet_dma_writel(priv, val, ENETDMA_FLOWCH_REG(priv->rx_chan));
  1852. /* all set, enable mac and interrupts, start dma engine and
  1853. * kick rx dma channel
  1854. */
  1855. wmb();
  1856. enet_dma_writel(priv, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG);
  1857. enet_dmac_writel(priv, ENETDMAC_CHANCFG_EN_MASK,
  1858. ENETDMAC_CHANCFG, priv->rx_chan);
  1859. /* watch "packet transferred" interrupt in rx and tx */
  1860. enet_dmac_writel(priv, ENETDMAC_IR_PKTDONE_MASK,
  1861. ENETDMAC_IR, priv->rx_chan);
  1862. enet_dmac_writel(priv, ENETDMAC_IR_PKTDONE_MASK,
  1863. ENETDMAC_IR, priv->tx_chan);
  1864. /* make sure we enable napi before rx interrupt */
  1865. napi_enable(&priv->napi);
  1866. enet_dmac_writel(priv, ENETDMAC_IR_PKTDONE_MASK,
  1867. ENETDMAC_IRMASK, priv->rx_chan);
  1868. enet_dmac_writel(priv, ENETDMAC_IR_PKTDONE_MASK,
  1869. ENETDMAC_IRMASK, priv->tx_chan);
  1870. netif_carrier_on(dev);
  1871. netif_start_queue(dev);
  1872. /* apply override config for bypass_link ports here. */
  1873. for (i = 0; i < priv->num_ports; i++) {
  1874. struct bcm63xx_enetsw_port *port;
  1875. u8 override;
  1876. port = &priv->used_ports[i];
  1877. if (!port->used)
  1878. continue;
  1879. if (!port->bypass_link)
  1880. continue;
  1881. override = ENETSW_PORTOV_ENABLE_MASK |
  1882. ENETSW_PORTOV_LINKUP_MASK;
  1883. switch (port->force_speed) {
  1884. case 1000:
  1885. override |= ENETSW_IMPOV_1000_MASK;
  1886. break;
  1887. case 100:
  1888. override |= ENETSW_IMPOV_100_MASK;
  1889. break;
  1890. case 10:
  1891. break;
  1892. default:
  1893. pr_warn("invalid forced speed on port %s: assume 10\n",
  1894. port->name);
  1895. break;
  1896. }
  1897. if (port->force_duplex_full)
  1898. override |= ENETSW_IMPOV_FDX_MASK;
  1899. enetsw_writeb(priv, override, ENETSW_PORTOV_REG(i));
  1900. enetsw_writeb(priv, 0, ENETSW_PTCTRL_REG(i));
  1901. }
  1902. /* start phy polling timer */
  1903. timer_setup(&priv->swphy_poll, swphy_poll_timer, 0);
  1904. mod_timer(&priv->swphy_poll, jiffies);
  1905. return 0;
  1906. out:
  1907. for (i = 0; i < priv->rx_ring_size; i++) {
  1908. struct bcm_enet_desc *desc;
  1909. if (!priv->rx_skb[i])
  1910. continue;
  1911. desc = &priv->rx_desc_cpu[i];
  1912. dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
  1913. DMA_FROM_DEVICE);
  1914. kfree_skb(priv->rx_skb[i]);
  1915. }
  1916. kfree(priv->rx_skb);
  1917. out_free_tx_skb:
  1918. kfree(priv->tx_skb);
  1919. out_free_tx_ring:
  1920. dma_free_coherent(kdev, priv->tx_desc_alloc_size,
  1921. priv->tx_desc_cpu, priv->tx_desc_dma);
  1922. out_free_rx_ring:
  1923. dma_free_coherent(kdev, priv->rx_desc_alloc_size,
  1924. priv->rx_desc_cpu, priv->rx_desc_dma);
  1925. out_freeirq_tx:
  1926. if (priv->irq_tx != -1)
  1927. free_irq(priv->irq_tx, dev);
  1928. out_freeirq_rx:
  1929. free_irq(priv->irq_rx, dev);
  1930. out_freeirq:
  1931. return ret;
  1932. }
  1933. /* stop callback */
  1934. static int bcm_enetsw_stop(struct net_device *dev)
  1935. {
  1936. struct bcm_enet_priv *priv;
  1937. struct device *kdev;
  1938. int i;
  1939. priv = netdev_priv(dev);
  1940. kdev = &priv->pdev->dev;
  1941. del_timer_sync(&priv->swphy_poll);
  1942. netif_stop_queue(dev);
  1943. napi_disable(&priv->napi);
  1944. del_timer_sync(&priv->rx_timeout);
  1945. /* mask all interrupts */
  1946. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->rx_chan);
  1947. enet_dmac_writel(priv, 0, ENETDMAC_IRMASK, priv->tx_chan);
  1948. /* disable dma & mac */
  1949. bcm_enet_disable_dma(priv, priv->tx_chan);
  1950. bcm_enet_disable_dma(priv, priv->rx_chan);
  1951. /* force reclaim of all tx buffers */
  1952. bcm_enet_tx_reclaim(dev, 1);
  1953. /* free the rx skb ring */
  1954. for (i = 0; i < priv->rx_ring_size; i++) {
  1955. struct bcm_enet_desc *desc;
  1956. if (!priv->rx_skb[i])
  1957. continue;
  1958. desc = &priv->rx_desc_cpu[i];
  1959. dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
  1960. DMA_FROM_DEVICE);
  1961. kfree_skb(priv->rx_skb[i]);
  1962. }
  1963. /* free remaining allocated memory */
  1964. kfree(priv->rx_skb);
  1965. kfree(priv->tx_skb);
  1966. dma_free_coherent(kdev, priv->rx_desc_alloc_size,
  1967. priv->rx_desc_cpu, priv->rx_desc_dma);
  1968. dma_free_coherent(kdev, priv->tx_desc_alloc_size,
  1969. priv->tx_desc_cpu, priv->tx_desc_dma);
  1970. if (priv->irq_tx != -1)
  1971. free_irq(priv->irq_tx, dev);
  1972. free_irq(priv->irq_rx, dev);
  1973. return 0;
  1974. }
  1975. /* try to sort out phy external status by walking the used_port field
  1976. * in the bcm_enet_priv structure. in case the phy address is not
  1977. * assigned to any physical port on the switch, assume it is external
  1978. * (and yell at the user).
  1979. */
  1980. static int bcm_enetsw_phy_is_external(struct bcm_enet_priv *priv, int phy_id)
  1981. {
  1982. int i;
  1983. for (i = 0; i < priv->num_ports; ++i) {
  1984. if (!priv->used_ports[i].used)
  1985. continue;
  1986. if (priv->used_ports[i].phy_id == phy_id)
  1987. return bcm_enet_port_is_rgmii(i);
  1988. }
  1989. printk_once(KERN_WARNING "bcm63xx_enet: could not find a used port with phy_id %i, assuming phy is external\n",
  1990. phy_id);
  1991. return 1;
  1992. }
  1993. /* can't use bcmenet_sw_mdio_read directly as we need to sort out
  1994. * external/internal status of the given phy_id first.
  1995. */
  1996. static int bcm_enetsw_mii_mdio_read(struct net_device *dev, int phy_id,
  1997. int location)
  1998. {
  1999. struct bcm_enet_priv *priv;
  2000. priv = netdev_priv(dev);
  2001. return bcmenet_sw_mdio_read(priv,
  2002. bcm_enetsw_phy_is_external(priv, phy_id),
  2003. phy_id, location);
  2004. }
  2005. /* can't use bcmenet_sw_mdio_write directly as we need to sort out
  2006. * external/internal status of the given phy_id first.
  2007. */
  2008. static void bcm_enetsw_mii_mdio_write(struct net_device *dev, int phy_id,
  2009. int location,
  2010. int val)
  2011. {
  2012. struct bcm_enet_priv *priv;
  2013. priv = netdev_priv(dev);
  2014. bcmenet_sw_mdio_write(priv, bcm_enetsw_phy_is_external(priv, phy_id),
  2015. phy_id, location, val);
  2016. }
  2017. static int bcm_enetsw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2018. {
  2019. struct mii_if_info mii;
  2020. mii.dev = dev;
  2021. mii.mdio_read = bcm_enetsw_mii_mdio_read;
  2022. mii.mdio_write = bcm_enetsw_mii_mdio_write;
  2023. mii.phy_id = 0;
  2024. mii.phy_id_mask = 0x3f;
  2025. mii.reg_num_mask = 0x1f;
  2026. return generic_mii_ioctl(&mii, if_mii(rq), cmd, NULL);
  2027. }
  2028. static const struct net_device_ops bcm_enetsw_ops = {
  2029. .ndo_open = bcm_enetsw_open,
  2030. .ndo_stop = bcm_enetsw_stop,
  2031. .ndo_start_xmit = bcm_enet_start_xmit,
  2032. .ndo_change_mtu = bcm_enet_change_mtu,
  2033. .ndo_do_ioctl = bcm_enetsw_ioctl,
  2034. };
  2035. static const struct bcm_enet_stats bcm_enetsw_gstrings_stats[] = {
  2036. { "rx_packets", DEV_STAT(rx_packets), -1 },
  2037. { "tx_packets", DEV_STAT(tx_packets), -1 },
  2038. { "rx_bytes", DEV_STAT(rx_bytes), -1 },
  2039. { "tx_bytes", DEV_STAT(tx_bytes), -1 },
  2040. { "rx_errors", DEV_STAT(rx_errors), -1 },
  2041. { "tx_errors", DEV_STAT(tx_errors), -1 },
  2042. { "rx_dropped", DEV_STAT(rx_dropped), -1 },
  2043. { "tx_dropped", DEV_STAT(tx_dropped), -1 },
  2044. { "tx_good_octets", GEN_STAT(mib.tx_gd_octets), ETHSW_MIB_RX_GD_OCT },
  2045. { "tx_unicast", GEN_STAT(mib.tx_unicast), ETHSW_MIB_RX_BRDCAST },
  2046. { "tx_broadcast", GEN_STAT(mib.tx_brdcast), ETHSW_MIB_RX_BRDCAST },
  2047. { "tx_multicast", GEN_STAT(mib.tx_mult), ETHSW_MIB_RX_MULT },
  2048. { "tx_64_octets", GEN_STAT(mib.tx_64), ETHSW_MIB_RX_64 },
  2049. { "tx_65_127_oct", GEN_STAT(mib.tx_65_127), ETHSW_MIB_RX_65_127 },
  2050. { "tx_128_255_oct", GEN_STAT(mib.tx_128_255), ETHSW_MIB_RX_128_255 },
  2051. { "tx_256_511_oct", GEN_STAT(mib.tx_256_511), ETHSW_MIB_RX_256_511 },
  2052. { "tx_512_1023_oct", GEN_STAT(mib.tx_512_1023), ETHSW_MIB_RX_512_1023},
  2053. { "tx_1024_1522_oct", GEN_STAT(mib.tx_1024_max),
  2054. ETHSW_MIB_RX_1024_1522 },
  2055. { "tx_1523_2047_oct", GEN_STAT(mib.tx_1523_2047),
  2056. ETHSW_MIB_RX_1523_2047 },
  2057. { "tx_2048_4095_oct", GEN_STAT(mib.tx_2048_4095),
  2058. ETHSW_MIB_RX_2048_4095 },
  2059. { "tx_4096_8191_oct", GEN_STAT(mib.tx_4096_8191),
  2060. ETHSW_MIB_RX_4096_8191 },
  2061. { "tx_8192_9728_oct", GEN_STAT(mib.tx_8192_9728),
  2062. ETHSW_MIB_RX_8192_9728 },
  2063. { "tx_oversize", GEN_STAT(mib.tx_ovr), ETHSW_MIB_RX_OVR },
  2064. { "tx_oversize_drop", GEN_STAT(mib.tx_ovr), ETHSW_MIB_RX_OVR_DISC },
  2065. { "tx_dropped", GEN_STAT(mib.tx_drop), ETHSW_MIB_RX_DROP },
  2066. { "tx_undersize", GEN_STAT(mib.tx_underrun), ETHSW_MIB_RX_UND },
  2067. { "tx_pause", GEN_STAT(mib.tx_pause), ETHSW_MIB_RX_PAUSE },
  2068. { "rx_good_octets", GEN_STAT(mib.rx_gd_octets), ETHSW_MIB_TX_ALL_OCT },
  2069. { "rx_broadcast", GEN_STAT(mib.rx_brdcast), ETHSW_MIB_TX_BRDCAST },
  2070. { "rx_multicast", GEN_STAT(mib.rx_mult), ETHSW_MIB_TX_MULT },
  2071. { "rx_unicast", GEN_STAT(mib.rx_unicast), ETHSW_MIB_TX_MULT },
  2072. { "rx_pause", GEN_STAT(mib.rx_pause), ETHSW_MIB_TX_PAUSE },
  2073. { "rx_dropped", GEN_STAT(mib.rx_drop), ETHSW_MIB_TX_DROP_PKTS },
  2074. };
  2075. #define BCM_ENETSW_STATS_LEN \
  2076. (sizeof(bcm_enetsw_gstrings_stats) / sizeof(struct bcm_enet_stats))
  2077. static void bcm_enetsw_get_strings(struct net_device *netdev,
  2078. u32 stringset, u8 *data)
  2079. {
  2080. int i;
  2081. switch (stringset) {
  2082. case ETH_SS_STATS:
  2083. for (i = 0; i < BCM_ENETSW_STATS_LEN; i++) {
  2084. memcpy(data + i * ETH_GSTRING_LEN,
  2085. bcm_enetsw_gstrings_stats[i].stat_string,
  2086. ETH_GSTRING_LEN);
  2087. }
  2088. break;
  2089. }
  2090. }
  2091. static int bcm_enetsw_get_sset_count(struct net_device *netdev,
  2092. int string_set)
  2093. {
  2094. switch (string_set) {
  2095. case ETH_SS_STATS:
  2096. return BCM_ENETSW_STATS_LEN;
  2097. default:
  2098. return -EINVAL;
  2099. }
  2100. }
  2101. static void bcm_enetsw_get_drvinfo(struct net_device *netdev,
  2102. struct ethtool_drvinfo *drvinfo)
  2103. {
  2104. strncpy(drvinfo->driver, bcm_enet_driver_name, 32);
  2105. strncpy(drvinfo->version, bcm_enet_driver_version, 32);
  2106. strncpy(drvinfo->fw_version, "N/A", 32);
  2107. strncpy(drvinfo->bus_info, "bcm63xx", 32);
  2108. }
  2109. static void bcm_enetsw_get_ethtool_stats(struct net_device *netdev,
  2110. struct ethtool_stats *stats,
  2111. u64 *data)
  2112. {
  2113. struct bcm_enet_priv *priv;
  2114. int i;
  2115. priv = netdev_priv(netdev);
  2116. for (i = 0; i < BCM_ENETSW_STATS_LEN; i++) {
  2117. const struct bcm_enet_stats *s;
  2118. u32 lo, hi;
  2119. char *p;
  2120. int reg;
  2121. s = &bcm_enetsw_gstrings_stats[i];
  2122. reg = s->mib_reg;
  2123. if (reg == -1)
  2124. continue;
  2125. lo = enetsw_readl(priv, ENETSW_MIB_REG(reg));
  2126. p = (char *)priv + s->stat_offset;
  2127. if (s->sizeof_stat == sizeof(u64)) {
  2128. hi = enetsw_readl(priv, ENETSW_MIB_REG(reg + 1));
  2129. *(u64 *)p = ((u64)hi << 32 | lo);
  2130. } else {
  2131. *(u32 *)p = lo;
  2132. }
  2133. }
  2134. for (i = 0; i < BCM_ENETSW_STATS_LEN; i++) {
  2135. const struct bcm_enet_stats *s;
  2136. char *p;
  2137. s = &bcm_enetsw_gstrings_stats[i];
  2138. if (s->mib_reg == -1)
  2139. p = (char *)&netdev->stats + s->stat_offset;
  2140. else
  2141. p = (char *)priv + s->stat_offset;
  2142. data[i] = (s->sizeof_stat == sizeof(u64)) ?
  2143. *(u64 *)p : *(u32 *)p;
  2144. }
  2145. }
  2146. static void bcm_enetsw_get_ringparam(struct net_device *dev,
  2147. struct ethtool_ringparam *ering)
  2148. {
  2149. struct bcm_enet_priv *priv;
  2150. priv = netdev_priv(dev);
  2151. /* rx/tx ring is actually only limited by memory */
  2152. ering->rx_max_pending = 8192;
  2153. ering->tx_max_pending = 8192;
  2154. ering->rx_mini_max_pending = 0;
  2155. ering->rx_jumbo_max_pending = 0;
  2156. ering->rx_pending = priv->rx_ring_size;
  2157. ering->tx_pending = priv->tx_ring_size;
  2158. }
  2159. static int bcm_enetsw_set_ringparam(struct net_device *dev,
  2160. struct ethtool_ringparam *ering)
  2161. {
  2162. struct bcm_enet_priv *priv;
  2163. int was_running;
  2164. priv = netdev_priv(dev);
  2165. was_running = 0;
  2166. if (netif_running(dev)) {
  2167. bcm_enetsw_stop(dev);
  2168. was_running = 1;
  2169. }
  2170. priv->rx_ring_size = ering->rx_pending;
  2171. priv->tx_ring_size = ering->tx_pending;
  2172. if (was_running) {
  2173. int err;
  2174. err = bcm_enetsw_open(dev);
  2175. if (err)
  2176. dev_close(dev);
  2177. }
  2178. return 0;
  2179. }
  2180. static const struct ethtool_ops bcm_enetsw_ethtool_ops = {
  2181. .get_strings = bcm_enetsw_get_strings,
  2182. .get_sset_count = bcm_enetsw_get_sset_count,
  2183. .get_ethtool_stats = bcm_enetsw_get_ethtool_stats,
  2184. .get_drvinfo = bcm_enetsw_get_drvinfo,
  2185. .get_ringparam = bcm_enetsw_get_ringparam,
  2186. .set_ringparam = bcm_enetsw_set_ringparam,
  2187. };
  2188. /* allocate netdevice, request register memory and register device. */
  2189. static int bcm_enetsw_probe(struct platform_device *pdev)
  2190. {
  2191. struct bcm_enet_priv *priv;
  2192. struct net_device *dev;
  2193. struct bcm63xx_enetsw_platform_data *pd;
  2194. struct resource *res_mem;
  2195. int ret, irq_rx, irq_tx;
  2196. if (!bcm_enet_shared_base[0])
  2197. return -EPROBE_DEFER;
  2198. res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2199. irq_rx = platform_get_irq(pdev, 0);
  2200. irq_tx = platform_get_irq(pdev, 1);
  2201. if (!res_mem || irq_rx < 0)
  2202. return -ENODEV;
  2203. ret = 0;
  2204. dev = alloc_etherdev(sizeof(*priv));
  2205. if (!dev)
  2206. return -ENOMEM;
  2207. priv = netdev_priv(dev);
  2208. memset(priv, 0, sizeof(*priv));
  2209. /* initialize default and fetch platform data */
  2210. priv->enet_is_sw = true;
  2211. priv->irq_rx = irq_rx;
  2212. priv->irq_tx = irq_tx;
  2213. priv->rx_ring_size = BCMENET_DEF_RX_DESC;
  2214. priv->tx_ring_size = BCMENET_DEF_TX_DESC;
  2215. priv->dma_maxburst = BCMENETSW_DMA_MAXBURST;
  2216. pd = dev_get_platdata(&pdev->dev);
  2217. if (pd) {
  2218. memcpy(dev->dev_addr, pd->mac_addr, ETH_ALEN);
  2219. memcpy(priv->used_ports, pd->used_ports,
  2220. sizeof(pd->used_ports));
  2221. priv->num_ports = pd->num_ports;
  2222. priv->dma_has_sram = pd->dma_has_sram;
  2223. priv->dma_chan_en_mask = pd->dma_chan_en_mask;
  2224. priv->dma_chan_int_mask = pd->dma_chan_int_mask;
  2225. priv->dma_chan_width = pd->dma_chan_width;
  2226. }
  2227. ret = bcm_enet_change_mtu(dev, dev->mtu);
  2228. if (ret)
  2229. goto out;
  2230. priv->base = devm_ioremap_resource(&pdev->dev, res_mem);
  2231. if (IS_ERR(priv->base)) {
  2232. ret = PTR_ERR(priv->base);
  2233. goto out;
  2234. }
  2235. priv->mac_clk = devm_clk_get(&pdev->dev, "enetsw");
  2236. if (IS_ERR(priv->mac_clk)) {
  2237. ret = PTR_ERR(priv->mac_clk);
  2238. goto out;
  2239. }
  2240. ret = clk_prepare_enable(priv->mac_clk);
  2241. if (ret)
  2242. goto out;
  2243. priv->rx_chan = 0;
  2244. priv->tx_chan = 1;
  2245. spin_lock_init(&priv->rx_lock);
  2246. /* init rx timeout (used for oom) */
  2247. timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
  2248. /* register netdevice */
  2249. dev->netdev_ops = &bcm_enetsw_ops;
  2250. netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
  2251. dev->ethtool_ops = &bcm_enetsw_ethtool_ops;
  2252. SET_NETDEV_DEV(dev, &pdev->dev);
  2253. spin_lock_init(&priv->enetsw_mdio_lock);
  2254. ret = register_netdev(dev);
  2255. if (ret)
  2256. goto out_disable_clk;
  2257. netif_carrier_off(dev);
  2258. platform_set_drvdata(pdev, dev);
  2259. priv->pdev = pdev;
  2260. priv->net_dev = dev;
  2261. return 0;
  2262. out_disable_clk:
  2263. clk_disable_unprepare(priv->mac_clk);
  2264. out:
  2265. free_netdev(dev);
  2266. return ret;
  2267. }
  2268. /* exit func, stops hardware and unregisters netdevice */
  2269. static int bcm_enetsw_remove(struct platform_device *pdev)
  2270. {
  2271. struct bcm_enet_priv *priv;
  2272. struct net_device *dev;
  2273. /* stop netdevice */
  2274. dev = platform_get_drvdata(pdev);
  2275. priv = netdev_priv(dev);
  2276. unregister_netdev(dev);
  2277. clk_disable_unprepare(priv->mac_clk);
  2278. free_netdev(dev);
  2279. return 0;
  2280. }
  2281. struct platform_driver bcm63xx_enetsw_driver = {
  2282. .probe = bcm_enetsw_probe,
  2283. .remove = bcm_enetsw_remove,
  2284. .driver = {
  2285. .name = "bcm63xx_enetsw",
  2286. .owner = THIS_MODULE,
  2287. },
  2288. };
  2289. /* reserve & remap memory space shared between all macs */
  2290. static int bcm_enet_shared_probe(struct platform_device *pdev)
  2291. {
  2292. struct resource *res;
  2293. void __iomem *p[3];
  2294. unsigned int i;
  2295. memset(bcm_enet_shared_base, 0, sizeof(bcm_enet_shared_base));
  2296. for (i = 0; i < 3; i++) {
  2297. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  2298. p[i] = devm_ioremap_resource(&pdev->dev, res);
  2299. if (IS_ERR(p[i]))
  2300. return PTR_ERR(p[i]);
  2301. }
  2302. memcpy(bcm_enet_shared_base, p, sizeof(bcm_enet_shared_base));
  2303. return 0;
  2304. }
  2305. static int bcm_enet_shared_remove(struct platform_device *pdev)
  2306. {
  2307. return 0;
  2308. }
  2309. /* this "shared" driver is needed because both macs share a single
  2310. * address space
  2311. */
  2312. struct platform_driver bcm63xx_enet_shared_driver = {
  2313. .probe = bcm_enet_shared_probe,
  2314. .remove = bcm_enet_shared_remove,
  2315. .driver = {
  2316. .name = "bcm63xx_enet_shared",
  2317. .owner = THIS_MODULE,
  2318. },
  2319. };
  2320. static struct platform_driver * const drivers[] = {
  2321. &bcm63xx_enet_shared_driver,
  2322. &bcm63xx_enet_driver,
  2323. &bcm63xx_enetsw_driver,
  2324. };
  2325. /* entry point */
  2326. static int __init bcm_enet_init(void)
  2327. {
  2328. return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  2329. }
  2330. static void __exit bcm_enet_exit(void)
  2331. {
  2332. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  2333. }
  2334. module_init(bcm_enet_init);
  2335. module_exit(bcm_enet_exit);
  2336. MODULE_DESCRIPTION("BCM63xx internal ethernet mac driver");
  2337. MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
  2338. MODULE_LICENSE("GPL");