gianfar.c 62 KB

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