gianfar.c 62 KB

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