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