Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / net / gianfar.c
blobe663be7b1a925e0dec78c09236e18a8a5cf234be
1 /*
2 * drivers/net/gianfar.c
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
9 * Author: Andy Fleming
10 * Maintainer: Kumar Gala
12 * Copyright (c) 2002-2006 Freescale Semiconductor, Inc.
13 * Copyright (c) 2007 MontaVista Software, Inc.
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.
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
26 * Theory of operation
28 * The driver is initialized through platform_device. Structures which
29 * define the configuration needed by the board are defined in a
30 * board structure in arch/ppc/platforms (though I do not
31 * discount the possibility that other architectures could one
32 * day be supported.
34 * The Gianfar Ethernet Controller uses a ring of buffer
35 * descriptors. The beginning is indicated by a register
36 * pointing to the physical address of the start of the ring.
37 * The end is determined by a "wrap" bit being set in the
38 * last descriptor of the ring.
40 * When a packet is received, the RXF bit in the
41 * IEVENT register is set, triggering an interrupt when the
42 * corresponding bit in the IMASK register is also set (if
43 * interrupt coalescing is active, then the interrupt may not
44 * happen immediately, but will wait until either a set number
45 * of frames or amount of time have passed). In NAPI, the
46 * interrupt handler will signal there is work to be done, and
47 * exit. Without NAPI, the packet(s) will be handled
48 * immediately. Both methods will start at the last known empty
49 * descriptor, and process every subsequent descriptor until there
50 * are none left with data (NAPI will stop after a set number of
51 * packets to give time to other tasks, but will eventually
52 * process all the packets). The data arrives inside a
53 * pre-allocated skb, and so after the skb is passed up to the
54 * stack, a new skb must be allocated, and the address field in
55 * the buffer descriptor must be updated to indicate this new
56 * skb.
58 * When the kernel requests that a packet be transmitted, the
59 * driver starts where it left off last time, and points the
60 * descriptor at the buffer which was passed in. The driver
61 * then informs the DMA engine that there are packets ready to
62 * be transmitted. Once the controller is finished transmitting
63 * the packet, an interrupt may be triggered (under the same
64 * conditions as for reception, but depending on the TXF bit).
65 * The driver then cleans up the buffer.
68 #include <linux/kernel.h>
69 #include <linux/string.h>
70 #include <linux/errno.h>
71 #include <linux/unistd.h>
72 #include <linux/slab.h>
73 #include <linux/interrupt.h>
74 #include <linux/init.h>
75 #include <linux/delay.h>
76 #include <linux/netdevice.h>
77 #include <linux/etherdevice.h>
78 #include <linux/skbuff.h>
79 #include <linux/if_vlan.h>
80 #include <linux/spinlock.h>
81 #include <linux/mm.h>
82 #include <linux/platform_device.h>
83 #include <linux/ip.h>
84 #include <linux/tcp.h>
85 #include <linux/udp.h>
86 #include <linux/in.h>
88 #include <asm/io.h>
89 #include <asm/irq.h>
90 #include <asm/uaccess.h>
91 #include <linux/module.h>
92 #include <linux/dma-mapping.h>
93 #include <linux/crc32.h>
94 #include <linux/mii.h>
95 #include <linux/phy.h>
97 #include "gianfar.h"
98 #include "gianfar_mii.h"
100 #define TX_TIMEOUT (1*HZ)
101 #define SKB_ALLOC_TIMEOUT 1000000
102 #undef BRIEF_GFAR_ERRORS
103 #undef VERBOSE_GFAR_ERRORS
105 #ifdef CONFIG_GFAR_NAPI
106 #define RECEIVE(x) netif_receive_skb(x)
107 #else
108 #define RECEIVE(x) netif_rx(x)
109 #endif
111 const char gfar_driver_name[] = "Gianfar Ethernet";
112 const char gfar_driver_version[] = "1.3";
114 static int gfar_enet_open(struct net_device *dev);
115 static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
116 static void gfar_timeout(struct net_device *dev);
117 static int gfar_close(struct net_device *dev);
118 struct sk_buff *gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp);
119 static int gfar_set_mac_address(struct net_device *dev);
120 static int gfar_change_mtu(struct net_device *dev, int new_mtu);
121 static irqreturn_t gfar_error(int irq, void *dev_id);
122 static irqreturn_t gfar_transmit(int irq, void *dev_id);
123 static irqreturn_t gfar_interrupt(int irq, void *dev_id);
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 platform_device *pdev);
128 static int gfar_remove(struct platform_device *pdev);
129 static 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 static void gfar_configure_serdes(struct net_device *dev);
133 <<<<<<< HEAD:drivers/net/gianfar.c
134 extern int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id, int regnum, u16 value);
135 extern int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum);
136 =======
137 extern int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id, int regnum, u16 value);
138 extern int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum);
139 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
140 #ifdef CONFIG_GFAR_NAPI
141 static int gfar_poll(struct napi_struct *napi, int budget);
142 #endif
143 #ifdef CONFIG_NET_POLL_CONTROLLER
144 static void gfar_netpoll(struct net_device *dev);
145 #endif
146 int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
147 static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
148 static void gfar_vlan_rx_register(struct net_device *netdev,
149 struct vlan_group *grp);
150 void gfar_halt(struct net_device *dev);
151 void gfar_start(struct net_device *dev);
152 static void gfar_clear_exact_match(struct net_device *dev);
153 static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
155 extern const struct ethtool_ops gfar_ethtool_ops;
157 MODULE_AUTHOR("Freescale Semiconductor, Inc");
158 MODULE_DESCRIPTION("Gianfar Ethernet Driver");
159 MODULE_LICENSE("GPL");
161 /* Returns 1 if incoming frames use an FCB */
162 static inline int gfar_uses_fcb(struct gfar_private *priv)
164 return (priv->vlan_enable || priv->rx_csum_enable);
167 /* Set up the ethernet device structure, private data,
168 * and anything else we need before we start */
169 static int gfar_probe(struct platform_device *pdev)
171 u32 tempval;
172 struct net_device *dev = NULL;
173 struct gfar_private *priv = NULL;
174 struct gianfar_platform_data *einfo;
175 struct resource *r;
176 int err = 0;
177 DECLARE_MAC_BUF(mac);
179 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data;
181 if (NULL == einfo) {
182 printk(KERN_ERR "gfar %d: Missing additional data!\n",
183 pdev->id);
185 return -ENODEV;
188 /* Create an ethernet device instance */
189 dev = alloc_etherdev(sizeof (*priv));
191 if (NULL == dev)
192 return -ENOMEM;
194 priv = netdev_priv(dev);
195 priv->dev = dev;
197 /* Set the info in the priv to the current info */
198 priv->einfo = einfo;
200 /* fill out IRQ fields */
201 if (einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
202 priv->interruptTransmit = platform_get_irq_byname(pdev, "tx");
203 priv->interruptReceive = platform_get_irq_byname(pdev, "rx");
204 priv->interruptError = platform_get_irq_byname(pdev, "error");
205 if (priv->interruptTransmit < 0 || priv->interruptReceive < 0 || priv->interruptError < 0)
206 goto regs_fail;
207 } else {
208 priv->interruptTransmit = platform_get_irq(pdev, 0);
209 if (priv->interruptTransmit < 0)
210 goto regs_fail;
213 /* get a pointer to the register memory */
214 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
215 priv->regs = ioremap(r->start, sizeof (struct gfar));
217 if (NULL == priv->regs) {
218 err = -ENOMEM;
219 goto regs_fail;
222 spin_lock_init(&priv->txlock);
223 spin_lock_init(&priv->rxlock);
225 platform_set_drvdata(pdev, dev);
227 /* Stop the DMA engine now, in case it was running before */
228 /* (The firmware could have used it, and left it running). */
229 /* To do this, we write Graceful Receive Stop and Graceful */
230 /* Transmit Stop, and then wait until the corresponding bits */
231 /* in IEVENT indicate the stops have completed. */
232 tempval = gfar_read(&priv->regs->dmactrl);
233 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
234 gfar_write(&priv->regs->dmactrl, tempval);
236 tempval = gfar_read(&priv->regs->dmactrl);
237 tempval |= (DMACTRL_GRS | DMACTRL_GTS);
238 gfar_write(&priv->regs->dmactrl, tempval);
240 while (!(gfar_read(&priv->regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC)))
241 cpu_relax();
243 /* Reset MAC layer */
244 gfar_write(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
246 tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
247 gfar_write(&priv->regs->maccfg1, tempval);
249 /* Initialize MACCFG2. */
250 gfar_write(&priv->regs->maccfg2, MACCFG2_INIT_SETTINGS);
252 /* Initialize ECNTRL */
253 gfar_write(&priv->regs->ecntrl, ECNTRL_INIT_SETTINGS);
255 /* Copy the station address into the dev structure, */
256 memcpy(dev->dev_addr, einfo->mac_addr, MAC_ADDR_LEN);
258 /* Set the dev->base_addr to the gfar reg region */
259 dev->base_addr = (unsigned long) (priv->regs);
261 SET_NETDEV_DEV(dev, &pdev->dev);
263 /* Fill in the dev structure */
264 dev->open = gfar_enet_open;
265 dev->hard_start_xmit = gfar_start_xmit;
266 dev->tx_timeout = gfar_timeout;
267 dev->watchdog_timeo = TX_TIMEOUT;
268 #ifdef CONFIG_GFAR_NAPI
269 netif_napi_add(dev, &priv->napi, gfar_poll, GFAR_DEV_WEIGHT);
270 #endif
271 #ifdef CONFIG_NET_POLL_CONTROLLER
272 dev->poll_controller = gfar_netpoll;
273 #endif
274 dev->stop = gfar_close;
275 dev->change_mtu = gfar_change_mtu;
276 dev->mtu = 1500;
277 dev->set_multicast_list = gfar_set_multi;
279 dev->ethtool_ops = &gfar_ethtool_ops;
281 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
282 priv->rx_csum_enable = 1;
283 dev->features |= NETIF_F_IP_CSUM;
284 } else
285 priv->rx_csum_enable = 0;
287 priv->vlgrp = NULL;
289 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
290 dev->vlan_rx_register = gfar_vlan_rx_register;
292 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
294 priv->vlan_enable = 1;
297 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
298 priv->extended_hash = 1;
299 priv->hash_width = 9;
301 priv->hash_regs[0] = &priv->regs->igaddr0;
302 priv->hash_regs[1] = &priv->regs->igaddr1;
303 priv->hash_regs[2] = &priv->regs->igaddr2;
304 priv->hash_regs[3] = &priv->regs->igaddr3;
305 priv->hash_regs[4] = &priv->regs->igaddr4;
306 priv->hash_regs[5] = &priv->regs->igaddr5;
307 priv->hash_regs[6] = &priv->regs->igaddr6;
308 priv->hash_regs[7] = &priv->regs->igaddr7;
309 priv->hash_regs[8] = &priv->regs->gaddr0;
310 priv->hash_regs[9] = &priv->regs->gaddr1;
311 priv->hash_regs[10] = &priv->regs->gaddr2;
312 priv->hash_regs[11] = &priv->regs->gaddr3;
313 priv->hash_regs[12] = &priv->regs->gaddr4;
314 priv->hash_regs[13] = &priv->regs->gaddr5;
315 priv->hash_regs[14] = &priv->regs->gaddr6;
316 priv->hash_regs[15] = &priv->regs->gaddr7;
318 } else {
319 priv->extended_hash = 0;
320 priv->hash_width = 8;
322 priv->hash_regs[0] = &priv->regs->gaddr0;
323 priv->hash_regs[1] = &priv->regs->gaddr1;
324 priv->hash_regs[2] = &priv->regs->gaddr2;
325 priv->hash_regs[3] = &priv->regs->gaddr3;
326 priv->hash_regs[4] = &priv->regs->gaddr4;
327 priv->hash_regs[5] = &priv->regs->gaddr5;
328 priv->hash_regs[6] = &priv->regs->gaddr6;
329 priv->hash_regs[7] = &priv->regs->gaddr7;
332 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
333 priv->padding = DEFAULT_PADDING;
334 else
335 priv->padding = 0;
337 if (dev->features & NETIF_F_IP_CSUM)
338 dev->hard_header_len += GMAC_FCB_LEN;
340 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
341 priv->tx_ring_size = DEFAULT_TX_RING_SIZE;
342 priv->rx_ring_size = DEFAULT_RX_RING_SIZE;
344 priv->txcoalescing = DEFAULT_TX_COALESCE;
345 priv->txcount = DEFAULT_TXCOUNT;
346 priv->txtime = DEFAULT_TXTIME;
347 priv->rxcoalescing = DEFAULT_RX_COALESCE;
348 priv->rxcount = DEFAULT_RXCOUNT;
349 priv->rxtime = DEFAULT_RXTIME;
351 /* Enable most messages by default */
352 priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
354 err = register_netdev(dev);
356 if (err) {
357 printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
358 dev->name);
359 goto register_fail;
362 /* Create all the sysfs files */
363 gfar_init_sysfs(dev);
365 /* Print out the device info */
366 printk(KERN_INFO DEVICE_NAME "%s\n",
367 dev->name, print_mac(mac, dev->dev_addr));
369 /* Even more device info helps when determining which kernel */
370 /* provided which set of benchmarks. */
371 #ifdef CONFIG_GFAR_NAPI
372 printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name);
373 #else
374 printk(KERN_INFO "%s: Running with NAPI disabled\n", dev->name);
375 #endif
376 printk(KERN_INFO "%s: %d/%d RX/TX BD ring size\n",
377 dev->name, priv->rx_ring_size, priv->tx_ring_size);
379 return 0;
381 register_fail:
382 iounmap(priv->regs);
383 regs_fail:
384 free_netdev(dev);
385 return err;
388 static int gfar_remove(struct platform_device *pdev)
390 struct net_device *dev = platform_get_drvdata(pdev);
391 struct gfar_private *priv = netdev_priv(dev);
393 platform_set_drvdata(pdev, NULL);
395 iounmap(priv->regs);
396 free_netdev(dev);
398 return 0;
402 /* Reads the controller's registers to determine what interface
403 * connects it to the PHY.
405 static phy_interface_t gfar_get_interface(struct net_device *dev)
407 struct gfar_private *priv = netdev_priv(dev);
408 u32 ecntrl = gfar_read(&priv->regs->ecntrl);
410 if (ecntrl & ECNTRL_SGMII_MODE)
411 return PHY_INTERFACE_MODE_SGMII;
413 if (ecntrl & ECNTRL_TBI_MODE) {
414 if (ecntrl & ECNTRL_REDUCED_MODE)
415 return PHY_INTERFACE_MODE_RTBI;
416 else
417 return PHY_INTERFACE_MODE_TBI;
420 if (ecntrl & ECNTRL_REDUCED_MODE) {
421 if (ecntrl & ECNTRL_REDUCED_MII_MODE)
422 return PHY_INTERFACE_MODE_RMII;
423 else {
424 phy_interface_t interface = priv->einfo->interface;
427 * This isn't autodetected right now, so it must
428 * be set by the device tree or platform code.
430 if (interface == PHY_INTERFACE_MODE_RGMII_ID)
431 return PHY_INTERFACE_MODE_RGMII_ID;
433 return PHY_INTERFACE_MODE_RGMII;
437 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
438 return PHY_INTERFACE_MODE_GMII;
440 return PHY_INTERFACE_MODE_MII;
444 /* Initializes driver's PHY state, and attaches to the PHY.
445 * Returns 0 on success.
447 static int init_phy(struct net_device *dev)
449 struct gfar_private *priv = netdev_priv(dev);
450 uint gigabit_support =
451 priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
452 SUPPORTED_1000baseT_Full : 0;
453 struct phy_device *phydev;
454 char phy_id[BUS_ID_SIZE];
455 phy_interface_t interface;
457 priv->oldlink = 0;
458 priv->oldspeed = 0;
459 priv->oldduplex = -1;
461 snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT, priv->einfo->bus_id, priv->einfo->phy_id);
463 interface = gfar_get_interface(dev);
465 phydev = phy_connect(dev, phy_id, &adjust_link, 0, interface);
467 if (interface == PHY_INTERFACE_MODE_SGMII)
468 gfar_configure_serdes(dev);
470 if (IS_ERR(phydev)) {
471 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
472 return PTR_ERR(phydev);
475 /* Remove any features not supported by the controller */
476 phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
477 phydev->advertising = phydev->supported;
479 priv->phydev = phydev;
481 return 0;
484 static void gfar_configure_serdes(struct net_device *dev)
486 struct gfar_private *priv = netdev_priv(dev);
487 struct gfar_mii __iomem *regs =
488 (void __iomem *)&priv->regs->gfar_mii_regs;
490 /* Initialise TBI i/f to communicate with serdes (lynx phy) */
492 /* Single clk mode, mii mode off(for aerdes communication) */
493 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_TBICON, TBICON_CLK_SELECT);
495 /* Supported pause and full-duplex, no half-duplex */
496 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_ADVERTISE,
497 ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
498 ADVERTISE_1000XPSE_ASYM);
500 /* ANEG enable, restart ANEG, full duplex mode, speed[1] set */
501 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_BMCR, BMCR_ANENABLE |
502 BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
505 static void init_registers(struct net_device *dev)
507 struct gfar_private *priv = netdev_priv(dev);
509 /* Clear IEVENT */
510 gfar_write(&priv->regs->ievent, IEVENT_INIT_CLEAR);
512 /* Initialize IMASK */
513 gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
515 /* Init hash registers to zero */
516 gfar_write(&priv->regs->igaddr0, 0);
517 gfar_write(&priv->regs->igaddr1, 0);
518 gfar_write(&priv->regs->igaddr2, 0);
519 gfar_write(&priv->regs->igaddr3, 0);
520 gfar_write(&priv->regs->igaddr4, 0);
521 gfar_write(&priv->regs->igaddr5, 0);
522 gfar_write(&priv->regs->igaddr6, 0);
523 gfar_write(&priv->regs->igaddr7, 0);
525 gfar_write(&priv->regs->gaddr0, 0);
526 gfar_write(&priv->regs->gaddr1, 0);
527 gfar_write(&priv->regs->gaddr2, 0);
528 gfar_write(&priv->regs->gaddr3, 0);
529 gfar_write(&priv->regs->gaddr4, 0);
530 gfar_write(&priv->regs->gaddr5, 0);
531 gfar_write(&priv->regs->gaddr6, 0);
532 gfar_write(&priv->regs->gaddr7, 0);
534 /* Zero out the rmon mib registers if it has them */
535 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
536 memset_io(&(priv->regs->rmon), 0, sizeof (struct rmon_mib));
538 /* Mask off the CAM interrupts */
539 gfar_write(&priv->regs->rmon.cam1, 0xffffffff);
540 gfar_write(&priv->regs->rmon.cam2, 0xffffffff);
543 /* Initialize the max receive buffer length */
544 gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
546 /* Initialize the Minimum Frame Length Register */
547 gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
549 /* Assign the TBI an address which won't conflict with the PHYs */
550 gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
554 /* Halt the receive and transmit queues */
555 void gfar_halt(struct net_device *dev)
557 struct gfar_private *priv = netdev_priv(dev);
558 struct gfar __iomem *regs = priv->regs;
559 u32 tempval;
561 /* Mask all interrupts */
562 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
564 /* Clear all interrupts */
565 gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
567 /* Stop the DMA, and wait for it to stop */
568 tempval = gfar_read(&priv->regs->dmactrl);
569 if ((tempval & (DMACTRL_GRS | DMACTRL_GTS))
570 != (DMACTRL_GRS | DMACTRL_GTS)) {
571 tempval |= (DMACTRL_GRS | DMACTRL_GTS);
572 gfar_write(&priv->regs->dmactrl, tempval);
574 while (!(gfar_read(&priv->regs->ievent) &
575 (IEVENT_GRSC | IEVENT_GTSC)))
576 cpu_relax();
579 /* Disable Rx and Tx */
580 tempval = gfar_read(&regs->maccfg1);
581 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
582 gfar_write(&regs->maccfg1, tempval);
585 void stop_gfar(struct net_device *dev)
587 struct gfar_private *priv = netdev_priv(dev);
588 struct gfar __iomem *regs = priv->regs;
589 unsigned long flags;
591 phy_stop(priv->phydev);
593 /* Lock it down */
594 spin_lock_irqsave(&priv->txlock, flags);
595 spin_lock(&priv->rxlock);
597 gfar_halt(dev);
599 spin_unlock(&priv->rxlock);
600 spin_unlock_irqrestore(&priv->txlock, flags);
602 /* Free the IRQs */
603 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
604 free_irq(priv->interruptError, dev);
605 free_irq(priv->interruptTransmit, dev);
606 free_irq(priv->interruptReceive, dev);
607 } else {
608 free_irq(priv->interruptTransmit, dev);
611 free_skb_resources(priv);
613 <<<<<<< HEAD:drivers/net/gianfar.c
614 dma_free_coherent(NULL,
615 =======
616 dma_free_coherent(&dev->dev,
617 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
618 sizeof(struct txbd8)*priv->tx_ring_size
619 + sizeof(struct rxbd8)*priv->rx_ring_size,
620 priv->tx_bd_base,
621 gfar_read(&regs->tbase0));
624 /* If there are any tx skbs or rx skbs still around, free them.
625 * Then free tx_skbuff and rx_skbuff */
626 static void free_skb_resources(struct gfar_private *priv)
628 struct rxbd8 *rxbdp;
629 struct txbd8 *txbdp;
630 int i;
632 /* Go through all the buffer descriptors and free their data buffers */
633 txbdp = priv->tx_bd_base;
635 for (i = 0; i < priv->tx_ring_size; i++) {
637 if (priv->tx_skbuff[i]) {
638 <<<<<<< HEAD:drivers/net/gianfar.c
639 dma_unmap_single(NULL, txbdp->bufPtr,
640 =======
641 dma_unmap_single(&priv->dev->dev, txbdp->bufPtr,
642 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
643 txbdp->length,
644 DMA_TO_DEVICE);
645 dev_kfree_skb_any(priv->tx_skbuff[i]);
646 priv->tx_skbuff[i] = NULL;
650 kfree(priv->tx_skbuff);
652 rxbdp = priv->rx_bd_base;
654 /* rx_skbuff is not guaranteed to be allocated, so only
655 * free it and its contents if it is allocated */
656 if(priv->rx_skbuff != NULL) {
657 for (i = 0; i < priv->rx_ring_size; i++) {
658 if (priv->rx_skbuff[i]) {
659 <<<<<<< HEAD:drivers/net/gianfar.c
660 dma_unmap_single(NULL, rxbdp->bufPtr,
661 =======
662 dma_unmap_single(&priv->dev->dev, rxbdp->bufPtr,
663 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
664 priv->rx_buffer_size,
665 DMA_FROM_DEVICE);
667 dev_kfree_skb_any(priv->rx_skbuff[i]);
668 priv->rx_skbuff[i] = NULL;
671 rxbdp->status = 0;
672 rxbdp->length = 0;
673 rxbdp->bufPtr = 0;
675 rxbdp++;
678 kfree(priv->rx_skbuff);
682 void gfar_start(struct net_device *dev)
684 struct gfar_private *priv = netdev_priv(dev);
685 struct gfar __iomem *regs = priv->regs;
686 u32 tempval;
688 /* Enable Rx and Tx in MACCFG1 */
689 tempval = gfar_read(&regs->maccfg1);
690 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
691 gfar_write(&regs->maccfg1, tempval);
693 /* Initialize DMACTRL to have WWR and WOP */
694 tempval = gfar_read(&priv->regs->dmactrl);
695 tempval |= DMACTRL_INIT_SETTINGS;
696 gfar_write(&priv->regs->dmactrl, tempval);
698 /* Make sure we aren't stopped */
699 tempval = gfar_read(&priv->regs->dmactrl);
700 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
701 gfar_write(&priv->regs->dmactrl, tempval);
703 /* Clear THLT/RHLT, so that the DMA starts polling now */
704 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
705 gfar_write(&regs->rstat, RSTAT_CLEAR_RHALT);
707 /* Unmask the interrupts we look for */
708 gfar_write(&regs->imask, IMASK_DEFAULT);
711 /* Bring the controller up and running */
712 int startup_gfar(struct net_device *dev)
714 struct txbd8 *txbdp;
715 struct rxbd8 *rxbdp;
716 dma_addr_t addr = 0;
717 unsigned long vaddr;
718 int i;
719 struct gfar_private *priv = netdev_priv(dev);
720 struct gfar __iomem *regs = priv->regs;
721 int err = 0;
722 u32 rctrl = 0;
723 u32 attrs = 0;
725 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
727 /* Allocate memory for the buffer descriptors */
728 <<<<<<< HEAD:drivers/net/gianfar.c
729 vaddr = (unsigned long) dma_alloc_coherent(NULL,
730 =======
731 vaddr = (unsigned long) dma_alloc_coherent(&dev->dev,
732 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
733 sizeof (struct txbd8) * priv->tx_ring_size +
734 sizeof (struct rxbd8) * priv->rx_ring_size,
735 &addr, GFP_KERNEL);
737 if (vaddr == 0) {
738 if (netif_msg_ifup(priv))
739 printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
740 dev->name);
741 return -ENOMEM;
744 priv->tx_bd_base = (struct txbd8 *) vaddr;
746 /* enet DMA only understands physical addresses */
747 gfar_write(&regs->tbase0, addr);
749 /* Start the rx descriptor ring where the tx ring leaves off */
750 addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
751 vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
752 priv->rx_bd_base = (struct rxbd8 *) vaddr;
753 gfar_write(&regs->rbase0, addr);
755 /* Setup the skbuff rings */
756 priv->tx_skbuff =
757 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
758 priv->tx_ring_size, GFP_KERNEL);
760 if (NULL == priv->tx_skbuff) {
761 if (netif_msg_ifup(priv))
762 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
763 dev->name);
764 err = -ENOMEM;
765 goto tx_skb_fail;
768 for (i = 0; i < priv->tx_ring_size; i++)
769 priv->tx_skbuff[i] = NULL;
771 priv->rx_skbuff =
772 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
773 priv->rx_ring_size, GFP_KERNEL);
775 if (NULL == priv->rx_skbuff) {
776 if (netif_msg_ifup(priv))
777 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
778 dev->name);
779 err = -ENOMEM;
780 goto rx_skb_fail;
783 for (i = 0; i < priv->rx_ring_size; i++)
784 priv->rx_skbuff[i] = NULL;
786 /* Initialize some variables in our dev structure */
787 priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
788 priv->cur_rx = priv->rx_bd_base;
789 priv->skb_curtx = priv->skb_dirtytx = 0;
790 priv->skb_currx = 0;
792 /* Initialize Transmit Descriptor Ring */
793 txbdp = priv->tx_bd_base;
794 for (i = 0; i < priv->tx_ring_size; i++) {
795 txbdp->status = 0;
796 txbdp->length = 0;
797 txbdp->bufPtr = 0;
798 txbdp++;
801 /* Set the last descriptor in the ring to indicate wrap */
802 txbdp--;
803 txbdp->status |= TXBD_WRAP;
805 rxbdp = priv->rx_bd_base;
806 for (i = 0; i < priv->rx_ring_size; i++) {
807 struct sk_buff *skb = NULL;
809 rxbdp->status = 0;
811 skb = gfar_new_skb(dev, rxbdp);
813 priv->rx_skbuff[i] = skb;
815 rxbdp++;
818 /* Set the last descriptor in the ring to wrap */
819 rxbdp--;
820 rxbdp->status |= RXBD_WRAP;
822 /* If the device has multiple interrupts, register for
823 * them. Otherwise, only register for the one */
824 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
825 /* Install our interrupt handlers for Error,
826 * Transmit, and Receive */
827 if (request_irq(priv->interruptError, gfar_error,
828 0, "enet_error", dev) < 0) {
829 if (netif_msg_intr(priv))
830 printk(KERN_ERR "%s: Can't get IRQ %d\n",
831 dev->name, priv->interruptError);
833 err = -1;
834 goto err_irq_fail;
837 if (request_irq(priv->interruptTransmit, gfar_transmit,
838 0, "enet_tx", dev) < 0) {
839 if (netif_msg_intr(priv))
840 printk(KERN_ERR "%s: Can't get IRQ %d\n",
841 dev->name, priv->interruptTransmit);
843 err = -1;
845 goto tx_irq_fail;
848 if (request_irq(priv->interruptReceive, gfar_receive,
849 0, "enet_rx", dev) < 0) {
850 if (netif_msg_intr(priv))
851 printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
852 dev->name, priv->interruptReceive);
854 err = -1;
855 goto rx_irq_fail;
857 } else {
858 if (request_irq(priv->interruptTransmit, gfar_interrupt,
859 0, "gfar_interrupt", dev) < 0) {
860 if (netif_msg_intr(priv))
861 printk(KERN_ERR "%s: Can't get IRQ %d\n",
862 dev->name, priv->interruptError);
864 err = -1;
865 goto err_irq_fail;
869 phy_start(priv->phydev);
871 /* Configure the coalescing support */
872 if (priv->txcoalescing)
873 gfar_write(&regs->txic,
874 mk_ic_value(priv->txcount, priv->txtime));
875 else
876 gfar_write(&regs->txic, 0);
878 if (priv->rxcoalescing)
879 gfar_write(&regs->rxic,
880 mk_ic_value(priv->rxcount, priv->rxtime));
881 else
882 gfar_write(&regs->rxic, 0);
884 if (priv->rx_csum_enable)
885 rctrl |= RCTRL_CHECKSUMMING;
887 if (priv->extended_hash) {
888 rctrl |= RCTRL_EXTHASH;
890 gfar_clear_exact_match(dev);
891 rctrl |= RCTRL_EMEN;
894 if (priv->vlan_enable)
895 rctrl |= RCTRL_VLAN;
897 if (priv->padding) {
898 rctrl &= ~RCTRL_PAL_MASK;
899 rctrl |= RCTRL_PADDING(priv->padding);
902 /* Init rctrl based on our settings */
903 gfar_write(&priv->regs->rctrl, rctrl);
905 if (dev->features & NETIF_F_IP_CSUM)
906 gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
908 /* Set the extraction length and index */
909 attrs = ATTRELI_EL(priv->rx_stash_size) |
910 ATTRELI_EI(priv->rx_stash_index);
912 gfar_write(&priv->regs->attreli, attrs);
914 /* Start with defaults, and add stashing or locking
915 * depending on the approprate variables */
916 attrs = ATTR_INIT_SETTINGS;
918 if (priv->bd_stash_en)
919 attrs |= ATTR_BDSTASH;
921 if (priv->rx_stash_size != 0)
922 attrs |= ATTR_BUFSTASH;
924 gfar_write(&priv->regs->attr, attrs);
926 gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold);
927 gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve);
928 gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
930 /* Start the controller */
931 gfar_start(dev);
933 return 0;
935 rx_irq_fail:
936 free_irq(priv->interruptTransmit, dev);
937 tx_irq_fail:
938 free_irq(priv->interruptError, dev);
939 err_irq_fail:
940 rx_skb_fail:
941 free_skb_resources(priv);
942 tx_skb_fail:
943 <<<<<<< HEAD:drivers/net/gianfar.c
944 dma_free_coherent(NULL,
945 =======
946 dma_free_coherent(&dev->dev,
947 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
948 sizeof(struct txbd8)*priv->tx_ring_size
949 + sizeof(struct rxbd8)*priv->rx_ring_size,
950 priv->tx_bd_base,
951 gfar_read(&regs->tbase0));
953 return err;
956 /* Called when something needs to use the ethernet device */
957 /* Returns 0 for success. */
958 static int gfar_enet_open(struct net_device *dev)
960 #ifdef CONFIG_GFAR_NAPI
961 struct gfar_private *priv = netdev_priv(dev);
962 #endif
963 int err;
965 #ifdef CONFIG_GFAR_NAPI
966 napi_enable(&priv->napi);
967 #endif
969 /* Initialize a bunch of registers */
970 init_registers(dev);
972 gfar_set_mac_address(dev);
974 err = init_phy(dev);
976 if(err) {
977 #ifdef CONFIG_GFAR_NAPI
978 napi_disable(&priv->napi);
979 #endif
980 return err;
983 err = startup_gfar(dev);
984 if (err) {
985 #ifdef CONFIG_GFAR_NAPI
986 napi_disable(&priv->napi);
987 #endif
988 return err;
991 netif_start_queue(dev);
993 return err;
996 static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp)
998 struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
1000 memset(fcb, 0, GMAC_FCB_LEN);
1002 return fcb;
1005 static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
1007 u8 flags = 0;
1009 /* If we're here, it's a IP packet with a TCP or UDP
1010 * payload. We set it to checksum, using a pseudo-header
1011 * we provide
1013 flags = TXFCB_DEFAULT;
1015 /* Tell the controller what the protocol is */
1016 /* And provide the already calculated phcs */
1017 if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
1018 flags |= TXFCB_UDP;
1019 fcb->phcs = udp_hdr(skb)->check;
1020 } else
1021 fcb->phcs = tcp_hdr(skb)->check;
1023 /* l3os is the distance between the start of the
1024 * frame (skb->data) and the start of the IP hdr.
1025 * l4os is the distance between the start of the
1026 * l3 hdr and the l4 hdr */
1027 fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN);
1028 fcb->l4os = skb_network_header_len(skb);
1030 fcb->flags = flags;
1033 void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
1035 fcb->flags |= TXFCB_VLN;
1036 fcb->vlctl = vlan_tx_tag_get(skb);
1039 /* This is called by the kernel when a frame is ready for transmission. */
1040 /* It is pointed to by the dev->hard_start_xmit function pointer */
1041 static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1043 struct gfar_private *priv = netdev_priv(dev);
1044 struct txfcb *fcb = NULL;
1045 struct txbd8 *txbdp;
1046 u16 status;
1047 unsigned long flags;
1049 /* Update transmit stats */
1050 dev->stats.tx_bytes += skb->len;
1052 /* Lock priv now */
1053 spin_lock_irqsave(&priv->txlock, flags);
1055 /* Point at the first free tx descriptor */
1056 txbdp = priv->cur_tx;
1058 /* Clear all but the WRAP status flags */
1059 status = txbdp->status & TXBD_WRAP;
1061 /* Set up checksumming */
1062 if (likely((dev->features & NETIF_F_IP_CSUM)
1063 && (CHECKSUM_PARTIAL == skb->ip_summed))) {
1064 fcb = gfar_add_fcb(skb, txbdp);
1065 status |= TXBD_TOE;
1066 gfar_tx_checksum(skb, fcb);
1069 if (priv->vlan_enable &&
1070 unlikely(priv->vlgrp && vlan_tx_tag_present(skb))) {
1071 if (unlikely(NULL == fcb)) {
1072 fcb = gfar_add_fcb(skb, txbdp);
1073 status |= TXBD_TOE;
1076 gfar_tx_vlan(skb, fcb);
1079 /* Set buffer length and pointer */
1080 txbdp->length = skb->len;
1081 <<<<<<< HEAD:drivers/net/gianfar.c
1082 txbdp->bufPtr = dma_map_single(NULL, skb->data,
1083 =======
1084 txbdp->bufPtr = dma_map_single(&dev->dev, skb->data,
1085 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
1086 skb->len, DMA_TO_DEVICE);
1088 /* Save the skb pointer so we can free it later */
1089 priv->tx_skbuff[priv->skb_curtx] = skb;
1091 /* Update the current skb pointer (wrapping if this was the last) */
1092 priv->skb_curtx =
1093 (priv->skb_curtx + 1) & TX_RING_MOD_MASK(priv->tx_ring_size);
1095 /* Flag the BD as interrupt-causing */
1096 status |= TXBD_INTERRUPT;
1098 /* Flag the BD as ready to go, last in frame, and */
1099 /* in need of CRC */
1100 status |= (TXBD_READY | TXBD_LAST | TXBD_CRC);
1102 dev->trans_start = jiffies;
1104 /* The powerpc-specific eieio() is used, as wmb() has too strong
1105 * semantics (it requires synchronization between cacheable and
1106 * uncacheable mappings, which eieio doesn't provide and which we
1107 * don't need), thus requiring a more expensive sync instruction. At
1108 * some point, the set of architecture-independent barrier functions
1109 * should be expanded to include weaker barriers.
1112 eieio();
1113 txbdp->status = status;
1115 /* If this was the last BD in the ring, the next one */
1116 /* is at the beginning of the ring */
1117 if (txbdp->status & TXBD_WRAP)
1118 txbdp = priv->tx_bd_base;
1119 else
1120 txbdp++;
1122 /* If the next BD still needs to be cleaned up, then the bds
1123 are full. We need to tell the kernel to stop sending us stuff. */
1124 if (txbdp == priv->dirty_tx) {
1125 netif_stop_queue(dev);
1127 dev->stats.tx_fifo_errors++;
1130 /* Update the current txbd to the next one */
1131 priv->cur_tx = txbdp;
1133 /* Tell the DMA to go go go */
1134 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1136 /* Unlock priv */
1137 spin_unlock_irqrestore(&priv->txlock, flags);
1139 return 0;
1142 /* Stops the kernel queue, and halts the controller */
1143 static int gfar_close(struct net_device *dev)
1145 struct gfar_private *priv = netdev_priv(dev);
1147 #ifdef CONFIG_GFAR_NAPI
1148 napi_disable(&priv->napi);
1149 #endif
1151 stop_gfar(dev);
1153 /* Disconnect from the PHY */
1154 phy_disconnect(priv->phydev);
1155 priv->phydev = NULL;
1157 netif_stop_queue(dev);
1159 return 0;
1162 /* Changes the mac address if the controller is not running. */
1163 int gfar_set_mac_address(struct net_device *dev)
1165 gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
1167 return 0;
1171 /* Enables and disables VLAN insertion/extraction */
1172 static void gfar_vlan_rx_register(struct net_device *dev,
1173 struct vlan_group *grp)
1175 struct gfar_private *priv = netdev_priv(dev);
1176 unsigned long flags;
1177 u32 tempval;
1179 spin_lock_irqsave(&priv->rxlock, flags);
1181 priv->vlgrp = grp;
1183 if (grp) {
1184 /* Enable VLAN tag insertion */
1185 tempval = gfar_read(&priv->regs->tctrl);
1186 tempval |= TCTRL_VLINS;
1188 gfar_write(&priv->regs->tctrl, tempval);
1190 /* Enable VLAN tag extraction */
1191 tempval = gfar_read(&priv->regs->rctrl);
1192 tempval |= RCTRL_VLEX;
1193 gfar_write(&priv->regs->rctrl, tempval);
1194 } else {
1195 /* Disable VLAN tag insertion */
1196 tempval = gfar_read(&priv->regs->tctrl);
1197 tempval &= ~TCTRL_VLINS;
1198 gfar_write(&priv->regs->tctrl, tempval);
1200 /* Disable VLAN tag extraction */
1201 tempval = gfar_read(&priv->regs->rctrl);
1202 tempval &= ~RCTRL_VLEX;
1203 gfar_write(&priv->regs->rctrl, tempval);
1206 spin_unlock_irqrestore(&priv->rxlock, flags);
1209 static int gfar_change_mtu(struct net_device *dev, int new_mtu)
1211 int tempsize, tempval;
1212 struct gfar_private *priv = netdev_priv(dev);
1213 int oldsize = priv->rx_buffer_size;
1214 int frame_size = new_mtu + ETH_HLEN;
1216 if (priv->vlan_enable)
1217 frame_size += VLAN_ETH_HLEN;
1219 if (gfar_uses_fcb(priv))
1220 frame_size += GMAC_FCB_LEN;
1222 frame_size += priv->padding;
1224 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
1225 if (netif_msg_drv(priv))
1226 printk(KERN_ERR "%s: Invalid MTU setting\n",
1227 dev->name);
1228 return -EINVAL;
1231 tempsize =
1232 (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
1233 INCREMENTAL_BUFFER_SIZE;
1235 /* Only stop and start the controller if it isn't already
1236 * stopped, and we changed something */
1237 if ((oldsize != tempsize) && (dev->flags & IFF_UP))
1238 stop_gfar(dev);
1240 priv->rx_buffer_size = tempsize;
1242 dev->mtu = new_mtu;
1244 gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
1245 gfar_write(&priv->regs->maxfrm, priv->rx_buffer_size);
1247 /* If the mtu is larger than the max size for standard
1248 * ethernet frames (ie, a jumbo frame), then set maccfg2
1249 * to allow huge frames, and to check the length */
1250 tempval = gfar_read(&priv->regs->maccfg2);
1252 if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE)
1253 tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
1254 else
1255 tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
1257 gfar_write(&priv->regs->maccfg2, tempval);
1259 if ((oldsize != tempsize) && (dev->flags & IFF_UP))
1260 startup_gfar(dev);
1262 return 0;
1265 /* gfar_timeout gets called when a packet has not been
1266 * transmitted after a set amount of time.
1267 * For now, assume that clearing out all the structures, and
1268 * starting over will fix the problem. */
1269 static void gfar_timeout(struct net_device *dev)
1271 dev->stats.tx_errors++;
1273 if (dev->flags & IFF_UP) {
1274 stop_gfar(dev);
1275 startup_gfar(dev);
1278 netif_schedule(dev);
1281 /* Interrupt Handler for Transmit complete */
1282 static irqreturn_t gfar_transmit(int irq, void *dev_id)
1284 struct net_device *dev = (struct net_device *) dev_id;
1285 struct gfar_private *priv = netdev_priv(dev);
1286 struct txbd8 *bdp;
1288 /* Clear IEVENT */
1289 gfar_write(&priv->regs->ievent, IEVENT_TX_MASK);
1291 /* Lock priv */
1292 spin_lock(&priv->txlock);
1293 bdp = priv->dirty_tx;
1294 while ((bdp->status & TXBD_READY) == 0) {
1295 /* If dirty_tx and cur_tx are the same, then either the */
1296 /* ring is empty or full now (it could only be full in the beginning, */
1297 /* obviously). If it is empty, we are done. */
1298 if ((bdp == priv->cur_tx) && (netif_queue_stopped(dev) == 0))
1299 break;
1301 dev->stats.tx_packets++;
1303 /* Deferred means some collisions occurred during transmit, */
1304 /* but we eventually sent the packet. */
1305 if (bdp->status & TXBD_DEF)
1306 dev->stats.collisions++;
1308 /* Free the sk buffer associated with this TxBD */
1309 dev_kfree_skb_irq(priv->tx_skbuff[priv->skb_dirtytx]);
1310 priv->tx_skbuff[priv->skb_dirtytx] = NULL;
1311 priv->skb_dirtytx =
1312 (priv->skb_dirtytx +
1313 1) & TX_RING_MOD_MASK(priv->tx_ring_size);
1315 /* update bdp to point at next bd in the ring (wrapping if necessary) */
1316 if (bdp->status & TXBD_WRAP)
1317 bdp = priv->tx_bd_base;
1318 else
1319 bdp++;
1321 /* Move dirty_tx to be the next bd */
1322 priv->dirty_tx = bdp;
1324 /* We freed a buffer, so now we can restart transmission */
1325 if (netif_queue_stopped(dev))
1326 netif_wake_queue(dev);
1327 } /* while ((bdp->status & TXBD_READY) == 0) */
1329 /* If we are coalescing the interrupts, reset the timer */
1330 /* Otherwise, clear it */
1331 if (priv->txcoalescing)
1332 gfar_write(&priv->regs->txic,
1333 mk_ic_value(priv->txcount, priv->txtime));
1334 else
1335 gfar_write(&priv->regs->txic, 0);
1337 spin_unlock(&priv->txlock);
1339 return IRQ_HANDLED;
1342 struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1344 unsigned int alignamount;
1345 struct gfar_private *priv = netdev_priv(dev);
1346 struct sk_buff *skb = NULL;
1347 unsigned int timeout = SKB_ALLOC_TIMEOUT;
1349 /* We have to allocate the skb, so keep trying till we succeed */
1350 while ((!skb) && timeout--)
1351 skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT);
1353 if (NULL == skb)
1354 return NULL;
1356 alignamount = RXBUF_ALIGNMENT -
1357 (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1));
1359 /* We need the data buffer to be aligned properly. We will reserve
1360 * as many bytes as needed to align the data properly
1362 skb_reserve(skb, alignamount);
1364 <<<<<<< HEAD:drivers/net/gianfar.c
1365 bdp->bufPtr = dma_map_single(NULL, skb->data,
1366 =======
1367 bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
1368 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/gianfar.c
1369 priv->rx_buffer_size, DMA_FROM_DEVICE);
1371 bdp->length = 0;
1373 /* Mark the buffer empty */
1374 eieio();
1375 bdp->status |= (RXBD_EMPTY | RXBD_INTERRUPT);
1377 return skb;
1380 static inline void count_errors(unsigned short status, struct net_device *dev)
1382 struct gfar_private *priv = netdev_priv(dev);
1383 struct net_device_stats *stats = &dev->stats;
1384 struct gfar_extra_stats *estats = &priv->extra_stats;
1386 /* If the packet was truncated, none of the other errors
1387 * matter */
1388 if (status & RXBD_TRUNCATED) {
1389 stats->rx_length_errors++;
1391 estats->rx_trunc++;
1393 return;
1395 /* Count the errors, if there were any */
1396 if (status & (RXBD_LARGE | RXBD_SHORT)) {
1397 stats->rx_length_errors++;
1399 if (status & RXBD_LARGE)
1400 estats->rx_large++;
1401 else
1402 estats->rx_short++;
1404 if (status & RXBD_NONOCTET) {
1405 stats->rx_frame_errors++;
1406 estats->rx_nonoctet++;
1408 if (status & RXBD_CRCERR) {
1409 estats->rx_crcerr++;
1410 stats->rx_crc_errors++;
1412 if (status & RXBD_OVERRUN) {
1413 estats->rx_overrun++;
1414 stats->rx_crc_errors++;
1418 irqreturn_t gfar_receive(int irq, void *dev_id)
1420 struct net_device *dev = (struct net_device *) dev_id;
1421 struct gfar_private *priv = netdev_priv(dev);
1422 #ifdef CONFIG_GFAR_NAPI
1423 u32 tempval;
1424 #else
1425 unsigned long flags;
1426 #endif
1428 /* Clear IEVENT, so rx interrupt isn't called again
1429 * because of this interrupt */
1430 gfar_write(&priv->regs->ievent, IEVENT_RX_MASK);
1432 /* support NAPI */
1433 #ifdef CONFIG_GFAR_NAPI
1434 if (netif_rx_schedule_prep(dev, &priv->napi)) {
1435 tempval = gfar_read(&priv->regs->imask);
1436 tempval &= IMASK_RX_DISABLED;
1437 gfar_write(&priv->regs->imask, tempval);
1439 __netif_rx_schedule(dev, &priv->napi);
1440 } else {
1441 if (netif_msg_rx_err(priv))
1442 printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
1443 dev->name, gfar_read(&priv->regs->ievent),
1444 gfar_read(&priv->regs->imask));
1446 #else
1448 spin_lock_irqsave(&priv->rxlock, flags);
1449 gfar_clean_rx_ring(dev, priv->rx_ring_size);
1451 /* If we are coalescing interrupts, update the timer */
1452 /* Otherwise, clear it */
1453 if (priv->rxcoalescing)
1454 gfar_write(&priv->regs->rxic,
1455 mk_ic_value(priv->rxcount, priv->rxtime));
1456 else
1457 gfar_write(&priv->regs->rxic, 0);
1459 spin_unlock_irqrestore(&priv->rxlock, flags);
1460 #endif
1462 return IRQ_HANDLED;
1465 static inline int gfar_rx_vlan(struct sk_buff *skb,
1466 struct vlan_group *vlgrp, unsigned short vlctl)
1468 #ifdef CONFIG_GFAR_NAPI
1469 return vlan_hwaccel_receive_skb(skb, vlgrp, vlctl);
1470 #else
1471 return vlan_hwaccel_rx(skb, vlgrp, vlctl);
1472 #endif
1475 static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
1477 /* If valid headers were found, and valid sums
1478 * were verified, then we tell the kernel that no
1479 * checksumming is necessary. Otherwise, it is */
1480 if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
1481 skb->ip_summed = CHECKSUM_UNNECESSARY;
1482 else
1483 skb->ip_summed = CHECKSUM_NONE;
1487 static inline struct rxfcb *gfar_get_fcb(struct sk_buff *skb)
1489 struct rxfcb *fcb = (struct rxfcb *)skb->data;
1491 /* Remove the FCB from the skb */
1492 skb_pull(skb, GMAC_FCB_LEN);
1494 return fcb;
1497 /* gfar_process_frame() -- handle one incoming packet if skb
1498 * isn't NULL. */
1499 static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
1500 int length)
1502 struct gfar_private *priv = netdev_priv(dev);
1503 struct rxfcb *fcb = NULL;
1505 if (NULL == skb) {
1506 if (netif_msg_rx_err(priv))
1507 printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name);
1508 dev->stats.rx_dropped++;
1509 priv->extra_stats.rx_skbmissing++;
1510 } else {
1511 int ret;
1513 /* Prep the skb for the packet */
1514 skb_put(skb, length);
1516 /* Grab the FCB if there is one */
1517 if (gfar_uses_fcb(priv))
1518 fcb = gfar_get_fcb(skb);
1520 /* Remove the padded bytes, if there are any */
1521 if (priv->padding)
1522 skb_pull(skb, priv->padding);
1524 if (priv->rx_csum_enable)
1525 gfar_rx_checksum(skb, fcb);
1527 /* Tell the skb what kind of packet this is */
1528 skb->protocol = eth_type_trans(skb, dev);
1530 /* Send the packet up the stack */
1531 if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN)))
1532 ret = gfar_rx_vlan(skb, priv->vlgrp, fcb->vlctl);
1533 else
1534 ret = RECEIVE(skb);
1536 if (NET_RX_DROP == ret)
1537 priv->extra_stats.kernel_dropped++;
1540 return 0;
1543 /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
1544 * until the budget/quota has been reached. Returns the number
1545 * of frames handled
1547 int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1549 struct rxbd8 *bdp;
1550 struct sk_buff *skb;
1551 u16 pkt_len;
1552 int howmany = 0;
1553 struct gfar_private *priv = netdev_priv(dev);
1555 /* Get the first full descriptor */
1556 bdp = priv->cur_rx;
1558 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
1559 rmb();
1560 skb = priv->rx_skbuff[priv->skb_currx];
1562 if (!(bdp->status &
1563 (RXBD_LARGE | RXBD_SHORT | RXBD_NONOCTET
1564 | RXBD_CRCERR | RXBD_OVERRUN | RXBD_TRUNCATED))) {
1565 /* Increment the number of packets */
1566 dev->stats.rx_packets++;
1567 howmany++;
1569 /* Remove the FCS from the packet length */
1570 pkt_len = bdp->length - 4;
1572 gfar_process_frame(dev, skb, pkt_len);
1574 dev->stats.rx_bytes += pkt_len;
1575 } else {
1576 count_errors(bdp->status, dev);
1578 if (skb)
1579 dev_kfree_skb_any(skb);
1581 priv->rx_skbuff[priv->skb_currx] = NULL;
1584 dev->last_rx = jiffies;
1586 /* Clear the status flags for this buffer */
1587 bdp->status &= ~RXBD_STATS;
1589 /* Add another skb for the future */
1590 skb = gfar_new_skb(dev, bdp);
1591 priv->rx_skbuff[priv->skb_currx] = skb;
1593 /* Update to the next pointer */
1594 if (bdp->status & RXBD_WRAP)
1595 bdp = priv->rx_bd_base;
1596 else
1597 bdp++;
1599 /* update to point at the next skb */
1600 priv->skb_currx =
1601 (priv->skb_currx +
1602 1) & RX_RING_MOD_MASK(priv->rx_ring_size);
1606 /* Update the current rxbd pointer to be the next one */
1607 priv->cur_rx = bdp;
1609 return howmany;
1612 #ifdef CONFIG_GFAR_NAPI
1613 static int gfar_poll(struct napi_struct *napi, int budget)
1615 struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
1616 struct net_device *dev = priv->dev;
1617 int howmany;
1619 howmany = gfar_clean_rx_ring(dev, budget);
1621 if (howmany < budget) {
1622 netif_rx_complete(dev, napi);
1624 /* Clear the halt bit in RSTAT */
1625 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1627 gfar_write(&priv->regs->imask, IMASK_DEFAULT);
1629 /* If we are coalescing interrupts, update the timer */
1630 /* Otherwise, clear it */
1631 if (priv->rxcoalescing)
1632 gfar_write(&priv->regs->rxic,
1633 mk_ic_value(priv->rxcount, priv->rxtime));
1634 else
1635 gfar_write(&priv->regs->rxic, 0);
1638 return howmany;
1640 #endif
1642 #ifdef CONFIG_NET_POLL_CONTROLLER
1644 * Polling 'interrupt' - used by things like netconsole to send skbs
1645 * without having to re-enable interrupts. It's not called while
1646 * the interrupt routine is executing.
1648 static void gfar_netpoll(struct net_device *dev)
1650 struct gfar_private *priv = netdev_priv(dev);
1652 /* If the device has multiple interrupts, run tx/rx */
1653 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
1654 disable_irq(priv->interruptTransmit);
1655 disable_irq(priv->interruptReceive);
1656 disable_irq(priv->interruptError);
1657 gfar_interrupt(priv->interruptTransmit, dev);
1658 enable_irq(priv->interruptError);
1659 enable_irq(priv->interruptReceive);
1660 enable_irq(priv->interruptTransmit);
1661 } else {
1662 disable_irq(priv->interruptTransmit);
1663 gfar_interrupt(priv->interruptTransmit, dev);
1664 enable_irq(priv->interruptTransmit);
1667 #endif
1669 /* The interrupt handler for devices with one interrupt */
1670 static irqreturn_t gfar_interrupt(int irq, void *dev_id)
1672 struct net_device *dev = dev_id;
1673 struct gfar_private *priv = netdev_priv(dev);
1675 /* Save ievent for future reference */
1676 u32 events = gfar_read(&priv->regs->ievent);
1678 /* Check for reception */
1679 if (events & IEVENT_RX_MASK)
1680 gfar_receive(irq, dev_id);
1682 /* Check for transmit completion */
1683 if (events & IEVENT_TX_MASK)
1684 gfar_transmit(irq, dev_id);
1686 /* Check for errors */
1687 if (events & IEVENT_ERR_MASK)
1688 gfar_error(irq, dev_id);
1690 return IRQ_HANDLED;
1693 /* Called every time the controller might need to be made
1694 * aware of new link state. The PHY code conveys this
1695 * information through variables in the phydev structure, and this
1696 * function converts those variables into the appropriate
1697 * register values, and can bring down the device if needed.
1699 static void adjust_link(struct net_device *dev)
1701 struct gfar_private *priv = netdev_priv(dev);
1702 struct gfar __iomem *regs = priv->regs;
1703 unsigned long flags;
1704 struct phy_device *phydev = priv->phydev;
1705 int new_state = 0;
1707 spin_lock_irqsave(&priv->txlock, flags);
1708 if (phydev->link) {
1709 u32 tempval = gfar_read(&regs->maccfg2);
1710 u32 ecntrl = gfar_read(&regs->ecntrl);
1712 /* Now we make sure that we can be in full duplex mode.
1713 * If not, we operate in half-duplex mode. */
1714 if (phydev->duplex != priv->oldduplex) {
1715 new_state = 1;
1716 if (!(phydev->duplex))
1717 tempval &= ~(MACCFG2_FULL_DUPLEX);
1718 else
1719 tempval |= MACCFG2_FULL_DUPLEX;
1721 priv->oldduplex = phydev->duplex;
1724 if (phydev->speed != priv->oldspeed) {
1725 new_state = 1;
1726 switch (phydev->speed) {
1727 case 1000:
1728 tempval =
1729 ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
1730 break;
1731 case 100:
1732 case 10:
1733 tempval =
1734 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
1736 /* Reduced mode distinguishes
1737 * between 10 and 100 */
1738 if (phydev->speed == SPEED_100)
1739 ecntrl |= ECNTRL_R100;
1740 else
1741 ecntrl &= ~(ECNTRL_R100);
1742 break;
1743 default:
1744 if (netif_msg_link(priv))
1745 printk(KERN_WARNING
1746 "%s: Ack! Speed (%d) is not 10/100/1000!\n",
1747 dev->name, phydev->speed);
1748 break;
1751 priv->oldspeed = phydev->speed;
1754 gfar_write(&regs->maccfg2, tempval);
1755 gfar_write(&regs->ecntrl, ecntrl);
1757 if (!priv->oldlink) {
1758 new_state = 1;
1759 priv->oldlink = 1;
1760 netif_schedule(dev);
1762 } else if (priv->oldlink) {
1763 new_state = 1;
1764 priv->oldlink = 0;
1765 priv->oldspeed = 0;
1766 priv->oldduplex = -1;
1769 if (new_state && netif_msg_link(priv))
1770 phy_print_status(phydev);
1772 spin_unlock_irqrestore(&priv->txlock, flags);
1775 /* Update the hash table based on the current list of multicast
1776 * addresses we subscribe to. Also, change the promiscuity of
1777 * the device based on the flags (this function is called
1778 * whenever dev->flags is changed */
1779 static void gfar_set_multi(struct net_device *dev)
1781 struct dev_mc_list *mc_ptr;
1782 struct gfar_private *priv = netdev_priv(dev);
1783 struct gfar __iomem *regs = priv->regs;
1784 u32 tempval;
1786 if(dev->flags & IFF_PROMISC) {
1787 /* Set RCTRL to PROM */
1788 tempval = gfar_read(&regs->rctrl);
1789 tempval |= RCTRL_PROM;
1790 gfar_write(&regs->rctrl, tempval);
1791 } else {
1792 /* Set RCTRL to not PROM */
1793 tempval = gfar_read(&regs->rctrl);
1794 tempval &= ~(RCTRL_PROM);
1795 gfar_write(&regs->rctrl, tempval);
1798 if(dev->flags & IFF_ALLMULTI) {
1799 /* Set the hash to rx all multicast frames */
1800 gfar_write(&regs->igaddr0, 0xffffffff);
1801 gfar_write(&regs->igaddr1, 0xffffffff);
1802 gfar_write(&regs->igaddr2, 0xffffffff);
1803 gfar_write(&regs->igaddr3, 0xffffffff);
1804 gfar_write(&regs->igaddr4, 0xffffffff);
1805 gfar_write(&regs->igaddr5, 0xffffffff);
1806 gfar_write(&regs->igaddr6, 0xffffffff);
1807 gfar_write(&regs->igaddr7, 0xffffffff);
1808 gfar_write(&regs->gaddr0, 0xffffffff);
1809 gfar_write(&regs->gaddr1, 0xffffffff);
1810 gfar_write(&regs->gaddr2, 0xffffffff);
1811 gfar_write(&regs->gaddr3, 0xffffffff);
1812 gfar_write(&regs->gaddr4, 0xffffffff);
1813 gfar_write(&regs->gaddr5, 0xffffffff);
1814 gfar_write(&regs->gaddr6, 0xffffffff);
1815 gfar_write(&regs->gaddr7, 0xffffffff);
1816 } else {
1817 int em_num;
1818 int idx;
1820 /* zero out the hash */
1821 gfar_write(&regs->igaddr0, 0x0);
1822 gfar_write(&regs->igaddr1, 0x0);
1823 gfar_write(&regs->igaddr2, 0x0);
1824 gfar_write(&regs->igaddr3, 0x0);
1825 gfar_write(&regs->igaddr4, 0x0);
1826 gfar_write(&regs->igaddr5, 0x0);
1827 gfar_write(&regs->igaddr6, 0x0);
1828 gfar_write(&regs->igaddr7, 0x0);
1829 gfar_write(&regs->gaddr0, 0x0);
1830 gfar_write(&regs->gaddr1, 0x0);
1831 gfar_write(&regs->gaddr2, 0x0);
1832 gfar_write(&regs->gaddr3, 0x0);
1833 gfar_write(&regs->gaddr4, 0x0);
1834 gfar_write(&regs->gaddr5, 0x0);
1835 gfar_write(&regs->gaddr6, 0x0);
1836 gfar_write(&regs->gaddr7, 0x0);
1838 /* If we have extended hash tables, we need to
1839 * clear the exact match registers to prepare for
1840 * setting them */
1841 if (priv->extended_hash) {
1842 em_num = GFAR_EM_NUM + 1;
1843 gfar_clear_exact_match(dev);
1844 idx = 1;
1845 } else {
1846 idx = 0;
1847 em_num = 0;
1850 if(dev->mc_count == 0)
1851 return;
1853 /* Parse the list, and set the appropriate bits */
1854 for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
1855 if (idx < em_num) {
1856 gfar_set_mac_for_addr(dev, idx,
1857 mc_ptr->dmi_addr);
1858 idx++;
1859 } else
1860 gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
1864 return;
1868 /* Clears each of the exact match registers to zero, so they
1869 * don't interfere with normal reception */
1870 static void gfar_clear_exact_match(struct net_device *dev)
1872 int idx;
1873 u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0};
1875 for(idx = 1;idx < GFAR_EM_NUM + 1;idx++)
1876 gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr);
1879 /* Set the appropriate hash bit for the given addr */
1880 /* The algorithm works like so:
1881 * 1) Take the Destination Address (ie the multicast address), and
1882 * do a CRC on it (little endian), and reverse the bits of the
1883 * result.
1884 * 2) Use the 8 most significant bits as a hash into a 256-entry
1885 * table. The table is controlled through 8 32-bit registers:
1886 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1887 * gaddr7. This means that the 3 most significant bits in the
1888 * hash index which gaddr register to use, and the 5 other bits
1889 * indicate which bit (assuming an IBM numbering scheme, which
1890 * for PowerPC (tm) is usually the case) in the register holds
1891 * the entry. */
1892 static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
1894 u32 tempval;
1895 struct gfar_private *priv = netdev_priv(dev);
1896 u32 result = ether_crc(MAC_ADDR_LEN, addr);
1897 int width = priv->hash_width;
1898 u8 whichbit = (result >> (32 - width)) & 0x1f;
1899 u8 whichreg = result >> (32 - width + 5);
1900 u32 value = (1 << (31-whichbit));
1902 tempval = gfar_read(priv->hash_regs[whichreg]);
1903 tempval |= value;
1904 gfar_write(priv->hash_regs[whichreg], tempval);
1906 return;
1910 /* There are multiple MAC Address register pairs on some controllers
1911 * This function sets the numth pair to a given address
1913 static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr)
1915 struct gfar_private *priv = netdev_priv(dev);
1916 int idx;
1917 char tmpbuf[MAC_ADDR_LEN];
1918 u32 tempval;
1919 u32 __iomem *macptr = &priv->regs->macstnaddr1;
1921 macptr += num*2;
1923 /* Now copy it into the mac registers backwards, cuz */
1924 /* little endian is silly */
1925 for (idx = 0; idx < MAC_ADDR_LEN; idx++)
1926 tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx];
1928 gfar_write(macptr, *((u32 *) (tmpbuf)));
1930 tempval = *((u32 *) (tmpbuf + 4));
1932 gfar_write(macptr+1, tempval);
1935 /* GFAR error interrupt handler */
1936 static irqreturn_t gfar_error(int irq, void *dev_id)
1938 struct net_device *dev = dev_id;
1939 struct gfar_private *priv = netdev_priv(dev);
1941 /* Save ievent for future reference */
1942 u32 events = gfar_read(&priv->regs->ievent);
1944 /* Clear IEVENT */
1945 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK);
1947 /* Hmm... */
1948 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
1949 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
1950 dev->name, events, gfar_read(&priv->regs->imask));
1952 /* Update the error counters */
1953 if (events & IEVENT_TXE) {
1954 dev->stats.tx_errors++;
1956 if (events & IEVENT_LC)
1957 dev->stats.tx_window_errors++;
1958 if (events & IEVENT_CRL)
1959 dev->stats.tx_aborted_errors++;
1960 if (events & IEVENT_XFUN) {
1961 if (netif_msg_tx_err(priv))
1962 printk(KERN_DEBUG "%s: TX FIFO underrun, "
1963 "packet dropped.\n", dev->name);
1964 dev->stats.tx_dropped++;
1965 priv->extra_stats.tx_underrun++;
1967 /* Reactivate the Tx Queues */
1968 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1970 if (netif_msg_tx_err(priv))
1971 printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
1973 if (events & IEVENT_BSY) {
1974 dev->stats.rx_errors++;
1975 priv->extra_stats.rx_bsy++;
1977 gfar_receive(irq, dev_id);
1979 #ifndef CONFIG_GFAR_NAPI
1980 /* Clear the halt bit in RSTAT */
1981 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1982 #endif
1984 if (netif_msg_rx_err(priv))
1985 printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
1986 dev->name, gfar_read(&priv->regs->rstat));
1988 if (events & IEVENT_BABR) {
1989 dev->stats.rx_errors++;
1990 priv->extra_stats.rx_babr++;
1992 if (netif_msg_rx_err(priv))
1993 printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
1995 if (events & IEVENT_EBERR) {
1996 priv->extra_stats.eberr++;
1997 if (netif_msg_rx_err(priv))
1998 printk(KERN_DEBUG "%s: bus error\n", dev->name);
2000 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
2001 printk(KERN_DEBUG "%s: control frame\n", dev->name);
2003 if (events & IEVENT_BABT) {
2004 priv->extra_stats.tx_babt++;
2005 if (netif_msg_tx_err(priv))
2006 printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
2008 return IRQ_HANDLED;
2011 /* Structure for a device driver */
2012 static struct platform_driver gfar_driver = {
2013 .probe = gfar_probe,
2014 .remove = gfar_remove,
2015 .driver = {
2016 .name = "fsl-gianfar",
2020 static int __init gfar_init(void)
2022 int err = gfar_mdio_init();
2024 if (err)
2025 return err;
2027 err = platform_driver_register(&gfar_driver);
2029 if (err)
2030 gfar_mdio_exit();
2032 return err;
2035 static void __exit gfar_exit(void)
2037 platform_driver_unregister(&gfar_driver);
2038 gfar_mdio_exit();
2041 module_init(gfar_init);
2042 module_exit(gfar_exit);