gianfar.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354
  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 attrs = 0;
  761. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  762. /* Allocate memory for the buffer descriptors */
  763. vaddr = (unsigned long) dma_alloc_coherent(&priv->ofdev->dev,
  764. sizeof (struct txbd8) * priv->tx_ring_size +
  765. sizeof (struct rxbd8) * priv->rx_ring_size,
  766. &addr, GFP_KERNEL);
  767. if (vaddr == 0) {
  768. if (netif_msg_ifup(priv))
  769. printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
  770. dev->name);
  771. return -ENOMEM;
  772. }
  773. priv->tx_bd_base = (struct txbd8 *) vaddr;
  774. /* enet DMA only understands physical addresses */
  775. gfar_write(&regs->tbase0, addr);
  776. /* Start the rx descriptor ring where the tx ring leaves off */
  777. addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
  778. vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
  779. priv->rx_bd_base = (struct rxbd8 *) vaddr;
  780. gfar_write(&regs->rbase0, addr);
  781. /* Setup the skbuff rings */
  782. priv->tx_skbuff =
  783. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  784. priv->tx_ring_size, GFP_KERNEL);
  785. if (NULL == priv->tx_skbuff) {
  786. if (netif_msg_ifup(priv))
  787. printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
  788. dev->name);
  789. err = -ENOMEM;
  790. goto tx_skb_fail;
  791. }
  792. for (i = 0; i < priv->tx_ring_size; i++)
  793. priv->tx_skbuff[i] = NULL;
  794. priv->rx_skbuff =
  795. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  796. priv->rx_ring_size, GFP_KERNEL);
  797. if (NULL == priv->rx_skbuff) {
  798. if (netif_msg_ifup(priv))
  799. printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
  800. dev->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(dev);
  826. if (!skb) {
  827. printk(KERN_ERR "%s: Can't allocate RX buffers\n",
  828. dev->name);
  829. goto err_rxalloc_fail;
  830. }
  831. priv->rx_skbuff[i] = skb;
  832. gfar_new_rxbdp(dev, 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. if (request_irq(priv->interruptError, gfar_error,
  844. 0, priv->int_name_er, dev) < 0) {
  845. if (netif_msg_intr(priv))
  846. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  847. dev->name, priv->interruptError);
  848. err = -1;
  849. goto err_irq_fail;
  850. }
  851. if (request_irq(priv->interruptTransmit, gfar_transmit,
  852. 0, priv->int_name_tx, dev) < 0) {
  853. if (netif_msg_intr(priv))
  854. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  855. dev->name, priv->interruptTransmit);
  856. err = -1;
  857. goto tx_irq_fail;
  858. }
  859. if (request_irq(priv->interruptReceive, gfar_receive,
  860. 0, priv->int_name_rx, dev) < 0) {
  861. if (netif_msg_intr(priv))
  862. printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
  863. dev->name, priv->interruptReceive);
  864. err = -1;
  865. goto rx_irq_fail;
  866. }
  867. } else {
  868. if (request_irq(priv->interruptTransmit, gfar_interrupt,
  869. 0, priv->int_name_tx, dev) < 0) {
  870. if (netif_msg_intr(priv))
  871. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  872. dev->name, priv->interruptTransmit);
  873. err = -1;
  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(dev);
  890. rctrl |= RCTRL_EMEN;
  891. }
  892. if (priv->padding) {
  893. rctrl &= ~RCTRL_PAL_MASK;
  894. rctrl |= RCTRL_PADDING(priv->padding);
  895. }
  896. /* Init rctrl based on our settings */
  897. gfar_write(&priv->regs->rctrl, rctrl);
  898. if (dev->features & NETIF_F_IP_CSUM)
  899. gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
  900. /* Set the extraction length and index */
  901. attrs = ATTRELI_EL(priv->rx_stash_size) |
  902. ATTRELI_EI(priv->rx_stash_index);
  903. gfar_write(&priv->regs->attreli, attrs);
  904. /* Start with defaults, and add stashing or locking
  905. * depending on the approprate variables */
  906. attrs = ATTR_INIT_SETTINGS;
  907. if (priv->bd_stash_en)
  908. attrs |= ATTR_BDSTASH;
  909. if (priv->rx_stash_size != 0)
  910. attrs |= ATTR_BUFSTASH;
  911. gfar_write(&priv->regs->attr, attrs);
  912. gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold);
  913. gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve);
  914. gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
  915. /* Start the controller */
  916. gfar_start(dev);
  917. return 0;
  918. rx_irq_fail:
  919. free_irq(priv->interruptTransmit, dev);
  920. tx_irq_fail:
  921. free_irq(priv->interruptError, dev);
  922. err_irq_fail:
  923. err_rxalloc_fail:
  924. rx_skb_fail:
  925. free_skb_resources(priv);
  926. tx_skb_fail:
  927. dma_free_coherent(&priv->ofdev->dev,
  928. sizeof(struct txbd8)*priv->tx_ring_size
  929. + sizeof(struct rxbd8)*priv->rx_ring_size,
  930. priv->tx_bd_base,
  931. gfar_read(&regs->tbase0));
  932. return err;
  933. }
  934. /* Called when something needs to use the ethernet device */
  935. /* Returns 0 for success. */
  936. static int gfar_enet_open(struct net_device *dev)
  937. {
  938. struct gfar_private *priv = netdev_priv(dev);
  939. int err;
  940. napi_enable(&priv->napi);
  941. skb_queue_head_init(&priv->rx_recycle);
  942. /* Initialize a bunch of registers */
  943. init_registers(dev);
  944. gfar_set_mac_address(dev);
  945. err = init_phy(dev);
  946. if(err) {
  947. napi_disable(&priv->napi);
  948. return err;
  949. }
  950. err = startup_gfar(dev);
  951. if (err) {
  952. napi_disable(&priv->napi);
  953. return err;
  954. }
  955. netif_start_queue(dev);
  956. device_set_wakeup_enable(&dev->dev, priv->wol_en);
  957. return err;
  958. }
  959. static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
  960. {
  961. struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
  962. memset(fcb, 0, GMAC_FCB_LEN);
  963. return fcb;
  964. }
  965. static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
  966. {
  967. u8 flags = 0;
  968. /* If we're here, it's a IP packet with a TCP or UDP
  969. * payload. We set it to checksum, using a pseudo-header
  970. * we provide
  971. */
  972. flags = TXFCB_DEFAULT;
  973. /* Tell the controller what the protocol is */
  974. /* And provide the already calculated phcs */
  975. if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
  976. flags |= TXFCB_UDP;
  977. fcb->phcs = udp_hdr(skb)->check;
  978. } else
  979. fcb->phcs = tcp_hdr(skb)->check;
  980. /* l3os is the distance between the start of the
  981. * frame (skb->data) and the start of the IP hdr.
  982. * l4os is the distance between the start of the
  983. * l3 hdr and the l4 hdr */
  984. fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN);
  985. fcb->l4os = skb_network_header_len(skb);
  986. fcb->flags = flags;
  987. }
  988. void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
  989. {
  990. fcb->flags |= TXFCB_VLN;
  991. fcb->vlctl = vlan_tx_tag_get(skb);
  992. }
  993. static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
  994. struct txbd8 *base, int ring_size)
  995. {
  996. struct txbd8 *new_bd = bdp + stride;
  997. return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
  998. }
  999. static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
  1000. int ring_size)
  1001. {
  1002. return skip_txbd(bdp, 1, base, ring_size);
  1003. }
  1004. /* This is called by the kernel when a frame is ready for transmission. */
  1005. /* It is pointed to by the dev->hard_start_xmit function pointer */
  1006. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1007. {
  1008. struct gfar_private *priv = netdev_priv(dev);
  1009. struct txfcb *fcb = NULL;
  1010. struct txbd8 *txbdp, *txbdp_start, *base;
  1011. u32 lstatus;
  1012. int i;
  1013. u32 bufaddr;
  1014. unsigned long flags;
  1015. unsigned int nr_frags, length;
  1016. base = priv->tx_bd_base;
  1017. /* make space for additional header when fcb is needed */
  1018. if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
  1019. (priv->vlgrp && vlan_tx_tag_present(skb))) &&
  1020. (skb_headroom(skb) < GMAC_FCB_LEN)) {
  1021. struct sk_buff *skb_new;
  1022. skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
  1023. if (!skb_new) {
  1024. dev->stats.tx_errors++;
  1025. kfree_skb(skb);
  1026. return NETDEV_TX_OK;
  1027. }
  1028. kfree_skb(skb);
  1029. skb = skb_new;
  1030. }
  1031. /* total number of fragments in the SKB */
  1032. nr_frags = skb_shinfo(skb)->nr_frags;
  1033. spin_lock_irqsave(&priv->txlock, flags);
  1034. /* check if there is space to queue this packet */
  1035. if ((nr_frags+1) > priv->num_txbdfree) {
  1036. /* no space, stop the queue */
  1037. netif_stop_queue(dev);
  1038. dev->stats.tx_fifo_errors++;
  1039. spin_unlock_irqrestore(&priv->txlock, flags);
  1040. return NETDEV_TX_BUSY;
  1041. }
  1042. /* Update transmit stats */
  1043. dev->stats.tx_bytes += skb->len;
  1044. txbdp = txbdp_start = priv->cur_tx;
  1045. if (nr_frags == 0) {
  1046. lstatus = txbdp->lstatus | BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1047. } else {
  1048. /* Place the fragment addresses and lengths into the TxBDs */
  1049. for (i = 0; i < nr_frags; i++) {
  1050. /* Point at the next BD, wrapping as needed */
  1051. txbdp = next_txbd(txbdp, base, priv->tx_ring_size);
  1052. length = skb_shinfo(skb)->frags[i].size;
  1053. lstatus = txbdp->lstatus | length |
  1054. BD_LFLAG(TXBD_READY);
  1055. /* Handle the last BD specially */
  1056. if (i == nr_frags - 1)
  1057. lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1058. bufaddr = dma_map_page(&priv->ofdev->dev,
  1059. skb_shinfo(skb)->frags[i].page,
  1060. skb_shinfo(skb)->frags[i].page_offset,
  1061. length,
  1062. DMA_TO_DEVICE);
  1063. /* set the TxBD length and buffer pointer */
  1064. txbdp->bufPtr = bufaddr;
  1065. txbdp->lstatus = lstatus;
  1066. }
  1067. lstatus = txbdp_start->lstatus;
  1068. }
  1069. /* Set up checksumming */
  1070. if (CHECKSUM_PARTIAL == skb->ip_summed) {
  1071. fcb = gfar_add_fcb(skb);
  1072. lstatus |= BD_LFLAG(TXBD_TOE);
  1073. gfar_tx_checksum(skb, fcb);
  1074. }
  1075. if (priv->vlgrp && vlan_tx_tag_present(skb)) {
  1076. if (unlikely(NULL == fcb)) {
  1077. fcb = gfar_add_fcb(skb);
  1078. lstatus |= BD_LFLAG(TXBD_TOE);
  1079. }
  1080. gfar_tx_vlan(skb, fcb);
  1081. }
  1082. /* setup the TxBD length and buffer pointer for the first BD */
  1083. priv->tx_skbuff[priv->skb_curtx] = skb;
  1084. txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1085. skb_headlen(skb), DMA_TO_DEVICE);
  1086. lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
  1087. /*
  1088. * The powerpc-specific eieio() is used, as wmb() has too strong
  1089. * semantics (it requires synchronization between cacheable and
  1090. * uncacheable mappings, which eieio doesn't provide and which we
  1091. * don't need), thus requiring a more expensive sync instruction. At
  1092. * some point, the set of architecture-independent barrier functions
  1093. * should be expanded to include weaker barriers.
  1094. */
  1095. eieio();
  1096. txbdp_start->lstatus = lstatus;
  1097. /* Update the current skb pointer to the next entry we will use
  1098. * (wrapping if necessary) */
  1099. priv->skb_curtx = (priv->skb_curtx + 1) &
  1100. TX_RING_MOD_MASK(priv->tx_ring_size);
  1101. priv->cur_tx = next_txbd(txbdp, base, priv->tx_ring_size);
  1102. /* reduce TxBD free count */
  1103. priv->num_txbdfree -= (nr_frags + 1);
  1104. dev->trans_start = jiffies;
  1105. /* If the next BD still needs to be cleaned up, then the bds
  1106. are full. We need to tell the kernel to stop sending us stuff. */
  1107. if (!priv->num_txbdfree) {
  1108. netif_stop_queue(dev);
  1109. dev->stats.tx_fifo_errors++;
  1110. }
  1111. /* Tell the DMA to go go go */
  1112. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1113. /* Unlock priv */
  1114. spin_unlock_irqrestore(&priv->txlock, flags);
  1115. return NETDEV_TX_OK;
  1116. }
  1117. /* Stops the kernel queue, and halts the controller */
  1118. static int gfar_close(struct net_device *dev)
  1119. {
  1120. struct gfar_private *priv = netdev_priv(dev);
  1121. napi_disable(&priv->napi);
  1122. skb_queue_purge(&priv->rx_recycle);
  1123. cancel_work_sync(&priv->reset_task);
  1124. stop_gfar(dev);
  1125. /* Disconnect from the PHY */
  1126. phy_disconnect(priv->phydev);
  1127. priv->phydev = NULL;
  1128. netif_stop_queue(dev);
  1129. return 0;
  1130. }
  1131. /* Changes the mac address if the controller is not running. */
  1132. static int gfar_set_mac_address(struct net_device *dev)
  1133. {
  1134. gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
  1135. return 0;
  1136. }
  1137. /* Enables and disables VLAN insertion/extraction */
  1138. static void gfar_vlan_rx_register(struct net_device *dev,
  1139. struct vlan_group *grp)
  1140. {
  1141. struct gfar_private *priv = netdev_priv(dev);
  1142. unsigned long flags;
  1143. u32 tempval;
  1144. spin_lock_irqsave(&priv->rxlock, flags);
  1145. priv->vlgrp = grp;
  1146. if (grp) {
  1147. /* Enable VLAN tag insertion */
  1148. tempval = gfar_read(&priv->regs->tctrl);
  1149. tempval |= TCTRL_VLINS;
  1150. gfar_write(&priv->regs->tctrl, tempval);
  1151. /* Enable VLAN tag extraction */
  1152. tempval = gfar_read(&priv->regs->rctrl);
  1153. tempval |= RCTRL_VLEX;
  1154. tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT);
  1155. gfar_write(&priv->regs->rctrl, tempval);
  1156. } else {
  1157. /* Disable VLAN tag insertion */
  1158. tempval = gfar_read(&priv->regs->tctrl);
  1159. tempval &= ~TCTRL_VLINS;
  1160. gfar_write(&priv->regs->tctrl, tempval);
  1161. /* Disable VLAN tag extraction */
  1162. tempval = gfar_read(&priv->regs->rctrl);
  1163. tempval &= ~RCTRL_VLEX;
  1164. /* If parse is no longer required, then disable parser */
  1165. if (tempval & RCTRL_REQ_PARSER)
  1166. tempval |= RCTRL_PRSDEP_INIT;
  1167. else
  1168. tempval &= ~RCTRL_PRSDEP_INIT;
  1169. gfar_write(&priv->regs->rctrl, tempval);
  1170. }
  1171. gfar_change_mtu(dev, dev->mtu);
  1172. spin_unlock_irqrestore(&priv->rxlock, flags);
  1173. }
  1174. static int gfar_change_mtu(struct net_device *dev, int new_mtu)
  1175. {
  1176. int tempsize, tempval;
  1177. struct gfar_private *priv = netdev_priv(dev);
  1178. int oldsize = priv->rx_buffer_size;
  1179. int frame_size = new_mtu + ETH_HLEN;
  1180. if (priv->vlgrp)
  1181. frame_size += VLAN_HLEN;
  1182. if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
  1183. if (netif_msg_drv(priv))
  1184. printk(KERN_ERR "%s: Invalid MTU setting\n",
  1185. dev->name);
  1186. return -EINVAL;
  1187. }
  1188. if (gfar_uses_fcb(priv))
  1189. frame_size += GMAC_FCB_LEN;
  1190. frame_size += priv->padding;
  1191. tempsize =
  1192. (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
  1193. INCREMENTAL_BUFFER_SIZE;
  1194. /* Only stop and start the controller if it isn't already
  1195. * stopped, and we changed something */
  1196. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1197. stop_gfar(dev);
  1198. priv->rx_buffer_size = tempsize;
  1199. dev->mtu = new_mtu;
  1200. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  1201. gfar_write(&priv->regs->maxfrm, priv->rx_buffer_size);
  1202. /* If the mtu is larger than the max size for standard
  1203. * ethernet frames (ie, a jumbo frame), then set maccfg2
  1204. * to allow huge frames, and to check the length */
  1205. tempval = gfar_read(&priv->regs->maccfg2);
  1206. if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE)
  1207. tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1208. else
  1209. tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1210. gfar_write(&priv->regs->maccfg2, tempval);
  1211. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1212. startup_gfar(dev);
  1213. return 0;
  1214. }
  1215. /* gfar_reset_task gets scheduled when a packet has not been
  1216. * transmitted after a set amount of time.
  1217. * For now, assume that clearing out all the structures, and
  1218. * starting over will fix the problem.
  1219. */
  1220. static void gfar_reset_task(struct work_struct *work)
  1221. {
  1222. struct gfar_private *priv = container_of(work, struct gfar_private,
  1223. reset_task);
  1224. struct net_device *dev = priv->ndev;
  1225. if (dev->flags & IFF_UP) {
  1226. netif_stop_queue(dev);
  1227. stop_gfar(dev);
  1228. startup_gfar(dev);
  1229. netif_start_queue(dev);
  1230. }
  1231. netif_tx_schedule_all(dev);
  1232. }
  1233. static void gfar_timeout(struct net_device *dev)
  1234. {
  1235. struct gfar_private *priv = netdev_priv(dev);
  1236. dev->stats.tx_errors++;
  1237. schedule_work(&priv->reset_task);
  1238. }
  1239. /* Interrupt Handler for Transmit complete */
  1240. static int gfar_clean_tx_ring(struct net_device *dev)
  1241. {
  1242. struct gfar_private *priv = netdev_priv(dev);
  1243. struct txbd8 *bdp;
  1244. struct txbd8 *lbdp = NULL;
  1245. struct txbd8 *base = priv->tx_bd_base;
  1246. struct sk_buff *skb;
  1247. int skb_dirtytx;
  1248. int tx_ring_size = priv->tx_ring_size;
  1249. int frags = 0;
  1250. int i;
  1251. int howmany = 0;
  1252. u32 lstatus;
  1253. bdp = priv->dirty_tx;
  1254. skb_dirtytx = priv->skb_dirtytx;
  1255. while ((skb = priv->tx_skbuff[skb_dirtytx])) {
  1256. frags = skb_shinfo(skb)->nr_frags;
  1257. lbdp = skip_txbd(bdp, frags, base, tx_ring_size);
  1258. lstatus = lbdp->lstatus;
  1259. /* Only clean completed frames */
  1260. if ((lstatus & BD_LFLAG(TXBD_READY)) &&
  1261. (lstatus & BD_LENGTH_MASK))
  1262. break;
  1263. dma_unmap_single(&priv->ofdev->dev,
  1264. bdp->bufPtr,
  1265. bdp->length,
  1266. DMA_TO_DEVICE);
  1267. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1268. bdp = next_txbd(bdp, base, tx_ring_size);
  1269. for (i = 0; i < frags; i++) {
  1270. dma_unmap_page(&priv->ofdev->dev,
  1271. bdp->bufPtr,
  1272. bdp->length,
  1273. DMA_TO_DEVICE);
  1274. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1275. bdp = next_txbd(bdp, base, tx_ring_size);
  1276. }
  1277. /*
  1278. * If there's room in the queue (limit it to rx_buffer_size)
  1279. * we add this skb back into the pool, if it's the right size
  1280. */
  1281. if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
  1282. skb_recycle_check(skb, priv->rx_buffer_size +
  1283. RXBUF_ALIGNMENT))
  1284. __skb_queue_head(&priv->rx_recycle, skb);
  1285. else
  1286. dev_kfree_skb_any(skb);
  1287. priv->tx_skbuff[skb_dirtytx] = NULL;
  1288. skb_dirtytx = (skb_dirtytx + 1) &
  1289. TX_RING_MOD_MASK(tx_ring_size);
  1290. howmany++;
  1291. priv->num_txbdfree += frags + 1;
  1292. }
  1293. /* If we freed a buffer, we can restart transmission, if necessary */
  1294. if (netif_queue_stopped(dev) && priv->num_txbdfree)
  1295. netif_wake_queue(dev);
  1296. /* Update dirty indicators */
  1297. priv->skb_dirtytx = skb_dirtytx;
  1298. priv->dirty_tx = bdp;
  1299. dev->stats.tx_packets += howmany;
  1300. return howmany;
  1301. }
  1302. static void gfar_schedule_cleanup(struct net_device *dev)
  1303. {
  1304. struct gfar_private *priv = netdev_priv(dev);
  1305. unsigned long flags;
  1306. spin_lock_irqsave(&priv->txlock, flags);
  1307. spin_lock(&priv->rxlock);
  1308. if (napi_schedule_prep(&priv->napi)) {
  1309. gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
  1310. __napi_schedule(&priv->napi);
  1311. } else {
  1312. /*
  1313. * Clear IEVENT, so interrupts aren't called again
  1314. * because of the packets that have already arrived.
  1315. */
  1316. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1317. }
  1318. spin_unlock(&priv->rxlock);
  1319. spin_unlock_irqrestore(&priv->txlock, flags);
  1320. }
  1321. /* Interrupt Handler for Transmit complete */
  1322. static irqreturn_t gfar_transmit(int irq, void *dev_id)
  1323. {
  1324. gfar_schedule_cleanup((struct net_device *)dev_id);
  1325. return IRQ_HANDLED;
  1326. }
  1327. static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
  1328. struct sk_buff *skb)
  1329. {
  1330. struct gfar_private *priv = netdev_priv(dev);
  1331. u32 lstatus;
  1332. bdp->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1333. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1334. lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
  1335. if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
  1336. lstatus |= BD_LFLAG(RXBD_WRAP);
  1337. eieio();
  1338. bdp->lstatus = lstatus;
  1339. }
  1340. struct sk_buff * gfar_new_skb(struct net_device *dev)
  1341. {
  1342. unsigned int alignamount;
  1343. struct gfar_private *priv = netdev_priv(dev);
  1344. struct sk_buff *skb = NULL;
  1345. skb = __skb_dequeue(&priv->rx_recycle);
  1346. if (!skb)
  1347. skb = netdev_alloc_skb(dev,
  1348. priv->rx_buffer_size + RXBUF_ALIGNMENT);
  1349. if (!skb)
  1350. return NULL;
  1351. alignamount = RXBUF_ALIGNMENT -
  1352. (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1));
  1353. /* We need the data buffer to be aligned properly. We will reserve
  1354. * as many bytes as needed to align the data properly
  1355. */
  1356. skb_reserve(skb, alignamount);
  1357. return skb;
  1358. }
  1359. static inline void count_errors(unsigned short status, struct net_device *dev)
  1360. {
  1361. struct gfar_private *priv = netdev_priv(dev);
  1362. struct net_device_stats *stats = &dev->stats;
  1363. struct gfar_extra_stats *estats = &priv->extra_stats;
  1364. /* If the packet was truncated, none of the other errors
  1365. * matter */
  1366. if (status & RXBD_TRUNCATED) {
  1367. stats->rx_length_errors++;
  1368. estats->rx_trunc++;
  1369. return;
  1370. }
  1371. /* Count the errors, if there were any */
  1372. if (status & (RXBD_LARGE | RXBD_SHORT)) {
  1373. stats->rx_length_errors++;
  1374. if (status & RXBD_LARGE)
  1375. estats->rx_large++;
  1376. else
  1377. estats->rx_short++;
  1378. }
  1379. if (status & RXBD_NONOCTET) {
  1380. stats->rx_frame_errors++;
  1381. estats->rx_nonoctet++;
  1382. }
  1383. if (status & RXBD_CRCERR) {
  1384. estats->rx_crcerr++;
  1385. stats->rx_crc_errors++;
  1386. }
  1387. if (status & RXBD_OVERRUN) {
  1388. estats->rx_overrun++;
  1389. stats->rx_crc_errors++;
  1390. }
  1391. }
  1392. irqreturn_t gfar_receive(int irq, void *dev_id)
  1393. {
  1394. gfar_schedule_cleanup((struct net_device *)dev_id);
  1395. return IRQ_HANDLED;
  1396. }
  1397. static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
  1398. {
  1399. /* If valid headers were found, and valid sums
  1400. * were verified, then we tell the kernel that no
  1401. * checksumming is necessary. Otherwise, it is */
  1402. if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
  1403. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1404. else
  1405. skb->ip_summed = CHECKSUM_NONE;
  1406. }
  1407. /* gfar_process_frame() -- handle one incoming packet if skb
  1408. * isn't NULL. */
  1409. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  1410. int amount_pull)
  1411. {
  1412. struct gfar_private *priv = netdev_priv(dev);
  1413. struct rxfcb *fcb = NULL;
  1414. int ret;
  1415. /* fcb is at the beginning if exists */
  1416. fcb = (struct rxfcb *)skb->data;
  1417. /* Remove the FCB from the skb */
  1418. /* Remove the padded bytes, if there are any */
  1419. if (amount_pull)
  1420. skb_pull(skb, amount_pull);
  1421. if (priv->rx_csum_enable)
  1422. gfar_rx_checksum(skb, fcb);
  1423. /* Tell the skb what kind of packet this is */
  1424. skb->protocol = eth_type_trans(skb, dev);
  1425. /* Send the packet up the stack */
  1426. if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN)))
  1427. ret = vlan_hwaccel_receive_skb(skb, priv->vlgrp, fcb->vlctl);
  1428. else
  1429. ret = netif_receive_skb(skb);
  1430. if (NET_RX_DROP == ret)
  1431. priv->extra_stats.kernel_dropped++;
  1432. return 0;
  1433. }
  1434. /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
  1435. * until the budget/quota has been reached. Returns the number
  1436. * of frames handled
  1437. */
  1438. int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
  1439. {
  1440. struct rxbd8 *bdp, *base;
  1441. struct sk_buff *skb;
  1442. int pkt_len;
  1443. int amount_pull;
  1444. int howmany = 0;
  1445. struct gfar_private *priv = netdev_priv(dev);
  1446. /* Get the first full descriptor */
  1447. bdp = priv->cur_rx;
  1448. base = priv->rx_bd_base;
  1449. amount_pull = (gfar_uses_fcb(priv) ? GMAC_FCB_LEN : 0) +
  1450. priv->padding;
  1451. while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
  1452. struct sk_buff *newskb;
  1453. rmb();
  1454. /* Add another skb for the future */
  1455. newskb = gfar_new_skb(dev);
  1456. skb = priv->rx_skbuff[priv->skb_currx];
  1457. dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
  1458. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1459. /* We drop the frame if we failed to allocate a new buffer */
  1460. if (unlikely(!newskb || !(bdp->status & RXBD_LAST) ||
  1461. bdp->status & RXBD_ERR)) {
  1462. count_errors(bdp->status, dev);
  1463. if (unlikely(!newskb))
  1464. newskb = skb;
  1465. else if (skb) {
  1466. /*
  1467. * We need to reset ->data to what it
  1468. * was before gfar_new_skb() re-aligned
  1469. * it to an RXBUF_ALIGNMENT boundary
  1470. * before we put the skb back on the
  1471. * recycle list.
  1472. */
  1473. skb->data = skb->head + NET_SKB_PAD;
  1474. __skb_queue_head(&priv->rx_recycle, skb);
  1475. }
  1476. } else {
  1477. /* Increment the number of packets */
  1478. dev->stats.rx_packets++;
  1479. howmany++;
  1480. if (likely(skb)) {
  1481. pkt_len = bdp->length - ETH_FCS_LEN;
  1482. /* Remove the FCS from the packet length */
  1483. skb_put(skb, pkt_len);
  1484. dev->stats.rx_bytes += pkt_len;
  1485. if (in_irq() || irqs_disabled())
  1486. printk("Interrupt problem!\n");
  1487. gfar_process_frame(dev, skb, amount_pull);
  1488. } else {
  1489. if (netif_msg_rx_err(priv))
  1490. printk(KERN_WARNING
  1491. "%s: Missing skb!\n", dev->name);
  1492. dev->stats.rx_dropped++;
  1493. priv->extra_stats.rx_skbmissing++;
  1494. }
  1495. }
  1496. priv->rx_skbuff[priv->skb_currx] = newskb;
  1497. /* Setup the new bdp */
  1498. gfar_new_rxbdp(dev, bdp, newskb);
  1499. /* Update to the next pointer */
  1500. bdp = next_bd(bdp, base, priv->rx_ring_size);
  1501. /* update to point at the next skb */
  1502. priv->skb_currx =
  1503. (priv->skb_currx + 1) &
  1504. RX_RING_MOD_MASK(priv->rx_ring_size);
  1505. }
  1506. /* Update the current rxbd pointer to be the next one */
  1507. priv->cur_rx = bdp;
  1508. return howmany;
  1509. }
  1510. static int gfar_poll(struct napi_struct *napi, int budget)
  1511. {
  1512. struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
  1513. struct net_device *dev = priv->ndev;
  1514. int tx_cleaned = 0;
  1515. int rx_cleaned = 0;
  1516. unsigned long flags;
  1517. /* Clear IEVENT, so interrupts aren't called again
  1518. * because of the packets that have already arrived */
  1519. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1520. /* If we fail to get the lock, don't bother with the TX BDs */
  1521. if (spin_trylock_irqsave(&priv->txlock, flags)) {
  1522. tx_cleaned = gfar_clean_tx_ring(dev);
  1523. spin_unlock_irqrestore(&priv->txlock, flags);
  1524. }
  1525. rx_cleaned = gfar_clean_rx_ring(dev, budget);
  1526. if (tx_cleaned)
  1527. return budget;
  1528. if (rx_cleaned < budget) {
  1529. napi_complete(napi);
  1530. /* Clear the halt bit in RSTAT */
  1531. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1532. gfar_write(&priv->regs->imask, IMASK_DEFAULT);
  1533. /* If we are coalescing interrupts, update the timer */
  1534. /* Otherwise, clear it */
  1535. if (likely(priv->rxcoalescing)) {
  1536. gfar_write(&priv->regs->rxic, 0);
  1537. gfar_write(&priv->regs->rxic, priv->rxic);
  1538. }
  1539. if (likely(priv->txcoalescing)) {
  1540. gfar_write(&priv->regs->txic, 0);
  1541. gfar_write(&priv->regs->txic, priv->txic);
  1542. }
  1543. }
  1544. return rx_cleaned;
  1545. }
  1546. #ifdef CONFIG_NET_POLL_CONTROLLER
  1547. /*
  1548. * Polling 'interrupt' - used by things like netconsole to send skbs
  1549. * without having to re-enable interrupts. It's not called while
  1550. * the interrupt routine is executing.
  1551. */
  1552. static void gfar_netpoll(struct net_device *dev)
  1553. {
  1554. struct gfar_private *priv = netdev_priv(dev);
  1555. /* If the device has multiple interrupts, run tx/rx */
  1556. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1557. disable_irq(priv->interruptTransmit);
  1558. disable_irq(priv->interruptReceive);
  1559. disable_irq(priv->interruptError);
  1560. gfar_interrupt(priv->interruptTransmit, dev);
  1561. enable_irq(priv->interruptError);
  1562. enable_irq(priv->interruptReceive);
  1563. enable_irq(priv->interruptTransmit);
  1564. } else {
  1565. disable_irq(priv->interruptTransmit);
  1566. gfar_interrupt(priv->interruptTransmit, dev);
  1567. enable_irq(priv->interruptTransmit);
  1568. }
  1569. }
  1570. #endif
  1571. /* The interrupt handler for devices with one interrupt */
  1572. static irqreturn_t gfar_interrupt(int irq, void *dev_id)
  1573. {
  1574. struct net_device *dev = dev_id;
  1575. struct gfar_private *priv = netdev_priv(dev);
  1576. /* Save ievent for future reference */
  1577. u32 events = gfar_read(&priv->regs->ievent);
  1578. /* Check for reception */
  1579. if (events & IEVENT_RX_MASK)
  1580. gfar_receive(irq, dev_id);
  1581. /* Check for transmit completion */
  1582. if (events & IEVENT_TX_MASK)
  1583. gfar_transmit(irq, dev_id);
  1584. /* Check for errors */
  1585. if (events & IEVENT_ERR_MASK)
  1586. gfar_error(irq, dev_id);
  1587. return IRQ_HANDLED;
  1588. }
  1589. /* Called every time the controller might need to be made
  1590. * aware of new link state. The PHY code conveys this
  1591. * information through variables in the phydev structure, and this
  1592. * function converts those variables into the appropriate
  1593. * register values, and can bring down the device if needed.
  1594. */
  1595. static void adjust_link(struct net_device *dev)
  1596. {
  1597. struct gfar_private *priv = netdev_priv(dev);
  1598. struct gfar __iomem *regs = priv->regs;
  1599. unsigned long flags;
  1600. struct phy_device *phydev = priv->phydev;
  1601. int new_state = 0;
  1602. spin_lock_irqsave(&priv->txlock, flags);
  1603. if (phydev->link) {
  1604. u32 tempval = gfar_read(&regs->maccfg2);
  1605. u32 ecntrl = gfar_read(&regs->ecntrl);
  1606. /* Now we make sure that we can be in full duplex mode.
  1607. * If not, we operate in half-duplex mode. */
  1608. if (phydev->duplex != priv->oldduplex) {
  1609. new_state = 1;
  1610. if (!(phydev->duplex))
  1611. tempval &= ~(MACCFG2_FULL_DUPLEX);
  1612. else
  1613. tempval |= MACCFG2_FULL_DUPLEX;
  1614. priv->oldduplex = phydev->duplex;
  1615. }
  1616. if (phydev->speed != priv->oldspeed) {
  1617. new_state = 1;
  1618. switch (phydev->speed) {
  1619. case 1000:
  1620. tempval =
  1621. ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
  1622. ecntrl &= ~(ECNTRL_R100);
  1623. break;
  1624. case 100:
  1625. case 10:
  1626. tempval =
  1627. ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
  1628. /* Reduced mode distinguishes
  1629. * between 10 and 100 */
  1630. if (phydev->speed == SPEED_100)
  1631. ecntrl |= ECNTRL_R100;
  1632. else
  1633. ecntrl &= ~(ECNTRL_R100);
  1634. break;
  1635. default:
  1636. if (netif_msg_link(priv))
  1637. printk(KERN_WARNING
  1638. "%s: Ack! Speed (%d) is not 10/100/1000!\n",
  1639. dev->name, phydev->speed);
  1640. break;
  1641. }
  1642. priv->oldspeed = phydev->speed;
  1643. }
  1644. gfar_write(&regs->maccfg2, tempval);
  1645. gfar_write(&regs->ecntrl, ecntrl);
  1646. if (!priv->oldlink) {
  1647. new_state = 1;
  1648. priv->oldlink = 1;
  1649. }
  1650. } else if (priv->oldlink) {
  1651. new_state = 1;
  1652. priv->oldlink = 0;
  1653. priv->oldspeed = 0;
  1654. priv->oldduplex = -1;
  1655. }
  1656. if (new_state && netif_msg_link(priv))
  1657. phy_print_status(phydev);
  1658. spin_unlock_irqrestore(&priv->txlock, flags);
  1659. }
  1660. /* Update the hash table based on the current list of multicast
  1661. * addresses we subscribe to. Also, change the promiscuity of
  1662. * the device based on the flags (this function is called
  1663. * whenever dev->flags is changed */
  1664. static void gfar_set_multi(struct net_device *dev)
  1665. {
  1666. struct dev_mc_list *mc_ptr;
  1667. struct gfar_private *priv = netdev_priv(dev);
  1668. struct gfar __iomem *regs = priv->regs;
  1669. u32 tempval;
  1670. if(dev->flags & IFF_PROMISC) {
  1671. /* Set RCTRL to PROM */
  1672. tempval = gfar_read(&regs->rctrl);
  1673. tempval |= RCTRL_PROM;
  1674. gfar_write(&regs->rctrl, tempval);
  1675. } else {
  1676. /* Set RCTRL to not PROM */
  1677. tempval = gfar_read(&regs->rctrl);
  1678. tempval &= ~(RCTRL_PROM);
  1679. gfar_write(&regs->rctrl, tempval);
  1680. }
  1681. if(dev->flags & IFF_ALLMULTI) {
  1682. /* Set the hash to rx all multicast frames */
  1683. gfar_write(&regs->igaddr0, 0xffffffff);
  1684. gfar_write(&regs->igaddr1, 0xffffffff);
  1685. gfar_write(&regs->igaddr2, 0xffffffff);
  1686. gfar_write(&regs->igaddr3, 0xffffffff);
  1687. gfar_write(&regs->igaddr4, 0xffffffff);
  1688. gfar_write(&regs->igaddr5, 0xffffffff);
  1689. gfar_write(&regs->igaddr6, 0xffffffff);
  1690. gfar_write(&regs->igaddr7, 0xffffffff);
  1691. gfar_write(&regs->gaddr0, 0xffffffff);
  1692. gfar_write(&regs->gaddr1, 0xffffffff);
  1693. gfar_write(&regs->gaddr2, 0xffffffff);
  1694. gfar_write(&regs->gaddr3, 0xffffffff);
  1695. gfar_write(&regs->gaddr4, 0xffffffff);
  1696. gfar_write(&regs->gaddr5, 0xffffffff);
  1697. gfar_write(&regs->gaddr6, 0xffffffff);
  1698. gfar_write(&regs->gaddr7, 0xffffffff);
  1699. } else {
  1700. int em_num;
  1701. int idx;
  1702. /* zero out the hash */
  1703. gfar_write(&regs->igaddr0, 0x0);
  1704. gfar_write(&regs->igaddr1, 0x0);
  1705. gfar_write(&regs->igaddr2, 0x0);
  1706. gfar_write(&regs->igaddr3, 0x0);
  1707. gfar_write(&regs->igaddr4, 0x0);
  1708. gfar_write(&regs->igaddr5, 0x0);
  1709. gfar_write(&regs->igaddr6, 0x0);
  1710. gfar_write(&regs->igaddr7, 0x0);
  1711. gfar_write(&regs->gaddr0, 0x0);
  1712. gfar_write(&regs->gaddr1, 0x0);
  1713. gfar_write(&regs->gaddr2, 0x0);
  1714. gfar_write(&regs->gaddr3, 0x0);
  1715. gfar_write(&regs->gaddr4, 0x0);
  1716. gfar_write(&regs->gaddr5, 0x0);
  1717. gfar_write(&regs->gaddr6, 0x0);
  1718. gfar_write(&regs->gaddr7, 0x0);
  1719. /* If we have extended hash tables, we need to
  1720. * clear the exact match registers to prepare for
  1721. * setting them */
  1722. if (priv->extended_hash) {
  1723. em_num = GFAR_EM_NUM + 1;
  1724. gfar_clear_exact_match(dev);
  1725. idx = 1;
  1726. } else {
  1727. idx = 0;
  1728. em_num = 0;
  1729. }
  1730. if(dev->mc_count == 0)
  1731. return;
  1732. /* Parse the list, and set the appropriate bits */
  1733. for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
  1734. if (idx < em_num) {
  1735. gfar_set_mac_for_addr(dev, idx,
  1736. mc_ptr->dmi_addr);
  1737. idx++;
  1738. } else
  1739. gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
  1740. }
  1741. }
  1742. return;
  1743. }
  1744. /* Clears each of the exact match registers to zero, so they
  1745. * don't interfere with normal reception */
  1746. static void gfar_clear_exact_match(struct net_device *dev)
  1747. {
  1748. int idx;
  1749. u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0};
  1750. for(idx = 1;idx < GFAR_EM_NUM + 1;idx++)
  1751. gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr);
  1752. }
  1753. /* Set the appropriate hash bit for the given addr */
  1754. /* The algorithm works like so:
  1755. * 1) Take the Destination Address (ie the multicast address), and
  1756. * do a CRC on it (little endian), and reverse the bits of the
  1757. * result.
  1758. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1759. * table. The table is controlled through 8 32-bit registers:
  1760. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1761. * gaddr7. This means that the 3 most significant bits in the
  1762. * hash index which gaddr register to use, and the 5 other bits
  1763. * indicate which bit (assuming an IBM numbering scheme, which
  1764. * for PowerPC (tm) is usually the case) in the register holds
  1765. * the entry. */
  1766. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
  1767. {
  1768. u32 tempval;
  1769. struct gfar_private *priv = netdev_priv(dev);
  1770. u32 result = ether_crc(MAC_ADDR_LEN, addr);
  1771. int width = priv->hash_width;
  1772. u8 whichbit = (result >> (32 - width)) & 0x1f;
  1773. u8 whichreg = result >> (32 - width + 5);
  1774. u32 value = (1 << (31-whichbit));
  1775. tempval = gfar_read(priv->hash_regs[whichreg]);
  1776. tempval |= value;
  1777. gfar_write(priv->hash_regs[whichreg], tempval);
  1778. return;
  1779. }
  1780. /* There are multiple MAC Address register pairs on some controllers
  1781. * This function sets the numth pair to a given address
  1782. */
  1783. static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr)
  1784. {
  1785. struct gfar_private *priv = netdev_priv(dev);
  1786. int idx;
  1787. char tmpbuf[MAC_ADDR_LEN];
  1788. u32 tempval;
  1789. u32 __iomem *macptr = &priv->regs->macstnaddr1;
  1790. macptr += num*2;
  1791. /* Now copy it into the mac registers backwards, cuz */
  1792. /* little endian is silly */
  1793. for (idx = 0; idx < MAC_ADDR_LEN; idx++)
  1794. tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx];
  1795. gfar_write(macptr, *((u32 *) (tmpbuf)));
  1796. tempval = *((u32 *) (tmpbuf + 4));
  1797. gfar_write(macptr+1, tempval);
  1798. }
  1799. /* GFAR error interrupt handler */
  1800. static irqreturn_t gfar_error(int irq, void *dev_id)
  1801. {
  1802. struct net_device *dev = dev_id;
  1803. struct gfar_private *priv = netdev_priv(dev);
  1804. /* Save ievent for future reference */
  1805. u32 events = gfar_read(&priv->regs->ievent);
  1806. /* Clear IEVENT */
  1807. gfar_write(&priv->regs->ievent, events & IEVENT_ERR_MASK);
  1808. /* Magic Packet is not an error. */
  1809. if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  1810. (events & IEVENT_MAG))
  1811. events &= ~IEVENT_MAG;
  1812. /* Hmm... */
  1813. if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
  1814. printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
  1815. dev->name, events, gfar_read(&priv->regs->imask));
  1816. /* Update the error counters */
  1817. if (events & IEVENT_TXE) {
  1818. dev->stats.tx_errors++;
  1819. if (events & IEVENT_LC)
  1820. dev->stats.tx_window_errors++;
  1821. if (events & IEVENT_CRL)
  1822. dev->stats.tx_aborted_errors++;
  1823. if (events & IEVENT_XFUN) {
  1824. if (netif_msg_tx_err(priv))
  1825. printk(KERN_DEBUG "%s: TX FIFO underrun, "
  1826. "packet dropped.\n", dev->name);
  1827. dev->stats.tx_dropped++;
  1828. priv->extra_stats.tx_underrun++;
  1829. /* Reactivate the Tx Queues */
  1830. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1831. }
  1832. if (netif_msg_tx_err(priv))
  1833. printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
  1834. }
  1835. if (events & IEVENT_BSY) {
  1836. dev->stats.rx_errors++;
  1837. priv->extra_stats.rx_bsy++;
  1838. gfar_receive(irq, dev_id);
  1839. if (netif_msg_rx_err(priv))
  1840. printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
  1841. dev->name, gfar_read(&priv->regs->rstat));
  1842. }
  1843. if (events & IEVENT_BABR) {
  1844. dev->stats.rx_errors++;
  1845. priv->extra_stats.rx_babr++;
  1846. if (netif_msg_rx_err(priv))
  1847. printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
  1848. }
  1849. if (events & IEVENT_EBERR) {
  1850. priv->extra_stats.eberr++;
  1851. if (netif_msg_rx_err(priv))
  1852. printk(KERN_DEBUG "%s: bus error\n", dev->name);
  1853. }
  1854. if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
  1855. printk(KERN_DEBUG "%s: control frame\n", dev->name);
  1856. if (events & IEVENT_BABT) {
  1857. priv->extra_stats.tx_babt++;
  1858. if (netif_msg_tx_err(priv))
  1859. printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
  1860. }
  1861. return IRQ_HANDLED;
  1862. }
  1863. /* work with hotplug and coldplug */
  1864. MODULE_ALIAS("platform:fsl-gianfar");
  1865. static struct of_device_id gfar_match[] =
  1866. {
  1867. {
  1868. .type = "network",
  1869. .compatible = "gianfar",
  1870. },
  1871. {},
  1872. };
  1873. /* Structure for a device driver */
  1874. static struct of_platform_driver gfar_driver = {
  1875. .name = "fsl-gianfar",
  1876. .match_table = gfar_match,
  1877. .probe = gfar_probe,
  1878. .remove = gfar_remove,
  1879. .suspend = gfar_suspend,
  1880. .resume = gfar_resume,
  1881. };
  1882. static int __init gfar_init(void)
  1883. {
  1884. return of_register_platform_driver(&gfar_driver);
  1885. }
  1886. static void __exit gfar_exit(void)
  1887. {
  1888. of_unregister_platform_driver(&gfar_driver);
  1889. }
  1890. module_init(gfar_init);
  1891. module_exit(gfar_exit);