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