gianfar.c 62 KB

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