gianfar.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. /*
  2. * drivers/net/gianfar.c
  3. *
  4. * Gianfar Ethernet Driver
  5. * Driver for FEC on MPC8540 and TSEC on MPC8540/MPC8560
  6. * Based on 8260_io/fcc_enet.c
  7. *
  8. * Author: Andy Fleming
  9. * Maintainer: Kumar Gala (kumar.gala@freescale.com)
  10. *
  11. * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * Gianfar: AKA Lambda Draconis, "Dragon"
  19. * RA 11 31 24.2
  20. * Dec +69 19 52
  21. * V 3.84
  22. * B-V +1.62
  23. *
  24. * Theory of operation
  25. * This driver is designed for the Triple-speed Ethernet
  26. * controllers on the Freescale 8540/8560 integrated processors,
  27. * as well as the Fast Ethernet Controller on the 8540.
  28. *
  29. * The driver is initialized through platform_device. Structures which
  30. * define the configuration needed by the board are defined in a
  31. * board structure in arch/ppc/platforms (though I do not
  32. * discount the possibility that other architectures could one
  33. * day be supported. One assumption the driver currently makes
  34. * is that the PHY is configured in such a way to advertise all
  35. * capabilities. This is a sensible default, and on certain
  36. * PHYs, changing this default encounters substantial errata
  37. * issues. Future versions may remove this requirement, but for
  38. * now, it is best for the firmware to ensure this is the case.
  39. *
  40. * The Gianfar Ethernet Controller uses a ring of buffer
  41. * descriptors. The beginning is indicated by a register
  42. * pointing to the physical address of the start of the ring.
  43. * The end is determined by a "wrap" bit being set in the
  44. * last descriptor of the ring.
  45. *
  46. * When a packet is received, the RXF bit in the
  47. * IEVENT register is set, triggering an interrupt when the
  48. * corresponding bit in the IMASK register is also set (if
  49. * interrupt coalescing is active, then the interrupt may not
  50. * happen immediately, but will wait until either a set number
  51. * of frames or amount of time have passed.). In NAPI, the
  52. * interrupt handler will signal there is work to be done, and
  53. * exit. Without NAPI, the packet(s) will be handled
  54. * immediately. Both methods will start at the last known empty
  55. * descriptor, and process every subsequent descriptor until there
  56. * are none left with data (NAPI will stop after a set number of
  57. * packets to give time to other tasks, but will eventually
  58. * process all the packets). The data arrives inside a
  59. * pre-allocated skb, and so after the skb is passed up to the
  60. * stack, a new skb must be allocated, and the address field in
  61. * the buffer descriptor must be updated to indicate this new
  62. * skb.
  63. *
  64. * When the kernel requests that a packet be transmitted, the
  65. * driver starts where it left off last time, and points the
  66. * descriptor at the buffer which was passed in. The driver
  67. * then informs the DMA engine that there are packets ready to
  68. * be transmitted. Once the controller is finished transmitting
  69. * the packet, an interrupt may be triggered (under the same
  70. * conditions as for reception, but depending on the TXF bit).
  71. * The driver then cleans up the buffer.
  72. */
  73. #include <linux/config.h>
  74. #include <linux/kernel.h>
  75. #include <linux/sched.h>
  76. #include <linux/string.h>
  77. #include <linux/errno.h>
  78. #include <linux/slab.h>
  79. #include <linux/interrupt.h>
  80. #include <linux/init.h>
  81. #include <linux/delay.h>
  82. #include <linux/netdevice.h>
  83. #include <linux/etherdevice.h>
  84. #include <linux/skbuff.h>
  85. #include <linux/spinlock.h>
  86. #include <linux/mm.h>
  87. #include <linux/device.h>
  88. #include <asm/io.h>
  89. #include <asm/irq.h>
  90. #include <asm/uaccess.h>
  91. #include <linux/module.h>
  92. #include <linux/version.h>
  93. #include <linux/dma-mapping.h>
  94. #include <linux/crc32.h>
  95. #include "gianfar.h"
  96. #include "gianfar_phy.h"
  97. #define TX_TIMEOUT (1*HZ)
  98. #define SKB_ALLOC_TIMEOUT 1000000
  99. #undef BRIEF_GFAR_ERRORS
  100. #undef VERBOSE_GFAR_ERRORS
  101. #ifdef CONFIG_GFAR_NAPI
  102. #define RECEIVE(x) netif_receive_skb(x)
  103. #else
  104. #define RECEIVE(x) netif_rx(x)
  105. #endif
  106. const char gfar_driver_name[] = "Gianfar Ethernet";
  107. const char gfar_driver_version[] = "1.1";
  108. int startup_gfar(struct net_device *dev);
  109. static int gfar_enet_open(struct net_device *dev);
  110. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
  111. static void gfar_timeout(struct net_device *dev);
  112. static int gfar_close(struct net_device *dev);
  113. struct sk_buff *gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp);
  114. static struct net_device_stats *gfar_get_stats(struct net_device *dev);
  115. static int gfar_set_mac_address(struct net_device *dev);
  116. static int gfar_change_mtu(struct net_device *dev, int new_mtu);
  117. static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs);
  118. static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs);
  119. irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs);
  120. static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  121. static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  122. static void gfar_phy_change(void *data);
  123. static void gfar_phy_timer(unsigned long data);
  124. static void adjust_link(struct net_device *dev);
  125. static void init_registers(struct net_device *dev);
  126. static int init_phy(struct net_device *dev);
  127. static int gfar_probe(struct device *device);
  128. static int gfar_remove(struct device *device);
  129. void free_skb_resources(struct gfar_private *priv);
  130. static void gfar_set_multi(struct net_device *dev);
  131. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
  132. #ifdef CONFIG_GFAR_NAPI
  133. static int gfar_poll(struct net_device *dev, int *budget);
  134. #endif
  135. static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
  136. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
  137. static void gfar_phy_startup_timer(unsigned long data);
  138. extern struct ethtool_ops gfar_ethtool_ops;
  139. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  140. MODULE_DESCRIPTION("Gianfar Ethernet Driver");
  141. MODULE_LICENSE("GPL");
  142. static int gfar_probe(struct device *device)
  143. {
  144. u32 tempval;
  145. struct net_device *dev = NULL;
  146. struct gfar_private *priv = NULL;
  147. struct platform_device *pdev = to_platform_device(device);
  148. struct gianfar_platform_data *einfo;
  149. struct resource *r;
  150. int idx;
  151. int err = 0;
  152. int dev_ethtool_ops = 0;
  153. einfo = (struct gianfar_platform_data *) pdev->dev.platform_data;
  154. if (einfo == NULL) {
  155. printk(KERN_ERR "gfar %d: Missing additional data!\n",
  156. pdev->id);
  157. return -ENODEV;
  158. }
  159. /* Create an ethernet device instance */
  160. dev = alloc_etherdev(sizeof (*priv));
  161. if (dev == NULL)
  162. return -ENOMEM;
  163. priv = netdev_priv(dev);
  164. /* Set the info in the priv to the current info */
  165. priv->einfo = einfo;
  166. /* fill out IRQ fields */
  167. if (einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  168. priv->interruptTransmit = platform_get_irq_byname(pdev, "tx");
  169. priv->interruptReceive = platform_get_irq_byname(pdev, "rx");
  170. priv->interruptError = platform_get_irq_byname(pdev, "error");
  171. } else {
  172. priv->interruptTransmit = platform_get_irq(pdev, 0);
  173. }
  174. /* get a pointer to the register memory */
  175. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  176. priv->regs = (struct gfar *)
  177. ioremap(r->start, sizeof (struct gfar));
  178. if (priv->regs == NULL) {
  179. err = -ENOMEM;
  180. goto regs_fail;
  181. }
  182. /* Set the PHY base address */
  183. priv->phyregs = (struct gfar *)
  184. ioremap(einfo->phy_reg_addr, sizeof (struct gfar));
  185. if (priv->phyregs == NULL) {
  186. err = -ENOMEM;
  187. goto phy_regs_fail;
  188. }
  189. spin_lock_init(&priv->lock);
  190. dev_set_drvdata(device, dev);
  191. /* Stop the DMA engine now, in case it was running before */
  192. /* (The firmware could have used it, and left it running). */
  193. /* To do this, we write Graceful Receive Stop and Graceful */
  194. /* Transmit Stop, and then wait until the corresponding bits */
  195. /* in IEVENT indicate the stops have completed. */
  196. tempval = gfar_read(&priv->regs->dmactrl);
  197. tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
  198. gfar_write(&priv->regs->dmactrl, tempval);
  199. tempval = gfar_read(&priv->regs->dmactrl);
  200. tempval |= (DMACTRL_GRS | DMACTRL_GTS);
  201. gfar_write(&priv->regs->dmactrl, tempval);
  202. while (!(gfar_read(&priv->regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC)))
  203. cpu_relax();
  204. /* Reset MAC layer */
  205. gfar_write(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
  206. tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
  207. gfar_write(&priv->regs->maccfg1, tempval);
  208. /* Initialize MACCFG2. */
  209. gfar_write(&priv->regs->maccfg2, MACCFG2_INIT_SETTINGS);
  210. /* Initialize ECNTRL */
  211. gfar_write(&priv->regs->ecntrl, ECNTRL_INIT_SETTINGS);
  212. /* Copy the station address into the dev structure, */
  213. memcpy(dev->dev_addr, einfo->mac_addr, MAC_ADDR_LEN);
  214. /* Set the dev->base_addr to the gfar reg region */
  215. dev->base_addr = (unsigned long) (priv->regs);
  216. SET_MODULE_OWNER(dev);
  217. SET_NETDEV_DEV(dev, device);
  218. /* Fill in the dev structure */
  219. dev->open = gfar_enet_open;
  220. dev->hard_start_xmit = gfar_start_xmit;
  221. dev->tx_timeout = gfar_timeout;
  222. dev->watchdog_timeo = TX_TIMEOUT;
  223. #ifdef CONFIG_GFAR_NAPI
  224. dev->poll = gfar_poll;
  225. dev->weight = GFAR_DEV_WEIGHT;
  226. #endif
  227. dev->stop = gfar_close;
  228. dev->get_stats = gfar_get_stats;
  229. dev->change_mtu = gfar_change_mtu;
  230. dev->mtu = 1500;
  231. dev->set_multicast_list = gfar_set_multi;
  232. /* Index into the array of possible ethtool
  233. * ops to catch all 4 possibilities */
  234. if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) == 0)
  235. dev_ethtool_ops += 1;
  236. if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE) == 0)
  237. dev_ethtool_ops += 2;
  238. dev->ethtool_ops = gfar_op_array[dev_ethtool_ops];
  239. priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
  240. #ifdef CONFIG_GFAR_BUFSTASH
  241. priv->rx_stash_size = STASH_LENGTH;
  242. #endif
  243. priv->tx_ring_size = DEFAULT_TX_RING_SIZE;
  244. priv->rx_ring_size = DEFAULT_RX_RING_SIZE;
  245. priv->txcoalescing = DEFAULT_TX_COALESCE;
  246. priv->txcount = DEFAULT_TXCOUNT;
  247. priv->txtime = DEFAULT_TXTIME;
  248. priv->rxcoalescing = DEFAULT_RX_COALESCE;
  249. priv->rxcount = DEFAULT_RXCOUNT;
  250. priv->rxtime = DEFAULT_RXTIME;
  251. err = register_netdev(dev);
  252. if (err) {
  253. printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
  254. dev->name);
  255. goto register_fail;
  256. }
  257. /* Print out the device info */
  258. printk(KERN_INFO DEVICE_NAME, dev->name);
  259. for (idx = 0; idx < 6; idx++)
  260. printk("%2.2x%c", dev->dev_addr[idx], idx == 5 ? ' ' : ':');
  261. printk("\n");
  262. /* Even more device info helps when determining which kernel */
  263. /* provided which set of benchmarks. Since this is global for all */
  264. /* devices, we only print it once */
  265. #ifdef CONFIG_GFAR_NAPI
  266. printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name);
  267. #else
  268. printk(KERN_INFO "%s: Running with NAPI disabled\n", dev->name);
  269. #endif
  270. printk(KERN_INFO "%s: %d/%d RX/TX BD ring size\n",
  271. dev->name, priv->rx_ring_size, priv->tx_ring_size);
  272. return 0;
  273. register_fail:
  274. iounmap((void *) priv->phyregs);
  275. phy_regs_fail:
  276. iounmap((void *) priv->regs);
  277. regs_fail:
  278. free_netdev(dev);
  279. return -ENOMEM;
  280. }
  281. static int gfar_remove(struct device *device)
  282. {
  283. struct net_device *dev = dev_get_drvdata(device);
  284. struct gfar_private *priv = netdev_priv(dev);
  285. dev_set_drvdata(device, NULL);
  286. iounmap((void *) priv->regs);
  287. iounmap((void *) priv->phyregs);
  288. free_netdev(dev);
  289. return 0;
  290. }
  291. /* Configure the PHY for dev.
  292. * returns 0 if success. -1 if failure
  293. */
  294. static int init_phy(struct net_device *dev)
  295. {
  296. struct gfar_private *priv = netdev_priv(dev);
  297. struct phy_info *curphy;
  298. unsigned int timeout = PHY_INIT_TIMEOUT;
  299. struct gfar *phyregs = priv->phyregs;
  300. struct gfar_mii_info *mii_info;
  301. int err;
  302. priv->oldlink = 0;
  303. priv->oldspeed = 0;
  304. priv->oldduplex = -1;
  305. mii_info = kmalloc(sizeof(struct gfar_mii_info),
  306. GFP_KERNEL);
  307. if(NULL == mii_info) {
  308. printk(KERN_ERR "%s: Could not allocate mii_info\n",
  309. dev->name);
  310. return -ENOMEM;
  311. }
  312. mii_info->speed = SPEED_1000;
  313. mii_info->duplex = DUPLEX_FULL;
  314. mii_info->pause = 0;
  315. mii_info->link = 1;
  316. mii_info->advertising = (ADVERTISED_10baseT_Half |
  317. ADVERTISED_10baseT_Full |
  318. ADVERTISED_100baseT_Half |
  319. ADVERTISED_100baseT_Full |
  320. ADVERTISED_1000baseT_Full);
  321. mii_info->autoneg = 1;
  322. spin_lock_init(&mii_info->mdio_lock);
  323. mii_info->mii_id = priv->einfo->phyid;
  324. mii_info->dev = dev;
  325. mii_info->mdio_read = &read_phy_reg;
  326. mii_info->mdio_write = &write_phy_reg;
  327. priv->mii_info = mii_info;
  328. /* Reset the management interface */
  329. gfar_write(&phyregs->miimcfg, MIIMCFG_RESET);
  330. /* Setup the MII Mgmt clock speed */
  331. gfar_write(&phyregs->miimcfg, MIIMCFG_INIT_VALUE);
  332. /* Wait until the bus is free */
  333. while ((gfar_read(&phyregs->miimind) & MIIMIND_BUSY) &&
  334. timeout--)
  335. cpu_relax();
  336. if(timeout <= 0) {
  337. printk(KERN_ERR "%s: The MII Bus is stuck!\n",
  338. dev->name);
  339. err = -1;
  340. goto bus_fail;
  341. }
  342. /* get info for this PHY */
  343. curphy = get_phy_info(priv->mii_info);
  344. if (curphy == NULL) {
  345. printk(KERN_ERR "%s: No PHY found\n", dev->name);
  346. err = -1;
  347. goto no_phy;
  348. }
  349. mii_info->phyinfo = curphy;
  350. /* Run the commands which initialize the PHY */
  351. if(curphy->init) {
  352. err = curphy->init(priv->mii_info);
  353. if (err)
  354. goto phy_init_fail;
  355. }
  356. return 0;
  357. phy_init_fail:
  358. no_phy:
  359. bus_fail:
  360. kfree(mii_info);
  361. return err;
  362. }
  363. static void init_registers(struct net_device *dev)
  364. {
  365. struct gfar_private *priv = netdev_priv(dev);
  366. /* Clear IEVENT */
  367. gfar_write(&priv->regs->ievent, IEVENT_INIT_CLEAR);
  368. /* Initialize IMASK */
  369. gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
  370. /* Init hash registers to zero */
  371. gfar_write(&priv->regs->iaddr0, 0);
  372. gfar_write(&priv->regs->iaddr1, 0);
  373. gfar_write(&priv->regs->iaddr2, 0);
  374. gfar_write(&priv->regs->iaddr3, 0);
  375. gfar_write(&priv->regs->iaddr4, 0);
  376. gfar_write(&priv->regs->iaddr5, 0);
  377. gfar_write(&priv->regs->iaddr6, 0);
  378. gfar_write(&priv->regs->iaddr7, 0);
  379. gfar_write(&priv->regs->gaddr0, 0);
  380. gfar_write(&priv->regs->gaddr1, 0);
  381. gfar_write(&priv->regs->gaddr2, 0);
  382. gfar_write(&priv->regs->gaddr3, 0);
  383. gfar_write(&priv->regs->gaddr4, 0);
  384. gfar_write(&priv->regs->gaddr5, 0);
  385. gfar_write(&priv->regs->gaddr6, 0);
  386. gfar_write(&priv->regs->gaddr7, 0);
  387. /* Zero out rctrl */
  388. gfar_write(&priv->regs->rctrl, 0x00000000);
  389. /* Zero out the rmon mib registers if it has them */
  390. if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  391. memset((void *) &(priv->regs->rmon), 0,
  392. sizeof (struct rmon_mib));
  393. /* Mask off the CAM interrupts */
  394. gfar_write(&priv->regs->rmon.cam1, 0xffffffff);
  395. gfar_write(&priv->regs->rmon.cam2, 0xffffffff);
  396. }
  397. /* Initialize the max receive buffer length */
  398. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  399. #ifdef CONFIG_GFAR_BUFSTASH
  400. /* If we are stashing buffers, we need to set the
  401. * extraction length to the size of the buffer */
  402. gfar_write(&priv->regs->attreli, priv->rx_stash_size << 16);
  403. #endif
  404. /* Initialize the Minimum Frame Length Register */
  405. gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
  406. /* Setup Attributes so that snooping is on for rx */
  407. gfar_write(&priv->regs->attr, ATTR_INIT_SETTINGS);
  408. gfar_write(&priv->regs->attreli, ATTRELI_INIT_SETTINGS);
  409. /* Assign the TBI an address which won't conflict with the PHYs */
  410. gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
  411. }
  412. void stop_gfar(struct net_device *dev)
  413. {
  414. struct gfar_private *priv = netdev_priv(dev);
  415. struct gfar *regs = priv->regs;
  416. unsigned long flags;
  417. u32 tempval;
  418. /* Lock it down */
  419. spin_lock_irqsave(&priv->lock, flags);
  420. /* Tell the kernel the link is down */
  421. priv->mii_info->link = 0;
  422. adjust_link(dev);
  423. /* Mask all interrupts */
  424. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  425. /* Clear all interrupts */
  426. gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
  427. /* Stop the DMA, and wait for it to stop */
  428. tempval = gfar_read(&priv->regs->dmactrl);
  429. if ((tempval & (DMACTRL_GRS | DMACTRL_GTS))
  430. != (DMACTRL_GRS | DMACTRL_GTS)) {
  431. tempval |= (DMACTRL_GRS | DMACTRL_GTS);
  432. gfar_write(&priv->regs->dmactrl, tempval);
  433. while (!(gfar_read(&priv->regs->ievent) &
  434. (IEVENT_GRSC | IEVENT_GTSC)))
  435. cpu_relax();
  436. }
  437. /* Disable Rx and Tx */
  438. tempval = gfar_read(&regs->maccfg1);
  439. tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
  440. gfar_write(&regs->maccfg1, tempval);
  441. if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
  442. /* Clear any pending interrupts */
  443. mii_clear_phy_interrupt(priv->mii_info);
  444. /* Disable PHY Interrupts */
  445. mii_configure_phy_interrupt(priv->mii_info,
  446. MII_INTERRUPT_DISABLED);
  447. }
  448. spin_unlock_irqrestore(&priv->lock, flags);
  449. /* Free the IRQs */
  450. if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  451. free_irq(priv->interruptError, dev);
  452. free_irq(priv->interruptTransmit, dev);
  453. free_irq(priv->interruptReceive, dev);
  454. } else {
  455. free_irq(priv->interruptTransmit, dev);
  456. }
  457. if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
  458. free_irq(priv->einfo->interruptPHY, dev);
  459. } else {
  460. del_timer_sync(&priv->phy_info_timer);
  461. }
  462. free_skb_resources(priv);
  463. dma_free_coherent(NULL,
  464. sizeof(struct txbd8)*priv->tx_ring_size
  465. + sizeof(struct rxbd8)*priv->rx_ring_size,
  466. priv->tx_bd_base,
  467. gfar_read(&regs->tbase));
  468. }
  469. /* If there are any tx skbs or rx skbs still around, free them.
  470. * Then free tx_skbuff and rx_skbuff */
  471. void free_skb_resources(struct gfar_private *priv)
  472. {
  473. struct rxbd8 *rxbdp;
  474. struct txbd8 *txbdp;
  475. int i;
  476. /* Go through all the buffer descriptors and free their data buffers */
  477. txbdp = priv->tx_bd_base;
  478. for (i = 0; i < priv->tx_ring_size; i++) {
  479. if (priv->tx_skbuff[i]) {
  480. dma_unmap_single(NULL, txbdp->bufPtr,
  481. txbdp->length,
  482. DMA_TO_DEVICE);
  483. dev_kfree_skb_any(priv->tx_skbuff[i]);
  484. priv->tx_skbuff[i] = NULL;
  485. }
  486. }
  487. kfree(priv->tx_skbuff);
  488. rxbdp = priv->rx_bd_base;
  489. /* rx_skbuff is not guaranteed to be allocated, so only
  490. * free it and its contents if it is allocated */
  491. if(priv->rx_skbuff != NULL) {
  492. for (i = 0; i < priv->rx_ring_size; i++) {
  493. if (priv->rx_skbuff[i]) {
  494. dma_unmap_single(NULL, rxbdp->bufPtr,
  495. priv->rx_buffer_size
  496. + RXBUF_ALIGNMENT,
  497. DMA_FROM_DEVICE);
  498. dev_kfree_skb_any(priv->rx_skbuff[i]);
  499. priv->rx_skbuff[i] = NULL;
  500. }
  501. rxbdp->status = 0;
  502. rxbdp->length = 0;
  503. rxbdp->bufPtr = 0;
  504. rxbdp++;
  505. }
  506. kfree(priv->rx_skbuff);
  507. }
  508. }
  509. /* Bring the controller up and running */
  510. int startup_gfar(struct net_device *dev)
  511. {
  512. struct txbd8 *txbdp;
  513. struct rxbd8 *rxbdp;
  514. dma_addr_t addr;
  515. unsigned long vaddr;
  516. int i;
  517. struct gfar_private *priv = netdev_priv(dev);
  518. struct gfar *regs = priv->regs;
  519. u32 tempval;
  520. int err = 0;
  521. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  522. /* Allocate memory for the buffer descriptors */
  523. vaddr = (unsigned long) dma_alloc_coherent(NULL,
  524. sizeof (struct txbd8) * priv->tx_ring_size +
  525. sizeof (struct rxbd8) * priv->rx_ring_size,
  526. &addr, GFP_KERNEL);
  527. if (vaddr == 0) {
  528. printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
  529. dev->name);
  530. return -ENOMEM;
  531. }
  532. priv->tx_bd_base = (struct txbd8 *) vaddr;
  533. /* enet DMA only understands physical addresses */
  534. gfar_write(&regs->tbase, addr);
  535. /* Start the rx descriptor ring where the tx ring leaves off */
  536. addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
  537. vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
  538. priv->rx_bd_base = (struct rxbd8 *) vaddr;
  539. gfar_write(&regs->rbase, addr);
  540. /* Setup the skbuff rings */
  541. priv->tx_skbuff =
  542. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  543. priv->tx_ring_size, GFP_KERNEL);
  544. if (priv->tx_skbuff == NULL) {
  545. printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
  546. dev->name);
  547. err = -ENOMEM;
  548. goto tx_skb_fail;
  549. }
  550. for (i = 0; i < priv->tx_ring_size; i++)
  551. priv->tx_skbuff[i] = NULL;
  552. priv->rx_skbuff =
  553. (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
  554. priv->rx_ring_size, GFP_KERNEL);
  555. if (priv->rx_skbuff == NULL) {
  556. printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
  557. dev->name);
  558. err = -ENOMEM;
  559. goto rx_skb_fail;
  560. }
  561. for (i = 0; i < priv->rx_ring_size; i++)
  562. priv->rx_skbuff[i] = NULL;
  563. /* Initialize some variables in our dev structure */
  564. priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
  565. priv->cur_rx = priv->rx_bd_base;
  566. priv->skb_curtx = priv->skb_dirtytx = 0;
  567. priv->skb_currx = 0;
  568. /* Initialize Transmit Descriptor Ring */
  569. txbdp = priv->tx_bd_base;
  570. for (i = 0; i < priv->tx_ring_size; i++) {
  571. txbdp->status = 0;
  572. txbdp->length = 0;
  573. txbdp->bufPtr = 0;
  574. txbdp++;
  575. }
  576. /* Set the last descriptor in the ring to indicate wrap */
  577. txbdp--;
  578. txbdp->status |= TXBD_WRAP;
  579. rxbdp = priv->rx_bd_base;
  580. for (i = 0; i < priv->rx_ring_size; i++) {
  581. struct sk_buff *skb = NULL;
  582. rxbdp->status = 0;
  583. skb = gfar_new_skb(dev, rxbdp);
  584. priv->rx_skbuff[i] = skb;
  585. rxbdp++;
  586. }
  587. /* Set the last descriptor in the ring to wrap */
  588. rxbdp--;
  589. rxbdp->status |= RXBD_WRAP;
  590. /* If the device has multiple interrupts, register for
  591. * them. Otherwise, only register for the one */
  592. if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  593. /* Install our interrupt handlers for Error,
  594. * Transmit, and Receive */
  595. if (request_irq(priv->interruptError, gfar_error,
  596. 0, "enet_error", dev) < 0) {
  597. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  598. dev->name, priv->interruptError);
  599. err = -1;
  600. goto err_irq_fail;
  601. }
  602. if (request_irq(priv->interruptTransmit, gfar_transmit,
  603. 0, "enet_tx", dev) < 0) {
  604. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  605. dev->name, priv->interruptTransmit);
  606. err = -1;
  607. goto tx_irq_fail;
  608. }
  609. if (request_irq(priv->interruptReceive, gfar_receive,
  610. 0, "enet_rx", dev) < 0) {
  611. printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
  612. dev->name, priv->interruptReceive);
  613. err = -1;
  614. goto rx_irq_fail;
  615. }
  616. } else {
  617. if (request_irq(priv->interruptTransmit, gfar_interrupt,
  618. 0, "gfar_interrupt", dev) < 0) {
  619. printk(KERN_ERR "%s: Can't get IRQ %d\n",
  620. dev->name, priv->interruptError);
  621. err = -1;
  622. goto err_irq_fail;
  623. }
  624. }
  625. /* Set up the PHY change work queue */
  626. INIT_WORK(&priv->tq, gfar_phy_change, dev);
  627. init_timer(&priv->phy_info_timer);
  628. priv->phy_info_timer.function = &gfar_phy_startup_timer;
  629. priv->phy_info_timer.data = (unsigned long) priv->mii_info;
  630. mod_timer(&priv->phy_info_timer, jiffies + HZ);
  631. /* Configure the coalescing support */
  632. if (priv->txcoalescing)
  633. gfar_write(&regs->txic,
  634. mk_ic_value(priv->txcount, priv->txtime));
  635. else
  636. gfar_write(&regs->txic, 0);
  637. if (priv->rxcoalescing)
  638. gfar_write(&regs->rxic,
  639. mk_ic_value(priv->rxcount, priv->rxtime));
  640. else
  641. gfar_write(&regs->rxic, 0);
  642. init_waitqueue_head(&priv->rxcleanupq);
  643. /* Enable Rx and Tx in MACCFG1 */
  644. tempval = gfar_read(&regs->maccfg1);
  645. tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  646. gfar_write(&regs->maccfg1, tempval);
  647. /* Initialize DMACTRL to have WWR and WOP */
  648. tempval = gfar_read(&priv->regs->dmactrl);
  649. tempval |= DMACTRL_INIT_SETTINGS;
  650. gfar_write(&priv->regs->dmactrl, tempval);
  651. /* Clear THLT, so that the DMA starts polling now */
  652. gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
  653. /* Make sure we aren't stopped */
  654. tempval = gfar_read(&priv->regs->dmactrl);
  655. tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
  656. gfar_write(&priv->regs->dmactrl, tempval);
  657. /* Unmask the interrupts we look for */
  658. gfar_write(&regs->imask, IMASK_DEFAULT);
  659. return 0;
  660. rx_irq_fail:
  661. free_irq(priv->interruptTransmit, dev);
  662. tx_irq_fail:
  663. free_irq(priv->interruptError, dev);
  664. err_irq_fail:
  665. rx_skb_fail:
  666. free_skb_resources(priv);
  667. tx_skb_fail:
  668. dma_free_coherent(NULL,
  669. sizeof(struct txbd8)*priv->tx_ring_size
  670. + sizeof(struct rxbd8)*priv->rx_ring_size,
  671. priv->tx_bd_base,
  672. gfar_read(&regs->tbase));
  673. if (priv->mii_info->phyinfo->close)
  674. priv->mii_info->phyinfo->close(priv->mii_info);
  675. kfree(priv->mii_info);
  676. return err;
  677. }
  678. /* Called when something needs to use the ethernet device */
  679. /* Returns 0 for success. */
  680. static int gfar_enet_open(struct net_device *dev)
  681. {
  682. int err;
  683. /* Initialize a bunch of registers */
  684. init_registers(dev);
  685. gfar_set_mac_address(dev);
  686. err = init_phy(dev);
  687. if(err)
  688. return err;
  689. err = startup_gfar(dev);
  690. netif_start_queue(dev);
  691. return err;
  692. }
  693. /* This is called by the kernel when a frame is ready for transmission. */
  694. /* It is pointed to by the dev->hard_start_xmit function pointer */
  695. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
  696. {
  697. struct gfar_private *priv = netdev_priv(dev);
  698. struct txbd8 *txbdp;
  699. /* Update transmit stats */
  700. priv->stats.tx_bytes += skb->len;
  701. /* Lock priv now */
  702. spin_lock_irq(&priv->lock);
  703. /* Point at the first free tx descriptor */
  704. txbdp = priv->cur_tx;
  705. /* Clear all but the WRAP status flags */
  706. txbdp->status &= TXBD_WRAP;
  707. /* Set buffer length and pointer */
  708. txbdp->length = skb->len;
  709. txbdp->bufPtr = dma_map_single(NULL, skb->data,
  710. skb->len, DMA_TO_DEVICE);
  711. /* Save the skb pointer so we can free it later */
  712. priv->tx_skbuff[priv->skb_curtx] = skb;
  713. /* Update the current skb pointer (wrapping if this was the last) */
  714. priv->skb_curtx =
  715. (priv->skb_curtx + 1) & TX_RING_MOD_MASK(priv->tx_ring_size);
  716. /* Flag the BD as interrupt-causing */
  717. txbdp->status |= TXBD_INTERRUPT;
  718. /* Flag the BD as ready to go, last in frame, and */
  719. /* in need of CRC */
  720. txbdp->status |= (TXBD_READY | TXBD_LAST | TXBD_CRC);
  721. dev->trans_start = jiffies;
  722. /* If this was the last BD in the ring, the next one */
  723. /* is at the beginning of the ring */
  724. if (txbdp->status & TXBD_WRAP)
  725. txbdp = priv->tx_bd_base;
  726. else
  727. txbdp++;
  728. /* If the next BD still needs to be cleaned up, then the bds
  729. are full. We need to tell the kernel to stop sending us stuff. */
  730. if (txbdp == priv->dirty_tx) {
  731. netif_stop_queue(dev);
  732. priv->stats.tx_fifo_errors++;
  733. }
  734. /* Update the current txbd to the next one */
  735. priv->cur_tx = txbdp;
  736. /* Tell the DMA to go go go */
  737. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  738. /* Unlock priv */
  739. spin_unlock_irq(&priv->lock);
  740. return 0;
  741. }
  742. /* Stops the kernel queue, and halts the controller */
  743. static int gfar_close(struct net_device *dev)
  744. {
  745. struct gfar_private *priv = netdev_priv(dev);
  746. stop_gfar(dev);
  747. /* Shutdown the PHY */
  748. if (priv->mii_info->phyinfo->close)
  749. priv->mii_info->phyinfo->close(priv->mii_info);
  750. kfree(priv->mii_info);
  751. netif_stop_queue(dev);
  752. return 0;
  753. }
  754. /* returns a net_device_stats structure pointer */
  755. static struct net_device_stats * gfar_get_stats(struct net_device *dev)
  756. {
  757. struct gfar_private *priv = netdev_priv(dev);
  758. return &(priv->stats);
  759. }
  760. /* Changes the mac address if the controller is not running. */
  761. int gfar_set_mac_address(struct net_device *dev)
  762. {
  763. struct gfar_private *priv = netdev_priv(dev);
  764. int i;
  765. char tmpbuf[MAC_ADDR_LEN];
  766. u32 tempval;
  767. /* Now copy it into the mac registers backwards, cuz */
  768. /* little endian is silly */
  769. for (i = 0; i < MAC_ADDR_LEN; i++)
  770. tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->dev_addr[i];
  771. gfar_write(&priv->regs->macstnaddr1, *((u32 *) (tmpbuf)));
  772. tempval = *((u32 *) (tmpbuf + 4));
  773. gfar_write(&priv->regs->macstnaddr2, tempval);
  774. return 0;
  775. }
  776. static int gfar_change_mtu(struct net_device *dev, int new_mtu)
  777. {
  778. int tempsize, tempval;
  779. struct gfar_private *priv = netdev_priv(dev);
  780. int oldsize = priv->rx_buffer_size;
  781. int frame_size = new_mtu + 18;
  782. if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
  783. printk(KERN_ERR "%s: Invalid MTU setting\n", dev->name);
  784. return -EINVAL;
  785. }
  786. tempsize =
  787. (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
  788. INCREMENTAL_BUFFER_SIZE;
  789. /* Only stop and start the controller if it isn't already
  790. * stopped */
  791. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  792. stop_gfar(dev);
  793. priv->rx_buffer_size = tempsize;
  794. dev->mtu = new_mtu;
  795. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  796. gfar_write(&priv->regs->maxfrm, priv->rx_buffer_size);
  797. /* If the mtu is larger than the max size for standard
  798. * ethernet frames (ie, a jumbo frame), then set maccfg2
  799. * to allow huge frames, and to check the length */
  800. tempval = gfar_read(&priv->regs->maccfg2);
  801. if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE)
  802. tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  803. else
  804. tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  805. gfar_write(&priv->regs->maccfg2, tempval);
  806. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  807. startup_gfar(dev);
  808. return 0;
  809. }
  810. /* gfar_timeout gets called when a packet has not been
  811. * transmitted after a set amount of time.
  812. * For now, assume that clearing out all the structures, and
  813. * starting over will fix the problem. */
  814. static void gfar_timeout(struct net_device *dev)
  815. {
  816. struct gfar_private *priv = netdev_priv(dev);
  817. priv->stats.tx_errors++;
  818. if (dev->flags & IFF_UP) {
  819. stop_gfar(dev);
  820. startup_gfar(dev);
  821. }
  822. netif_schedule(dev);
  823. }
  824. /* Interrupt Handler for Transmit complete */
  825. static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs)
  826. {
  827. struct net_device *dev = (struct net_device *) dev_id;
  828. struct gfar_private *priv = netdev_priv(dev);
  829. struct txbd8 *bdp;
  830. /* Clear IEVENT */
  831. gfar_write(&priv->regs->ievent, IEVENT_TX_MASK);
  832. /* Lock priv */
  833. spin_lock(&priv->lock);
  834. bdp = priv->dirty_tx;
  835. while ((bdp->status & TXBD_READY) == 0) {
  836. /* If dirty_tx and cur_tx are the same, then either the */
  837. /* ring is empty or full now (it could only be full in the beginning, */
  838. /* obviously). If it is empty, we are done. */
  839. if ((bdp == priv->cur_tx) && (netif_queue_stopped(dev) == 0))
  840. break;
  841. priv->stats.tx_packets++;
  842. /* Deferred means some collisions occurred during transmit, */
  843. /* but we eventually sent the packet. */
  844. if (bdp->status & TXBD_DEF)
  845. priv->stats.collisions++;
  846. /* Free the sk buffer associated with this TxBD */
  847. dev_kfree_skb_irq(priv->tx_skbuff[priv->skb_dirtytx]);
  848. priv->tx_skbuff[priv->skb_dirtytx] = NULL;
  849. priv->skb_dirtytx =
  850. (priv->skb_dirtytx +
  851. 1) & TX_RING_MOD_MASK(priv->tx_ring_size);
  852. /* update bdp to point at next bd in the ring (wrapping if necessary) */
  853. if (bdp->status & TXBD_WRAP)
  854. bdp = priv->tx_bd_base;
  855. else
  856. bdp++;
  857. /* Move dirty_tx to be the next bd */
  858. priv->dirty_tx = bdp;
  859. /* We freed a buffer, so now we can restart transmission */
  860. if (netif_queue_stopped(dev))
  861. netif_wake_queue(dev);
  862. } /* while ((bdp->status & TXBD_READY) == 0) */
  863. /* If we are coalescing the interrupts, reset the timer */
  864. /* Otherwise, clear it */
  865. if (priv->txcoalescing)
  866. gfar_write(&priv->regs->txic,
  867. mk_ic_value(priv->txcount, priv->txtime));
  868. else
  869. gfar_write(&priv->regs->txic, 0);
  870. spin_unlock(&priv->lock);
  871. return IRQ_HANDLED;
  872. }
  873. struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
  874. {
  875. struct gfar_private *priv = netdev_priv(dev);
  876. struct sk_buff *skb = NULL;
  877. unsigned int timeout = SKB_ALLOC_TIMEOUT;
  878. /* We have to allocate the skb, so keep trying till we succeed */
  879. while ((!skb) && timeout--)
  880. skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT);
  881. if (skb == NULL)
  882. return NULL;
  883. /* We need the data buffer to be aligned properly. We will reserve
  884. * as many bytes as needed to align the data properly
  885. */
  886. skb_reserve(skb,
  887. RXBUF_ALIGNMENT -
  888. (((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1)));
  889. skb->dev = dev;
  890. bdp->bufPtr = dma_map_single(NULL, skb->data,
  891. priv->rx_buffer_size + RXBUF_ALIGNMENT,
  892. DMA_FROM_DEVICE);
  893. bdp->length = 0;
  894. /* Mark the buffer empty */
  895. bdp->status |= (RXBD_EMPTY | RXBD_INTERRUPT);
  896. return skb;
  897. }
  898. static inline void count_errors(unsigned short status, struct gfar_private *priv)
  899. {
  900. struct net_device_stats *stats = &priv->stats;
  901. struct gfar_extra_stats *estats = &priv->extra_stats;
  902. /* If the packet was truncated, none of the other errors
  903. * matter */
  904. if (status & RXBD_TRUNCATED) {
  905. stats->rx_length_errors++;
  906. estats->rx_trunc++;
  907. return;
  908. }
  909. /* Count the errors, if there were any */
  910. if (status & (RXBD_LARGE | RXBD_SHORT)) {
  911. stats->rx_length_errors++;
  912. if (status & RXBD_LARGE)
  913. estats->rx_large++;
  914. else
  915. estats->rx_short++;
  916. }
  917. if (status & RXBD_NONOCTET) {
  918. stats->rx_frame_errors++;
  919. estats->rx_nonoctet++;
  920. }
  921. if (status & RXBD_CRCERR) {
  922. estats->rx_crcerr++;
  923. stats->rx_crc_errors++;
  924. }
  925. if (status & RXBD_OVERRUN) {
  926. estats->rx_overrun++;
  927. stats->rx_crc_errors++;
  928. }
  929. }
  930. irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs)
  931. {
  932. struct net_device *dev = (struct net_device *) dev_id;
  933. struct gfar_private *priv = netdev_priv(dev);
  934. #ifdef CONFIG_GFAR_NAPI
  935. u32 tempval;
  936. #endif
  937. /* Clear IEVENT, so rx interrupt isn't called again
  938. * because of this interrupt */
  939. gfar_write(&priv->regs->ievent, IEVENT_RX_MASK);
  940. /* support NAPI */
  941. #ifdef CONFIG_GFAR_NAPI
  942. if (netif_rx_schedule_prep(dev)) {
  943. tempval = gfar_read(&priv->regs->imask);
  944. tempval &= IMASK_RX_DISABLED;
  945. gfar_write(&priv->regs->imask, tempval);
  946. __netif_rx_schedule(dev);
  947. } else {
  948. #ifdef VERBOSE_GFAR_ERRORS
  949. printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
  950. dev->name, gfar_read(&priv->regs->ievent),
  951. gfar_read(&priv->regs->imask));
  952. #endif
  953. }
  954. #else
  955. spin_lock(&priv->lock);
  956. gfar_clean_rx_ring(dev, priv->rx_ring_size);
  957. /* If we are coalescing interrupts, update the timer */
  958. /* Otherwise, clear it */
  959. if (priv->rxcoalescing)
  960. gfar_write(&priv->regs->rxic,
  961. mk_ic_value(priv->rxcount, priv->rxtime));
  962. else
  963. gfar_write(&priv->regs->rxic, 0);
  964. /* Just in case we need to wake the ring param changer */
  965. priv->rxclean = 1;
  966. spin_unlock(&priv->lock);
  967. #endif
  968. return IRQ_HANDLED;
  969. }
  970. /* gfar_process_frame() -- handle one incoming packet if skb
  971. * isn't NULL. */
  972. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  973. int length)
  974. {
  975. struct gfar_private *priv = netdev_priv(dev);
  976. if (skb == NULL) {
  977. #ifdef BRIEF_GFAR_ERRORS
  978. printk(KERN_WARNING "%s: Missing skb!!.\n",
  979. dev->name);
  980. #endif
  981. priv->stats.rx_dropped++;
  982. priv->extra_stats.rx_skbmissing++;
  983. } else {
  984. /* Prep the skb for the packet */
  985. skb_put(skb, length);
  986. /* Tell the skb what kind of packet this is */
  987. skb->protocol = eth_type_trans(skb, dev);
  988. /* Send the packet up the stack */
  989. if (RECEIVE(skb) == NET_RX_DROP) {
  990. priv->extra_stats.kernel_dropped++;
  991. }
  992. }
  993. return 0;
  994. }
  995. /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
  996. * until the budget/quota has been reached. Returns the number
  997. * of frames handled
  998. */
  999. static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
  1000. {
  1001. struct rxbd8 *bdp;
  1002. struct sk_buff *skb;
  1003. u16 pkt_len;
  1004. int howmany = 0;
  1005. struct gfar_private *priv = netdev_priv(dev);
  1006. /* Get the first full descriptor */
  1007. bdp = priv->cur_rx;
  1008. while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
  1009. skb = priv->rx_skbuff[priv->skb_currx];
  1010. if (!(bdp->status &
  1011. (RXBD_LARGE | RXBD_SHORT | RXBD_NONOCTET
  1012. | RXBD_CRCERR | RXBD_OVERRUN | RXBD_TRUNCATED))) {
  1013. /* Increment the number of packets */
  1014. priv->stats.rx_packets++;
  1015. howmany++;
  1016. /* Remove the FCS from the packet length */
  1017. pkt_len = bdp->length - 4;
  1018. gfar_process_frame(dev, skb, pkt_len);
  1019. priv->stats.rx_bytes += pkt_len;
  1020. } else {
  1021. count_errors(bdp->status, priv);
  1022. if (skb)
  1023. dev_kfree_skb_any(skb);
  1024. priv->rx_skbuff[priv->skb_currx] = NULL;
  1025. }
  1026. dev->last_rx = jiffies;
  1027. /* Clear the status flags for this buffer */
  1028. bdp->status &= ~RXBD_STATS;
  1029. /* Add another skb for the future */
  1030. skb = gfar_new_skb(dev, bdp);
  1031. priv->rx_skbuff[priv->skb_currx] = skb;
  1032. /* Update to the next pointer */
  1033. if (bdp->status & RXBD_WRAP)
  1034. bdp = priv->rx_bd_base;
  1035. else
  1036. bdp++;
  1037. /* update to point at the next skb */
  1038. priv->skb_currx =
  1039. (priv->skb_currx +
  1040. 1) & RX_RING_MOD_MASK(priv->rx_ring_size);
  1041. }
  1042. /* Update the current rxbd pointer to be the next one */
  1043. priv->cur_rx = bdp;
  1044. /* If no packets have arrived since the
  1045. * last one we processed, clear the IEVENT RX and
  1046. * BSY bits so that another interrupt won't be
  1047. * generated when we set IMASK */
  1048. if (bdp->status & RXBD_EMPTY)
  1049. gfar_write(&priv->regs->ievent, IEVENT_RX_MASK);
  1050. return howmany;
  1051. }
  1052. #ifdef CONFIG_GFAR_NAPI
  1053. static int gfar_poll(struct net_device *dev, int *budget)
  1054. {
  1055. int howmany;
  1056. struct gfar_private *priv = netdev_priv(dev);
  1057. int rx_work_limit = *budget;
  1058. if (rx_work_limit > dev->quota)
  1059. rx_work_limit = dev->quota;
  1060. howmany = gfar_clean_rx_ring(dev, rx_work_limit);
  1061. dev->quota -= howmany;
  1062. rx_work_limit -= howmany;
  1063. *budget -= howmany;
  1064. if (rx_work_limit >= 0) {
  1065. netif_rx_complete(dev);
  1066. /* Clear the halt bit in RSTAT */
  1067. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1068. gfar_write(&priv->regs->imask, IMASK_DEFAULT);
  1069. /* If we are coalescing interrupts, update the timer */
  1070. /* Otherwise, clear it */
  1071. if (priv->rxcoalescing)
  1072. gfar_write(&priv->regs->rxic,
  1073. mk_ic_value(priv->rxcount, priv->rxtime));
  1074. else
  1075. gfar_write(&priv->regs->rxic, 0);
  1076. /* Signal to the ring size changer that it's safe to go */
  1077. priv->rxclean = 1;
  1078. }
  1079. return (rx_work_limit < 0) ? 1 : 0;
  1080. }
  1081. #endif
  1082. /* The interrupt handler for devices with one interrupt */
  1083. static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1084. {
  1085. struct net_device *dev = dev_id;
  1086. struct gfar_private *priv = netdev_priv(dev);
  1087. /* Save ievent for future reference */
  1088. u32 events = gfar_read(&priv->regs->ievent);
  1089. /* Clear IEVENT */
  1090. gfar_write(&priv->regs->ievent, events);
  1091. /* Check for reception */
  1092. if ((events & IEVENT_RXF0) || (events & IEVENT_RXB0))
  1093. gfar_receive(irq, dev_id, regs);
  1094. /* Check for transmit completion */
  1095. if ((events & IEVENT_TXF) || (events & IEVENT_TXB))
  1096. gfar_transmit(irq, dev_id, regs);
  1097. /* Update error statistics */
  1098. if (events & IEVENT_TXE) {
  1099. priv->stats.tx_errors++;
  1100. if (events & IEVENT_LC)
  1101. priv->stats.tx_window_errors++;
  1102. if (events & IEVENT_CRL)
  1103. priv->stats.tx_aborted_errors++;
  1104. if (events & IEVENT_XFUN) {
  1105. #ifdef VERBOSE_GFAR_ERRORS
  1106. printk(KERN_WARNING "%s: tx underrun. dropped packet\n",
  1107. dev->name);
  1108. #endif
  1109. priv->stats.tx_dropped++;
  1110. priv->extra_stats.tx_underrun++;
  1111. /* Reactivate the Tx Queues */
  1112. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1113. }
  1114. }
  1115. if (events & IEVENT_BSY) {
  1116. priv->stats.rx_errors++;
  1117. priv->extra_stats.rx_bsy++;
  1118. gfar_receive(irq, dev_id, regs);
  1119. #ifndef CONFIG_GFAR_NAPI
  1120. /* Clear the halt bit in RSTAT */
  1121. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1122. #endif
  1123. #ifdef VERBOSE_GFAR_ERRORS
  1124. printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name,
  1125. gfar_read(&priv->regs->rstat));
  1126. #endif
  1127. }
  1128. if (events & IEVENT_BABR) {
  1129. priv->stats.rx_errors++;
  1130. priv->extra_stats.rx_babr++;
  1131. #ifdef VERBOSE_GFAR_ERRORS
  1132. printk(KERN_DEBUG "%s: babbling error\n", dev->name);
  1133. #endif
  1134. }
  1135. if (events & IEVENT_EBERR) {
  1136. priv->extra_stats.eberr++;
  1137. #ifdef VERBOSE_GFAR_ERRORS
  1138. printk(KERN_DEBUG "%s: EBERR\n", dev->name);
  1139. #endif
  1140. }
  1141. if (events & IEVENT_RXC) {
  1142. #ifdef VERBOSE_GFAR_ERRORS
  1143. printk(KERN_DEBUG "%s: control frame\n", dev->name);
  1144. #endif
  1145. }
  1146. if (events & IEVENT_BABT) {
  1147. priv->extra_stats.tx_babt++;
  1148. #ifdef VERBOSE_GFAR_ERRORS
  1149. printk(KERN_DEBUG "%s: babt error\n", dev->name);
  1150. #endif
  1151. }
  1152. return IRQ_HANDLED;
  1153. }
  1154. static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1155. {
  1156. struct net_device *dev = (struct net_device *) dev_id;
  1157. struct gfar_private *priv = netdev_priv(dev);
  1158. /* Clear the interrupt */
  1159. mii_clear_phy_interrupt(priv->mii_info);
  1160. /* Disable PHY interrupts */
  1161. mii_configure_phy_interrupt(priv->mii_info,
  1162. MII_INTERRUPT_DISABLED);
  1163. /* Schedule the phy change */
  1164. schedule_work(&priv->tq);
  1165. return IRQ_HANDLED;
  1166. }
  1167. /* Scheduled by the phy_interrupt/timer to handle PHY changes */
  1168. static void gfar_phy_change(void *data)
  1169. {
  1170. struct net_device *dev = (struct net_device *) data;
  1171. struct gfar_private *priv = netdev_priv(dev);
  1172. int result = 0;
  1173. /* Delay to give the PHY a chance to change the
  1174. * register state */
  1175. msleep(1);
  1176. /* Update the link, speed, duplex */
  1177. result = priv->mii_info->phyinfo->read_status(priv->mii_info);
  1178. /* Adjust the known status as long as the link
  1179. * isn't still coming up */
  1180. if((0 == result) || (priv->mii_info->link == 0))
  1181. adjust_link(dev);
  1182. /* Reenable interrupts, if needed */
  1183. if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR)
  1184. mii_configure_phy_interrupt(priv->mii_info,
  1185. MII_INTERRUPT_ENABLED);
  1186. }
  1187. /* Called every so often on systems that don't interrupt
  1188. * the core for PHY changes */
  1189. static void gfar_phy_timer(unsigned long data)
  1190. {
  1191. struct net_device *dev = (struct net_device *) data;
  1192. struct gfar_private *priv = netdev_priv(dev);
  1193. schedule_work(&priv->tq);
  1194. mod_timer(&priv->phy_info_timer, jiffies +
  1195. GFAR_PHY_CHANGE_TIME * HZ);
  1196. }
  1197. /* Keep trying aneg for some time
  1198. * If, after GFAR_AN_TIMEOUT seconds, it has not
  1199. * finished, we switch to forced.
  1200. * Either way, once the process has completed, we either
  1201. * request the interrupt, or switch the timer over to
  1202. * using gfar_phy_timer to check status */
  1203. static void gfar_phy_startup_timer(unsigned long data)
  1204. {
  1205. int result;
  1206. static int secondary = GFAR_AN_TIMEOUT;
  1207. struct gfar_mii_info *mii_info = (struct gfar_mii_info *)data;
  1208. struct gfar_private *priv = netdev_priv(mii_info->dev);
  1209. /* Configure the Auto-negotiation */
  1210. result = mii_info->phyinfo->config_aneg(mii_info);
  1211. /* If autonegotiation failed to start, and
  1212. * we haven't timed out, reset the timer, and return */
  1213. if (result && secondary--) {
  1214. mod_timer(&priv->phy_info_timer, jiffies + HZ);
  1215. return;
  1216. } else if (result) {
  1217. /* Couldn't start autonegotiation.
  1218. * Try switching to forced */
  1219. mii_info->autoneg = 0;
  1220. result = mii_info->phyinfo->config_aneg(mii_info);
  1221. /* Forcing failed! Give up */
  1222. if(result) {
  1223. printk(KERN_ERR "%s: Forcing failed!\n",
  1224. mii_info->dev->name);
  1225. return;
  1226. }
  1227. }
  1228. /* Kill the timer so it can be restarted */
  1229. del_timer_sync(&priv->phy_info_timer);
  1230. /* Grab the PHY interrupt, if necessary/possible */
  1231. if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
  1232. if (request_irq(priv->einfo->interruptPHY,
  1233. phy_interrupt,
  1234. SA_SHIRQ,
  1235. "phy_interrupt",
  1236. mii_info->dev) < 0) {
  1237. printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n",
  1238. mii_info->dev->name,
  1239. priv->einfo->interruptPHY);
  1240. } else {
  1241. mii_configure_phy_interrupt(priv->mii_info,
  1242. MII_INTERRUPT_ENABLED);
  1243. return;
  1244. }
  1245. }
  1246. /* Start the timer again, this time in order to
  1247. * handle a change in status */
  1248. init_timer(&priv->phy_info_timer);
  1249. priv->phy_info_timer.function = &gfar_phy_timer;
  1250. priv->phy_info_timer.data = (unsigned long) mii_info->dev;
  1251. mod_timer(&priv->phy_info_timer, jiffies +
  1252. GFAR_PHY_CHANGE_TIME * HZ);
  1253. }
  1254. /* Called every time the controller might need to be made
  1255. * aware of new link state. The PHY code conveys this
  1256. * information through variables in the priv structure, and this
  1257. * function converts those variables into the appropriate
  1258. * register values, and can bring down the device if needed.
  1259. */
  1260. static void adjust_link(struct net_device *dev)
  1261. {
  1262. struct gfar_private *priv = netdev_priv(dev);
  1263. struct gfar *regs = priv->regs;
  1264. u32 tempval;
  1265. struct gfar_mii_info *mii_info = priv->mii_info;
  1266. if (mii_info->link) {
  1267. /* Now we make sure that we can be in full duplex mode.
  1268. * If not, we operate in half-duplex mode. */
  1269. if (mii_info->duplex != priv->oldduplex) {
  1270. if (!(mii_info->duplex)) {
  1271. tempval = gfar_read(&regs->maccfg2);
  1272. tempval &= ~(MACCFG2_FULL_DUPLEX);
  1273. gfar_write(&regs->maccfg2, tempval);
  1274. printk(KERN_INFO "%s: Half Duplex\n",
  1275. dev->name);
  1276. } else {
  1277. tempval = gfar_read(&regs->maccfg2);
  1278. tempval |= MACCFG2_FULL_DUPLEX;
  1279. gfar_write(&regs->maccfg2, tempval);
  1280. printk(KERN_INFO "%s: Full Duplex\n",
  1281. dev->name);
  1282. }
  1283. priv->oldduplex = mii_info->duplex;
  1284. }
  1285. if (mii_info->speed != priv->oldspeed) {
  1286. switch (mii_info->speed) {
  1287. case 1000:
  1288. tempval = gfar_read(&regs->maccfg2);
  1289. tempval =
  1290. ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
  1291. gfar_write(&regs->maccfg2, tempval);
  1292. break;
  1293. case 100:
  1294. case 10:
  1295. tempval = gfar_read(&regs->maccfg2);
  1296. tempval =
  1297. ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
  1298. gfar_write(&regs->maccfg2, tempval);
  1299. break;
  1300. default:
  1301. printk(KERN_WARNING
  1302. "%s: Ack! Speed (%d) is not 10/100/1000!\n",
  1303. dev->name, mii_info->speed);
  1304. break;
  1305. }
  1306. printk(KERN_INFO "%s: Speed %dBT\n", dev->name,
  1307. mii_info->speed);
  1308. priv->oldspeed = mii_info->speed;
  1309. }
  1310. if (!priv->oldlink) {
  1311. printk(KERN_INFO "%s: Link is up\n", dev->name);
  1312. priv->oldlink = 1;
  1313. netif_carrier_on(dev);
  1314. netif_schedule(dev);
  1315. }
  1316. } else {
  1317. if (priv->oldlink) {
  1318. printk(KERN_INFO "%s: Link is down\n", dev->name);
  1319. priv->oldlink = 0;
  1320. priv->oldspeed = 0;
  1321. priv->oldduplex = -1;
  1322. netif_carrier_off(dev);
  1323. }
  1324. }
  1325. }
  1326. /* Update the hash table based on the current list of multicast
  1327. * addresses we subscribe to. Also, change the promiscuity of
  1328. * the device based on the flags (this function is called
  1329. * whenever dev->flags is changed */
  1330. static void gfar_set_multi(struct net_device *dev)
  1331. {
  1332. struct dev_mc_list *mc_ptr;
  1333. struct gfar_private *priv = netdev_priv(dev);
  1334. struct gfar *regs = priv->regs;
  1335. u32 tempval;
  1336. if(dev->flags & IFF_PROMISC) {
  1337. printk(KERN_INFO "%s: Entering promiscuous mode.\n",
  1338. dev->name);
  1339. /* Set RCTRL to PROM */
  1340. tempval = gfar_read(&regs->rctrl);
  1341. tempval |= RCTRL_PROM;
  1342. gfar_write(&regs->rctrl, tempval);
  1343. } else {
  1344. /* Set RCTRL to not PROM */
  1345. tempval = gfar_read(&regs->rctrl);
  1346. tempval &= ~(RCTRL_PROM);
  1347. gfar_write(&regs->rctrl, tempval);
  1348. }
  1349. if(dev->flags & IFF_ALLMULTI) {
  1350. /* Set the hash to rx all multicast frames */
  1351. gfar_write(&regs->gaddr0, 0xffffffff);
  1352. gfar_write(&regs->gaddr1, 0xffffffff);
  1353. gfar_write(&regs->gaddr2, 0xffffffff);
  1354. gfar_write(&regs->gaddr3, 0xffffffff);
  1355. gfar_write(&regs->gaddr4, 0xffffffff);
  1356. gfar_write(&regs->gaddr5, 0xffffffff);
  1357. gfar_write(&regs->gaddr6, 0xffffffff);
  1358. gfar_write(&regs->gaddr7, 0xffffffff);
  1359. } else {
  1360. /* zero out the hash */
  1361. gfar_write(&regs->gaddr0, 0x0);
  1362. gfar_write(&regs->gaddr1, 0x0);
  1363. gfar_write(&regs->gaddr2, 0x0);
  1364. gfar_write(&regs->gaddr3, 0x0);
  1365. gfar_write(&regs->gaddr4, 0x0);
  1366. gfar_write(&regs->gaddr5, 0x0);
  1367. gfar_write(&regs->gaddr6, 0x0);
  1368. gfar_write(&regs->gaddr7, 0x0);
  1369. if(dev->mc_count == 0)
  1370. return;
  1371. /* Parse the list, and set the appropriate bits */
  1372. for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
  1373. gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
  1374. }
  1375. }
  1376. return;
  1377. }
  1378. /* Set the appropriate hash bit for the given addr */
  1379. /* The algorithm works like so:
  1380. * 1) Take the Destination Address (ie the multicast address), and
  1381. * do a CRC on it (little endian), and reverse the bits of the
  1382. * result.
  1383. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1384. * table. The table is controlled through 8 32-bit registers:
  1385. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1386. * gaddr7. This means that the 3 most significant bits in the
  1387. * hash index which gaddr register to use, and the 5 other bits
  1388. * indicate which bit (assuming an IBM numbering scheme, which
  1389. * for PowerPC (tm) is usually the case) in the register holds
  1390. * the entry. */
  1391. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
  1392. {
  1393. u32 tempval;
  1394. struct gfar_private *priv = netdev_priv(dev);
  1395. struct gfar *regs = priv->regs;
  1396. u32 *hash = &regs->gaddr0;
  1397. u32 result = ether_crc(MAC_ADDR_LEN, addr);
  1398. u8 whichreg = ((result >> 29) & 0x7);
  1399. u8 whichbit = ((result >> 24) & 0x1f);
  1400. u32 value = (1 << (31-whichbit));
  1401. tempval = gfar_read(&hash[whichreg]);
  1402. tempval |= value;
  1403. gfar_write(&hash[whichreg], tempval);
  1404. return;
  1405. }
  1406. /* GFAR error interrupt handler */
  1407. static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
  1408. {
  1409. struct net_device *dev = dev_id;
  1410. struct gfar_private *priv = netdev_priv(dev);
  1411. /* Save ievent for future reference */
  1412. u32 events = gfar_read(&priv->regs->ievent);
  1413. /* Clear IEVENT */
  1414. gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK);
  1415. /* Hmm... */
  1416. #if defined (BRIEF_GFAR_ERRORS) || defined (VERBOSE_GFAR_ERRORS)
  1417. printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
  1418. dev->name, events, gfar_read(&priv->regs->imask));
  1419. #endif
  1420. /* Update the error counters */
  1421. if (events & IEVENT_TXE) {
  1422. priv->stats.tx_errors++;
  1423. if (events & IEVENT_LC)
  1424. priv->stats.tx_window_errors++;
  1425. if (events & IEVENT_CRL)
  1426. priv->stats.tx_aborted_errors++;
  1427. if (events & IEVENT_XFUN) {
  1428. #ifdef VERBOSE_GFAR_ERRORS
  1429. printk(KERN_DEBUG "%s: underrun. packet dropped.\n",
  1430. dev->name);
  1431. #endif
  1432. priv->stats.tx_dropped++;
  1433. priv->extra_stats.tx_underrun++;
  1434. /* Reactivate the Tx Queues */
  1435. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1436. }
  1437. #ifdef VERBOSE_GFAR_ERRORS
  1438. printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
  1439. #endif
  1440. }
  1441. if (events & IEVENT_BSY) {
  1442. priv->stats.rx_errors++;
  1443. priv->extra_stats.rx_bsy++;
  1444. gfar_receive(irq, dev_id, regs);
  1445. #ifndef CONFIG_GFAR_NAPI
  1446. /* Clear the halt bit in RSTAT */
  1447. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1448. #endif
  1449. #ifdef VERBOSE_GFAR_ERRORS
  1450. printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name,
  1451. gfar_read(&priv->regs->rstat));
  1452. #endif
  1453. }
  1454. if (events & IEVENT_BABR) {
  1455. priv->stats.rx_errors++;
  1456. priv->extra_stats.rx_babr++;
  1457. #ifdef VERBOSE_GFAR_ERRORS
  1458. printk(KERN_DEBUG "%s: babbling error\n", dev->name);
  1459. #endif
  1460. }
  1461. if (events & IEVENT_EBERR) {
  1462. priv->extra_stats.eberr++;
  1463. #ifdef VERBOSE_GFAR_ERRORS
  1464. printk(KERN_DEBUG "%s: EBERR\n", dev->name);
  1465. #endif
  1466. }
  1467. if (events & IEVENT_RXC)
  1468. #ifdef VERBOSE_GFAR_ERRORS
  1469. printk(KERN_DEBUG "%s: control frame\n", dev->name);
  1470. #endif
  1471. if (events & IEVENT_BABT) {
  1472. priv->extra_stats.tx_babt++;
  1473. #ifdef VERBOSE_GFAR_ERRORS
  1474. printk(KERN_DEBUG "%s: babt error\n", dev->name);
  1475. #endif
  1476. }
  1477. return IRQ_HANDLED;
  1478. }
  1479. /* Structure for a device driver */
  1480. static struct device_driver gfar_driver = {
  1481. .name = "fsl-gianfar",
  1482. .bus = &platform_bus_type,
  1483. .probe = gfar_probe,
  1484. .remove = gfar_remove,
  1485. };
  1486. static int __init gfar_init(void)
  1487. {
  1488. return driver_register(&gfar_driver);
  1489. }
  1490. static void __exit gfar_exit(void)
  1491. {
  1492. driver_unregister(&gfar_driver);
  1493. }
  1494. module_init(gfar_init);
  1495. module_exit(gfar_exit);