gianfar.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361
  1. /*
  2. * drivers/net/gianfar.c
  3. *
  4. * Gianfar Ethernet Driver
  5. * This driver is designed for the non-CPM ethernet controllers
  6. * on the 85xx and 83xx family of integrated processors
  7. * Based on 8260_io/fcc_enet.c
  8. *
  9. * Author: Andy Fleming
  10. * Maintainer: Kumar Gala
  11. *
  12. * Copyright (c) 2002-2006 Freescale Semiconductor, Inc.
  13. * Copyright (c) 2007 MontaVista Software, Inc.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. *
  20. * Gianfar: AKA Lambda Draconis, "Dragon"
  21. * RA 11 31 24.2
  22. * Dec +69 19 52
  23. * V 3.84
  24. * B-V +1.62
  25. *
  26. * Theory of operation
  27. *
  28. * The driver is initialized through of_device. Configuration information
  29. * is therefore conveyed through an OF-style device tree.
  30. *
  31. * The Gianfar Ethernet Controller uses a ring of buffer
  32. * descriptors. The beginning is indicated by a register
  33. * pointing to the physical address of the start of the ring.
  34. * The end is determined by a "wrap" bit being set in the
  35. * last descriptor of the ring.
  36. *
  37. * When a packet is received, the RXF bit in the
  38. * IEVENT register is set, triggering an interrupt when the
  39. * corresponding bit in the IMASK register is also set (if
  40. * interrupt coalescing is active, then the interrupt may not
  41. * happen immediately, but will wait until either a set number
  42. * of frames or amount of time have passed). In NAPI, the
  43. * interrupt handler will signal there is work to be done, and
  44. * exit. This method will start at the last known empty
  45. * descriptor, and process every subsequent descriptor until there
  46. * are none left with data (NAPI will stop after a set number of
  47. * packets to give time to other tasks, but will eventually
  48. * process all the packets). The data arrives inside a
  49. * pre-allocated skb, and so after the skb is passed up to the
  50. * stack, a new skb must be allocated, and the address field in
  51. * the buffer descriptor must be updated to indicate this new
  52. * skb.
  53. *
  54. * When the kernel requests that a packet be transmitted, the
  55. * driver starts where it left off last time, and points the
  56. * descriptor at the buffer which was passed in. The driver
  57. * then informs the DMA engine that there are packets ready to
  58. * be transmitted. Once the controller is finished transmitting
  59. * the packet, an interrupt may be triggered (under the same
  60. * conditions as for reception, but depending on the TXF bit).
  61. * The driver then cleans up the buffer.
  62. */
  63. #include <linux/kernel.h>
  64. #include <linux/string.h>
  65. #include <linux/errno.h>
  66. #include <linux/unistd.h>
  67. #include <linux/slab.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/init.h>
  70. #include <linux/delay.h>
  71. #include <linux/netdevice.h>
  72. #include <linux/etherdevice.h>
  73. #include <linux/skbuff.h>
  74. #include <linux/if_vlan.h>
  75. #include <linux/spinlock.h>
  76. #include <linux/mm.h>
  77. #include <linux/of_mdio.h>
  78. #include <linux/of_platform.h>
  79. #include <linux/ip.h>
  80. #include <linux/tcp.h>
  81. #include <linux/udp.h>
  82. #include <linux/in.h>
  83. #include <asm/io.h>
  84. #include <asm/irq.h>
  85. #include <asm/uaccess.h>
  86. #include <linux/module.h>
  87. #include <linux/dma-mapping.h>
  88. #include <linux/crc32.h>
  89. #include <linux/mii.h>
  90. #include <linux/phy.h>
  91. #include <linux/phy_fixed.h>
  92. #include <linux/of.h>
  93. #include "gianfar.h"
  94. #include "fsl_pq_mdio.h"
  95. #define TX_TIMEOUT (1*HZ)
  96. #undef BRIEF_GFAR_ERRORS
  97. #undef VERBOSE_GFAR_ERRORS
  98. const char gfar_driver_name[] = "Gianfar Ethernet";
  99. const char gfar_driver_version[] = "1.3";
  100. static int gfar_enet_open(struct net_device *dev);
  101. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
  102. static void gfar_reset_task(struct work_struct *work);
  103. static void gfar_timeout(struct net_device *dev);
  104. static int gfar_close(struct net_device *dev);
  105. struct sk_buff *gfar_new_skb(struct net_device *dev);
  106. static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
  107. struct sk_buff *skb);
  108. static int gfar_set_mac_address(struct net_device *dev);
  109. static int gfar_change_mtu(struct net_device *dev, int new_mtu);
  110. static irqreturn_t gfar_error(int irq, void *dev_id);
  111. static irqreturn_t gfar_transmit(int irq, void *dev_id);
  112. static irqreturn_t gfar_interrupt(int irq, void *dev_id);
  113. static void adjust_link(struct net_device *dev);
  114. static void init_registers(struct net_device *dev);
  115. static int init_phy(struct net_device *dev);
  116. static int gfar_probe(struct of_device *ofdev,
  117. const struct of_device_id *match);
  118. static int gfar_remove(struct of_device *ofdev);
  119. static void free_skb_resources(struct gfar_private *priv);
  120. static void gfar_set_multi(struct net_device *dev);
  121. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
  122. static void gfar_configure_serdes(struct net_device *dev);
  123. static int gfar_poll(struct napi_struct *napi, int budget);
  124. #ifdef CONFIG_NET_POLL_CONTROLLER
  125. static void gfar_netpoll(struct net_device *dev);
  126. #endif
  127. int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
  128. static int gfar_clean_tx_ring(struct net_device *dev);
  129. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  130. int amount_pull);
  131. static void gfar_vlan_rx_register(struct net_device *netdev,
  132. struct vlan_group *grp);
  133. void gfar_halt(struct net_device *dev);
  134. static void gfar_halt_nodisable(struct net_device *dev);
  135. void gfar_start(struct net_device *dev);
  136. static void gfar_clear_exact_match(struct net_device *dev);
  137. static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
  138. static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  139. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  140. MODULE_DESCRIPTION("Gianfar Ethernet Driver");
  141. MODULE_LICENSE("GPL");
  142. static const struct net_device_ops gfar_netdev_ops = {
  143. .ndo_open = gfar_enet_open,
  144. .ndo_start_xmit = gfar_start_xmit,
  145. .ndo_stop = gfar_close,
  146. .ndo_change_mtu = gfar_change_mtu,
  147. .ndo_set_multicast_list = gfar_set_multi,
  148. .ndo_tx_timeout = gfar_timeout,
  149. .ndo_do_ioctl = gfar_ioctl,
  150. .ndo_vlan_rx_register = gfar_vlan_rx_register,
  151. #ifdef CONFIG_NET_POLL_CONTROLLER
  152. .ndo_poll_controller = gfar_netpoll,
  153. #endif
  154. };
  155. /* Returns 1 if incoming frames use an FCB */
  156. static inline int gfar_uses_fcb(struct gfar_private *priv)
  157. {
  158. return priv->vlgrp || priv->rx_csum_enable;
  159. }
  160. static int gfar_of_init(struct net_device *dev)
  161. {
  162. const char *model;
  163. const char *ctype;
  164. const void *mac_addr;
  165. u64 addr, size;
  166. int err = 0;
  167. struct gfar_private *priv = netdev_priv(dev);
  168. struct device_node *np = priv->node;
  169. const u32 *stash;
  170. const u32 *stash_len;
  171. const u32 *stash_idx;
  172. if (!np || !of_device_is_available(np))
  173. return -ENODEV;
  174. /* get a pointer to the register memory */
  175. addr = of_translate_address(np, of_get_address(np, 0, &size, NULL));
  176. priv->regs = ioremap(addr, size);
  177. if (priv->regs == NULL)
  178. return -ENOMEM;
  179. priv->interruptTransmit = irq_of_parse_and_map(np, 0);
  180. model = of_get_property(np, "model", NULL);
  181. /* If we aren't the FEC we have multiple interrupts */
  182. if (model && strcasecmp(model, "FEC")) {
  183. priv->interruptReceive = irq_of_parse_and_map(np, 1);
  184. priv->interruptError = irq_of_parse_and_map(np, 2);
  185. if (priv->interruptTransmit < 0 ||
  186. priv->interruptReceive < 0 ||
  187. priv->interruptError < 0) {
  188. err = -EINVAL;
  189. goto err_out;
  190. }
  191. }
  192. stash = of_get_property(np, "bd-stash", NULL);
  193. if(stash) {
  194. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
  195. priv->bd_stash_en = 1;
  196. }
  197. stash_len = of_get_property(np, "rx-stash-len", NULL);
  198. if (stash_len)
  199. priv->rx_stash_size = *stash_len;
  200. stash_idx = of_get_property(np, "rx-stash-idx", NULL);
  201. if (stash_idx)
  202. priv->rx_stash_index = *stash_idx;
  203. if (stash_len || stash_idx)
  204. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
  205. mac_addr = of_get_mac_address(np);
  206. if (mac_addr)
  207. memcpy(dev->dev_addr, mac_addr, MAC_ADDR_LEN);
  208. if (model && !strcasecmp(model, "TSEC"))
  209. priv->device_flags =
  210. FSL_GIANFAR_DEV_HAS_GIGABIT |
  211. FSL_GIANFAR_DEV_HAS_COALESCE |
  212. FSL_GIANFAR_DEV_HAS_RMON |
  213. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  214. if (model && !strcasecmp(model, "eTSEC"))
  215. priv->device_flags =
  216. FSL_GIANFAR_DEV_HAS_GIGABIT |
  217. FSL_GIANFAR_DEV_HAS_COALESCE |
  218. FSL_GIANFAR_DEV_HAS_RMON |
  219. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  220. FSL_GIANFAR_DEV_HAS_PADDING |
  221. FSL_GIANFAR_DEV_HAS_CSUM |
  222. FSL_GIANFAR_DEV_HAS_VLAN |
  223. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
  224. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  225. ctype = of_get_property(np, "phy-connection-type", NULL);
  226. /* We only care about rgmii-id. The rest are autodetected */
  227. if (ctype && !strcmp(ctype, "rgmii-id"))
  228. priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
  229. else
  230. priv->interface = PHY_INTERFACE_MODE_MII;
  231. if (of_get_property(np, "fsl,magic-packet", NULL))
  232. priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
  233. priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
  234. if (!priv->phy_node) {
  235. u32 *fixed_link;
  236. fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
  237. if (!fixed_link) {
  238. err = -ENODEV;
  239. goto err_out;
  240. }
  241. }
  242. /* Find the TBI PHY. If it's not there, we don't support SGMII */
  243. priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
  244. return 0;
  245. err_out:
  246. iounmap(priv->regs);
  247. return err;
  248. }
  249. /* Ioctl MII Interface */
  250. static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  251. {
  252. struct gfar_private *priv = netdev_priv(dev);
  253. if (!netif_running(dev))
  254. return -EINVAL;
  255. if (!priv->phydev)
  256. return -ENODEV;
  257. return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
  258. }
  259. /* Set up the ethernet device structure, private data,
  260. * and anything else we need before we start */
  261. static int gfar_probe(struct of_device *ofdev,
  262. const struct of_device_id *match)
  263. {
  264. u32 tempval;
  265. struct net_device *dev = NULL;
  266. struct gfar_private *priv = NULL;
  267. DECLARE_MAC_BUF(mac);
  268. int err = 0;
  269. int len_devname;
  270. /* Create an ethernet device instance */
  271. dev = alloc_etherdev(sizeof (*priv));
  272. if (NULL == dev)
  273. return -ENOMEM;
  274. priv = netdev_priv(dev);
  275. priv->ndev = dev;
  276. priv->ofdev = ofdev;
  277. priv->node = ofdev->node;
  278. SET_NETDEV_DEV(dev, &ofdev->dev);
  279. err = gfar_of_init(dev);
  280. if (err)
  281. goto regs_fail;
  282. spin_lock_init(&priv->txlock);
  283. spin_lock_init(&priv->rxlock);
  284. spin_lock_init(&priv->bflock);
  285. INIT_WORK(&priv->reset_task, gfar_reset_task);
  286. dev_set_drvdata(&ofdev->dev, priv);
  287. /* Stop the DMA engine now, in case it was running before */
  288. /* (The firmware could have used it, and left it running). */
  289. gfar_halt(dev);
  290. /* Reset MAC layer */
  291. gfar_write(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
  292. /* We need to delay at least 3 TX clocks */
  293. udelay(2);
  294. tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
  295. gfar_write(&priv->regs->maccfg1, tempval);
  296. /* Initialize MACCFG2. */
  297. gfar_write(&priv->regs->maccfg2, MACCFG2_INIT_SETTINGS);
  298. /* Initialize ECNTRL */
  299. gfar_write(&priv->regs->ecntrl, ECNTRL_INIT_SETTINGS);
  300. /* Set the dev->base_addr to the gfar reg region */
  301. dev->base_addr = (unsigned long) (priv->regs);
  302. SET_NETDEV_DEV(dev, &ofdev->dev);
  303. /* Fill in the dev structure */
  304. dev->watchdog_timeo = TX_TIMEOUT;
  305. netif_napi_add(dev, &priv->napi, gfar_poll, GFAR_DEV_WEIGHT);
  306. dev->mtu = 1500;
  307. dev->netdev_ops = &gfar_netdev_ops;
  308. dev->ethtool_ops = &gfar_ethtool_ops;
  309. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
  310. priv->rx_csum_enable = 1;
  311. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA;
  312. } else
  313. priv->rx_csum_enable = 0;
  314. priv->vlgrp = NULL;
  315. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN)
  316. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  317. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
  318. priv->extended_hash = 1;
  319. priv->hash_width = 9;
  320. priv->hash_regs[0] = &priv->regs->igaddr0;
  321. priv->hash_regs[1] = &priv->regs->igaddr1;
  322. priv->hash_regs[2] = &priv->regs->igaddr2;
  323. priv->hash_regs[3] = &priv->regs->igaddr3;
  324. priv->hash_regs[4] = &priv->regs->igaddr4;
  325. priv->hash_regs[5] = &priv->regs->igaddr5;
  326. priv->hash_regs[6] = &priv->regs->igaddr6;
  327. priv->hash_regs[7] = &priv->regs->igaddr7;
  328. priv->hash_regs[8] = &priv->regs->gaddr0;
  329. priv->hash_regs[9] = &priv->regs->gaddr1;
  330. priv->hash_regs[10] = &priv->regs->gaddr2;
  331. priv->hash_regs[11] = &priv->regs->gaddr3;
  332. priv->hash_regs[12] = &priv->regs->gaddr4;
  333. priv->hash_regs[13] = &priv->regs->gaddr5;
  334. priv->hash_regs[14] = &priv->regs->gaddr6;
  335. priv->hash_regs[15] = &priv->regs->gaddr7;
  336. } else {
  337. priv->extended_hash = 0;
  338. priv->hash_width = 8;
  339. priv->hash_regs[0] = &priv->regs->gaddr0;
  340. priv->hash_regs[1] = &priv->regs->gaddr1;
  341. priv->hash_regs[2] = &priv->regs->gaddr2;
  342. priv->hash_regs[3] = &priv->regs->gaddr3;
  343. priv->hash_regs[4] = &priv->regs->gaddr4;
  344. priv->hash_regs[5] = &priv->regs->gaddr5;
  345. priv->hash_regs[6] = &priv->regs->gaddr6;
  346. priv->hash_regs[7] = &priv->regs->gaddr7;
  347. }
  348. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
  349. priv->padding = DEFAULT_PADDING;
  350. else
  351. priv->padding = 0;
  352. if (dev->features & NETIF_F_IP_CSUM)
  353. dev->hard_header_len += GMAC_FCB_LEN;
  354. priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
  355. priv->tx_ring_size = DEFAULT_TX_RING_SIZE;
  356. priv->rx_ring_size = DEFAULT_RX_RING_SIZE;
  357. priv->num_txbdfree = DEFAULT_TX_RING_SIZE;
  358. priv->txcoalescing = DEFAULT_TX_COALESCE;
  359. priv->txic = DEFAULT_TXIC;
  360. priv->rxcoalescing = DEFAULT_RX_COALESCE;
  361. priv->rxic = DEFAULT_RXIC;
  362. /* Enable most messages by default */
  363. priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
  364. /* Carrier starts down, phylib will bring it up */
  365. netif_carrier_off(dev);
  366. err = register_netdev(dev);
  367. if (err) {
  368. printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
  369. dev->name);
  370. goto register_fail;
  371. }
  372. device_init_wakeup(&dev->dev,
  373. priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  374. /* fill out IRQ number and name fields */
  375. len_devname = strlen(dev->name);
  376. strncpy(&priv->int_name_tx[0], dev->name, len_devname);
  377. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  378. strncpy(&priv->int_name_tx[len_devname],
  379. "_tx", sizeof("_tx") + 1);
  380. strncpy(&priv->int_name_rx[0], dev->name, len_devname);
  381. strncpy(&priv->int_name_rx[len_devname],
  382. "_rx", sizeof("_rx") + 1);
  383. strncpy(&priv->int_name_er[0], dev->name, len_devname);
  384. strncpy(&priv->int_name_er[len_devname],
  385. "_er", sizeof("_er") + 1);
  386. } else
  387. priv->int_name_tx[len_devname] = '\0';
  388. /* Create all the sysfs files */
  389. gfar_init_sysfs(dev);
  390. /* Print out the device info */
  391. printk(KERN_INFO DEVICE_NAME "%pM\n", dev->name, dev->dev_addr);
  392. /* Even more device info helps when determining which kernel */
  393. /* provided which set of benchmarks. */
  394. printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name);
  395. printk(KERN_INFO "%s: %d/%d RX/TX BD ring size\n",
  396. dev->name, priv->rx_ring_size, priv->tx_ring_size);
  397. return 0;
  398. register_fail:
  399. iounmap(priv->regs);
  400. regs_fail:
  401. if (priv->phy_node)
  402. of_node_put(priv->phy_node);
  403. if (priv->tbi_node)
  404. of_node_put(priv->tbi_node);
  405. free_netdev(dev);
  406. return err;
  407. }
  408. static int gfar_remove(struct of_device *ofdev)
  409. {
  410. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  411. if (priv->phy_node)
  412. of_node_put(priv->phy_node);
  413. if (priv->tbi_node)
  414. of_node_put(priv->tbi_node);
  415. dev_set_drvdata(&ofdev->dev, NULL);
  416. iounmap(priv->regs);
  417. free_netdev(priv->ndev);
  418. return 0;
  419. }
  420. #ifdef CONFIG_PM
  421. static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
  422. {
  423. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  424. struct net_device *dev = priv->ndev;
  425. unsigned long flags;
  426. u32 tempval;
  427. int magic_packet = priv->wol_en &&
  428. (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  429. netif_device_detach(dev);
  430. if (netif_running(dev)) {
  431. spin_lock_irqsave(&priv->txlock, flags);
  432. spin_lock(&priv->rxlock);
  433. gfar_halt_nodisable(dev);
  434. /* Disable Tx, and Rx if wake-on-LAN is disabled. */
  435. tempval = gfar_read(&priv->regs->maccfg1);
  436. tempval &= ~MACCFG1_TX_EN;
  437. if (!magic_packet)
  438. tempval &= ~MACCFG1_RX_EN;
  439. gfar_write(&priv->regs->maccfg1, tempval);
  440. spin_unlock(&priv->rxlock);
  441. spin_unlock_irqrestore(&priv->txlock, flags);
  442. napi_disable(&priv->napi);
  443. if (magic_packet) {
  444. /* Enable interrupt on Magic Packet */
  445. gfar_write(&priv->regs->imask, IMASK_MAG);
  446. /* Enable Magic Packet mode */
  447. tempval = gfar_read(&priv->regs->maccfg2);
  448. tempval |= MACCFG2_MPEN;
  449. gfar_write(&priv->regs->maccfg2, tempval);
  450. } else {
  451. phy_stop(priv->phydev);
  452. }
  453. }
  454. return 0;
  455. }
  456. static int gfar_resume(struct of_device *ofdev)
  457. {
  458. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  459. struct net_device *dev = priv->ndev;
  460. unsigned long flags;
  461. u32 tempval;
  462. int magic_packet = priv->wol_en &&
  463. (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  464. if (!netif_running(dev)) {
  465. netif_device_attach(dev);
  466. return 0;
  467. }
  468. if (!magic_packet && priv->phydev)
  469. phy_start(priv->phydev);
  470. /* Disable Magic Packet mode, in case something
  471. * else woke us up.
  472. */
  473. spin_lock_irqsave(&priv->txlock, flags);
  474. spin_lock(&priv->rxlock);
  475. tempval = gfar_read(&priv->regs->maccfg2);
  476. tempval &= ~MACCFG2_MPEN;
  477. gfar_write(&priv->regs->maccfg2, tempval);
  478. gfar_start(dev);
  479. spin_unlock(&priv->rxlock);
  480. spin_unlock_irqrestore(&priv->txlock, flags);
  481. netif_device_attach(dev);
  482. napi_enable(&priv->napi);
  483. return 0;
  484. }
  485. #else
  486. #define gfar_suspend NULL
  487. #define gfar_resume NULL
  488. #endif
  489. /* Reads the controller's registers to determine what interface
  490. * connects it to the PHY.
  491. */
  492. static phy_interface_t gfar_get_interface(struct net_device *dev)
  493. {
  494. struct gfar_private *priv = netdev_priv(dev);
  495. u32 ecntrl = gfar_read(&priv->regs->ecntrl);
  496. if (ecntrl & ECNTRL_SGMII_MODE)
  497. return PHY_INTERFACE_MODE_SGMII;
  498. if (ecntrl & ECNTRL_TBI_MODE) {
  499. if (ecntrl & ECNTRL_REDUCED_MODE)
  500. return PHY_INTERFACE_MODE_RTBI;
  501. else
  502. return PHY_INTERFACE_MODE_TBI;
  503. }
  504. if (ecntrl & ECNTRL_REDUCED_MODE) {
  505. if (ecntrl & ECNTRL_REDUCED_MII_MODE)
  506. return PHY_INTERFACE_MODE_RMII;
  507. else {
  508. phy_interface_t interface = priv->interface;
  509. /*
  510. * This isn't autodetected right now, so it must
  511. * be set by the device tree or platform code.
  512. */
  513. if (interface == PHY_INTERFACE_MODE_RGMII_ID)
  514. return PHY_INTERFACE_MODE_RGMII_ID;
  515. return PHY_INTERFACE_MODE_RGMII;
  516. }
  517. }
  518. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
  519. return PHY_INTERFACE_MODE_GMII;
  520. return PHY_INTERFACE_MODE_MII;
  521. }
  522. /* Initializes driver's PHY state, and attaches to the PHY.
  523. * Returns 0 on success.
  524. */
  525. static int init_phy(struct net_device *dev)
  526. {
  527. struct gfar_private *priv = netdev_priv(dev);
  528. uint gigabit_support =
  529. priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
  530. SUPPORTED_1000baseT_Full : 0;
  531. phy_interface_t interface;
  532. priv->oldlink = 0;
  533. priv->oldspeed = 0;
  534. priv->oldduplex = -1;
  535. interface = gfar_get_interface(dev);
  536. if (priv->phy_node) {
  537. priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link,
  538. 0, interface);
  539. if (!priv->phydev) {
  540. dev_err(&dev->dev, "error: Could not attach to PHY\n");
  541. return -ENODEV;
  542. }
  543. }
  544. if (interface == PHY_INTERFACE_MODE_SGMII)
  545. gfar_configure_serdes(dev);
  546. /* Remove any features not supported by the controller */
  547. priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
  548. priv->phydev->advertising = priv->phydev->supported;
  549. return 0;
  550. }
  551. /*
  552. * Initialize TBI PHY interface for communicating with the
  553. * SERDES lynx PHY on the chip. We communicate with this PHY
  554. * through the MDIO bus on each controller, treating it as a
  555. * "normal" PHY at the address found in the TBIPA register. We assume
  556. * that the TBIPA register is valid. Either the MDIO bus code will set
  557. * it to a value that doesn't conflict with other PHYs on the bus, or the
  558. * value doesn't matter, as there are no other PHYs on the bus.
  559. */
  560. static void gfar_configure_serdes(struct net_device *dev)
  561. {
  562. struct gfar_private *priv = netdev_priv(dev);
  563. struct phy_device *tbiphy;
  564. if (!priv->tbi_node) {
  565. dev_warn(&dev->dev, "error: SGMII mode requires that the "
  566. "device tree specify a tbi-handle\n");
  567. return;
  568. }
  569. tbiphy = of_phy_find_device(priv->tbi_node);
  570. if (!tbiphy) {
  571. dev_err(&dev->dev, "error: Could not get TBI device\n");
  572. return;
  573. }
  574. /*
  575. * If the link is already up, we must already be ok, and don't need to
  576. * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
  577. * everything for us? Resetting it takes the link down and requires
  578. * several seconds for it to come back.
  579. */
  580. if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
  581. return;
  582. /* Single clk mode, mii mode off(for serdes communication) */
  583. phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
  584. phy_write(tbiphy, MII_ADVERTISE,
  585. ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
  586. ADVERTISE_1000XPSE_ASYM);
  587. phy_write(tbiphy, MII_BMCR, BMCR_ANENABLE |
  588. BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
  589. }
  590. static void init_registers(struct net_device *dev)
  591. {
  592. struct gfar_private *priv = netdev_priv(dev);
  593. /* Clear IEVENT */
  594. gfar_write(&priv->regs->ievent, IEVENT_INIT_CLEAR);
  595. /* Initialize IMASK */
  596. gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
  597. /* Init hash registers to zero */
  598. gfar_write(&priv->regs->igaddr0, 0);
  599. gfar_write(&priv->regs->igaddr1, 0);
  600. gfar_write(&priv->regs->igaddr2, 0);
  601. gfar_write(&priv->regs->igaddr3, 0);
  602. gfar_write(&priv->regs->igaddr4, 0);
  603. gfar_write(&priv->regs->igaddr5, 0);
  604. gfar_write(&priv->regs->igaddr6, 0);
  605. gfar_write(&priv->regs->igaddr7, 0);
  606. gfar_write(&priv->regs->gaddr0, 0);
  607. gfar_write(&priv->regs->gaddr1, 0);
  608. gfar_write(&priv->regs->gaddr2, 0);
  609. gfar_write(&priv->regs->gaddr3, 0);
  610. gfar_write(&priv->regs->gaddr4, 0);
  611. gfar_write(&priv->regs->gaddr5, 0);
  612. gfar_write(&priv->regs->gaddr6, 0);
  613. gfar_write(&priv->regs->gaddr7, 0);
  614. /* Zero out the rmon mib registers if it has them */
  615. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  616. memset_io(&(priv->regs->rmon), 0, sizeof (struct rmon_mib));
  617. /* Mask off the CAM interrupts */
  618. gfar_write(&priv->regs->rmon.cam1, 0xffffffff);
  619. gfar_write(&priv->regs->rmon.cam2, 0xffffffff);
  620. }
  621. /* Initialize the max receive buffer length */
  622. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  623. /* Initialize the Minimum Frame Length Register */
  624. gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
  625. }
  626. /* Halt the receive and transmit queues */
  627. static void gfar_halt_nodisable(struct net_device *dev)
  628. {
  629. struct gfar_private *priv = netdev_priv(dev);
  630. struct gfar __iomem *regs = priv->regs;
  631. u32 tempval;
  632. /* Mask all interrupts */
  633. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  634. /* Clear all interrupts */
  635. gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
  636. /* Stop the DMA, and wait for it to stop */
  637. tempval = gfar_read(&priv->regs->dmactrl);
  638. if ((tempval & (DMACTRL_GRS | DMACTRL_GTS))
  639. != (DMACTRL_GRS | DMACTRL_GTS)) {
  640. tempval |= (DMACTRL_GRS | DMACTRL_GTS);
  641. gfar_write(&priv->regs->dmactrl, tempval);
  642. while (!(gfar_read(&priv->regs->ievent) &
  643. (IEVENT_GRSC | IEVENT_GTSC)))
  644. cpu_relax();
  645. }
  646. }
  647. /* Halt the receive and transmit queues */
  648. void gfar_halt(struct net_device *dev)
  649. {
  650. struct gfar_private *priv = netdev_priv(dev);
  651. struct gfar __iomem *regs = priv->regs;
  652. u32 tempval;
  653. gfar_halt_nodisable(dev);
  654. /* Disable Rx and Tx */
  655. tempval = gfar_read(&regs->maccfg1);
  656. tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
  657. gfar_write(&regs->maccfg1, tempval);
  658. }
  659. void stop_gfar(struct net_device *dev)
  660. {
  661. struct gfar_private *priv = netdev_priv(dev);
  662. struct gfar __iomem *regs = priv->regs;
  663. unsigned long flags;
  664. phy_stop(priv->phydev);
  665. /* Lock it down */
  666. spin_lock_irqsave(&priv->txlock, flags);
  667. spin_lock(&priv->rxlock);
  668. gfar_halt(dev);
  669. spin_unlock(&priv->rxlock);
  670. spin_unlock_irqrestore(&priv->txlock, flags);
  671. /* Free the IRQs */
  672. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  673. free_irq(priv->interruptError, dev);
  674. free_irq(priv->interruptTransmit, dev);
  675. free_irq(priv->interruptReceive, dev);
  676. } else {
  677. free_irq(priv->interruptTransmit, dev);
  678. }
  679. free_skb_resources(priv);
  680. dma_free_coherent(&priv->ofdev->dev,
  681. sizeof(struct txbd8)*priv->tx_ring_size
  682. + sizeof(struct rxbd8)*priv->rx_ring_size,
  683. priv->tx_bd_base,
  684. gfar_read(&regs->tbase0));
  685. }
  686. /* If there are any tx skbs or rx skbs still around, free them.
  687. * Then free tx_skbuff and rx_skbuff */
  688. static void free_skb_resources(struct gfar_private *priv)
  689. {
  690. struct rxbd8 *rxbdp;
  691. struct txbd8 *txbdp;
  692. int i, j;
  693. /* Go through all the buffer descriptors and free their data buffers */
  694. txbdp = priv->tx_bd_base;
  695. for (i = 0; i < priv->tx_ring_size; i++) {
  696. if (!priv->tx_skbuff[i])
  697. continue;
  698. dma_unmap_single(&priv->ofdev->dev, txbdp->bufPtr,
  699. txbdp->length, DMA_TO_DEVICE);
  700. txbdp->lstatus = 0;
  701. for (j = 0; j < skb_shinfo(priv->tx_skbuff[i])->nr_frags; j++) {
  702. txbdp++;
  703. dma_unmap_page(&priv->ofdev->dev, txbdp->bufPtr,
  704. txbdp->length, DMA_TO_DEVICE);
  705. }
  706. txbdp++;
  707. dev_kfree_skb_any(priv->tx_skbuff[i]);
  708. priv->tx_skbuff[i] = NULL;
  709. }
  710. kfree(priv->tx_skbuff);
  711. rxbdp = priv->rx_bd_base;
  712. /* rx_skbuff is not guaranteed to be allocated, so only
  713. * free it and its contents if it is allocated */
  714. if(priv->rx_skbuff != NULL) {
  715. for (i = 0; i < priv->rx_ring_size; i++) {
  716. if (priv->rx_skbuff[i]) {
  717. dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
  718. priv->rx_buffer_size,
  719. DMA_FROM_DEVICE);
  720. dev_kfree_skb_any(priv->rx_skbuff[i]);
  721. priv->rx_skbuff[i] = NULL;
  722. }
  723. rxbdp->lstatus = 0;
  724. rxbdp->bufPtr = 0;
  725. rxbdp++;
  726. }
  727. kfree(priv->rx_skbuff);
  728. }
  729. }
  730. void gfar_start(struct net_device *dev)
  731. {
  732. struct gfar_private *priv = netdev_priv(dev);
  733. struct gfar __iomem *regs = priv->regs;
  734. u32 tempval;
  735. /* Enable Rx and Tx in MACCFG1 */
  736. tempval = gfar_read(&regs->maccfg1);
  737. tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  738. gfar_write(&regs->maccfg1, tempval);
  739. /* Initialize DMACTRL to have WWR and WOP */
  740. tempval = gfar_read(&priv->regs->dmactrl);
  741. tempval |= DMACTRL_INIT_SETTINGS;
  742. gfar_write(&priv->regs->dmactrl, tempval);
  743. /* Make sure we aren't stopped */
  744. tempval = gfar_read(&priv->regs->dmactrl);
  745. tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
  746. gfar_write(&priv->regs->dmactrl, tempval);
  747. /* Clear THLT/RHLT, so that the DMA starts polling now */
  748. gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
  749. gfar_write(&regs->rstat, RSTAT_CLEAR_RHALT);
  750. /* Unmask the interrupts we look for */
  751. gfar_write(&regs->imask, IMASK_DEFAULT);
  752. dev->trans_start = jiffies;
  753. }
  754. /* Bring the controller up and running */
  755. int startup_gfar(struct net_device *dev)
  756. {
  757. struct txbd8 *txbdp;
  758. struct rxbd8 *rxbdp;
  759. dma_addr_t addr = 0;
  760. unsigned long vaddr;
  761. int i;
  762. struct gfar_private *priv = netdev_priv(dev);
  763. struct gfar __iomem *regs = priv->regs;
  764. int err = 0;
  765. u32 rctrl = 0;
  766. u32 attrs = 0;
  767. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  768. /* Allocate memory for the buffer descriptors */
  769. vaddr = (unsigned long) dma_alloc_coherent(&priv->ofdev->dev,
  770. sizeof (struct txbd8) * priv->tx_ring_size +
  771. sizeof (struct rxbd8) * priv->rx_ring_size,
  772. &addr, GFP_KERNEL);
  773. if (vaddr == 0) {
  774. if (netif_msg_ifup(priv))
  775. printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
  776. dev->name);
  777. return -ENOMEM;
  778. }
  779. priv->tx_bd_base = (struct txbd8 *) vaddr;
  780. /* enet DMA only understands physical addresses */
  781. gfar_write(&regs->tbase0, addr);
  782. /* Start the rx descriptor ring where the tx ring leaves off */
  783. addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
  784. vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
  785. priv->rx_bd_base = (struct rxbd8 *) vaddr;
  786. gfar_write(&regs->rbase0, addr);
  787. /* Setup the skbuff rings */
  788. priv->tx_skbuff =
  789. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  790. priv->tx_ring_size, GFP_KERNEL);
  791. if (NULL == priv->tx_skbuff) {
  792. if (netif_msg_ifup(priv))
  793. printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
  794. dev->name);
  795. err = -ENOMEM;
  796. goto tx_skb_fail;
  797. }
  798. for (i = 0; i < priv->tx_ring_size; i++)
  799. priv->tx_skbuff[i] = NULL;
  800. priv->rx_skbuff =
  801. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  802. priv->rx_ring_size, GFP_KERNEL);
  803. if (NULL == priv->rx_skbuff) {
  804. if (netif_msg_ifup(priv))
  805. printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
  806. dev->name);
  807. err = -ENOMEM;
  808. goto rx_skb_fail;
  809. }
  810. for (i = 0; i < priv->rx_ring_size; i++)
  811. priv->rx_skbuff[i] = NULL;
  812. /* Initialize some variables in our dev structure */
  813. priv->num_txbdfree = priv->tx_ring_size;
  814. priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
  815. priv->cur_rx = priv->rx_bd_base;
  816. priv->skb_curtx = priv->skb_dirtytx = 0;
  817. priv->skb_currx = 0;
  818. /* Initialize Transmit Descriptor Ring */
  819. txbdp = priv->tx_bd_base;
  820. for (i = 0; i < priv->tx_ring_size; i++) {
  821. txbdp->lstatus = 0;
  822. txbdp->bufPtr = 0;
  823. txbdp++;
  824. }
  825. /* Set the last descriptor in the ring to indicate wrap */
  826. txbdp--;
  827. txbdp->status |= TXBD_WRAP;
  828. rxbdp = priv->rx_bd_base;
  829. for (i = 0; i < priv->rx_ring_size; i++) {
  830. struct sk_buff *skb;
  831. skb = gfar_new_skb(dev);
  832. if (!skb) {
  833. printk(KERN_ERR "%s: Can't allocate RX buffers\n",
  834. dev->name);
  835. goto err_rxalloc_fail;
  836. }
  837. priv->rx_skbuff[i] = skb;
  838. gfar_new_rxbdp(dev, rxbdp, skb);
  839. rxbdp++;
  840. }
  841. /* Set the last descriptor in the ring to wrap */
  842. rxbdp--;
  843. rxbdp->status |= RXBD_WRAP;
  844. /* If the device has multiple interrupts, register for
  845. * them. Otherwise, only register for the one */
  846. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  847. /* Install our interrupt handlers for Error,
  848. * Transmit, and Receive */
  849. if (request_irq(priv->interruptError, gfar_error,
  850. 0, priv->int_name_er, dev) < 0) {
  851. if (netif_msg_intr(priv))
  852. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  853. dev->name, priv->interruptError);
  854. err = -1;
  855. goto err_irq_fail;
  856. }
  857. if (request_irq(priv->interruptTransmit, gfar_transmit,
  858. 0, priv->int_name_tx, dev) < 0) {
  859. if (netif_msg_intr(priv))
  860. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  861. dev->name, priv->interruptTransmit);
  862. err = -1;
  863. goto tx_irq_fail;
  864. }
  865. if (request_irq(priv->interruptReceive, gfar_receive,
  866. 0, priv->int_name_rx, dev) < 0) {
  867. if (netif_msg_intr(priv))
  868. printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
  869. dev->name, priv->interruptReceive);
  870. err = -1;
  871. goto rx_irq_fail;
  872. }
  873. } else {
  874. if (request_irq(priv->interruptTransmit, gfar_interrupt,
  875. 0, priv->int_name_tx, dev) < 0) {
  876. if (netif_msg_intr(priv))
  877. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  878. dev->name, priv->interruptTransmit);
  879. err = -1;
  880. goto err_irq_fail;
  881. }
  882. }
  883. phy_start(priv->phydev);
  884. /* Configure the coalescing support */
  885. gfar_write(&regs->txic, 0);
  886. if (priv->txcoalescing)
  887. gfar_write(&regs->txic, priv->txic);
  888. gfar_write(&regs->rxic, 0);
  889. if (priv->rxcoalescing)
  890. gfar_write(&regs->rxic, priv->rxic);
  891. if (priv->rx_csum_enable)
  892. rctrl |= RCTRL_CHECKSUMMING;
  893. if (priv->extended_hash) {
  894. rctrl |= RCTRL_EXTHASH;
  895. gfar_clear_exact_match(dev);
  896. rctrl |= RCTRL_EMEN;
  897. }
  898. if (priv->padding) {
  899. rctrl &= ~RCTRL_PAL_MASK;
  900. rctrl |= RCTRL_PADDING(priv->padding);
  901. }
  902. /* Init rctrl based on our settings */
  903. gfar_write(&priv->regs->rctrl, rctrl);
  904. if (dev->features & NETIF_F_IP_CSUM)
  905. gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
  906. /* Set the extraction length and index */
  907. attrs = ATTRELI_EL(priv->rx_stash_size) |
  908. ATTRELI_EI(priv->rx_stash_index);
  909. gfar_write(&priv->regs->attreli, attrs);
  910. /* Start with defaults, and add stashing or locking
  911. * depending on the approprate variables */
  912. attrs = ATTR_INIT_SETTINGS;
  913. if (priv->bd_stash_en)
  914. attrs |= ATTR_BDSTASH;
  915. if (priv->rx_stash_size != 0)
  916. attrs |= ATTR_BUFSTASH;
  917. gfar_write(&priv->regs->attr, attrs);
  918. gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold);
  919. gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve);
  920. gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
  921. /* Start the controller */
  922. gfar_start(dev);
  923. return 0;
  924. rx_irq_fail:
  925. free_irq(priv->interruptTransmit, dev);
  926. tx_irq_fail:
  927. free_irq(priv->interruptError, dev);
  928. err_irq_fail:
  929. err_rxalloc_fail:
  930. rx_skb_fail:
  931. free_skb_resources(priv);
  932. tx_skb_fail:
  933. dma_free_coherent(&priv->ofdev->dev,
  934. sizeof(struct txbd8)*priv->tx_ring_size
  935. + sizeof(struct rxbd8)*priv->rx_ring_size,
  936. priv->tx_bd_base,
  937. gfar_read(&regs->tbase0));
  938. return err;
  939. }
  940. /* Called when something needs to use the ethernet device */
  941. /* Returns 0 for success. */
  942. static int gfar_enet_open(struct net_device *dev)
  943. {
  944. struct gfar_private *priv = netdev_priv(dev);
  945. int err;
  946. napi_enable(&priv->napi);
  947. skb_queue_head_init(&priv->rx_recycle);
  948. /* Initialize a bunch of registers */
  949. init_registers(dev);
  950. gfar_set_mac_address(dev);
  951. err = init_phy(dev);
  952. if(err) {
  953. napi_disable(&priv->napi);
  954. return err;
  955. }
  956. err = startup_gfar(dev);
  957. if (err) {
  958. napi_disable(&priv->napi);
  959. return err;
  960. }
  961. netif_start_queue(dev);
  962. device_set_wakeup_enable(&dev->dev, priv->wol_en);
  963. return err;
  964. }
  965. static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
  966. {
  967. struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
  968. memset(fcb, 0, GMAC_FCB_LEN);
  969. return fcb;
  970. }
  971. static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
  972. {
  973. u8 flags = 0;
  974. /* If we're here, it's a IP packet with a TCP or UDP
  975. * payload. We set it to checksum, using a pseudo-header
  976. * we provide
  977. */
  978. flags = TXFCB_DEFAULT;
  979. /* Tell the controller what the protocol is */
  980. /* And provide the already calculated phcs */
  981. if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
  982. flags |= TXFCB_UDP;
  983. fcb->phcs = udp_hdr(skb)->check;
  984. } else
  985. fcb->phcs = tcp_hdr(skb)->check;
  986. /* l3os is the distance between the start of the
  987. * frame (skb->data) and the start of the IP hdr.
  988. * l4os is the distance between the start of the
  989. * l3 hdr and the l4 hdr */
  990. fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN);
  991. fcb->l4os = skb_network_header_len(skb);
  992. fcb->flags = flags;
  993. }
  994. void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
  995. {
  996. fcb->flags |= TXFCB_VLN;
  997. fcb->vlctl = vlan_tx_tag_get(skb);
  998. }
  999. static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
  1000. struct txbd8 *base, int ring_size)
  1001. {
  1002. struct txbd8 *new_bd = bdp + stride;
  1003. return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
  1004. }
  1005. static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
  1006. int ring_size)
  1007. {
  1008. return skip_txbd(bdp, 1, base, ring_size);
  1009. }
  1010. /* This is called by the kernel when a frame is ready for transmission. */
  1011. /* It is pointed to by the dev->hard_start_xmit function pointer */
  1012. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1013. {
  1014. struct gfar_private *priv = netdev_priv(dev);
  1015. struct txfcb *fcb = NULL;
  1016. struct txbd8 *txbdp, *txbdp_start, *base;
  1017. u32 lstatus;
  1018. int i;
  1019. u32 bufaddr;
  1020. unsigned long flags;
  1021. unsigned int nr_frags, length;
  1022. base = priv->tx_bd_base;
  1023. /* make space for additional header when fcb is needed */
  1024. if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
  1025. (priv->vlgrp && vlan_tx_tag_present(skb))) &&
  1026. (skb_headroom(skb) < GMAC_FCB_LEN)) {
  1027. struct sk_buff *skb_new;
  1028. skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
  1029. if (!skb_new) {
  1030. dev->stats.tx_errors++;
  1031. kfree_skb(skb);
  1032. return NETDEV_TX_OK;
  1033. }
  1034. kfree_skb(skb);
  1035. skb = skb_new;
  1036. }
  1037. /* total number of fragments in the SKB */
  1038. nr_frags = skb_shinfo(skb)->nr_frags;
  1039. spin_lock_irqsave(&priv->txlock, flags);
  1040. /* check if there is space to queue this packet */
  1041. if ((nr_frags+1) > priv->num_txbdfree) {
  1042. /* no space, stop the queue */
  1043. netif_stop_queue(dev);
  1044. dev->stats.tx_fifo_errors++;
  1045. spin_unlock_irqrestore(&priv->txlock, flags);
  1046. return NETDEV_TX_BUSY;
  1047. }
  1048. /* Update transmit stats */
  1049. dev->stats.tx_bytes += skb->len;
  1050. txbdp = txbdp_start = priv->cur_tx;
  1051. if (nr_frags == 0) {
  1052. lstatus = txbdp->lstatus | BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1053. } else {
  1054. /* Place the fragment addresses and lengths into the TxBDs */
  1055. for (i = 0; i < nr_frags; i++) {
  1056. /* Point at the next BD, wrapping as needed */
  1057. txbdp = next_txbd(txbdp, base, priv->tx_ring_size);
  1058. length = skb_shinfo(skb)->frags[i].size;
  1059. lstatus = txbdp->lstatus | length |
  1060. BD_LFLAG(TXBD_READY);
  1061. /* Handle the last BD specially */
  1062. if (i == nr_frags - 1)
  1063. lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1064. bufaddr = dma_map_page(&priv->ofdev->dev,
  1065. skb_shinfo(skb)->frags[i].page,
  1066. skb_shinfo(skb)->frags[i].page_offset,
  1067. length,
  1068. DMA_TO_DEVICE);
  1069. /* set the TxBD length and buffer pointer */
  1070. txbdp->bufPtr = bufaddr;
  1071. txbdp->lstatus = lstatus;
  1072. }
  1073. lstatus = txbdp_start->lstatus;
  1074. }
  1075. /* Set up checksumming */
  1076. if (CHECKSUM_PARTIAL == skb->ip_summed) {
  1077. fcb = gfar_add_fcb(skb);
  1078. lstatus |= BD_LFLAG(TXBD_TOE);
  1079. gfar_tx_checksum(skb, fcb);
  1080. }
  1081. if (priv->vlgrp && vlan_tx_tag_present(skb)) {
  1082. if (unlikely(NULL == fcb)) {
  1083. fcb = gfar_add_fcb(skb);
  1084. lstatus |= BD_LFLAG(TXBD_TOE);
  1085. }
  1086. gfar_tx_vlan(skb, fcb);
  1087. }
  1088. /* setup the TxBD length and buffer pointer for the first BD */
  1089. priv->tx_skbuff[priv->skb_curtx] = skb;
  1090. txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1091. skb_headlen(skb), DMA_TO_DEVICE);
  1092. lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
  1093. /*
  1094. * The powerpc-specific eieio() is used, as wmb() has too strong
  1095. * semantics (it requires synchronization between cacheable and
  1096. * uncacheable mappings, which eieio doesn't provide and which we
  1097. * don't need), thus requiring a more expensive sync instruction. At
  1098. * some point, the set of architecture-independent barrier functions
  1099. * should be expanded to include weaker barriers.
  1100. */
  1101. eieio();
  1102. txbdp_start->lstatus = lstatus;
  1103. /* Update the current skb pointer to the next entry we will use
  1104. * (wrapping if necessary) */
  1105. priv->skb_curtx = (priv->skb_curtx + 1) &
  1106. TX_RING_MOD_MASK(priv->tx_ring_size);
  1107. priv->cur_tx = next_txbd(txbdp, base, priv->tx_ring_size);
  1108. /* reduce TxBD free count */
  1109. priv->num_txbdfree -= (nr_frags + 1);
  1110. dev->trans_start = jiffies;
  1111. /* If the next BD still needs to be cleaned up, then the bds
  1112. are full. We need to tell the kernel to stop sending us stuff. */
  1113. if (!priv->num_txbdfree) {
  1114. netif_stop_queue(dev);
  1115. dev->stats.tx_fifo_errors++;
  1116. }
  1117. /* Tell the DMA to go go go */
  1118. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1119. /* Unlock priv */
  1120. spin_unlock_irqrestore(&priv->txlock, flags);
  1121. return NETDEV_TX_OK;
  1122. }
  1123. /* Stops the kernel queue, and halts the controller */
  1124. static int gfar_close(struct net_device *dev)
  1125. {
  1126. struct gfar_private *priv = netdev_priv(dev);
  1127. napi_disable(&priv->napi);
  1128. skb_queue_purge(&priv->rx_recycle);
  1129. cancel_work_sync(&priv->reset_task);
  1130. stop_gfar(dev);
  1131. /* Disconnect from the PHY */
  1132. phy_disconnect(priv->phydev);
  1133. priv->phydev = NULL;
  1134. netif_stop_queue(dev);
  1135. return 0;
  1136. }
  1137. /* Changes the mac address if the controller is not running. */
  1138. static int gfar_set_mac_address(struct net_device *dev)
  1139. {
  1140. gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
  1141. return 0;
  1142. }
  1143. /* Enables and disables VLAN insertion/extraction */
  1144. static void gfar_vlan_rx_register(struct net_device *dev,
  1145. struct vlan_group *grp)
  1146. {
  1147. struct gfar_private *priv = netdev_priv(dev);
  1148. unsigned long flags;
  1149. u32 tempval;
  1150. spin_lock_irqsave(&priv->rxlock, flags);
  1151. priv->vlgrp = grp;
  1152. if (grp) {
  1153. /* Enable VLAN tag insertion */
  1154. tempval = gfar_read(&priv->regs->tctrl);
  1155. tempval |= TCTRL_VLINS;
  1156. gfar_write(&priv->regs->tctrl, tempval);
  1157. /* Enable VLAN tag extraction */
  1158. tempval = gfar_read(&priv->regs->rctrl);
  1159. tempval |= RCTRL_VLEX;
  1160. tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT);
  1161. gfar_write(&priv->regs->rctrl, tempval);
  1162. } else {
  1163. /* Disable VLAN tag insertion */
  1164. tempval = gfar_read(&priv->regs->tctrl);
  1165. tempval &= ~TCTRL_VLINS;
  1166. gfar_write(&priv->regs->tctrl, tempval);
  1167. /* Disable VLAN tag extraction */
  1168. tempval = gfar_read(&priv->regs->rctrl);
  1169. tempval &= ~RCTRL_VLEX;
  1170. /* If parse is no longer required, then disable parser */
  1171. if (tempval & RCTRL_REQ_PARSER)
  1172. tempval |= RCTRL_PRSDEP_INIT;
  1173. else
  1174. tempval &= ~RCTRL_PRSDEP_INIT;
  1175. gfar_write(&priv->regs->rctrl, tempval);
  1176. }
  1177. gfar_change_mtu(dev, dev->mtu);
  1178. spin_unlock_irqrestore(&priv->rxlock, flags);
  1179. }
  1180. static int gfar_change_mtu(struct net_device *dev, int new_mtu)
  1181. {
  1182. int tempsize, tempval;
  1183. struct gfar_private *priv = netdev_priv(dev);
  1184. int oldsize = priv->rx_buffer_size;
  1185. int frame_size = new_mtu + ETH_HLEN;
  1186. if (priv->vlgrp)
  1187. frame_size += VLAN_HLEN;
  1188. if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
  1189. if (netif_msg_drv(priv))
  1190. printk(KERN_ERR "%s: Invalid MTU setting\n",
  1191. dev->name);
  1192. return -EINVAL;
  1193. }
  1194. if (gfar_uses_fcb(priv))
  1195. frame_size += GMAC_FCB_LEN;
  1196. frame_size += priv->padding;
  1197. tempsize =
  1198. (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
  1199. INCREMENTAL_BUFFER_SIZE;
  1200. /* Only stop and start the controller if it isn't already
  1201. * stopped, and we changed something */
  1202. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1203. stop_gfar(dev);
  1204. priv->rx_buffer_size = tempsize;
  1205. dev->mtu = new_mtu;
  1206. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  1207. gfar_write(&priv->regs->maxfrm, priv->rx_buffer_size);
  1208. /* If the mtu is larger than the max size for standard
  1209. * ethernet frames (ie, a jumbo frame), then set maccfg2
  1210. * to allow huge frames, and to check the length */
  1211. tempval = gfar_read(&priv->regs->maccfg2);
  1212. if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE)
  1213. tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1214. else
  1215. tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1216. gfar_write(&priv->regs->maccfg2, tempval);
  1217. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1218. startup_gfar(dev);
  1219. return 0;
  1220. }
  1221. /* gfar_reset_task gets scheduled when a packet has not been
  1222. * transmitted after a set amount of time.
  1223. * For now, assume that clearing out all the structures, and
  1224. * starting over will fix the problem.
  1225. */
  1226. static void gfar_reset_task(struct work_struct *work)
  1227. {
  1228. struct gfar_private *priv = container_of(work, struct gfar_private,
  1229. reset_task);
  1230. struct net_device *dev = priv->ndev;
  1231. if (dev->flags & IFF_UP) {
  1232. netif_stop_queue(dev);
  1233. stop_gfar(dev);
  1234. startup_gfar(dev);
  1235. netif_start_queue(dev);
  1236. }
  1237. netif_tx_schedule_all(dev);
  1238. }
  1239. static void gfar_timeout(struct net_device *dev)
  1240. {
  1241. struct gfar_private *priv = netdev_priv(dev);
  1242. dev->stats.tx_errors++;
  1243. schedule_work(&priv->reset_task);
  1244. }
  1245. /* Interrupt Handler for Transmit complete */
  1246. static int gfar_clean_tx_ring(struct net_device *dev)
  1247. {
  1248. struct gfar_private *priv = netdev_priv(dev);
  1249. struct txbd8 *bdp;
  1250. struct txbd8 *lbdp = NULL;
  1251. struct txbd8 *base = priv->tx_bd_base;
  1252. struct sk_buff *skb;
  1253. int skb_dirtytx;
  1254. int tx_ring_size = priv->tx_ring_size;
  1255. int frags = 0;
  1256. int i;
  1257. int howmany = 0;
  1258. u32 lstatus;
  1259. bdp = priv->dirty_tx;
  1260. skb_dirtytx = priv->skb_dirtytx;
  1261. while ((skb = priv->tx_skbuff[skb_dirtytx])) {
  1262. frags = skb_shinfo(skb)->nr_frags;
  1263. lbdp = skip_txbd(bdp, frags, base, tx_ring_size);
  1264. lstatus = lbdp->lstatus;
  1265. /* Only clean completed frames */
  1266. if ((lstatus & BD_LFLAG(TXBD_READY)) &&
  1267. (lstatus & BD_LENGTH_MASK))
  1268. break;
  1269. dma_unmap_single(&priv->ofdev->dev,
  1270. bdp->bufPtr,
  1271. bdp->length,
  1272. DMA_TO_DEVICE);
  1273. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1274. bdp = next_txbd(bdp, base, tx_ring_size);
  1275. for (i = 0; i < frags; i++) {
  1276. dma_unmap_page(&priv->ofdev->dev,
  1277. bdp->bufPtr,
  1278. bdp->length,
  1279. DMA_TO_DEVICE);
  1280. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1281. bdp = next_txbd(bdp, base, tx_ring_size);
  1282. }
  1283. /*
  1284. * If there's room in the queue (limit it to rx_buffer_size)
  1285. * we add this skb back into the pool, if it's the right size
  1286. */
  1287. if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
  1288. skb_recycle_check(skb, priv->rx_buffer_size +
  1289. RXBUF_ALIGNMENT))
  1290. __skb_queue_head(&priv->rx_recycle, skb);
  1291. else
  1292. dev_kfree_skb_any(skb);
  1293. priv->tx_skbuff[skb_dirtytx] = NULL;
  1294. skb_dirtytx = (skb_dirtytx + 1) &
  1295. TX_RING_MOD_MASK(tx_ring_size);
  1296. howmany++;
  1297. priv->num_txbdfree += frags + 1;
  1298. }
  1299. /* If we freed a buffer, we can restart transmission, if necessary */
  1300. if (netif_queue_stopped(dev) && priv->num_txbdfree)
  1301. netif_wake_queue(dev);
  1302. /* Update dirty indicators */
  1303. priv->skb_dirtytx = skb_dirtytx;
  1304. priv->dirty_tx = bdp;
  1305. dev->stats.tx_packets += howmany;
  1306. return howmany;
  1307. }
  1308. static void gfar_schedule_cleanup(struct net_device *dev)
  1309. {
  1310. struct gfar_private *priv = netdev_priv(dev);
  1311. unsigned long flags;
  1312. spin_lock_irqsave(&priv->txlock, flags);
  1313. spin_lock(&priv->rxlock);
  1314. if (napi_schedule_prep(&priv->napi)) {
  1315. gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
  1316. __napi_schedule(&priv->napi);
  1317. } else {
  1318. /*
  1319. * Clear IEVENT, so interrupts aren't called again
  1320. * because of the packets that have already arrived.
  1321. */
  1322. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1323. }
  1324. spin_unlock(&priv->rxlock);
  1325. spin_unlock_irqrestore(&priv->txlock, flags);
  1326. }
  1327. /* Interrupt Handler for Transmit complete */
  1328. static irqreturn_t gfar_transmit(int irq, void *dev_id)
  1329. {
  1330. gfar_schedule_cleanup((struct net_device *)dev_id);
  1331. return IRQ_HANDLED;
  1332. }
  1333. static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
  1334. struct sk_buff *skb)
  1335. {
  1336. struct gfar_private *priv = netdev_priv(dev);
  1337. u32 lstatus;
  1338. bdp->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1339. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1340. lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
  1341. if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
  1342. lstatus |= BD_LFLAG(RXBD_WRAP);
  1343. eieio();
  1344. bdp->lstatus = lstatus;
  1345. }
  1346. struct sk_buff * gfar_new_skb(struct net_device *dev)
  1347. {
  1348. unsigned int alignamount;
  1349. struct gfar_private *priv = netdev_priv(dev);
  1350. struct sk_buff *skb = NULL;
  1351. skb = __skb_dequeue(&priv->rx_recycle);
  1352. if (!skb)
  1353. skb = netdev_alloc_skb(dev,
  1354. priv->rx_buffer_size + RXBUF_ALIGNMENT);
  1355. if (!skb)
  1356. return NULL;
  1357. alignamount = RXBUF_ALIGNMENT -
  1358. (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1));
  1359. /* We need the data buffer to be aligned properly. We will reserve
  1360. * as many bytes as needed to align the data properly
  1361. */
  1362. skb_reserve(skb, alignamount);
  1363. return skb;
  1364. }
  1365. static inline void count_errors(unsigned short status, struct net_device *dev)
  1366. {
  1367. struct gfar_private *priv = netdev_priv(dev);
  1368. struct net_device_stats *stats = &dev->stats;
  1369. struct gfar_extra_stats *estats = &priv->extra_stats;
  1370. /* If the packet was truncated, none of the other errors
  1371. * matter */
  1372. if (status & RXBD_TRUNCATED) {
  1373. stats->rx_length_errors++;
  1374. estats->rx_trunc++;
  1375. return;
  1376. }
  1377. /* Count the errors, if there were any */
  1378. if (status & (RXBD_LARGE | RXBD_SHORT)) {
  1379. stats->rx_length_errors++;
  1380. if (status & RXBD_LARGE)
  1381. estats->rx_large++;
  1382. else
  1383. estats->rx_short++;
  1384. }
  1385. if (status & RXBD_NONOCTET) {
  1386. stats->rx_frame_errors++;
  1387. estats->rx_nonoctet++;
  1388. }
  1389. if (status & RXBD_CRCERR) {
  1390. estats->rx_crcerr++;
  1391. stats->rx_crc_errors++;
  1392. }
  1393. if (status & RXBD_OVERRUN) {
  1394. estats->rx_overrun++;
  1395. stats->rx_crc_errors++;
  1396. }
  1397. }
  1398. irqreturn_t gfar_receive(int irq, void *dev_id)
  1399. {
  1400. gfar_schedule_cleanup((struct net_device *)dev_id);
  1401. return IRQ_HANDLED;
  1402. }
  1403. static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
  1404. {
  1405. /* If valid headers were found, and valid sums
  1406. * were verified, then we tell the kernel that no
  1407. * checksumming is necessary. Otherwise, it is */
  1408. if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
  1409. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1410. else
  1411. skb->ip_summed = CHECKSUM_NONE;
  1412. }
  1413. /* gfar_process_frame() -- handle one incoming packet if skb
  1414. * isn't NULL. */
  1415. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  1416. int amount_pull)
  1417. {
  1418. struct gfar_private *priv = netdev_priv(dev);
  1419. struct rxfcb *fcb = NULL;
  1420. int ret;
  1421. /* fcb is at the beginning if exists */
  1422. fcb = (struct rxfcb *)skb->data;
  1423. /* Remove the FCB from the skb */
  1424. /* Remove the padded bytes, if there are any */
  1425. if (amount_pull)
  1426. skb_pull(skb, amount_pull);
  1427. if (priv->rx_csum_enable)
  1428. gfar_rx_checksum(skb, fcb);
  1429. /* Tell the skb what kind of packet this is */
  1430. skb->protocol = eth_type_trans(skb, dev);
  1431. /* Send the packet up the stack */
  1432. if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN)))
  1433. ret = vlan_hwaccel_receive_skb(skb, priv->vlgrp, fcb->vlctl);
  1434. else
  1435. ret = netif_receive_skb(skb);
  1436. if (NET_RX_DROP == ret)
  1437. priv->extra_stats.kernel_dropped++;
  1438. return 0;
  1439. }
  1440. /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
  1441. * until the budget/quota has been reached. Returns the number
  1442. * of frames handled
  1443. */
  1444. int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
  1445. {
  1446. struct rxbd8 *bdp, *base;
  1447. struct sk_buff *skb;
  1448. int pkt_len;
  1449. int amount_pull;
  1450. int howmany = 0;
  1451. struct gfar_private *priv = netdev_priv(dev);
  1452. /* Get the first full descriptor */
  1453. bdp = priv->cur_rx;
  1454. base = priv->rx_bd_base;
  1455. amount_pull = (gfar_uses_fcb(priv) ? GMAC_FCB_LEN : 0) +
  1456. priv->padding;
  1457. while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
  1458. struct sk_buff *newskb;
  1459. rmb();
  1460. /* Add another skb for the future */
  1461. newskb = gfar_new_skb(dev);
  1462. skb = priv->rx_skbuff[priv->skb_currx];
  1463. dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
  1464. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1465. /* We drop the frame if we failed to allocate a new buffer */
  1466. if (unlikely(!newskb || !(bdp->status & RXBD_LAST) ||
  1467. bdp->status & RXBD_ERR)) {
  1468. count_errors(bdp->status, dev);
  1469. if (unlikely(!newskb))
  1470. newskb = skb;
  1471. else if (skb) {
  1472. /*
  1473. * We need to reset ->data to what it
  1474. * was before gfar_new_skb() re-aligned
  1475. * it to an RXBUF_ALIGNMENT boundary
  1476. * before we put the skb back on the
  1477. * recycle list.
  1478. */
  1479. skb->data = skb->head + NET_SKB_PAD;
  1480. __skb_queue_head(&priv->rx_recycle, skb);
  1481. }
  1482. } else {
  1483. /* Increment the number of packets */
  1484. dev->stats.rx_packets++;
  1485. howmany++;
  1486. if (likely(skb)) {
  1487. pkt_len = bdp->length - ETH_FCS_LEN;
  1488. /* Remove the FCS from the packet length */
  1489. skb_put(skb, pkt_len);
  1490. dev->stats.rx_bytes += pkt_len;
  1491. if (in_irq() || irqs_disabled())
  1492. printk("Interrupt problem!\n");
  1493. gfar_process_frame(dev, skb, amount_pull);
  1494. } else {
  1495. if (netif_msg_rx_err(priv))
  1496. printk(KERN_WARNING
  1497. "%s: Missing skb!\n", dev->name);
  1498. dev->stats.rx_dropped++;
  1499. priv->extra_stats.rx_skbmissing++;
  1500. }
  1501. }
  1502. priv->rx_skbuff[priv->skb_currx] = newskb;
  1503. /* Setup the new bdp */
  1504. gfar_new_rxbdp(dev, bdp, newskb);
  1505. /* Update to the next pointer */
  1506. bdp = next_bd(bdp, base, priv->rx_ring_size);
  1507. /* update to point at the next skb */
  1508. priv->skb_currx =
  1509. (priv->skb_currx + 1) &
  1510. RX_RING_MOD_MASK(priv->rx_ring_size);
  1511. }
  1512. /* Update the current rxbd pointer to be the next one */
  1513. priv->cur_rx = bdp;
  1514. return howmany;
  1515. }
  1516. static int gfar_poll(struct napi_struct *napi, int budget)
  1517. {
  1518. struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
  1519. struct net_device *dev = priv->ndev;
  1520. int tx_cleaned = 0;
  1521. int rx_cleaned = 0;
  1522. unsigned long flags;
  1523. /* Clear IEVENT, so interrupts aren't called again
  1524. * because of the packets that have already arrived */
  1525. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1526. /* If we fail to get the lock, don't bother with the TX BDs */
  1527. if (spin_trylock_irqsave(&priv->txlock, flags)) {
  1528. tx_cleaned = gfar_clean_tx_ring(dev);
  1529. spin_unlock_irqrestore(&priv->txlock, flags);
  1530. }
  1531. rx_cleaned = gfar_clean_rx_ring(dev, budget);
  1532. if (tx_cleaned)
  1533. return budget;
  1534. if (rx_cleaned < budget) {
  1535. napi_complete(napi);
  1536. /* Clear the halt bit in RSTAT */
  1537. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1538. gfar_write(&priv->regs->imask, IMASK_DEFAULT);
  1539. /* If we are coalescing interrupts, update the timer */
  1540. /* Otherwise, clear it */
  1541. if (likely(priv->rxcoalescing)) {
  1542. gfar_write(&priv->regs->rxic, 0);
  1543. gfar_write(&priv->regs->rxic, priv->rxic);
  1544. }
  1545. if (likely(priv->txcoalescing)) {
  1546. gfar_write(&priv->regs->txic, 0);
  1547. gfar_write(&priv->regs->txic, priv->txic);
  1548. }
  1549. }
  1550. return rx_cleaned;
  1551. }
  1552. #ifdef CONFIG_NET_POLL_CONTROLLER
  1553. /*
  1554. * Polling 'interrupt' - used by things like netconsole to send skbs
  1555. * without having to re-enable interrupts. It's not called while
  1556. * the interrupt routine is executing.
  1557. */
  1558. static void gfar_netpoll(struct net_device *dev)
  1559. {
  1560. struct gfar_private *priv = netdev_priv(dev);
  1561. /* If the device has multiple interrupts, run tx/rx */
  1562. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1563. disable_irq(priv->interruptTransmit);
  1564. disable_irq(priv->interruptReceive);
  1565. disable_irq(priv->interruptError);
  1566. gfar_interrupt(priv->interruptTransmit, dev);
  1567. enable_irq(priv->interruptError);
  1568. enable_irq(priv->interruptReceive);
  1569. enable_irq(priv->interruptTransmit);
  1570. } else {
  1571. disable_irq(priv->interruptTransmit);
  1572. gfar_interrupt(priv->interruptTransmit, dev);
  1573. enable_irq(priv->interruptTransmit);
  1574. }
  1575. }
  1576. #endif
  1577. /* The interrupt handler for devices with one interrupt */
  1578. static irqreturn_t gfar_interrupt(int irq, void *dev_id)
  1579. {
  1580. struct net_device *dev = dev_id;
  1581. struct gfar_private *priv = netdev_priv(dev);
  1582. /* Save ievent for future reference */
  1583. u32 events = gfar_read(&priv->regs->ievent);
  1584. /* Check for reception */
  1585. if (events & IEVENT_RX_MASK)
  1586. gfar_receive(irq, dev_id);
  1587. /* Check for transmit completion */
  1588. if (events & IEVENT_TX_MASK)
  1589. gfar_transmit(irq, dev_id);
  1590. /* Check for errors */
  1591. if (events & IEVENT_ERR_MASK)
  1592. gfar_error(irq, dev_id);
  1593. return IRQ_HANDLED;
  1594. }
  1595. /* Called every time the controller might need to be made
  1596. * aware of new link state. The PHY code conveys this
  1597. * information through variables in the phydev structure, and this
  1598. * function converts those variables into the appropriate
  1599. * register values, and can bring down the device if needed.
  1600. */
  1601. static void adjust_link(struct net_device *dev)
  1602. {
  1603. struct gfar_private *priv = netdev_priv(dev);
  1604. struct gfar __iomem *regs = priv->regs;
  1605. unsigned long flags;
  1606. struct phy_device *phydev = priv->phydev;
  1607. int new_state = 0;
  1608. spin_lock_irqsave(&priv->txlock, flags);
  1609. if (phydev->link) {
  1610. u32 tempval = gfar_read(&regs->maccfg2);
  1611. u32 ecntrl = gfar_read(&regs->ecntrl);
  1612. /* Now we make sure that we can be in full duplex mode.
  1613. * If not, we operate in half-duplex mode. */
  1614. if (phydev->duplex != priv->oldduplex) {
  1615. new_state = 1;
  1616. if (!(phydev->duplex))
  1617. tempval &= ~(MACCFG2_FULL_DUPLEX);
  1618. else
  1619. tempval |= MACCFG2_FULL_DUPLEX;
  1620. priv->oldduplex = phydev->duplex;
  1621. }
  1622. if (phydev->speed != priv->oldspeed) {
  1623. new_state = 1;
  1624. switch (phydev->speed) {
  1625. case 1000:
  1626. tempval =
  1627. ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
  1628. ecntrl &= ~(ECNTRL_R100);
  1629. break;
  1630. case 100:
  1631. case 10:
  1632. tempval =
  1633. ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
  1634. /* Reduced mode distinguishes
  1635. * between 10 and 100 */
  1636. if (phydev->speed == SPEED_100)
  1637. ecntrl |= ECNTRL_R100;
  1638. else
  1639. ecntrl &= ~(ECNTRL_R100);
  1640. break;
  1641. default:
  1642. if (netif_msg_link(priv))
  1643. printk(KERN_WARNING
  1644. "%s: Ack! Speed (%d) is not 10/100/1000!\n",
  1645. dev->name, phydev->speed);
  1646. break;
  1647. }
  1648. priv->oldspeed = phydev->speed;
  1649. }
  1650. gfar_write(&regs->maccfg2, tempval);
  1651. gfar_write(&regs->ecntrl, ecntrl);
  1652. if (!priv->oldlink) {
  1653. new_state = 1;
  1654. priv->oldlink = 1;
  1655. }
  1656. } else if (priv->oldlink) {
  1657. new_state = 1;
  1658. priv->oldlink = 0;
  1659. priv->oldspeed = 0;
  1660. priv->oldduplex = -1;
  1661. }
  1662. if (new_state && netif_msg_link(priv))
  1663. phy_print_status(phydev);
  1664. spin_unlock_irqrestore(&priv->txlock, flags);
  1665. }
  1666. /* Update the hash table based on the current list of multicast
  1667. * addresses we subscribe to. Also, change the promiscuity of
  1668. * the device based on the flags (this function is called
  1669. * whenever dev->flags is changed */
  1670. static void gfar_set_multi(struct net_device *dev)
  1671. {
  1672. struct dev_mc_list *mc_ptr;
  1673. struct gfar_private *priv = netdev_priv(dev);
  1674. struct gfar __iomem *regs = priv->regs;
  1675. u32 tempval;
  1676. if(dev->flags & IFF_PROMISC) {
  1677. /* Set RCTRL to PROM */
  1678. tempval = gfar_read(&regs->rctrl);
  1679. tempval |= RCTRL_PROM;
  1680. gfar_write(&regs->rctrl, tempval);
  1681. } else {
  1682. /* Set RCTRL to not PROM */
  1683. tempval = gfar_read(&regs->rctrl);
  1684. tempval &= ~(RCTRL_PROM);
  1685. gfar_write(&regs->rctrl, tempval);
  1686. }
  1687. if(dev->flags & IFF_ALLMULTI) {
  1688. /* Set the hash to rx all multicast frames */
  1689. gfar_write(&regs->igaddr0, 0xffffffff);
  1690. gfar_write(&regs->igaddr1, 0xffffffff);
  1691. gfar_write(&regs->igaddr2, 0xffffffff);
  1692. gfar_write(&regs->igaddr3, 0xffffffff);
  1693. gfar_write(&regs->igaddr4, 0xffffffff);
  1694. gfar_write(&regs->igaddr5, 0xffffffff);
  1695. gfar_write(&regs->igaddr6, 0xffffffff);
  1696. gfar_write(&regs->igaddr7, 0xffffffff);
  1697. gfar_write(&regs->gaddr0, 0xffffffff);
  1698. gfar_write(&regs->gaddr1, 0xffffffff);
  1699. gfar_write(&regs->gaddr2, 0xffffffff);
  1700. gfar_write(&regs->gaddr3, 0xffffffff);
  1701. gfar_write(&regs->gaddr4, 0xffffffff);
  1702. gfar_write(&regs->gaddr5, 0xffffffff);
  1703. gfar_write(&regs->gaddr6, 0xffffffff);
  1704. gfar_write(&regs->gaddr7, 0xffffffff);
  1705. } else {
  1706. int em_num;
  1707. int idx;
  1708. /* zero out the hash */
  1709. gfar_write(&regs->igaddr0, 0x0);
  1710. gfar_write(&regs->igaddr1, 0x0);
  1711. gfar_write(&regs->igaddr2, 0x0);
  1712. gfar_write(&regs->igaddr3, 0x0);
  1713. gfar_write(&regs->igaddr4, 0x0);
  1714. gfar_write(&regs->igaddr5, 0x0);
  1715. gfar_write(&regs->igaddr6, 0x0);
  1716. gfar_write(&regs->igaddr7, 0x0);
  1717. gfar_write(&regs->gaddr0, 0x0);
  1718. gfar_write(&regs->gaddr1, 0x0);
  1719. gfar_write(&regs->gaddr2, 0x0);
  1720. gfar_write(&regs->gaddr3, 0x0);
  1721. gfar_write(&regs->gaddr4, 0x0);
  1722. gfar_write(&regs->gaddr5, 0x0);
  1723. gfar_write(&regs->gaddr6, 0x0);
  1724. gfar_write(&regs->gaddr7, 0x0);
  1725. /* If we have extended hash tables, we need to
  1726. * clear the exact match registers to prepare for
  1727. * setting them */
  1728. if (priv->extended_hash) {
  1729. em_num = GFAR_EM_NUM + 1;
  1730. gfar_clear_exact_match(dev);
  1731. idx = 1;
  1732. } else {
  1733. idx = 0;
  1734. em_num = 0;
  1735. }
  1736. if(dev->mc_count == 0)
  1737. return;
  1738. /* Parse the list, and set the appropriate bits */
  1739. for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
  1740. if (idx < em_num) {
  1741. gfar_set_mac_for_addr(dev, idx,
  1742. mc_ptr->dmi_addr);
  1743. idx++;
  1744. } else
  1745. gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
  1746. }
  1747. }
  1748. return;
  1749. }
  1750. /* Clears each of the exact match registers to zero, so they
  1751. * don't interfere with normal reception */
  1752. static void gfar_clear_exact_match(struct net_device *dev)
  1753. {
  1754. int idx;
  1755. u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0};
  1756. for(idx = 1;idx < GFAR_EM_NUM + 1;idx++)
  1757. gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr);
  1758. }
  1759. /* Set the appropriate hash bit for the given addr */
  1760. /* The algorithm works like so:
  1761. * 1) Take the Destination Address (ie the multicast address), and
  1762. * do a CRC on it (little endian), and reverse the bits of the
  1763. * result.
  1764. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1765. * table. The table is controlled through 8 32-bit registers:
  1766. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1767. * gaddr7. This means that the 3 most significant bits in the
  1768. * hash index which gaddr register to use, and the 5 other bits
  1769. * indicate which bit (assuming an IBM numbering scheme, which
  1770. * for PowerPC (tm) is usually the case) in the register holds
  1771. * the entry. */
  1772. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
  1773. {
  1774. u32 tempval;
  1775. struct gfar_private *priv = netdev_priv(dev);
  1776. u32 result = ether_crc(MAC_ADDR_LEN, addr);
  1777. int width = priv->hash_width;
  1778. u8 whichbit = (result >> (32 - width)) & 0x1f;
  1779. u8 whichreg = result >> (32 - width + 5);
  1780. u32 value = (1 << (31-whichbit));
  1781. tempval = gfar_read(priv->hash_regs[whichreg]);
  1782. tempval |= value;
  1783. gfar_write(priv->hash_regs[whichreg], tempval);
  1784. return;
  1785. }
  1786. /* There are multiple MAC Address register pairs on some controllers
  1787. * This function sets the numth pair to a given address
  1788. */
  1789. static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr)
  1790. {
  1791. struct gfar_private *priv = netdev_priv(dev);
  1792. int idx;
  1793. char tmpbuf[MAC_ADDR_LEN];
  1794. u32 tempval;
  1795. u32 __iomem *macptr = &priv->regs->macstnaddr1;
  1796. macptr += num*2;
  1797. /* Now copy it into the mac registers backwards, cuz */
  1798. /* little endian is silly */
  1799. for (idx = 0; idx < MAC_ADDR_LEN; idx++)
  1800. tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx];
  1801. gfar_write(macptr, *((u32 *) (tmpbuf)));
  1802. tempval = *((u32 *) (tmpbuf + 4));
  1803. gfar_write(macptr+1, tempval);
  1804. }
  1805. /* GFAR error interrupt handler */
  1806. static irqreturn_t gfar_error(int irq, void *dev_id)
  1807. {
  1808. struct net_device *dev = dev_id;
  1809. struct gfar_private *priv = netdev_priv(dev);
  1810. /* Save ievent for future reference */
  1811. u32 events = gfar_read(&priv->regs->ievent);
  1812. /* Clear IEVENT */
  1813. gfar_write(&priv->regs->ievent, events & IEVENT_ERR_MASK);
  1814. /* Magic Packet is not an error. */
  1815. if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  1816. (events & IEVENT_MAG))
  1817. events &= ~IEVENT_MAG;
  1818. /* Hmm... */
  1819. if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
  1820. printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
  1821. dev->name, events, gfar_read(&priv->regs->imask));
  1822. /* Update the error counters */
  1823. if (events & IEVENT_TXE) {
  1824. dev->stats.tx_errors++;
  1825. if (events & IEVENT_LC)
  1826. dev->stats.tx_window_errors++;
  1827. if (events & IEVENT_CRL)
  1828. dev->stats.tx_aborted_errors++;
  1829. if (events & IEVENT_XFUN) {
  1830. if (netif_msg_tx_err(priv))
  1831. printk(KERN_DEBUG "%s: TX FIFO underrun, "
  1832. "packet dropped.\n", dev->name);
  1833. dev->stats.tx_dropped++;
  1834. priv->extra_stats.tx_underrun++;
  1835. /* Reactivate the Tx Queues */
  1836. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1837. }
  1838. if (netif_msg_tx_err(priv))
  1839. printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
  1840. }
  1841. if (events & IEVENT_BSY) {
  1842. dev->stats.rx_errors++;
  1843. priv->extra_stats.rx_bsy++;
  1844. gfar_receive(irq, dev_id);
  1845. if (netif_msg_rx_err(priv))
  1846. printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
  1847. dev->name, gfar_read(&priv->regs->rstat));
  1848. }
  1849. if (events & IEVENT_BABR) {
  1850. dev->stats.rx_errors++;
  1851. priv->extra_stats.rx_babr++;
  1852. if (netif_msg_rx_err(priv))
  1853. printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
  1854. }
  1855. if (events & IEVENT_EBERR) {
  1856. priv->extra_stats.eberr++;
  1857. if (netif_msg_rx_err(priv))
  1858. printk(KERN_DEBUG "%s: bus error\n", dev->name);
  1859. }
  1860. if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
  1861. printk(KERN_DEBUG "%s: control frame\n", dev->name);
  1862. if (events & IEVENT_BABT) {
  1863. priv->extra_stats.tx_babt++;
  1864. if (netif_msg_tx_err(priv))
  1865. printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
  1866. }
  1867. return IRQ_HANDLED;
  1868. }
  1869. /* work with hotplug and coldplug */
  1870. MODULE_ALIAS("platform:fsl-gianfar");
  1871. static struct of_device_id gfar_match[] =
  1872. {
  1873. {
  1874. .type = "network",
  1875. .compatible = "gianfar",
  1876. },
  1877. {},
  1878. };
  1879. /* Structure for a device driver */
  1880. static struct of_platform_driver gfar_driver = {
  1881. .name = "fsl-gianfar",
  1882. .match_table = gfar_match,
  1883. .probe = gfar_probe,
  1884. .remove = gfar_remove,
  1885. .suspend = gfar_suspend,
  1886. .resume = gfar_resume,
  1887. };
  1888. static int __init gfar_init(void)
  1889. {
  1890. return of_register_platform_driver(&gfar_driver);
  1891. }
  1892. static void __exit gfar_exit(void)
  1893. {
  1894. of_unregister_platform_driver(&gfar_driver);
  1895. }
  1896. module_init(gfar_init);
  1897. module_exit(gfar_exit);