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