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