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