gianfar.c 62 KB

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