10977f817SJan Ceuleers /* drivers/net/ethernet/freescale/gianfar.c 2ec21e2ecSJeff Kirsher * 3ec21e2ecSJeff Kirsher * Gianfar Ethernet Driver 4ec21e2ecSJeff Kirsher * This driver is designed for the non-CPM ethernet controllers 5ec21e2ecSJeff Kirsher * on the 85xx and 83xx family of integrated processors 6ec21e2ecSJeff Kirsher * Based on 8260_io/fcc_enet.c 7ec21e2ecSJeff Kirsher * 8ec21e2ecSJeff Kirsher * Author: Andy Fleming 9ec21e2ecSJeff Kirsher * Maintainer: Kumar Gala 10ec21e2ecSJeff Kirsher * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> 11ec21e2ecSJeff Kirsher * 12ec21e2ecSJeff Kirsher * Copyright 2002-2009, 2011 Freescale Semiconductor, Inc. 13ec21e2ecSJeff Kirsher * Copyright 2007 MontaVista Software, Inc. 14ec21e2ecSJeff Kirsher * 15ec21e2ecSJeff Kirsher * This program is free software; you can redistribute it and/or modify it 16ec21e2ecSJeff Kirsher * under the terms of the GNU General Public License as published by the 17ec21e2ecSJeff Kirsher * Free Software Foundation; either version 2 of the License, or (at your 18ec21e2ecSJeff Kirsher * option) any later version. 19ec21e2ecSJeff Kirsher * 20ec21e2ecSJeff Kirsher * Gianfar: AKA Lambda Draconis, "Dragon" 21ec21e2ecSJeff Kirsher * RA 11 31 24.2 22ec21e2ecSJeff Kirsher * Dec +69 19 52 23ec21e2ecSJeff Kirsher * V 3.84 24ec21e2ecSJeff Kirsher * B-V +1.62 25ec21e2ecSJeff Kirsher * 26ec21e2ecSJeff Kirsher * Theory of operation 27ec21e2ecSJeff Kirsher * 28ec21e2ecSJeff Kirsher * The driver is initialized through of_device. Configuration information 29ec21e2ecSJeff Kirsher * is therefore conveyed through an OF-style device tree. 30ec21e2ecSJeff Kirsher * 31ec21e2ecSJeff Kirsher * The Gianfar Ethernet Controller uses a ring of buffer 32ec21e2ecSJeff Kirsher * descriptors. The beginning is indicated by a register 33ec21e2ecSJeff Kirsher * pointing to the physical address of the start of the ring. 34ec21e2ecSJeff Kirsher * The end is determined by a "wrap" bit being set in the 35ec21e2ecSJeff Kirsher * last descriptor of the ring. 36ec21e2ecSJeff Kirsher * 37ec21e2ecSJeff Kirsher * When a packet is received, the RXF bit in the 38ec21e2ecSJeff Kirsher * IEVENT register is set, triggering an interrupt when the 39ec21e2ecSJeff Kirsher * corresponding bit in the IMASK register is also set (if 40ec21e2ecSJeff Kirsher * interrupt coalescing is active, then the interrupt may not 41ec21e2ecSJeff Kirsher * happen immediately, but will wait until either a set number 42ec21e2ecSJeff Kirsher * of frames or amount of time have passed). In NAPI, the 43ec21e2ecSJeff Kirsher * interrupt handler will signal there is work to be done, and 44ec21e2ecSJeff Kirsher * exit. This method will start at the last known empty 45ec21e2ecSJeff Kirsher * descriptor, and process every subsequent descriptor until there 46ec21e2ecSJeff Kirsher * are none left with data (NAPI will stop after a set number of 47ec21e2ecSJeff Kirsher * packets to give time to other tasks, but will eventually 48ec21e2ecSJeff Kirsher * process all the packets). The data arrives inside a 49ec21e2ecSJeff Kirsher * pre-allocated skb, and so after the skb is passed up to the 50ec21e2ecSJeff Kirsher * stack, a new skb must be allocated, and the address field in 51ec21e2ecSJeff Kirsher * the buffer descriptor must be updated to indicate this new 52ec21e2ecSJeff Kirsher * skb. 53ec21e2ecSJeff Kirsher * 54ec21e2ecSJeff Kirsher * When the kernel requests that a packet be transmitted, the 55ec21e2ecSJeff Kirsher * driver starts where it left off last time, and points the 56ec21e2ecSJeff Kirsher * descriptor at the buffer which was passed in. The driver 57ec21e2ecSJeff Kirsher * then informs the DMA engine that there are packets ready to 58ec21e2ecSJeff Kirsher * be transmitted. Once the controller is finished transmitting 59ec21e2ecSJeff Kirsher * the packet, an interrupt may be triggered (under the same 60ec21e2ecSJeff Kirsher * conditions as for reception, but depending on the TXF bit). 61ec21e2ecSJeff Kirsher * The driver then cleans up the buffer. 62ec21e2ecSJeff Kirsher */ 63ec21e2ecSJeff Kirsher 64ec21e2ecSJeff Kirsher #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 65ec21e2ecSJeff Kirsher #define DEBUG 66ec21e2ecSJeff Kirsher 67ec21e2ecSJeff Kirsher #include <linux/kernel.h> 68ec21e2ecSJeff Kirsher #include <linux/string.h> 69ec21e2ecSJeff Kirsher #include <linux/errno.h> 70ec21e2ecSJeff Kirsher #include <linux/unistd.h> 71ec21e2ecSJeff Kirsher #include <linux/slab.h> 72ec21e2ecSJeff Kirsher #include <linux/interrupt.h> 73ec21e2ecSJeff Kirsher #include <linux/init.h> 74ec21e2ecSJeff Kirsher #include <linux/delay.h> 75ec21e2ecSJeff Kirsher #include <linux/netdevice.h> 76ec21e2ecSJeff Kirsher #include <linux/etherdevice.h> 77ec21e2ecSJeff Kirsher #include <linux/skbuff.h> 78ec21e2ecSJeff Kirsher #include <linux/if_vlan.h> 79ec21e2ecSJeff Kirsher #include <linux/spinlock.h> 80ec21e2ecSJeff Kirsher #include <linux/mm.h> 81ec21e2ecSJeff Kirsher #include <linux/of_mdio.h> 82ec21e2ecSJeff Kirsher #include <linux/of_platform.h> 83ec21e2ecSJeff Kirsher #include <linux/ip.h> 84ec21e2ecSJeff Kirsher #include <linux/tcp.h> 85ec21e2ecSJeff Kirsher #include <linux/udp.h> 86ec21e2ecSJeff Kirsher #include <linux/in.h> 87ec21e2ecSJeff Kirsher #include <linux/net_tstamp.h> 88ec21e2ecSJeff Kirsher 89ec21e2ecSJeff Kirsher #include <asm/io.h> 90ec21e2ecSJeff Kirsher #include <asm/reg.h> 91ec21e2ecSJeff Kirsher #include <asm/irq.h> 92ec21e2ecSJeff Kirsher #include <asm/uaccess.h> 93ec21e2ecSJeff Kirsher #include <linux/module.h> 94ec21e2ecSJeff Kirsher #include <linux/dma-mapping.h> 95ec21e2ecSJeff Kirsher #include <linux/crc32.h> 96ec21e2ecSJeff Kirsher #include <linux/mii.h> 97ec21e2ecSJeff Kirsher #include <linux/phy.h> 98ec21e2ecSJeff Kirsher #include <linux/phy_fixed.h> 99ec21e2ecSJeff Kirsher #include <linux/of.h> 100ec21e2ecSJeff Kirsher #include <linux/of_net.h> 101ec21e2ecSJeff Kirsher 102ec21e2ecSJeff Kirsher #include "gianfar.h" 103ec21e2ecSJeff Kirsher 104ec21e2ecSJeff Kirsher #define TX_TIMEOUT (1*HZ) 105ec21e2ecSJeff Kirsher 106ec21e2ecSJeff Kirsher const char gfar_driver_version[] = "1.3"; 107ec21e2ecSJeff Kirsher 108ec21e2ecSJeff Kirsher static int gfar_enet_open(struct net_device *dev); 109ec21e2ecSJeff Kirsher static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); 110ec21e2ecSJeff Kirsher static void gfar_reset_task(struct work_struct *work); 111ec21e2ecSJeff Kirsher static void gfar_timeout(struct net_device *dev); 112ec21e2ecSJeff Kirsher static int gfar_close(struct net_device *dev); 113ec21e2ecSJeff Kirsher struct sk_buff *gfar_new_skb(struct net_device *dev); 114ec21e2ecSJeff Kirsher static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, 115ec21e2ecSJeff Kirsher struct sk_buff *skb); 116ec21e2ecSJeff Kirsher static int gfar_set_mac_address(struct net_device *dev); 117ec21e2ecSJeff Kirsher static int gfar_change_mtu(struct net_device *dev, int new_mtu); 118ec21e2ecSJeff Kirsher static irqreturn_t gfar_error(int irq, void *dev_id); 119ec21e2ecSJeff Kirsher static irqreturn_t gfar_transmit(int irq, void *dev_id); 120ec21e2ecSJeff Kirsher static irqreturn_t gfar_interrupt(int irq, void *dev_id); 121ec21e2ecSJeff Kirsher static void adjust_link(struct net_device *dev); 122ec21e2ecSJeff Kirsher static void init_registers(struct net_device *dev); 123ec21e2ecSJeff Kirsher static int init_phy(struct net_device *dev); 124ec21e2ecSJeff Kirsher static int gfar_probe(struct platform_device *ofdev); 125ec21e2ecSJeff Kirsher static int gfar_remove(struct platform_device *ofdev); 126ec21e2ecSJeff Kirsher static void free_skb_resources(struct gfar_private *priv); 127ec21e2ecSJeff Kirsher static void gfar_set_multi(struct net_device *dev); 128ec21e2ecSJeff Kirsher static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); 129ec21e2ecSJeff Kirsher static void gfar_configure_serdes(struct net_device *dev); 130ec21e2ecSJeff Kirsher static int gfar_poll(struct napi_struct *napi, int budget); 131ec21e2ecSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 132ec21e2ecSJeff Kirsher static void gfar_netpoll(struct net_device *dev); 133ec21e2ecSJeff Kirsher #endif 134ec21e2ecSJeff Kirsher int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit); 135ec21e2ecSJeff Kirsher static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue); 13661db26c6SClaudiu Manoil static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb, 137cd754a57SWu Jiajun-B06378 int amount_pull, struct napi_struct *napi); 138ec21e2ecSJeff Kirsher void gfar_halt(struct net_device *dev); 139ec21e2ecSJeff Kirsher static void gfar_halt_nodisable(struct net_device *dev); 140ec21e2ecSJeff Kirsher void gfar_start(struct net_device *dev); 141ec21e2ecSJeff Kirsher static void gfar_clear_exact_match(struct net_device *dev); 142ec21e2ecSJeff Kirsher static void gfar_set_mac_for_addr(struct net_device *dev, int num, 143ec21e2ecSJeff Kirsher const u8 *addr); 144ec21e2ecSJeff Kirsher static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 145ec21e2ecSJeff Kirsher 146ec21e2ecSJeff Kirsher MODULE_AUTHOR("Freescale Semiconductor, Inc"); 147ec21e2ecSJeff Kirsher MODULE_DESCRIPTION("Gianfar Ethernet Driver"); 148ec21e2ecSJeff Kirsher MODULE_LICENSE("GPL"); 149ec21e2ecSJeff Kirsher 150ec21e2ecSJeff Kirsher static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, 151ec21e2ecSJeff Kirsher dma_addr_t buf) 152ec21e2ecSJeff Kirsher { 153ec21e2ecSJeff Kirsher u32 lstatus; 154ec21e2ecSJeff Kirsher 155ec21e2ecSJeff Kirsher bdp->bufPtr = buf; 156ec21e2ecSJeff Kirsher 157ec21e2ecSJeff Kirsher lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT); 158ec21e2ecSJeff Kirsher if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1) 159ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(RXBD_WRAP); 160ec21e2ecSJeff Kirsher 161ec21e2ecSJeff Kirsher eieio(); 162ec21e2ecSJeff Kirsher 163ec21e2ecSJeff Kirsher bdp->lstatus = lstatus; 164ec21e2ecSJeff Kirsher } 165ec21e2ecSJeff Kirsher 166ec21e2ecSJeff Kirsher static int gfar_init_bds(struct net_device *ndev) 167ec21e2ecSJeff Kirsher { 168ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(ndev); 169ec21e2ecSJeff Kirsher struct gfar_priv_tx_q *tx_queue = NULL; 170ec21e2ecSJeff Kirsher struct gfar_priv_rx_q *rx_queue = NULL; 171ec21e2ecSJeff Kirsher struct txbd8 *txbdp; 172ec21e2ecSJeff Kirsher struct rxbd8 *rxbdp; 173ec21e2ecSJeff Kirsher int i, j; 174ec21e2ecSJeff Kirsher 175ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 176ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[i]; 177ec21e2ecSJeff Kirsher /* Initialize some variables in our dev structure */ 178ec21e2ecSJeff Kirsher tx_queue->num_txbdfree = tx_queue->tx_ring_size; 179ec21e2ecSJeff Kirsher tx_queue->dirty_tx = tx_queue->tx_bd_base; 180ec21e2ecSJeff Kirsher tx_queue->cur_tx = tx_queue->tx_bd_base; 181ec21e2ecSJeff Kirsher tx_queue->skb_curtx = 0; 182ec21e2ecSJeff Kirsher tx_queue->skb_dirtytx = 0; 183ec21e2ecSJeff Kirsher 184ec21e2ecSJeff Kirsher /* Initialize Transmit Descriptor Ring */ 185ec21e2ecSJeff Kirsher txbdp = tx_queue->tx_bd_base; 186ec21e2ecSJeff Kirsher for (j = 0; j < tx_queue->tx_ring_size; j++) { 187ec21e2ecSJeff Kirsher txbdp->lstatus = 0; 188ec21e2ecSJeff Kirsher txbdp->bufPtr = 0; 189ec21e2ecSJeff Kirsher txbdp++; 190ec21e2ecSJeff Kirsher } 191ec21e2ecSJeff Kirsher 192ec21e2ecSJeff Kirsher /* Set the last descriptor in the ring to indicate wrap */ 193ec21e2ecSJeff Kirsher txbdp--; 194ec21e2ecSJeff Kirsher txbdp->status |= TXBD_WRAP; 195ec21e2ecSJeff Kirsher } 196ec21e2ecSJeff Kirsher 197ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 198ec21e2ecSJeff Kirsher rx_queue = priv->rx_queue[i]; 199ec21e2ecSJeff Kirsher rx_queue->cur_rx = rx_queue->rx_bd_base; 200ec21e2ecSJeff Kirsher rx_queue->skb_currx = 0; 201ec21e2ecSJeff Kirsher rxbdp = rx_queue->rx_bd_base; 202ec21e2ecSJeff Kirsher 203ec21e2ecSJeff Kirsher for (j = 0; j < rx_queue->rx_ring_size; j++) { 204ec21e2ecSJeff Kirsher struct sk_buff *skb = rx_queue->rx_skbuff[j]; 205ec21e2ecSJeff Kirsher 206ec21e2ecSJeff Kirsher if (skb) { 207ec21e2ecSJeff Kirsher gfar_init_rxbdp(rx_queue, rxbdp, 208ec21e2ecSJeff Kirsher rxbdp->bufPtr); 209ec21e2ecSJeff Kirsher } else { 210ec21e2ecSJeff Kirsher skb = gfar_new_skb(ndev); 211ec21e2ecSJeff Kirsher if (!skb) { 212ec21e2ecSJeff Kirsher netdev_err(ndev, "Can't allocate RX buffers\n"); 2131eb8f7a7SClaudiu Manoil return -ENOMEM; 214ec21e2ecSJeff Kirsher } 215ec21e2ecSJeff Kirsher rx_queue->rx_skbuff[j] = skb; 216ec21e2ecSJeff Kirsher 217ec21e2ecSJeff Kirsher gfar_new_rxbdp(rx_queue, rxbdp, skb); 218ec21e2ecSJeff Kirsher } 219ec21e2ecSJeff Kirsher 220ec21e2ecSJeff Kirsher rxbdp++; 221ec21e2ecSJeff Kirsher } 222ec21e2ecSJeff Kirsher 223ec21e2ecSJeff Kirsher } 224ec21e2ecSJeff Kirsher 225ec21e2ecSJeff Kirsher return 0; 226ec21e2ecSJeff Kirsher } 227ec21e2ecSJeff Kirsher 228ec21e2ecSJeff Kirsher static int gfar_alloc_skb_resources(struct net_device *ndev) 229ec21e2ecSJeff Kirsher { 230ec21e2ecSJeff Kirsher void *vaddr; 231ec21e2ecSJeff Kirsher dma_addr_t addr; 232ec21e2ecSJeff Kirsher int i, j, k; 233ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(ndev); 234369ec162SClaudiu Manoil struct device *dev = priv->dev; 235ec21e2ecSJeff Kirsher struct gfar_priv_tx_q *tx_queue = NULL; 236ec21e2ecSJeff Kirsher struct gfar_priv_rx_q *rx_queue = NULL; 237ec21e2ecSJeff Kirsher 238ec21e2ecSJeff Kirsher priv->total_tx_ring_size = 0; 239ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 240ec21e2ecSJeff Kirsher priv->total_tx_ring_size += priv->tx_queue[i]->tx_ring_size; 241ec21e2ecSJeff Kirsher 242ec21e2ecSJeff Kirsher priv->total_rx_ring_size = 0; 243ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 244ec21e2ecSJeff Kirsher priv->total_rx_ring_size += priv->rx_queue[i]->rx_ring_size; 245ec21e2ecSJeff Kirsher 246ec21e2ecSJeff Kirsher /* Allocate memory for the buffer descriptors */ 247ec21e2ecSJeff Kirsher vaddr = dma_alloc_coherent(dev, 248ec21e2ecSJeff Kirsher sizeof(struct txbd8) * priv->total_tx_ring_size + 249ec21e2ecSJeff Kirsher sizeof(struct rxbd8) * priv->total_rx_ring_size, 250ec21e2ecSJeff Kirsher &addr, GFP_KERNEL); 251ec21e2ecSJeff Kirsher if (!vaddr) { 252ec21e2ecSJeff Kirsher netif_err(priv, ifup, ndev, 253ec21e2ecSJeff Kirsher "Could not allocate buffer descriptors!\n"); 254ec21e2ecSJeff Kirsher return -ENOMEM; 255ec21e2ecSJeff Kirsher } 256ec21e2ecSJeff Kirsher 257ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 258ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[i]; 259ec21e2ecSJeff Kirsher tx_queue->tx_bd_base = vaddr; 260ec21e2ecSJeff Kirsher tx_queue->tx_bd_dma_base = addr; 261ec21e2ecSJeff Kirsher tx_queue->dev = ndev; 262ec21e2ecSJeff Kirsher /* enet DMA only understands physical addresses */ 263ec21e2ecSJeff Kirsher addr += sizeof(struct txbd8) * tx_queue->tx_ring_size; 264ec21e2ecSJeff Kirsher vaddr += sizeof(struct txbd8) * tx_queue->tx_ring_size; 265ec21e2ecSJeff Kirsher } 266ec21e2ecSJeff Kirsher 267ec21e2ecSJeff Kirsher /* Start the rx descriptor ring where the tx ring leaves off */ 268ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 269ec21e2ecSJeff Kirsher rx_queue = priv->rx_queue[i]; 270ec21e2ecSJeff Kirsher rx_queue->rx_bd_base = vaddr; 271ec21e2ecSJeff Kirsher rx_queue->rx_bd_dma_base = addr; 272ec21e2ecSJeff Kirsher rx_queue->dev = ndev; 273ec21e2ecSJeff Kirsher addr += sizeof(struct rxbd8) * rx_queue->rx_ring_size; 274ec21e2ecSJeff Kirsher vaddr += sizeof(struct rxbd8) * rx_queue->rx_ring_size; 275ec21e2ecSJeff Kirsher } 276ec21e2ecSJeff Kirsher 277ec21e2ecSJeff Kirsher /* Setup the skbuff rings */ 278ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 279ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[i]; 28014f8dc49SJoe Perches tx_queue->tx_skbuff = 28114f8dc49SJoe Perches kmalloc_array(tx_queue->tx_ring_size, 28214f8dc49SJoe Perches sizeof(*tx_queue->tx_skbuff), 283bc4598bcSJan Ceuleers GFP_KERNEL); 28414f8dc49SJoe Perches if (!tx_queue->tx_skbuff) 285ec21e2ecSJeff Kirsher goto cleanup; 286ec21e2ecSJeff Kirsher 287ec21e2ecSJeff Kirsher for (k = 0; k < tx_queue->tx_ring_size; k++) 288ec21e2ecSJeff Kirsher tx_queue->tx_skbuff[k] = NULL; 289ec21e2ecSJeff Kirsher } 290ec21e2ecSJeff Kirsher 291ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 292ec21e2ecSJeff Kirsher rx_queue = priv->rx_queue[i]; 29314f8dc49SJoe Perches rx_queue->rx_skbuff = 29414f8dc49SJoe Perches kmalloc_array(rx_queue->rx_ring_size, 29514f8dc49SJoe Perches sizeof(*rx_queue->rx_skbuff), 296bc4598bcSJan Ceuleers GFP_KERNEL); 29714f8dc49SJoe Perches if (!rx_queue->rx_skbuff) 298ec21e2ecSJeff Kirsher goto cleanup; 299ec21e2ecSJeff Kirsher 300ec21e2ecSJeff Kirsher for (j = 0; j < rx_queue->rx_ring_size; j++) 301ec21e2ecSJeff Kirsher rx_queue->rx_skbuff[j] = NULL; 302ec21e2ecSJeff Kirsher } 303ec21e2ecSJeff Kirsher 304ec21e2ecSJeff Kirsher if (gfar_init_bds(ndev)) 305ec21e2ecSJeff Kirsher goto cleanup; 306ec21e2ecSJeff Kirsher 307ec21e2ecSJeff Kirsher return 0; 308ec21e2ecSJeff Kirsher 309ec21e2ecSJeff Kirsher cleanup: 310ec21e2ecSJeff Kirsher free_skb_resources(priv); 311ec21e2ecSJeff Kirsher return -ENOMEM; 312ec21e2ecSJeff Kirsher } 313ec21e2ecSJeff Kirsher 314ec21e2ecSJeff Kirsher static void gfar_init_tx_rx_base(struct gfar_private *priv) 315ec21e2ecSJeff Kirsher { 316ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 317ec21e2ecSJeff Kirsher u32 __iomem *baddr; 318ec21e2ecSJeff Kirsher int i; 319ec21e2ecSJeff Kirsher 320ec21e2ecSJeff Kirsher baddr = ®s->tbase0; 321ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 322ec21e2ecSJeff Kirsher gfar_write(baddr, priv->tx_queue[i]->tx_bd_dma_base); 323ec21e2ecSJeff Kirsher baddr += 2; 324ec21e2ecSJeff Kirsher } 325ec21e2ecSJeff Kirsher 326ec21e2ecSJeff Kirsher baddr = ®s->rbase0; 327ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 328ec21e2ecSJeff Kirsher gfar_write(baddr, priv->rx_queue[i]->rx_bd_dma_base); 329ec21e2ecSJeff Kirsher baddr += 2; 330ec21e2ecSJeff Kirsher } 331ec21e2ecSJeff Kirsher } 332ec21e2ecSJeff Kirsher 333ec21e2ecSJeff Kirsher static void gfar_init_mac(struct net_device *ndev) 334ec21e2ecSJeff Kirsher { 335ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(ndev); 336ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 337ec21e2ecSJeff Kirsher u32 rctrl = 0; 338ec21e2ecSJeff Kirsher u32 tctrl = 0; 339ec21e2ecSJeff Kirsher u32 attrs = 0; 340ec21e2ecSJeff Kirsher 341ec21e2ecSJeff Kirsher /* write the tx/rx base registers */ 342ec21e2ecSJeff Kirsher gfar_init_tx_rx_base(priv); 343ec21e2ecSJeff Kirsher 344ec21e2ecSJeff Kirsher /* Configure the coalescing support */ 345ec21e2ecSJeff Kirsher gfar_configure_coalescing(priv, 0xFF, 0xFF); 346ec21e2ecSJeff Kirsher 347ba779711SClaudiu Manoil /* set this when rx hw offload (TOE) functions are being used */ 348ba779711SClaudiu Manoil priv->uses_rxfcb = 0; 349ba779711SClaudiu Manoil 350ec21e2ecSJeff Kirsher if (priv->rx_filer_enable) { 351ec21e2ecSJeff Kirsher rctrl |= RCTRL_FILREN; 352ec21e2ecSJeff Kirsher /* Program the RIR0 reg with the required distribution */ 353ec21e2ecSJeff Kirsher gfar_write(®s->rir0, DEFAULT_RIR0); 354ec21e2ecSJeff Kirsher } 355ec21e2ecSJeff Kirsher 356f5ae6279SClaudiu Manoil /* Restore PROMISC mode */ 357f5ae6279SClaudiu Manoil if (ndev->flags & IFF_PROMISC) 358f5ae6279SClaudiu Manoil rctrl |= RCTRL_PROM; 359f5ae6279SClaudiu Manoil 360ba779711SClaudiu Manoil if (ndev->features & NETIF_F_RXCSUM) { 361ec21e2ecSJeff Kirsher rctrl |= RCTRL_CHECKSUMMING; 362ba779711SClaudiu Manoil priv->uses_rxfcb = 1; 363ba779711SClaudiu Manoil } 364ec21e2ecSJeff Kirsher 365ec21e2ecSJeff Kirsher if (priv->extended_hash) { 366ec21e2ecSJeff Kirsher rctrl |= RCTRL_EXTHASH; 367ec21e2ecSJeff Kirsher 368ec21e2ecSJeff Kirsher gfar_clear_exact_match(ndev); 369ec21e2ecSJeff Kirsher rctrl |= RCTRL_EMEN; 370ec21e2ecSJeff Kirsher } 371ec21e2ecSJeff Kirsher 372ec21e2ecSJeff Kirsher if (priv->padding) { 373ec21e2ecSJeff Kirsher rctrl &= ~RCTRL_PAL_MASK; 374ec21e2ecSJeff Kirsher rctrl |= RCTRL_PADDING(priv->padding); 375ec21e2ecSJeff Kirsher } 376ec21e2ecSJeff Kirsher 377ec21e2ecSJeff Kirsher /* Insert receive time stamps into padding alignment bytes */ 378ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) { 379ec21e2ecSJeff Kirsher rctrl &= ~RCTRL_PAL_MASK; 380ec21e2ecSJeff Kirsher rctrl |= RCTRL_PADDING(8); 381ec21e2ecSJeff Kirsher priv->padding = 8; 382ec21e2ecSJeff Kirsher } 383ec21e2ecSJeff Kirsher 384ec21e2ecSJeff Kirsher /* Enable HW time stamping if requested from user space */ 385ba779711SClaudiu Manoil if (priv->hwts_rx_en) { 386ec21e2ecSJeff Kirsher rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE; 387ba779711SClaudiu Manoil priv->uses_rxfcb = 1; 388ba779711SClaudiu Manoil } 389ec21e2ecSJeff Kirsher 390ba779711SClaudiu Manoil if (ndev->features & NETIF_F_HW_VLAN_RX) { 391ec21e2ecSJeff Kirsher rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT; 392ba779711SClaudiu Manoil priv->uses_rxfcb = 1; 393ba779711SClaudiu Manoil } 394ec21e2ecSJeff Kirsher 395ec21e2ecSJeff Kirsher /* Init rctrl based on our settings */ 396ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, rctrl); 397ec21e2ecSJeff Kirsher 398ec21e2ecSJeff Kirsher if (ndev->features & NETIF_F_IP_CSUM) 399ec21e2ecSJeff Kirsher tctrl |= TCTRL_INIT_CSUM; 400ec21e2ecSJeff Kirsher 401b98b8babSClaudiu Manoil if (priv->prio_sched_en) 402ec21e2ecSJeff Kirsher tctrl |= TCTRL_TXSCHED_PRIO; 403b98b8babSClaudiu Manoil else { 404b98b8babSClaudiu Manoil tctrl |= TCTRL_TXSCHED_WRRS; 405b98b8babSClaudiu Manoil gfar_write(®s->tr03wt, DEFAULT_WRRS_WEIGHT); 406b98b8babSClaudiu Manoil gfar_write(®s->tr47wt, DEFAULT_WRRS_WEIGHT); 407b98b8babSClaudiu Manoil } 408ec21e2ecSJeff Kirsher 409ec21e2ecSJeff Kirsher gfar_write(®s->tctrl, tctrl); 410ec21e2ecSJeff Kirsher 411ec21e2ecSJeff Kirsher /* Set the extraction length and index */ 412ec21e2ecSJeff Kirsher attrs = ATTRELI_EL(priv->rx_stash_size) | 413ec21e2ecSJeff Kirsher ATTRELI_EI(priv->rx_stash_index); 414ec21e2ecSJeff Kirsher 415ec21e2ecSJeff Kirsher gfar_write(®s->attreli, attrs); 416ec21e2ecSJeff Kirsher 417ec21e2ecSJeff Kirsher /* Start with defaults, and add stashing or locking 4180977f817SJan Ceuleers * depending on the approprate variables 4190977f817SJan Ceuleers */ 420ec21e2ecSJeff Kirsher attrs = ATTR_INIT_SETTINGS; 421ec21e2ecSJeff Kirsher 422ec21e2ecSJeff Kirsher if (priv->bd_stash_en) 423ec21e2ecSJeff Kirsher attrs |= ATTR_BDSTASH; 424ec21e2ecSJeff Kirsher 425ec21e2ecSJeff Kirsher if (priv->rx_stash_size != 0) 426ec21e2ecSJeff Kirsher attrs |= ATTR_BUFSTASH; 427ec21e2ecSJeff Kirsher 428ec21e2ecSJeff Kirsher gfar_write(®s->attr, attrs); 429ec21e2ecSJeff Kirsher 430ec21e2ecSJeff Kirsher gfar_write(®s->fifo_tx_thr, priv->fifo_threshold); 431ec21e2ecSJeff Kirsher gfar_write(®s->fifo_tx_starve, priv->fifo_starve); 432ec21e2ecSJeff Kirsher gfar_write(®s->fifo_tx_starve_shutoff, priv->fifo_starve_off); 433ec21e2ecSJeff Kirsher } 434ec21e2ecSJeff Kirsher 435ec21e2ecSJeff Kirsher static struct net_device_stats *gfar_get_stats(struct net_device *dev) 436ec21e2ecSJeff Kirsher { 437ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 438ec21e2ecSJeff Kirsher unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0; 439ec21e2ecSJeff Kirsher unsigned long tx_packets = 0, tx_bytes = 0; 4403a2e16c8SJan Ceuleers int i; 441ec21e2ecSJeff Kirsher 442ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 443ec21e2ecSJeff Kirsher rx_packets += priv->rx_queue[i]->stats.rx_packets; 444ec21e2ecSJeff Kirsher rx_bytes += priv->rx_queue[i]->stats.rx_bytes; 445ec21e2ecSJeff Kirsher rx_dropped += priv->rx_queue[i]->stats.rx_dropped; 446ec21e2ecSJeff Kirsher } 447ec21e2ecSJeff Kirsher 448ec21e2ecSJeff Kirsher dev->stats.rx_packets = rx_packets; 449ec21e2ecSJeff Kirsher dev->stats.rx_bytes = rx_bytes; 450ec21e2ecSJeff Kirsher dev->stats.rx_dropped = rx_dropped; 451ec21e2ecSJeff Kirsher 452ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 453ec21e2ecSJeff Kirsher tx_bytes += priv->tx_queue[i]->stats.tx_bytes; 454ec21e2ecSJeff Kirsher tx_packets += priv->tx_queue[i]->stats.tx_packets; 455ec21e2ecSJeff Kirsher } 456ec21e2ecSJeff Kirsher 457ec21e2ecSJeff Kirsher dev->stats.tx_bytes = tx_bytes; 458ec21e2ecSJeff Kirsher dev->stats.tx_packets = tx_packets; 459ec21e2ecSJeff Kirsher 460ec21e2ecSJeff Kirsher return &dev->stats; 461ec21e2ecSJeff Kirsher } 462ec21e2ecSJeff Kirsher 463ec21e2ecSJeff Kirsher static const struct net_device_ops gfar_netdev_ops = { 464ec21e2ecSJeff Kirsher .ndo_open = gfar_enet_open, 465ec21e2ecSJeff Kirsher .ndo_start_xmit = gfar_start_xmit, 466ec21e2ecSJeff Kirsher .ndo_stop = gfar_close, 467ec21e2ecSJeff Kirsher .ndo_change_mtu = gfar_change_mtu, 468ec21e2ecSJeff Kirsher .ndo_set_features = gfar_set_features, 469afc4b13dSJiri Pirko .ndo_set_rx_mode = gfar_set_multi, 470ec21e2ecSJeff Kirsher .ndo_tx_timeout = gfar_timeout, 471ec21e2ecSJeff Kirsher .ndo_do_ioctl = gfar_ioctl, 472ec21e2ecSJeff Kirsher .ndo_get_stats = gfar_get_stats, 473ec21e2ecSJeff Kirsher .ndo_set_mac_address = eth_mac_addr, 474ec21e2ecSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 475ec21e2ecSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 476ec21e2ecSJeff Kirsher .ndo_poll_controller = gfar_netpoll, 477ec21e2ecSJeff Kirsher #endif 478ec21e2ecSJeff Kirsher }; 479ec21e2ecSJeff Kirsher 480ec21e2ecSJeff Kirsher void lock_rx_qs(struct gfar_private *priv) 481ec21e2ecSJeff Kirsher { 4823a2e16c8SJan Ceuleers int i; 483ec21e2ecSJeff Kirsher 484ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 485ec21e2ecSJeff Kirsher spin_lock(&priv->rx_queue[i]->rxlock); 486ec21e2ecSJeff Kirsher } 487ec21e2ecSJeff Kirsher 488ec21e2ecSJeff Kirsher void lock_tx_qs(struct gfar_private *priv) 489ec21e2ecSJeff Kirsher { 4903a2e16c8SJan Ceuleers int i; 491ec21e2ecSJeff Kirsher 492ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 493ec21e2ecSJeff Kirsher spin_lock(&priv->tx_queue[i]->txlock); 494ec21e2ecSJeff Kirsher } 495ec21e2ecSJeff Kirsher 496ec21e2ecSJeff Kirsher void unlock_rx_qs(struct gfar_private *priv) 497ec21e2ecSJeff Kirsher { 4983a2e16c8SJan Ceuleers int i; 499ec21e2ecSJeff Kirsher 500ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 501ec21e2ecSJeff Kirsher spin_unlock(&priv->rx_queue[i]->rxlock); 502ec21e2ecSJeff Kirsher } 503ec21e2ecSJeff Kirsher 504ec21e2ecSJeff Kirsher void unlock_tx_qs(struct gfar_private *priv) 505ec21e2ecSJeff Kirsher { 5063a2e16c8SJan Ceuleers int i; 507ec21e2ecSJeff Kirsher 508ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 509ec21e2ecSJeff Kirsher spin_unlock(&priv->tx_queue[i]->txlock); 510ec21e2ecSJeff Kirsher } 511ec21e2ecSJeff Kirsher 512ec21e2ecSJeff Kirsher static void free_tx_pointers(struct gfar_private *priv) 513ec21e2ecSJeff Kirsher { 5143a2e16c8SJan Ceuleers int i; 515ec21e2ecSJeff Kirsher 516ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 517ec21e2ecSJeff Kirsher kfree(priv->tx_queue[i]); 518ec21e2ecSJeff Kirsher } 519ec21e2ecSJeff Kirsher 520ec21e2ecSJeff Kirsher static void free_rx_pointers(struct gfar_private *priv) 521ec21e2ecSJeff Kirsher { 5223a2e16c8SJan Ceuleers int i; 523ec21e2ecSJeff Kirsher 524ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 525ec21e2ecSJeff Kirsher kfree(priv->rx_queue[i]); 526ec21e2ecSJeff Kirsher } 527ec21e2ecSJeff Kirsher 528ec21e2ecSJeff Kirsher static void unmap_group_regs(struct gfar_private *priv) 529ec21e2ecSJeff Kirsher { 5303a2e16c8SJan Ceuleers int i; 531ec21e2ecSJeff Kirsher 532ec21e2ecSJeff Kirsher for (i = 0; i < MAXGROUPS; i++) 533ec21e2ecSJeff Kirsher if (priv->gfargrp[i].regs) 534ec21e2ecSJeff Kirsher iounmap(priv->gfargrp[i].regs); 535ec21e2ecSJeff Kirsher } 536ec21e2ecSJeff Kirsher 537ee873fdaSClaudiu Manoil static void free_gfar_dev(struct gfar_private *priv) 538ee873fdaSClaudiu Manoil { 539ee873fdaSClaudiu Manoil int i, j; 540ee873fdaSClaudiu Manoil 541ee873fdaSClaudiu Manoil for (i = 0; i < priv->num_grps; i++) 542ee873fdaSClaudiu Manoil for (j = 0; j < GFAR_NUM_IRQS; j++) { 543ee873fdaSClaudiu Manoil kfree(priv->gfargrp[i].irqinfo[j]); 544ee873fdaSClaudiu Manoil priv->gfargrp[i].irqinfo[j] = NULL; 545ee873fdaSClaudiu Manoil } 546ee873fdaSClaudiu Manoil 547ee873fdaSClaudiu Manoil free_netdev(priv->ndev); 548ee873fdaSClaudiu Manoil } 549ee873fdaSClaudiu Manoil 550ec21e2ecSJeff Kirsher static void disable_napi(struct gfar_private *priv) 551ec21e2ecSJeff Kirsher { 5523a2e16c8SJan Ceuleers int i; 553ec21e2ecSJeff Kirsher 554ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) 555ec21e2ecSJeff Kirsher napi_disable(&priv->gfargrp[i].napi); 556ec21e2ecSJeff Kirsher } 557ec21e2ecSJeff Kirsher 558ec21e2ecSJeff Kirsher static void enable_napi(struct gfar_private *priv) 559ec21e2ecSJeff Kirsher { 5603a2e16c8SJan Ceuleers int i; 561ec21e2ecSJeff Kirsher 562ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) 563ec21e2ecSJeff Kirsher napi_enable(&priv->gfargrp[i].napi); 564ec21e2ecSJeff Kirsher } 565ec21e2ecSJeff Kirsher 566ec21e2ecSJeff Kirsher static int gfar_parse_group(struct device_node *np, 567ec21e2ecSJeff Kirsher struct gfar_private *priv, const char *model) 568ec21e2ecSJeff Kirsher { 5695fedcc14SClaudiu Manoil struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps]; 570ec21e2ecSJeff Kirsher u32 *queue_mask; 571ee873fdaSClaudiu Manoil int i; 572ee873fdaSClaudiu Manoil 573ee873fdaSClaudiu Manoil for (i = 0; i < GFAR_NUM_IRQS; i++) { 574ee873fdaSClaudiu Manoil grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo), 575ee873fdaSClaudiu Manoil GFP_KERNEL); 576ee873fdaSClaudiu Manoil if (!grp->irqinfo[i]) 577ee873fdaSClaudiu Manoil return -ENOMEM; 578ee873fdaSClaudiu Manoil } 579ec21e2ecSJeff Kirsher 5805fedcc14SClaudiu Manoil grp->regs = of_iomap(np, 0); 5815fedcc14SClaudiu Manoil if (!grp->regs) 582ec21e2ecSJeff Kirsher return -ENOMEM; 583ec21e2ecSJeff Kirsher 584ee873fdaSClaudiu Manoil gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0); 585ec21e2ecSJeff Kirsher 586ec21e2ecSJeff Kirsher /* If we aren't the FEC we have multiple interrupts */ 587ec21e2ecSJeff Kirsher if (model && strcasecmp(model, "FEC")) { 588ee873fdaSClaudiu Manoil gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1); 589ee873fdaSClaudiu Manoil gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2); 590ee873fdaSClaudiu Manoil if (gfar_irq(grp, TX)->irq == NO_IRQ || 591ee873fdaSClaudiu Manoil gfar_irq(grp, RX)->irq == NO_IRQ || 592ee873fdaSClaudiu Manoil gfar_irq(grp, ER)->irq == NO_IRQ) 593ec21e2ecSJeff Kirsher return -EINVAL; 594ec21e2ecSJeff Kirsher } 595ec21e2ecSJeff Kirsher 5965fedcc14SClaudiu Manoil grp->grp_id = priv->num_grps; 5975fedcc14SClaudiu Manoil grp->priv = priv; 5985fedcc14SClaudiu Manoil spin_lock_init(&grp->grplock); 599ec21e2ecSJeff Kirsher if (priv->mode == MQ_MG_MODE) { 600bc4598bcSJan Ceuleers queue_mask = (u32 *)of_get_property(np, "fsl,rx-bit-map", NULL); 6015fedcc14SClaudiu Manoil grp->rx_bit_map = queue_mask ? 602bc4598bcSJan Ceuleers *queue_mask : (DEFAULT_MAPPING >> priv->num_grps); 603bc4598bcSJan Ceuleers queue_mask = (u32 *)of_get_property(np, "fsl,tx-bit-map", NULL); 6045fedcc14SClaudiu Manoil grp->tx_bit_map = queue_mask ? 605bc4598bcSJan Ceuleers *queue_mask : (DEFAULT_MAPPING >> priv->num_grps); 606ec21e2ecSJeff Kirsher } else { 6075fedcc14SClaudiu Manoil grp->rx_bit_map = 0xFF; 6085fedcc14SClaudiu Manoil grp->tx_bit_map = 0xFF; 609ec21e2ecSJeff Kirsher } 610ec21e2ecSJeff Kirsher priv->num_grps++; 611ec21e2ecSJeff Kirsher 612ec21e2ecSJeff Kirsher return 0; 613ec21e2ecSJeff Kirsher } 614ec21e2ecSJeff Kirsher 615ec21e2ecSJeff Kirsher static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) 616ec21e2ecSJeff Kirsher { 617ec21e2ecSJeff Kirsher const char *model; 618ec21e2ecSJeff Kirsher const char *ctype; 619ec21e2ecSJeff Kirsher const void *mac_addr; 620ec21e2ecSJeff Kirsher int err = 0, i; 621ec21e2ecSJeff Kirsher struct net_device *dev = NULL; 622ec21e2ecSJeff Kirsher struct gfar_private *priv = NULL; 623ec21e2ecSJeff Kirsher struct device_node *np = ofdev->dev.of_node; 624ec21e2ecSJeff Kirsher struct device_node *child = NULL; 625ec21e2ecSJeff Kirsher const u32 *stash; 626ec21e2ecSJeff Kirsher const u32 *stash_len; 627ec21e2ecSJeff Kirsher const u32 *stash_idx; 628ec21e2ecSJeff Kirsher unsigned int num_tx_qs, num_rx_qs; 629ec21e2ecSJeff Kirsher u32 *tx_queues, *rx_queues; 630ec21e2ecSJeff Kirsher 631ec21e2ecSJeff Kirsher if (!np || !of_device_is_available(np)) 632ec21e2ecSJeff Kirsher return -ENODEV; 633ec21e2ecSJeff Kirsher 634ec21e2ecSJeff Kirsher /* parse the num of tx and rx queues */ 635ec21e2ecSJeff Kirsher tx_queues = (u32 *)of_get_property(np, "fsl,num_tx_queues", NULL); 636ec21e2ecSJeff Kirsher num_tx_qs = tx_queues ? *tx_queues : 1; 637ec21e2ecSJeff Kirsher 638ec21e2ecSJeff Kirsher if (num_tx_qs > MAX_TX_QS) { 639ec21e2ecSJeff Kirsher pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n", 640ec21e2ecSJeff Kirsher num_tx_qs, MAX_TX_QS); 641ec21e2ecSJeff Kirsher pr_err("Cannot do alloc_etherdev, aborting\n"); 642ec21e2ecSJeff Kirsher return -EINVAL; 643ec21e2ecSJeff Kirsher } 644ec21e2ecSJeff Kirsher 645ec21e2ecSJeff Kirsher rx_queues = (u32 *)of_get_property(np, "fsl,num_rx_queues", NULL); 646ec21e2ecSJeff Kirsher num_rx_qs = rx_queues ? *rx_queues : 1; 647ec21e2ecSJeff Kirsher 648ec21e2ecSJeff Kirsher if (num_rx_qs > MAX_RX_QS) { 649ec21e2ecSJeff Kirsher pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n", 650ec21e2ecSJeff Kirsher num_rx_qs, MAX_RX_QS); 651ec21e2ecSJeff Kirsher pr_err("Cannot do alloc_etherdev, aborting\n"); 652ec21e2ecSJeff Kirsher return -EINVAL; 653ec21e2ecSJeff Kirsher } 654ec21e2ecSJeff Kirsher 655ec21e2ecSJeff Kirsher *pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs); 656ec21e2ecSJeff Kirsher dev = *pdev; 657ec21e2ecSJeff Kirsher if (NULL == dev) 658ec21e2ecSJeff Kirsher return -ENOMEM; 659ec21e2ecSJeff Kirsher 660ec21e2ecSJeff Kirsher priv = netdev_priv(dev); 661ec21e2ecSJeff Kirsher priv->ndev = dev; 662ec21e2ecSJeff Kirsher 663ec21e2ecSJeff Kirsher priv->num_tx_queues = num_tx_qs; 664ec21e2ecSJeff Kirsher netif_set_real_num_rx_queues(dev, num_rx_qs); 665ec21e2ecSJeff Kirsher priv->num_rx_queues = num_rx_qs; 666ec21e2ecSJeff Kirsher priv->num_grps = 0x0; 667ec21e2ecSJeff Kirsher 668ec21e2ecSJeff Kirsher /* Init Rx queue filer rule set linked list */ 669ec21e2ecSJeff Kirsher INIT_LIST_HEAD(&priv->rx_list.list); 670ec21e2ecSJeff Kirsher priv->rx_list.count = 0; 671ec21e2ecSJeff Kirsher mutex_init(&priv->rx_queue_access); 672ec21e2ecSJeff Kirsher 673ec21e2ecSJeff Kirsher model = of_get_property(np, "model", NULL); 674ec21e2ecSJeff Kirsher 675ec21e2ecSJeff Kirsher for (i = 0; i < MAXGROUPS; i++) 676ec21e2ecSJeff Kirsher priv->gfargrp[i].regs = NULL; 677ec21e2ecSJeff Kirsher 678ec21e2ecSJeff Kirsher /* Parse and initialize group specific information */ 679ec21e2ecSJeff Kirsher if (of_device_is_compatible(np, "fsl,etsec2")) { 680ec21e2ecSJeff Kirsher priv->mode = MQ_MG_MODE; 681ec21e2ecSJeff Kirsher for_each_child_of_node(np, child) { 682ec21e2ecSJeff Kirsher err = gfar_parse_group(child, priv, model); 683ec21e2ecSJeff Kirsher if (err) 684ec21e2ecSJeff Kirsher goto err_grp_init; 685ec21e2ecSJeff Kirsher } 686ec21e2ecSJeff Kirsher } else { 687ec21e2ecSJeff Kirsher priv->mode = SQ_SG_MODE; 688ec21e2ecSJeff Kirsher err = gfar_parse_group(np, priv, model); 689ec21e2ecSJeff Kirsher if (err) 690ec21e2ecSJeff Kirsher goto err_grp_init; 691ec21e2ecSJeff Kirsher } 692ec21e2ecSJeff Kirsher 693ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 694ec21e2ecSJeff Kirsher priv->tx_queue[i] = NULL; 695ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 696ec21e2ecSJeff Kirsher priv->rx_queue[i] = NULL; 697ec21e2ecSJeff Kirsher 698ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 699ec21e2ecSJeff Kirsher priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q), 700ec21e2ecSJeff Kirsher GFP_KERNEL); 701ec21e2ecSJeff Kirsher if (!priv->tx_queue[i]) { 702ec21e2ecSJeff Kirsher err = -ENOMEM; 703ec21e2ecSJeff Kirsher goto tx_alloc_failed; 704ec21e2ecSJeff Kirsher } 705ec21e2ecSJeff Kirsher priv->tx_queue[i]->tx_skbuff = NULL; 706ec21e2ecSJeff Kirsher priv->tx_queue[i]->qindex = i; 707ec21e2ecSJeff Kirsher priv->tx_queue[i]->dev = dev; 708ec21e2ecSJeff Kirsher spin_lock_init(&(priv->tx_queue[i]->txlock)); 709ec21e2ecSJeff Kirsher } 710ec21e2ecSJeff Kirsher 711ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 712ec21e2ecSJeff Kirsher priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q), 713ec21e2ecSJeff Kirsher GFP_KERNEL); 714ec21e2ecSJeff Kirsher if (!priv->rx_queue[i]) { 715ec21e2ecSJeff Kirsher err = -ENOMEM; 716ec21e2ecSJeff Kirsher goto rx_alloc_failed; 717ec21e2ecSJeff Kirsher } 718ec21e2ecSJeff Kirsher priv->rx_queue[i]->rx_skbuff = NULL; 719ec21e2ecSJeff Kirsher priv->rx_queue[i]->qindex = i; 720ec21e2ecSJeff Kirsher priv->rx_queue[i]->dev = dev; 721ec21e2ecSJeff Kirsher spin_lock_init(&(priv->rx_queue[i]->rxlock)); 722ec21e2ecSJeff Kirsher } 723ec21e2ecSJeff Kirsher 724ec21e2ecSJeff Kirsher 725ec21e2ecSJeff Kirsher stash = of_get_property(np, "bd-stash", NULL); 726ec21e2ecSJeff Kirsher 727ec21e2ecSJeff Kirsher if (stash) { 728ec21e2ecSJeff Kirsher priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING; 729ec21e2ecSJeff Kirsher priv->bd_stash_en = 1; 730ec21e2ecSJeff Kirsher } 731ec21e2ecSJeff Kirsher 732ec21e2ecSJeff Kirsher stash_len = of_get_property(np, "rx-stash-len", NULL); 733ec21e2ecSJeff Kirsher 734ec21e2ecSJeff Kirsher if (stash_len) 735ec21e2ecSJeff Kirsher priv->rx_stash_size = *stash_len; 736ec21e2ecSJeff Kirsher 737ec21e2ecSJeff Kirsher stash_idx = of_get_property(np, "rx-stash-idx", NULL); 738ec21e2ecSJeff Kirsher 739ec21e2ecSJeff Kirsher if (stash_idx) 740ec21e2ecSJeff Kirsher priv->rx_stash_index = *stash_idx; 741ec21e2ecSJeff Kirsher 742ec21e2ecSJeff Kirsher if (stash_len || stash_idx) 743ec21e2ecSJeff Kirsher priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING; 744ec21e2ecSJeff Kirsher 745ec21e2ecSJeff Kirsher mac_addr = of_get_mac_address(np); 746bc4598bcSJan Ceuleers 747ec21e2ecSJeff Kirsher if (mac_addr) 7486a3c910cSJoe Perches memcpy(dev->dev_addr, mac_addr, ETH_ALEN); 749ec21e2ecSJeff Kirsher 750ec21e2ecSJeff Kirsher if (model && !strcasecmp(model, "TSEC")) 751bc4598bcSJan Ceuleers priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT | 752ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_COALESCE | 753ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_RMON | 754ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_MULTI_INTR; 755bc4598bcSJan Ceuleers 756ec21e2ecSJeff Kirsher if (model && !strcasecmp(model, "eTSEC")) 757bc4598bcSJan Ceuleers priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT | 758ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_COALESCE | 759ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_RMON | 760ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_MULTI_INTR | 761ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_PADDING | 762ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_CSUM | 763ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_VLAN | 764ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_MAGIC_PACKET | 765ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_EXTENDED_HASH | 766ec21e2ecSJeff Kirsher FSL_GIANFAR_DEV_HAS_TIMER; 767ec21e2ecSJeff Kirsher 768ec21e2ecSJeff Kirsher ctype = of_get_property(np, "phy-connection-type", NULL); 769ec21e2ecSJeff Kirsher 770ec21e2ecSJeff Kirsher /* We only care about rgmii-id. The rest are autodetected */ 771ec21e2ecSJeff Kirsher if (ctype && !strcmp(ctype, "rgmii-id")) 772ec21e2ecSJeff Kirsher priv->interface = PHY_INTERFACE_MODE_RGMII_ID; 773ec21e2ecSJeff Kirsher else 774ec21e2ecSJeff Kirsher priv->interface = PHY_INTERFACE_MODE_MII; 775ec21e2ecSJeff Kirsher 776ec21e2ecSJeff Kirsher if (of_get_property(np, "fsl,magic-packet", NULL)) 777ec21e2ecSJeff Kirsher priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET; 778ec21e2ecSJeff Kirsher 779ec21e2ecSJeff Kirsher priv->phy_node = of_parse_phandle(np, "phy-handle", 0); 780ec21e2ecSJeff Kirsher 781ec21e2ecSJeff Kirsher /* Find the TBI PHY. If it's not there, we don't support SGMII */ 782ec21e2ecSJeff Kirsher priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0); 783ec21e2ecSJeff Kirsher 784ec21e2ecSJeff Kirsher return 0; 785ec21e2ecSJeff Kirsher 786ec21e2ecSJeff Kirsher rx_alloc_failed: 787ec21e2ecSJeff Kirsher free_rx_pointers(priv); 788ec21e2ecSJeff Kirsher tx_alloc_failed: 789ec21e2ecSJeff Kirsher free_tx_pointers(priv); 790ec21e2ecSJeff Kirsher err_grp_init: 791ec21e2ecSJeff Kirsher unmap_group_regs(priv); 792ee873fdaSClaudiu Manoil free_gfar_dev(priv); 793ec21e2ecSJeff Kirsher return err; 794ec21e2ecSJeff Kirsher } 795ec21e2ecSJeff Kirsher 796ec21e2ecSJeff Kirsher static int gfar_hwtstamp_ioctl(struct net_device *netdev, 797ec21e2ecSJeff Kirsher struct ifreq *ifr, int cmd) 798ec21e2ecSJeff Kirsher { 799ec21e2ecSJeff Kirsher struct hwtstamp_config config; 800ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(netdev); 801ec21e2ecSJeff Kirsher 802ec21e2ecSJeff Kirsher if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 803ec21e2ecSJeff Kirsher return -EFAULT; 804ec21e2ecSJeff Kirsher 805ec21e2ecSJeff Kirsher /* reserved for future extensions */ 806ec21e2ecSJeff Kirsher if (config.flags) 807ec21e2ecSJeff Kirsher return -EINVAL; 808ec21e2ecSJeff Kirsher 809ec21e2ecSJeff Kirsher switch (config.tx_type) { 810ec21e2ecSJeff Kirsher case HWTSTAMP_TX_OFF: 811ec21e2ecSJeff Kirsher priv->hwts_tx_en = 0; 812ec21e2ecSJeff Kirsher break; 813ec21e2ecSJeff Kirsher case HWTSTAMP_TX_ON: 814ec21e2ecSJeff Kirsher if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) 815ec21e2ecSJeff Kirsher return -ERANGE; 816ec21e2ecSJeff Kirsher priv->hwts_tx_en = 1; 817ec21e2ecSJeff Kirsher break; 818ec21e2ecSJeff Kirsher default: 819ec21e2ecSJeff Kirsher return -ERANGE; 820ec21e2ecSJeff Kirsher } 821ec21e2ecSJeff Kirsher 822ec21e2ecSJeff Kirsher switch (config.rx_filter) { 823ec21e2ecSJeff Kirsher case HWTSTAMP_FILTER_NONE: 824ec21e2ecSJeff Kirsher if (priv->hwts_rx_en) { 825ec21e2ecSJeff Kirsher stop_gfar(netdev); 826ec21e2ecSJeff Kirsher priv->hwts_rx_en = 0; 827ec21e2ecSJeff Kirsher startup_gfar(netdev); 828ec21e2ecSJeff Kirsher } 829ec21e2ecSJeff Kirsher break; 830ec21e2ecSJeff Kirsher default: 831ec21e2ecSJeff Kirsher if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) 832ec21e2ecSJeff Kirsher return -ERANGE; 833ec21e2ecSJeff Kirsher if (!priv->hwts_rx_en) { 834ec21e2ecSJeff Kirsher stop_gfar(netdev); 835ec21e2ecSJeff Kirsher priv->hwts_rx_en = 1; 836ec21e2ecSJeff Kirsher startup_gfar(netdev); 837ec21e2ecSJeff Kirsher } 838ec21e2ecSJeff Kirsher config.rx_filter = HWTSTAMP_FILTER_ALL; 839ec21e2ecSJeff Kirsher break; 840ec21e2ecSJeff Kirsher } 841ec21e2ecSJeff Kirsher 842ec21e2ecSJeff Kirsher return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? 843ec21e2ecSJeff Kirsher -EFAULT : 0; 844ec21e2ecSJeff Kirsher } 845ec21e2ecSJeff Kirsher 846ec21e2ecSJeff Kirsher /* Ioctl MII Interface */ 847ec21e2ecSJeff Kirsher static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 848ec21e2ecSJeff Kirsher { 849ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 850ec21e2ecSJeff Kirsher 851ec21e2ecSJeff Kirsher if (!netif_running(dev)) 852ec21e2ecSJeff Kirsher return -EINVAL; 853ec21e2ecSJeff Kirsher 854ec21e2ecSJeff Kirsher if (cmd == SIOCSHWTSTAMP) 855ec21e2ecSJeff Kirsher return gfar_hwtstamp_ioctl(dev, rq, cmd); 856ec21e2ecSJeff Kirsher 857ec21e2ecSJeff Kirsher if (!priv->phydev) 858ec21e2ecSJeff Kirsher return -ENODEV; 859ec21e2ecSJeff Kirsher 860ec21e2ecSJeff Kirsher return phy_mii_ioctl(priv->phydev, rq, cmd); 861ec21e2ecSJeff Kirsher } 862ec21e2ecSJeff Kirsher 863ec21e2ecSJeff Kirsher static unsigned int reverse_bitmap(unsigned int bit_map, unsigned int max_qs) 864ec21e2ecSJeff Kirsher { 865ec21e2ecSJeff Kirsher unsigned int new_bit_map = 0x0; 866ec21e2ecSJeff Kirsher int mask = 0x1 << (max_qs - 1), i; 867bc4598bcSJan Ceuleers 868ec21e2ecSJeff Kirsher for (i = 0; i < max_qs; i++) { 869ec21e2ecSJeff Kirsher if (bit_map & mask) 870ec21e2ecSJeff Kirsher new_bit_map = new_bit_map + (1 << i); 871ec21e2ecSJeff Kirsher mask = mask >> 0x1; 872ec21e2ecSJeff Kirsher } 873ec21e2ecSJeff Kirsher return new_bit_map; 874ec21e2ecSJeff Kirsher } 875ec21e2ecSJeff Kirsher 876ec21e2ecSJeff Kirsher static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar, 877ec21e2ecSJeff Kirsher u32 class) 878ec21e2ecSJeff Kirsher { 879ec21e2ecSJeff Kirsher u32 rqfpr = FPR_FILER_MASK; 880ec21e2ecSJeff Kirsher u32 rqfcr = 0x0; 881ec21e2ecSJeff Kirsher 882ec21e2ecSJeff Kirsher rqfar--; 883ec21e2ecSJeff Kirsher rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT; 884ec21e2ecSJeff Kirsher priv->ftp_rqfpr[rqfar] = rqfpr; 885ec21e2ecSJeff Kirsher priv->ftp_rqfcr[rqfar] = rqfcr; 886ec21e2ecSJeff Kirsher gfar_write_filer(priv, rqfar, rqfcr, rqfpr); 887ec21e2ecSJeff Kirsher 888ec21e2ecSJeff Kirsher rqfar--; 889ec21e2ecSJeff Kirsher rqfcr = RQFCR_CMP_NOMATCH; 890ec21e2ecSJeff Kirsher priv->ftp_rqfpr[rqfar] = rqfpr; 891ec21e2ecSJeff Kirsher priv->ftp_rqfcr[rqfar] = rqfcr; 892ec21e2ecSJeff Kirsher gfar_write_filer(priv, rqfar, rqfcr, rqfpr); 893ec21e2ecSJeff Kirsher 894ec21e2ecSJeff Kirsher rqfar--; 895ec21e2ecSJeff Kirsher rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND; 896ec21e2ecSJeff Kirsher rqfpr = class; 897ec21e2ecSJeff Kirsher priv->ftp_rqfcr[rqfar] = rqfcr; 898ec21e2ecSJeff Kirsher priv->ftp_rqfpr[rqfar] = rqfpr; 899ec21e2ecSJeff Kirsher gfar_write_filer(priv, rqfar, rqfcr, rqfpr); 900ec21e2ecSJeff Kirsher 901ec21e2ecSJeff Kirsher rqfar--; 902ec21e2ecSJeff Kirsher rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND; 903ec21e2ecSJeff Kirsher rqfpr = class; 904ec21e2ecSJeff Kirsher priv->ftp_rqfcr[rqfar] = rqfcr; 905ec21e2ecSJeff Kirsher priv->ftp_rqfpr[rqfar] = rqfpr; 906ec21e2ecSJeff Kirsher gfar_write_filer(priv, rqfar, rqfcr, rqfpr); 907ec21e2ecSJeff Kirsher 908ec21e2ecSJeff Kirsher return rqfar; 909ec21e2ecSJeff Kirsher } 910ec21e2ecSJeff Kirsher 911ec21e2ecSJeff Kirsher static void gfar_init_filer_table(struct gfar_private *priv) 912ec21e2ecSJeff Kirsher { 913ec21e2ecSJeff Kirsher int i = 0x0; 914ec21e2ecSJeff Kirsher u32 rqfar = MAX_FILER_IDX; 915ec21e2ecSJeff Kirsher u32 rqfcr = 0x0; 916ec21e2ecSJeff Kirsher u32 rqfpr = FPR_FILER_MASK; 917ec21e2ecSJeff Kirsher 918ec21e2ecSJeff Kirsher /* Default rule */ 919ec21e2ecSJeff Kirsher rqfcr = RQFCR_CMP_MATCH; 920ec21e2ecSJeff Kirsher priv->ftp_rqfcr[rqfar] = rqfcr; 921ec21e2ecSJeff Kirsher priv->ftp_rqfpr[rqfar] = rqfpr; 922ec21e2ecSJeff Kirsher gfar_write_filer(priv, rqfar, rqfcr, rqfpr); 923ec21e2ecSJeff Kirsher 924ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6); 925ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP); 926ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP); 927ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4); 928ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP); 929ec21e2ecSJeff Kirsher rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP); 930ec21e2ecSJeff Kirsher 931ec21e2ecSJeff Kirsher /* cur_filer_idx indicated the first non-masked rule */ 932ec21e2ecSJeff Kirsher priv->cur_filer_idx = rqfar; 933ec21e2ecSJeff Kirsher 934ec21e2ecSJeff Kirsher /* Rest are masked rules */ 935ec21e2ecSJeff Kirsher rqfcr = RQFCR_CMP_NOMATCH; 936ec21e2ecSJeff Kirsher for (i = 0; i < rqfar; i++) { 937ec21e2ecSJeff Kirsher priv->ftp_rqfcr[i] = rqfcr; 938ec21e2ecSJeff Kirsher priv->ftp_rqfpr[i] = rqfpr; 939ec21e2ecSJeff Kirsher gfar_write_filer(priv, i, rqfcr, rqfpr); 940ec21e2ecSJeff Kirsher } 941ec21e2ecSJeff Kirsher } 942ec21e2ecSJeff Kirsher 943ec21e2ecSJeff Kirsher static void gfar_detect_errata(struct gfar_private *priv) 944ec21e2ecSJeff Kirsher { 945ec21e2ecSJeff Kirsher struct device *dev = &priv->ofdev->dev; 946ec21e2ecSJeff Kirsher unsigned int pvr = mfspr(SPRN_PVR); 947ec21e2ecSJeff Kirsher unsigned int svr = mfspr(SPRN_SVR); 948ec21e2ecSJeff Kirsher unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */ 949ec21e2ecSJeff Kirsher unsigned int rev = svr & 0xffff; 950ec21e2ecSJeff Kirsher 951ec21e2ecSJeff Kirsher /* MPC8313 Rev 2.0 and higher; All MPC837x */ 952ec21e2ecSJeff Kirsher if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) || 953ec21e2ecSJeff Kirsher (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) 954ec21e2ecSJeff Kirsher priv->errata |= GFAR_ERRATA_74; 955ec21e2ecSJeff Kirsher 956ec21e2ecSJeff Kirsher /* MPC8313 and MPC837x all rev */ 957ec21e2ecSJeff Kirsher if ((pvr == 0x80850010 && mod == 0x80b0) || 958ec21e2ecSJeff Kirsher (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) 959ec21e2ecSJeff Kirsher priv->errata |= GFAR_ERRATA_76; 960ec21e2ecSJeff Kirsher 961ec21e2ecSJeff Kirsher /* MPC8313 and MPC837x all rev */ 962ec21e2ecSJeff Kirsher if ((pvr == 0x80850010 && mod == 0x80b0) || 963ec21e2ecSJeff Kirsher (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) 964ec21e2ecSJeff Kirsher priv->errata |= GFAR_ERRATA_A002; 965ec21e2ecSJeff Kirsher 966ec21e2ecSJeff Kirsher /* MPC8313 Rev < 2.0, MPC8548 rev 2.0 */ 967ec21e2ecSJeff Kirsher if ((pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020) || 968ec21e2ecSJeff Kirsher (pvr == 0x80210020 && mod == 0x8030 && rev == 0x0020)) 969ec21e2ecSJeff Kirsher priv->errata |= GFAR_ERRATA_12; 970ec21e2ecSJeff Kirsher 971ec21e2ecSJeff Kirsher if (priv->errata) 972ec21e2ecSJeff Kirsher dev_info(dev, "enabled errata workarounds, flags: 0x%x\n", 973ec21e2ecSJeff Kirsher priv->errata); 974ec21e2ecSJeff Kirsher } 975ec21e2ecSJeff Kirsher 976ec21e2ecSJeff Kirsher /* Set up the ethernet device structure, private data, 9770977f817SJan Ceuleers * and anything else we need before we start 9780977f817SJan Ceuleers */ 979ec21e2ecSJeff Kirsher static int gfar_probe(struct platform_device *ofdev) 980ec21e2ecSJeff Kirsher { 981ec21e2ecSJeff Kirsher u32 tempval; 982ec21e2ecSJeff Kirsher struct net_device *dev = NULL; 983ec21e2ecSJeff Kirsher struct gfar_private *priv = NULL; 984ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 985ec21e2ecSJeff Kirsher int err = 0, i, grp_idx = 0; 986ec21e2ecSJeff Kirsher u32 rstat = 0, tstat = 0, rqueue = 0, tqueue = 0; 987ec21e2ecSJeff Kirsher u32 isrg = 0; 988ec21e2ecSJeff Kirsher u32 __iomem *baddr; 989ec21e2ecSJeff Kirsher 990ec21e2ecSJeff Kirsher err = gfar_of_init(ofdev, &dev); 991ec21e2ecSJeff Kirsher 992ec21e2ecSJeff Kirsher if (err) 993ec21e2ecSJeff Kirsher return err; 994ec21e2ecSJeff Kirsher 995ec21e2ecSJeff Kirsher priv = netdev_priv(dev); 996ec21e2ecSJeff Kirsher priv->ndev = dev; 997ec21e2ecSJeff Kirsher priv->ofdev = ofdev; 998369ec162SClaudiu Manoil priv->dev = &ofdev->dev; 999ec21e2ecSJeff Kirsher SET_NETDEV_DEV(dev, &ofdev->dev); 1000ec21e2ecSJeff Kirsher 1001ec21e2ecSJeff Kirsher spin_lock_init(&priv->bflock); 1002ec21e2ecSJeff Kirsher INIT_WORK(&priv->reset_task, gfar_reset_task); 1003ec21e2ecSJeff Kirsher 1004ec21e2ecSJeff Kirsher dev_set_drvdata(&ofdev->dev, priv); 1005ec21e2ecSJeff Kirsher regs = priv->gfargrp[0].regs; 1006ec21e2ecSJeff Kirsher 1007ec21e2ecSJeff Kirsher gfar_detect_errata(priv); 1008ec21e2ecSJeff Kirsher 10090977f817SJan Ceuleers /* Stop the DMA engine now, in case it was running before 10100977f817SJan Ceuleers * (The firmware could have used it, and left it running). 10110977f817SJan Ceuleers */ 1012ec21e2ecSJeff Kirsher gfar_halt(dev); 1013ec21e2ecSJeff Kirsher 1014ec21e2ecSJeff Kirsher /* Reset MAC layer */ 1015ec21e2ecSJeff Kirsher gfar_write(®s->maccfg1, MACCFG1_SOFT_RESET); 1016ec21e2ecSJeff Kirsher 1017ec21e2ecSJeff Kirsher /* We need to delay at least 3 TX clocks */ 1018ec21e2ecSJeff Kirsher udelay(2); 1019ec21e2ecSJeff Kirsher 1020ec21e2ecSJeff Kirsher tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW); 1021ec21e2ecSJeff Kirsher gfar_write(®s->maccfg1, tempval); 1022ec21e2ecSJeff Kirsher 1023ec21e2ecSJeff Kirsher /* Initialize MACCFG2. */ 1024ec21e2ecSJeff Kirsher tempval = MACCFG2_INIT_SETTINGS; 1025ec21e2ecSJeff Kirsher if (gfar_has_errata(priv, GFAR_ERRATA_74)) 1026ec21e2ecSJeff Kirsher tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK; 1027ec21e2ecSJeff Kirsher gfar_write(®s->maccfg2, tempval); 1028ec21e2ecSJeff Kirsher 1029ec21e2ecSJeff Kirsher /* Initialize ECNTRL */ 1030ec21e2ecSJeff Kirsher gfar_write(®s->ecntrl, ECNTRL_INIT_SETTINGS); 1031ec21e2ecSJeff Kirsher 1032ec21e2ecSJeff Kirsher /* Set the dev->base_addr to the gfar reg region */ 1033ec21e2ecSJeff Kirsher dev->base_addr = (unsigned long) regs; 1034ec21e2ecSJeff Kirsher 1035ec21e2ecSJeff Kirsher /* Fill in the dev structure */ 1036ec21e2ecSJeff Kirsher dev->watchdog_timeo = TX_TIMEOUT; 1037ec21e2ecSJeff Kirsher dev->mtu = 1500; 1038ec21e2ecSJeff Kirsher dev->netdev_ops = &gfar_netdev_ops; 1039ec21e2ecSJeff Kirsher dev->ethtool_ops = &gfar_ethtool_ops; 1040ec21e2ecSJeff Kirsher 1041ec21e2ecSJeff Kirsher /* Register for napi ...We are registering NAPI for each grp */ 1042ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) 1043bc4598bcSJan Ceuleers netif_napi_add(dev, &priv->gfargrp[i].napi, gfar_poll, 1044bc4598bcSJan Ceuleers GFAR_DEV_WEIGHT); 1045ec21e2ecSJeff Kirsher 1046ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) { 1047ec21e2ecSJeff Kirsher dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 1048ec21e2ecSJeff Kirsher NETIF_F_RXCSUM; 1049ec21e2ecSJeff Kirsher dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | 1050ec21e2ecSJeff Kirsher NETIF_F_RXCSUM | NETIF_F_HIGHDMA; 1051ec21e2ecSJeff Kirsher } 1052ec21e2ecSJeff Kirsher 1053ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) { 1054ec21e2ecSJeff Kirsher dev->hw_features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; 1055e2c53be2SClaudiu Manoil dev->features |= NETIF_F_HW_VLAN_RX; 1056ec21e2ecSJeff Kirsher } 1057ec21e2ecSJeff Kirsher 1058ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) { 1059ec21e2ecSJeff Kirsher priv->extended_hash = 1; 1060ec21e2ecSJeff Kirsher priv->hash_width = 9; 1061ec21e2ecSJeff Kirsher 1062ec21e2ecSJeff Kirsher priv->hash_regs[0] = ®s->igaddr0; 1063ec21e2ecSJeff Kirsher priv->hash_regs[1] = ®s->igaddr1; 1064ec21e2ecSJeff Kirsher priv->hash_regs[2] = ®s->igaddr2; 1065ec21e2ecSJeff Kirsher priv->hash_regs[3] = ®s->igaddr3; 1066ec21e2ecSJeff Kirsher priv->hash_regs[4] = ®s->igaddr4; 1067ec21e2ecSJeff Kirsher priv->hash_regs[5] = ®s->igaddr5; 1068ec21e2ecSJeff Kirsher priv->hash_regs[6] = ®s->igaddr6; 1069ec21e2ecSJeff Kirsher priv->hash_regs[7] = ®s->igaddr7; 1070ec21e2ecSJeff Kirsher priv->hash_regs[8] = ®s->gaddr0; 1071ec21e2ecSJeff Kirsher priv->hash_regs[9] = ®s->gaddr1; 1072ec21e2ecSJeff Kirsher priv->hash_regs[10] = ®s->gaddr2; 1073ec21e2ecSJeff Kirsher priv->hash_regs[11] = ®s->gaddr3; 1074ec21e2ecSJeff Kirsher priv->hash_regs[12] = ®s->gaddr4; 1075ec21e2ecSJeff Kirsher priv->hash_regs[13] = ®s->gaddr5; 1076ec21e2ecSJeff Kirsher priv->hash_regs[14] = ®s->gaddr6; 1077ec21e2ecSJeff Kirsher priv->hash_regs[15] = ®s->gaddr7; 1078ec21e2ecSJeff Kirsher 1079ec21e2ecSJeff Kirsher } else { 1080ec21e2ecSJeff Kirsher priv->extended_hash = 0; 1081ec21e2ecSJeff Kirsher priv->hash_width = 8; 1082ec21e2ecSJeff Kirsher 1083ec21e2ecSJeff Kirsher priv->hash_regs[0] = ®s->gaddr0; 1084ec21e2ecSJeff Kirsher priv->hash_regs[1] = ®s->gaddr1; 1085ec21e2ecSJeff Kirsher priv->hash_regs[2] = ®s->gaddr2; 1086ec21e2ecSJeff Kirsher priv->hash_regs[3] = ®s->gaddr3; 1087ec21e2ecSJeff Kirsher priv->hash_regs[4] = ®s->gaddr4; 1088ec21e2ecSJeff Kirsher priv->hash_regs[5] = ®s->gaddr5; 1089ec21e2ecSJeff Kirsher priv->hash_regs[6] = ®s->gaddr6; 1090ec21e2ecSJeff Kirsher priv->hash_regs[7] = ®s->gaddr7; 1091ec21e2ecSJeff Kirsher } 1092ec21e2ecSJeff Kirsher 1093ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_PADDING) 1094ec21e2ecSJeff Kirsher priv->padding = DEFAULT_PADDING; 1095ec21e2ecSJeff Kirsher else 1096ec21e2ecSJeff Kirsher priv->padding = 0; 1097ec21e2ecSJeff Kirsher 1098ec21e2ecSJeff Kirsher if (dev->features & NETIF_F_IP_CSUM || 1099ec21e2ecSJeff Kirsher priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) 1100bee9e58cSWu Jiajun-B06378 dev->needed_headroom = GMAC_FCB_LEN; 1101ec21e2ecSJeff Kirsher 1102ec21e2ecSJeff Kirsher /* Program the isrg regs only if number of grps > 1 */ 1103ec21e2ecSJeff Kirsher if (priv->num_grps > 1) { 1104ec21e2ecSJeff Kirsher baddr = ®s->isrg0; 1105ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1106ec21e2ecSJeff Kirsher isrg |= (priv->gfargrp[i].rx_bit_map << ISRG_SHIFT_RX); 1107ec21e2ecSJeff Kirsher isrg |= (priv->gfargrp[i].tx_bit_map << ISRG_SHIFT_TX); 1108ec21e2ecSJeff Kirsher gfar_write(baddr, isrg); 1109ec21e2ecSJeff Kirsher baddr++; 1110ec21e2ecSJeff Kirsher isrg = 0x0; 1111ec21e2ecSJeff Kirsher } 1112ec21e2ecSJeff Kirsher } 1113ec21e2ecSJeff Kirsher 1114ec21e2ecSJeff Kirsher /* Need to reverse the bit maps as bit_map's MSB is q0 1115ec21e2ecSJeff Kirsher * but, for_each_set_bit parses from right to left, which 11160977f817SJan Ceuleers * basically reverses the queue numbers 11170977f817SJan Ceuleers */ 1118ec21e2ecSJeff Kirsher for (i = 0; i< priv->num_grps; i++) { 1119bc4598bcSJan Ceuleers priv->gfargrp[i].tx_bit_map = 1120bc4598bcSJan Ceuleers reverse_bitmap(priv->gfargrp[i].tx_bit_map, MAX_TX_QS); 1121bc4598bcSJan Ceuleers priv->gfargrp[i].rx_bit_map = 1122bc4598bcSJan Ceuleers reverse_bitmap(priv->gfargrp[i].rx_bit_map, MAX_RX_QS); 1123ec21e2ecSJeff Kirsher } 1124ec21e2ecSJeff Kirsher 1125ec21e2ecSJeff Kirsher /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values, 11260977f817SJan Ceuleers * also assign queues to groups 11270977f817SJan Ceuleers */ 1128ec21e2ecSJeff Kirsher for (grp_idx = 0; grp_idx < priv->num_grps; grp_idx++) { 1129ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].num_rx_queues = 0x0; 1130bc4598bcSJan Ceuleers 1131ec21e2ecSJeff Kirsher for_each_set_bit(i, &priv->gfargrp[grp_idx].rx_bit_map, 1132ec21e2ecSJeff Kirsher priv->num_rx_queues) { 1133ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].num_rx_queues++; 1134ec21e2ecSJeff Kirsher priv->rx_queue[i]->grp = &priv->gfargrp[grp_idx]; 1135ec21e2ecSJeff Kirsher rstat = rstat | (RSTAT_CLEAR_RHALT >> i); 1136ec21e2ecSJeff Kirsher rqueue = rqueue | ((RQUEUE_EN0 | RQUEUE_EX0) >> i); 1137ec21e2ecSJeff Kirsher } 1138ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].num_tx_queues = 0x0; 1139bc4598bcSJan Ceuleers 1140ec21e2ecSJeff Kirsher for_each_set_bit(i, &priv->gfargrp[grp_idx].tx_bit_map, 1141ec21e2ecSJeff Kirsher priv->num_tx_queues) { 1142ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].num_tx_queues++; 1143ec21e2ecSJeff Kirsher priv->tx_queue[i]->grp = &priv->gfargrp[grp_idx]; 1144ec21e2ecSJeff Kirsher tstat = tstat | (TSTAT_CLEAR_THALT >> i); 1145ec21e2ecSJeff Kirsher tqueue = tqueue | (TQUEUE_EN0 >> i); 1146ec21e2ecSJeff Kirsher } 1147ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].rstat = rstat; 1148ec21e2ecSJeff Kirsher priv->gfargrp[grp_idx].tstat = tstat; 1149ec21e2ecSJeff Kirsher rstat = tstat =0; 1150ec21e2ecSJeff Kirsher } 1151ec21e2ecSJeff Kirsher 1152ec21e2ecSJeff Kirsher gfar_write(®s->rqueue, rqueue); 1153ec21e2ecSJeff Kirsher gfar_write(®s->tqueue, tqueue); 1154ec21e2ecSJeff Kirsher 1155ec21e2ecSJeff Kirsher priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; 1156ec21e2ecSJeff Kirsher 1157ec21e2ecSJeff Kirsher /* Initializing some of the rx/tx queue level parameters */ 1158ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 1159ec21e2ecSJeff Kirsher priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE; 1160ec21e2ecSJeff Kirsher priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE; 1161ec21e2ecSJeff Kirsher priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE; 1162ec21e2ecSJeff Kirsher priv->tx_queue[i]->txic = DEFAULT_TXIC; 1163ec21e2ecSJeff Kirsher } 1164ec21e2ecSJeff Kirsher 1165ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 1166ec21e2ecSJeff Kirsher priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE; 1167ec21e2ecSJeff Kirsher priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE; 1168ec21e2ecSJeff Kirsher priv->rx_queue[i]->rxic = DEFAULT_RXIC; 1169ec21e2ecSJeff Kirsher } 1170ec21e2ecSJeff Kirsher 1171ec21e2ecSJeff Kirsher /* always enable rx filer */ 1172ec21e2ecSJeff Kirsher priv->rx_filer_enable = 1; 1173ec21e2ecSJeff Kirsher /* Enable most messages by default */ 1174ec21e2ecSJeff Kirsher priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1; 1175b98b8babSClaudiu Manoil /* use pritority h/w tx queue scheduling for single queue devices */ 1176b98b8babSClaudiu Manoil if (priv->num_tx_queues == 1) 1177b98b8babSClaudiu Manoil priv->prio_sched_en = 1; 1178ec21e2ecSJeff Kirsher 1179ec21e2ecSJeff Kirsher /* Carrier starts down, phylib will bring it up */ 1180ec21e2ecSJeff Kirsher netif_carrier_off(dev); 1181ec21e2ecSJeff Kirsher 1182ec21e2ecSJeff Kirsher err = register_netdev(dev); 1183ec21e2ecSJeff Kirsher 1184ec21e2ecSJeff Kirsher if (err) { 1185ec21e2ecSJeff Kirsher pr_err("%s: Cannot register net device, aborting\n", dev->name); 1186ec21e2ecSJeff Kirsher goto register_fail; 1187ec21e2ecSJeff Kirsher } 1188ec21e2ecSJeff Kirsher 1189ec21e2ecSJeff Kirsher device_init_wakeup(&dev->dev, 1190bc4598bcSJan Ceuleers priv->device_flags & 1191bc4598bcSJan Ceuleers FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); 1192ec21e2ecSJeff Kirsher 1193ec21e2ecSJeff Kirsher /* fill out IRQ number and name fields */ 1194ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1195ee873fdaSClaudiu Manoil struct gfar_priv_grp *grp = &priv->gfargrp[i]; 1196ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 1197ee873fdaSClaudiu Manoil sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s", 11980015e551SJoe Perches dev->name, "_g", '0' + i, "_tx"); 1199ee873fdaSClaudiu Manoil sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s", 12000015e551SJoe Perches dev->name, "_g", '0' + i, "_rx"); 1201ee873fdaSClaudiu Manoil sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s", 12020015e551SJoe Perches dev->name, "_g", '0' + i, "_er"); 1203ec21e2ecSJeff Kirsher } else 1204ee873fdaSClaudiu Manoil strcpy(gfar_irq(grp, TX)->name, dev->name); 1205ec21e2ecSJeff Kirsher } 1206ec21e2ecSJeff Kirsher 1207ec21e2ecSJeff Kirsher /* Initialize the filer table */ 1208ec21e2ecSJeff Kirsher gfar_init_filer_table(priv); 1209ec21e2ecSJeff Kirsher 1210ec21e2ecSJeff Kirsher /* Create all the sysfs files */ 1211ec21e2ecSJeff Kirsher gfar_init_sysfs(dev); 1212ec21e2ecSJeff Kirsher 1213ec21e2ecSJeff Kirsher /* Print out the device info */ 1214ec21e2ecSJeff Kirsher netdev_info(dev, "mac: %pM\n", dev->dev_addr); 1215ec21e2ecSJeff Kirsher 12160977f817SJan Ceuleers /* Even more device info helps when determining which kernel 12170977f817SJan Ceuleers * provided which set of benchmarks. 12180977f817SJan Ceuleers */ 1219ec21e2ecSJeff Kirsher netdev_info(dev, "Running with NAPI enabled\n"); 1220ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) 1221ec21e2ecSJeff Kirsher netdev_info(dev, "RX BD ring size for Q[%d]: %d\n", 1222ec21e2ecSJeff Kirsher i, priv->rx_queue[i]->rx_ring_size); 1223ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) 1224ec21e2ecSJeff Kirsher netdev_info(dev, "TX BD ring size for Q[%d]: %d\n", 1225ec21e2ecSJeff Kirsher i, priv->tx_queue[i]->tx_ring_size); 1226ec21e2ecSJeff Kirsher 1227ec21e2ecSJeff Kirsher return 0; 1228ec21e2ecSJeff Kirsher 1229ec21e2ecSJeff Kirsher register_fail: 1230ec21e2ecSJeff Kirsher unmap_group_regs(priv); 1231ec21e2ecSJeff Kirsher free_tx_pointers(priv); 1232ec21e2ecSJeff Kirsher free_rx_pointers(priv); 1233ec21e2ecSJeff Kirsher if (priv->phy_node) 1234ec21e2ecSJeff Kirsher of_node_put(priv->phy_node); 1235ec21e2ecSJeff Kirsher if (priv->tbi_node) 1236ec21e2ecSJeff Kirsher of_node_put(priv->tbi_node); 1237ee873fdaSClaudiu Manoil free_gfar_dev(priv); 1238ec21e2ecSJeff Kirsher return err; 1239ec21e2ecSJeff Kirsher } 1240ec21e2ecSJeff Kirsher 1241ec21e2ecSJeff Kirsher static int gfar_remove(struct platform_device *ofdev) 1242ec21e2ecSJeff Kirsher { 1243ec21e2ecSJeff Kirsher struct gfar_private *priv = dev_get_drvdata(&ofdev->dev); 1244ec21e2ecSJeff Kirsher 1245ec21e2ecSJeff Kirsher if (priv->phy_node) 1246ec21e2ecSJeff Kirsher of_node_put(priv->phy_node); 1247ec21e2ecSJeff Kirsher if (priv->tbi_node) 1248ec21e2ecSJeff Kirsher of_node_put(priv->tbi_node); 1249ec21e2ecSJeff Kirsher 1250ec21e2ecSJeff Kirsher dev_set_drvdata(&ofdev->dev, NULL); 1251ec21e2ecSJeff Kirsher 1252ec21e2ecSJeff Kirsher unregister_netdev(priv->ndev); 1253ec21e2ecSJeff Kirsher unmap_group_regs(priv); 1254ee873fdaSClaudiu Manoil free_gfar_dev(priv); 1255ec21e2ecSJeff Kirsher 1256ec21e2ecSJeff Kirsher return 0; 1257ec21e2ecSJeff Kirsher } 1258ec21e2ecSJeff Kirsher 1259ec21e2ecSJeff Kirsher #ifdef CONFIG_PM 1260ec21e2ecSJeff Kirsher 1261ec21e2ecSJeff Kirsher static int gfar_suspend(struct device *dev) 1262ec21e2ecSJeff Kirsher { 1263ec21e2ecSJeff Kirsher struct gfar_private *priv = dev_get_drvdata(dev); 1264ec21e2ecSJeff Kirsher struct net_device *ndev = priv->ndev; 1265ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1266ec21e2ecSJeff Kirsher unsigned long flags; 1267ec21e2ecSJeff Kirsher u32 tempval; 1268ec21e2ecSJeff Kirsher 1269ec21e2ecSJeff Kirsher int magic_packet = priv->wol_en && 1270bc4598bcSJan Ceuleers (priv->device_flags & 1271bc4598bcSJan Ceuleers FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); 1272ec21e2ecSJeff Kirsher 1273ec21e2ecSJeff Kirsher netif_device_detach(ndev); 1274ec21e2ecSJeff Kirsher 1275ec21e2ecSJeff Kirsher if (netif_running(ndev)) { 1276ec21e2ecSJeff Kirsher 1277ec21e2ecSJeff Kirsher local_irq_save(flags); 1278ec21e2ecSJeff Kirsher lock_tx_qs(priv); 1279ec21e2ecSJeff Kirsher lock_rx_qs(priv); 1280ec21e2ecSJeff Kirsher 1281ec21e2ecSJeff Kirsher gfar_halt_nodisable(ndev); 1282ec21e2ecSJeff Kirsher 1283ec21e2ecSJeff Kirsher /* Disable Tx, and Rx if wake-on-LAN is disabled. */ 1284ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg1); 1285ec21e2ecSJeff Kirsher 1286ec21e2ecSJeff Kirsher tempval &= ~MACCFG1_TX_EN; 1287ec21e2ecSJeff Kirsher 1288ec21e2ecSJeff Kirsher if (!magic_packet) 1289ec21e2ecSJeff Kirsher tempval &= ~MACCFG1_RX_EN; 1290ec21e2ecSJeff Kirsher 1291ec21e2ecSJeff Kirsher gfar_write(®s->maccfg1, tempval); 1292ec21e2ecSJeff Kirsher 1293ec21e2ecSJeff Kirsher unlock_rx_qs(priv); 1294ec21e2ecSJeff Kirsher unlock_tx_qs(priv); 1295ec21e2ecSJeff Kirsher local_irq_restore(flags); 1296ec21e2ecSJeff Kirsher 1297ec21e2ecSJeff Kirsher disable_napi(priv); 1298ec21e2ecSJeff Kirsher 1299ec21e2ecSJeff Kirsher if (magic_packet) { 1300ec21e2ecSJeff Kirsher /* Enable interrupt on Magic Packet */ 1301ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_MAG); 1302ec21e2ecSJeff Kirsher 1303ec21e2ecSJeff Kirsher /* Enable Magic Packet mode */ 1304ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg2); 1305ec21e2ecSJeff Kirsher tempval |= MACCFG2_MPEN; 1306ec21e2ecSJeff Kirsher gfar_write(®s->maccfg2, tempval); 1307ec21e2ecSJeff Kirsher } else { 1308ec21e2ecSJeff Kirsher phy_stop(priv->phydev); 1309ec21e2ecSJeff Kirsher } 1310ec21e2ecSJeff Kirsher } 1311ec21e2ecSJeff Kirsher 1312ec21e2ecSJeff Kirsher return 0; 1313ec21e2ecSJeff Kirsher } 1314ec21e2ecSJeff Kirsher 1315ec21e2ecSJeff Kirsher static int gfar_resume(struct device *dev) 1316ec21e2ecSJeff Kirsher { 1317ec21e2ecSJeff Kirsher struct gfar_private *priv = dev_get_drvdata(dev); 1318ec21e2ecSJeff Kirsher struct net_device *ndev = priv->ndev; 1319ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1320ec21e2ecSJeff Kirsher unsigned long flags; 1321ec21e2ecSJeff Kirsher u32 tempval; 1322ec21e2ecSJeff Kirsher int magic_packet = priv->wol_en && 1323bc4598bcSJan Ceuleers (priv->device_flags & 1324bc4598bcSJan Ceuleers FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); 1325ec21e2ecSJeff Kirsher 1326ec21e2ecSJeff Kirsher if (!netif_running(ndev)) { 1327ec21e2ecSJeff Kirsher netif_device_attach(ndev); 1328ec21e2ecSJeff Kirsher return 0; 1329ec21e2ecSJeff Kirsher } 1330ec21e2ecSJeff Kirsher 1331ec21e2ecSJeff Kirsher if (!magic_packet && priv->phydev) 1332ec21e2ecSJeff Kirsher phy_start(priv->phydev); 1333ec21e2ecSJeff Kirsher 1334ec21e2ecSJeff Kirsher /* Disable Magic Packet mode, in case something 1335ec21e2ecSJeff Kirsher * else woke us up. 1336ec21e2ecSJeff Kirsher */ 1337ec21e2ecSJeff Kirsher local_irq_save(flags); 1338ec21e2ecSJeff Kirsher lock_tx_qs(priv); 1339ec21e2ecSJeff Kirsher lock_rx_qs(priv); 1340ec21e2ecSJeff Kirsher 1341ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg2); 1342ec21e2ecSJeff Kirsher tempval &= ~MACCFG2_MPEN; 1343ec21e2ecSJeff Kirsher gfar_write(®s->maccfg2, tempval); 1344ec21e2ecSJeff Kirsher 1345ec21e2ecSJeff Kirsher gfar_start(ndev); 1346ec21e2ecSJeff Kirsher 1347ec21e2ecSJeff Kirsher unlock_rx_qs(priv); 1348ec21e2ecSJeff Kirsher unlock_tx_qs(priv); 1349ec21e2ecSJeff Kirsher local_irq_restore(flags); 1350ec21e2ecSJeff Kirsher 1351ec21e2ecSJeff Kirsher netif_device_attach(ndev); 1352ec21e2ecSJeff Kirsher 1353ec21e2ecSJeff Kirsher enable_napi(priv); 1354ec21e2ecSJeff Kirsher 1355ec21e2ecSJeff Kirsher return 0; 1356ec21e2ecSJeff Kirsher } 1357ec21e2ecSJeff Kirsher 1358ec21e2ecSJeff Kirsher static int gfar_restore(struct device *dev) 1359ec21e2ecSJeff Kirsher { 1360ec21e2ecSJeff Kirsher struct gfar_private *priv = dev_get_drvdata(dev); 1361ec21e2ecSJeff Kirsher struct net_device *ndev = priv->ndev; 1362ec21e2ecSJeff Kirsher 1363103cdd1dSWang Dongsheng if (!netif_running(ndev)) { 1364103cdd1dSWang Dongsheng netif_device_attach(ndev); 1365103cdd1dSWang Dongsheng 1366ec21e2ecSJeff Kirsher return 0; 1367103cdd1dSWang Dongsheng } 1368ec21e2ecSJeff Kirsher 13691eb8f7a7SClaudiu Manoil if (gfar_init_bds(ndev)) { 13701eb8f7a7SClaudiu Manoil free_skb_resources(priv); 13711eb8f7a7SClaudiu Manoil return -ENOMEM; 13721eb8f7a7SClaudiu Manoil } 13731eb8f7a7SClaudiu Manoil 1374ec21e2ecSJeff Kirsher init_registers(ndev); 1375ec21e2ecSJeff Kirsher gfar_set_mac_address(ndev); 1376ec21e2ecSJeff Kirsher gfar_init_mac(ndev); 1377ec21e2ecSJeff Kirsher gfar_start(ndev); 1378ec21e2ecSJeff Kirsher 1379ec21e2ecSJeff Kirsher priv->oldlink = 0; 1380ec21e2ecSJeff Kirsher priv->oldspeed = 0; 1381ec21e2ecSJeff Kirsher priv->oldduplex = -1; 1382ec21e2ecSJeff Kirsher 1383ec21e2ecSJeff Kirsher if (priv->phydev) 1384ec21e2ecSJeff Kirsher phy_start(priv->phydev); 1385ec21e2ecSJeff Kirsher 1386ec21e2ecSJeff Kirsher netif_device_attach(ndev); 1387ec21e2ecSJeff Kirsher enable_napi(priv); 1388ec21e2ecSJeff Kirsher 1389ec21e2ecSJeff Kirsher return 0; 1390ec21e2ecSJeff Kirsher } 1391ec21e2ecSJeff Kirsher 1392ec21e2ecSJeff Kirsher static struct dev_pm_ops gfar_pm_ops = { 1393ec21e2ecSJeff Kirsher .suspend = gfar_suspend, 1394ec21e2ecSJeff Kirsher .resume = gfar_resume, 1395ec21e2ecSJeff Kirsher .freeze = gfar_suspend, 1396ec21e2ecSJeff Kirsher .thaw = gfar_resume, 1397ec21e2ecSJeff Kirsher .restore = gfar_restore, 1398ec21e2ecSJeff Kirsher }; 1399ec21e2ecSJeff Kirsher 1400ec21e2ecSJeff Kirsher #define GFAR_PM_OPS (&gfar_pm_ops) 1401ec21e2ecSJeff Kirsher 1402ec21e2ecSJeff Kirsher #else 1403ec21e2ecSJeff Kirsher 1404ec21e2ecSJeff Kirsher #define GFAR_PM_OPS NULL 1405ec21e2ecSJeff Kirsher 1406ec21e2ecSJeff Kirsher #endif 1407ec21e2ecSJeff Kirsher 1408ec21e2ecSJeff Kirsher /* Reads the controller's registers to determine what interface 1409ec21e2ecSJeff Kirsher * connects it to the PHY. 1410ec21e2ecSJeff Kirsher */ 1411ec21e2ecSJeff Kirsher static phy_interface_t gfar_get_interface(struct net_device *dev) 1412ec21e2ecSJeff Kirsher { 1413ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1414ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1415ec21e2ecSJeff Kirsher u32 ecntrl; 1416ec21e2ecSJeff Kirsher 1417ec21e2ecSJeff Kirsher ecntrl = gfar_read(®s->ecntrl); 1418ec21e2ecSJeff Kirsher 1419ec21e2ecSJeff Kirsher if (ecntrl & ECNTRL_SGMII_MODE) 1420ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_SGMII; 1421ec21e2ecSJeff Kirsher 1422ec21e2ecSJeff Kirsher if (ecntrl & ECNTRL_TBI_MODE) { 1423ec21e2ecSJeff Kirsher if (ecntrl & ECNTRL_REDUCED_MODE) 1424ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_RTBI; 1425ec21e2ecSJeff Kirsher else 1426ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_TBI; 1427ec21e2ecSJeff Kirsher } 1428ec21e2ecSJeff Kirsher 1429ec21e2ecSJeff Kirsher if (ecntrl & ECNTRL_REDUCED_MODE) { 1430bc4598bcSJan Ceuleers if (ecntrl & ECNTRL_REDUCED_MII_MODE) { 1431ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_RMII; 1432bc4598bcSJan Ceuleers } 1433ec21e2ecSJeff Kirsher else { 1434ec21e2ecSJeff Kirsher phy_interface_t interface = priv->interface; 1435ec21e2ecSJeff Kirsher 14360977f817SJan Ceuleers /* This isn't autodetected right now, so it must 1437ec21e2ecSJeff Kirsher * be set by the device tree or platform code. 1438ec21e2ecSJeff Kirsher */ 1439ec21e2ecSJeff Kirsher if (interface == PHY_INTERFACE_MODE_RGMII_ID) 1440ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_RGMII_ID; 1441ec21e2ecSJeff Kirsher 1442ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_RGMII; 1443ec21e2ecSJeff Kirsher } 1444ec21e2ecSJeff Kirsher } 1445ec21e2ecSJeff Kirsher 1446ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT) 1447ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_GMII; 1448ec21e2ecSJeff Kirsher 1449ec21e2ecSJeff Kirsher return PHY_INTERFACE_MODE_MII; 1450ec21e2ecSJeff Kirsher } 1451ec21e2ecSJeff Kirsher 1452ec21e2ecSJeff Kirsher 1453ec21e2ecSJeff Kirsher /* Initializes driver's PHY state, and attaches to the PHY. 1454ec21e2ecSJeff Kirsher * Returns 0 on success. 1455ec21e2ecSJeff Kirsher */ 1456ec21e2ecSJeff Kirsher static int init_phy(struct net_device *dev) 1457ec21e2ecSJeff Kirsher { 1458ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1459ec21e2ecSJeff Kirsher uint gigabit_support = 1460ec21e2ecSJeff Kirsher priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ? 1461ec21e2ecSJeff Kirsher SUPPORTED_1000baseT_Full : 0; 1462ec21e2ecSJeff Kirsher phy_interface_t interface; 1463ec21e2ecSJeff Kirsher 1464ec21e2ecSJeff Kirsher priv->oldlink = 0; 1465ec21e2ecSJeff Kirsher priv->oldspeed = 0; 1466ec21e2ecSJeff Kirsher priv->oldduplex = -1; 1467ec21e2ecSJeff Kirsher 1468ec21e2ecSJeff Kirsher interface = gfar_get_interface(dev); 1469ec21e2ecSJeff Kirsher 1470ec21e2ecSJeff Kirsher priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0, 1471ec21e2ecSJeff Kirsher interface); 1472ec21e2ecSJeff Kirsher if (!priv->phydev) 1473ec21e2ecSJeff Kirsher priv->phydev = of_phy_connect_fixed_link(dev, &adjust_link, 1474ec21e2ecSJeff Kirsher interface); 1475ec21e2ecSJeff Kirsher if (!priv->phydev) { 1476ec21e2ecSJeff Kirsher dev_err(&dev->dev, "could not attach to PHY\n"); 1477ec21e2ecSJeff Kirsher return -ENODEV; 1478ec21e2ecSJeff Kirsher } 1479ec21e2ecSJeff Kirsher 1480ec21e2ecSJeff Kirsher if (interface == PHY_INTERFACE_MODE_SGMII) 1481ec21e2ecSJeff Kirsher gfar_configure_serdes(dev); 1482ec21e2ecSJeff Kirsher 1483ec21e2ecSJeff Kirsher /* Remove any features not supported by the controller */ 1484ec21e2ecSJeff Kirsher priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support); 1485ec21e2ecSJeff Kirsher priv->phydev->advertising = priv->phydev->supported; 1486ec21e2ecSJeff Kirsher 1487ec21e2ecSJeff Kirsher return 0; 1488ec21e2ecSJeff Kirsher } 1489ec21e2ecSJeff Kirsher 14900977f817SJan Ceuleers /* Initialize TBI PHY interface for communicating with the 1491ec21e2ecSJeff Kirsher * SERDES lynx PHY on the chip. We communicate with this PHY 1492ec21e2ecSJeff Kirsher * through the MDIO bus on each controller, treating it as a 1493ec21e2ecSJeff Kirsher * "normal" PHY at the address found in the TBIPA register. We assume 1494ec21e2ecSJeff Kirsher * that the TBIPA register is valid. Either the MDIO bus code will set 1495ec21e2ecSJeff Kirsher * it to a value that doesn't conflict with other PHYs on the bus, or the 1496ec21e2ecSJeff Kirsher * value doesn't matter, as there are no other PHYs on the bus. 1497ec21e2ecSJeff Kirsher */ 1498ec21e2ecSJeff Kirsher static void gfar_configure_serdes(struct net_device *dev) 1499ec21e2ecSJeff Kirsher { 1500ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1501ec21e2ecSJeff Kirsher struct phy_device *tbiphy; 1502ec21e2ecSJeff Kirsher 1503ec21e2ecSJeff Kirsher if (!priv->tbi_node) { 1504ec21e2ecSJeff Kirsher dev_warn(&dev->dev, "error: SGMII mode requires that the " 1505ec21e2ecSJeff Kirsher "device tree specify a tbi-handle\n"); 1506ec21e2ecSJeff Kirsher return; 1507ec21e2ecSJeff Kirsher } 1508ec21e2ecSJeff Kirsher 1509ec21e2ecSJeff Kirsher tbiphy = of_phy_find_device(priv->tbi_node); 1510ec21e2ecSJeff Kirsher if (!tbiphy) { 1511ec21e2ecSJeff Kirsher dev_err(&dev->dev, "error: Could not get TBI device\n"); 1512ec21e2ecSJeff Kirsher return; 1513ec21e2ecSJeff Kirsher } 1514ec21e2ecSJeff Kirsher 15150977f817SJan Ceuleers /* If the link is already up, we must already be ok, and don't need to 1516ec21e2ecSJeff Kirsher * configure and reset the TBI<->SerDes link. Maybe U-Boot configured 1517ec21e2ecSJeff Kirsher * everything for us? Resetting it takes the link down and requires 1518ec21e2ecSJeff Kirsher * several seconds for it to come back. 1519ec21e2ecSJeff Kirsher */ 1520ec21e2ecSJeff Kirsher if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS) 1521ec21e2ecSJeff Kirsher return; 1522ec21e2ecSJeff Kirsher 1523ec21e2ecSJeff Kirsher /* Single clk mode, mii mode off(for serdes communication) */ 1524ec21e2ecSJeff Kirsher phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT); 1525ec21e2ecSJeff Kirsher 1526ec21e2ecSJeff Kirsher phy_write(tbiphy, MII_ADVERTISE, 1527ec21e2ecSJeff Kirsher ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | 1528ec21e2ecSJeff Kirsher ADVERTISE_1000XPSE_ASYM); 1529ec21e2ecSJeff Kirsher 1530bc4598bcSJan Ceuleers phy_write(tbiphy, MII_BMCR, 1531bc4598bcSJan Ceuleers BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX | 1532bc4598bcSJan Ceuleers BMCR_SPEED1000); 1533ec21e2ecSJeff Kirsher } 1534ec21e2ecSJeff Kirsher 1535ec21e2ecSJeff Kirsher static void init_registers(struct net_device *dev) 1536ec21e2ecSJeff Kirsher { 1537ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1538ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 15393a2e16c8SJan Ceuleers int i; 1540ec21e2ecSJeff Kirsher 1541ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1542ec21e2ecSJeff Kirsher regs = priv->gfargrp[i].regs; 1543ec21e2ecSJeff Kirsher /* Clear IEVENT */ 1544ec21e2ecSJeff Kirsher gfar_write(®s->ievent, IEVENT_INIT_CLEAR); 1545ec21e2ecSJeff Kirsher 1546ec21e2ecSJeff Kirsher /* Initialize IMASK */ 1547ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_INIT_CLEAR); 1548ec21e2ecSJeff Kirsher } 1549ec21e2ecSJeff Kirsher 1550ec21e2ecSJeff Kirsher regs = priv->gfargrp[0].regs; 1551ec21e2ecSJeff Kirsher /* Init hash registers to zero */ 1552ec21e2ecSJeff Kirsher gfar_write(®s->igaddr0, 0); 1553ec21e2ecSJeff Kirsher gfar_write(®s->igaddr1, 0); 1554ec21e2ecSJeff Kirsher gfar_write(®s->igaddr2, 0); 1555ec21e2ecSJeff Kirsher gfar_write(®s->igaddr3, 0); 1556ec21e2ecSJeff Kirsher gfar_write(®s->igaddr4, 0); 1557ec21e2ecSJeff Kirsher gfar_write(®s->igaddr5, 0); 1558ec21e2ecSJeff Kirsher gfar_write(®s->igaddr6, 0); 1559ec21e2ecSJeff Kirsher gfar_write(®s->igaddr7, 0); 1560ec21e2ecSJeff Kirsher 1561ec21e2ecSJeff Kirsher gfar_write(®s->gaddr0, 0); 1562ec21e2ecSJeff Kirsher gfar_write(®s->gaddr1, 0); 1563ec21e2ecSJeff Kirsher gfar_write(®s->gaddr2, 0); 1564ec21e2ecSJeff Kirsher gfar_write(®s->gaddr3, 0); 1565ec21e2ecSJeff Kirsher gfar_write(®s->gaddr4, 0); 1566ec21e2ecSJeff Kirsher gfar_write(®s->gaddr5, 0); 1567ec21e2ecSJeff Kirsher gfar_write(®s->gaddr6, 0); 1568ec21e2ecSJeff Kirsher gfar_write(®s->gaddr7, 0); 1569ec21e2ecSJeff Kirsher 1570ec21e2ecSJeff Kirsher /* Zero out the rmon mib registers if it has them */ 1571ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { 1572ec21e2ecSJeff Kirsher memset_io(&(regs->rmon), 0, sizeof (struct rmon_mib)); 1573ec21e2ecSJeff Kirsher 1574ec21e2ecSJeff Kirsher /* Mask off the CAM interrupts */ 1575ec21e2ecSJeff Kirsher gfar_write(®s->rmon.cam1, 0xffffffff); 1576ec21e2ecSJeff Kirsher gfar_write(®s->rmon.cam2, 0xffffffff); 1577ec21e2ecSJeff Kirsher } 1578ec21e2ecSJeff Kirsher 1579ec21e2ecSJeff Kirsher /* Initialize the max receive buffer length */ 1580ec21e2ecSJeff Kirsher gfar_write(®s->mrblr, priv->rx_buffer_size); 1581ec21e2ecSJeff Kirsher 1582ec21e2ecSJeff Kirsher /* Initialize the Minimum Frame Length Register */ 1583ec21e2ecSJeff Kirsher gfar_write(®s->minflr, MINFLR_INIT_SETTINGS); 1584ec21e2ecSJeff Kirsher } 1585ec21e2ecSJeff Kirsher 1586ec21e2ecSJeff Kirsher static int __gfar_is_rx_idle(struct gfar_private *priv) 1587ec21e2ecSJeff Kirsher { 1588ec21e2ecSJeff Kirsher u32 res; 1589ec21e2ecSJeff Kirsher 15900977f817SJan Ceuleers /* Normaly TSEC should not hang on GRS commands, so we should 1591ec21e2ecSJeff Kirsher * actually wait for IEVENT_GRSC flag. 1592ec21e2ecSJeff Kirsher */ 1593ec21e2ecSJeff Kirsher if (likely(!gfar_has_errata(priv, GFAR_ERRATA_A002))) 1594ec21e2ecSJeff Kirsher return 0; 1595ec21e2ecSJeff Kirsher 15960977f817SJan Ceuleers /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are 1597ec21e2ecSJeff Kirsher * the same as bits 23-30, the eTSEC Rx is assumed to be idle 1598ec21e2ecSJeff Kirsher * and the Rx can be safely reset. 1599ec21e2ecSJeff Kirsher */ 1600ec21e2ecSJeff Kirsher res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c); 1601ec21e2ecSJeff Kirsher res &= 0x7f807f80; 1602ec21e2ecSJeff Kirsher if ((res & 0xffff) == (res >> 16)) 1603ec21e2ecSJeff Kirsher return 1; 1604ec21e2ecSJeff Kirsher 1605ec21e2ecSJeff Kirsher return 0; 1606ec21e2ecSJeff Kirsher } 1607ec21e2ecSJeff Kirsher 1608ec21e2ecSJeff Kirsher /* Halt the receive and transmit queues */ 1609ec21e2ecSJeff Kirsher static void gfar_halt_nodisable(struct net_device *dev) 1610ec21e2ecSJeff Kirsher { 1611ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1612ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 1613ec21e2ecSJeff Kirsher u32 tempval; 16143a2e16c8SJan Ceuleers int i; 1615ec21e2ecSJeff Kirsher 1616ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1617ec21e2ecSJeff Kirsher regs = priv->gfargrp[i].regs; 1618ec21e2ecSJeff Kirsher /* Mask all interrupts */ 1619ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_INIT_CLEAR); 1620ec21e2ecSJeff Kirsher 1621ec21e2ecSJeff Kirsher /* Clear all interrupts */ 1622ec21e2ecSJeff Kirsher gfar_write(®s->ievent, IEVENT_INIT_CLEAR); 1623ec21e2ecSJeff Kirsher } 1624ec21e2ecSJeff Kirsher 1625ec21e2ecSJeff Kirsher regs = priv->gfargrp[0].regs; 1626ec21e2ecSJeff Kirsher /* Stop the DMA, and wait for it to stop */ 1627ec21e2ecSJeff Kirsher tempval = gfar_read(®s->dmactrl); 1628bc4598bcSJan Ceuleers if ((tempval & (DMACTRL_GRS | DMACTRL_GTS)) != 1629bc4598bcSJan Ceuleers (DMACTRL_GRS | DMACTRL_GTS)) { 1630ec21e2ecSJeff Kirsher int ret; 1631ec21e2ecSJeff Kirsher 1632ec21e2ecSJeff Kirsher tempval |= (DMACTRL_GRS | DMACTRL_GTS); 1633ec21e2ecSJeff Kirsher gfar_write(®s->dmactrl, tempval); 1634ec21e2ecSJeff Kirsher 1635ec21e2ecSJeff Kirsher do { 1636ec21e2ecSJeff Kirsher ret = spin_event_timeout(((gfar_read(®s->ievent) & 1637ec21e2ecSJeff Kirsher (IEVENT_GRSC | IEVENT_GTSC)) == 1638ec21e2ecSJeff Kirsher (IEVENT_GRSC | IEVENT_GTSC)), 1000000, 0); 1639ec21e2ecSJeff Kirsher if (!ret && !(gfar_read(®s->ievent) & IEVENT_GRSC)) 1640ec21e2ecSJeff Kirsher ret = __gfar_is_rx_idle(priv); 1641ec21e2ecSJeff Kirsher } while (!ret); 1642ec21e2ecSJeff Kirsher } 1643ec21e2ecSJeff Kirsher } 1644ec21e2ecSJeff Kirsher 1645ec21e2ecSJeff Kirsher /* Halt the receive and transmit queues */ 1646ec21e2ecSJeff Kirsher void gfar_halt(struct net_device *dev) 1647ec21e2ecSJeff Kirsher { 1648ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1649ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1650ec21e2ecSJeff Kirsher u32 tempval; 1651ec21e2ecSJeff Kirsher 1652ec21e2ecSJeff Kirsher gfar_halt_nodisable(dev); 1653ec21e2ecSJeff Kirsher 1654ec21e2ecSJeff Kirsher /* Disable Rx and Tx */ 1655ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg1); 1656ec21e2ecSJeff Kirsher tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN); 1657ec21e2ecSJeff Kirsher gfar_write(®s->maccfg1, tempval); 1658ec21e2ecSJeff Kirsher } 1659ec21e2ecSJeff Kirsher 1660ec21e2ecSJeff Kirsher static void free_grp_irqs(struct gfar_priv_grp *grp) 1661ec21e2ecSJeff Kirsher { 1662ee873fdaSClaudiu Manoil free_irq(gfar_irq(grp, TX)->irq, grp); 1663ee873fdaSClaudiu Manoil free_irq(gfar_irq(grp, RX)->irq, grp); 1664ee873fdaSClaudiu Manoil free_irq(gfar_irq(grp, ER)->irq, grp); 1665ec21e2ecSJeff Kirsher } 1666ec21e2ecSJeff Kirsher 1667ec21e2ecSJeff Kirsher void stop_gfar(struct net_device *dev) 1668ec21e2ecSJeff Kirsher { 1669ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1670ec21e2ecSJeff Kirsher unsigned long flags; 1671ec21e2ecSJeff Kirsher int i; 1672ec21e2ecSJeff Kirsher 1673ec21e2ecSJeff Kirsher phy_stop(priv->phydev); 1674ec21e2ecSJeff Kirsher 1675ec21e2ecSJeff Kirsher 1676ec21e2ecSJeff Kirsher /* Lock it down */ 1677ec21e2ecSJeff Kirsher local_irq_save(flags); 1678ec21e2ecSJeff Kirsher lock_tx_qs(priv); 1679ec21e2ecSJeff Kirsher lock_rx_qs(priv); 1680ec21e2ecSJeff Kirsher 1681ec21e2ecSJeff Kirsher gfar_halt(dev); 1682ec21e2ecSJeff Kirsher 1683ec21e2ecSJeff Kirsher unlock_rx_qs(priv); 1684ec21e2ecSJeff Kirsher unlock_tx_qs(priv); 1685ec21e2ecSJeff Kirsher local_irq_restore(flags); 1686ec21e2ecSJeff Kirsher 1687ec21e2ecSJeff Kirsher /* Free the IRQs */ 1688ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 1689ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) 1690ec21e2ecSJeff Kirsher free_grp_irqs(&priv->gfargrp[i]); 1691ec21e2ecSJeff Kirsher } else { 1692ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) 1693ee873fdaSClaudiu Manoil free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq, 1694ec21e2ecSJeff Kirsher &priv->gfargrp[i]); 1695ec21e2ecSJeff Kirsher } 1696ec21e2ecSJeff Kirsher 1697ec21e2ecSJeff Kirsher free_skb_resources(priv); 1698ec21e2ecSJeff Kirsher } 1699ec21e2ecSJeff Kirsher 1700ec21e2ecSJeff Kirsher static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue) 1701ec21e2ecSJeff Kirsher { 1702ec21e2ecSJeff Kirsher struct txbd8 *txbdp; 1703ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(tx_queue->dev); 1704ec21e2ecSJeff Kirsher int i, j; 1705ec21e2ecSJeff Kirsher 1706ec21e2ecSJeff Kirsher txbdp = tx_queue->tx_bd_base; 1707ec21e2ecSJeff Kirsher 1708ec21e2ecSJeff Kirsher for (i = 0; i < tx_queue->tx_ring_size; i++) { 1709ec21e2ecSJeff Kirsher if (!tx_queue->tx_skbuff[i]) 1710ec21e2ecSJeff Kirsher continue; 1711ec21e2ecSJeff Kirsher 1712369ec162SClaudiu Manoil dma_unmap_single(priv->dev, txbdp->bufPtr, 1713ec21e2ecSJeff Kirsher txbdp->length, DMA_TO_DEVICE); 1714ec21e2ecSJeff Kirsher txbdp->lstatus = 0; 1715ec21e2ecSJeff Kirsher for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags; 1716ec21e2ecSJeff Kirsher j++) { 1717ec21e2ecSJeff Kirsher txbdp++; 1718369ec162SClaudiu Manoil dma_unmap_page(priv->dev, txbdp->bufPtr, 1719ec21e2ecSJeff Kirsher txbdp->length, DMA_TO_DEVICE); 1720ec21e2ecSJeff Kirsher } 1721ec21e2ecSJeff Kirsher txbdp++; 1722ec21e2ecSJeff Kirsher dev_kfree_skb_any(tx_queue->tx_skbuff[i]); 1723ec21e2ecSJeff Kirsher tx_queue->tx_skbuff[i] = NULL; 1724ec21e2ecSJeff Kirsher } 1725ec21e2ecSJeff Kirsher kfree(tx_queue->tx_skbuff); 17261eb8f7a7SClaudiu Manoil tx_queue->tx_skbuff = NULL; 1727ec21e2ecSJeff Kirsher } 1728ec21e2ecSJeff Kirsher 1729ec21e2ecSJeff Kirsher static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue) 1730ec21e2ecSJeff Kirsher { 1731ec21e2ecSJeff Kirsher struct rxbd8 *rxbdp; 1732ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(rx_queue->dev); 1733ec21e2ecSJeff Kirsher int i; 1734ec21e2ecSJeff Kirsher 1735ec21e2ecSJeff Kirsher rxbdp = rx_queue->rx_bd_base; 1736ec21e2ecSJeff Kirsher 1737ec21e2ecSJeff Kirsher for (i = 0; i < rx_queue->rx_ring_size; i++) { 1738ec21e2ecSJeff Kirsher if (rx_queue->rx_skbuff[i]) { 1739369ec162SClaudiu Manoil dma_unmap_single(priv->dev, rxbdp->bufPtr, 1740369ec162SClaudiu Manoil priv->rx_buffer_size, 1741ec21e2ecSJeff Kirsher DMA_FROM_DEVICE); 1742ec21e2ecSJeff Kirsher dev_kfree_skb_any(rx_queue->rx_skbuff[i]); 1743ec21e2ecSJeff Kirsher rx_queue->rx_skbuff[i] = NULL; 1744ec21e2ecSJeff Kirsher } 1745ec21e2ecSJeff Kirsher rxbdp->lstatus = 0; 1746ec21e2ecSJeff Kirsher rxbdp->bufPtr = 0; 1747ec21e2ecSJeff Kirsher rxbdp++; 1748ec21e2ecSJeff Kirsher } 1749ec21e2ecSJeff Kirsher kfree(rx_queue->rx_skbuff); 17501eb8f7a7SClaudiu Manoil rx_queue->rx_skbuff = NULL; 1751ec21e2ecSJeff Kirsher } 1752ec21e2ecSJeff Kirsher 1753ec21e2ecSJeff Kirsher /* If there are any tx skbs or rx skbs still around, free them. 17540977f817SJan Ceuleers * Then free tx_skbuff and rx_skbuff 17550977f817SJan Ceuleers */ 1756ec21e2ecSJeff Kirsher static void free_skb_resources(struct gfar_private *priv) 1757ec21e2ecSJeff Kirsher { 1758ec21e2ecSJeff Kirsher struct gfar_priv_tx_q *tx_queue = NULL; 1759ec21e2ecSJeff Kirsher struct gfar_priv_rx_q *rx_queue = NULL; 1760ec21e2ecSJeff Kirsher int i; 1761ec21e2ecSJeff Kirsher 1762ec21e2ecSJeff Kirsher /* Go through all the buffer descriptors and free their data buffers */ 1763ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_tx_queues; i++) { 1764d8a0f1b0SPaul Gortmaker struct netdev_queue *txq; 1765bc4598bcSJan Ceuleers 1766ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[i]; 1767d8a0f1b0SPaul Gortmaker txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex); 1768ec21e2ecSJeff Kirsher if (tx_queue->tx_skbuff) 1769ec21e2ecSJeff Kirsher free_skb_tx_queue(tx_queue); 1770d8a0f1b0SPaul Gortmaker netdev_tx_reset_queue(txq); 1771ec21e2ecSJeff Kirsher } 1772ec21e2ecSJeff Kirsher 1773ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_rx_queues; i++) { 1774ec21e2ecSJeff Kirsher rx_queue = priv->rx_queue[i]; 1775ec21e2ecSJeff Kirsher if (rx_queue->rx_skbuff) 1776ec21e2ecSJeff Kirsher free_skb_rx_queue(rx_queue); 1777ec21e2ecSJeff Kirsher } 1778ec21e2ecSJeff Kirsher 1779369ec162SClaudiu Manoil dma_free_coherent(priv->dev, 1780ec21e2ecSJeff Kirsher sizeof(struct txbd8) * priv->total_tx_ring_size + 1781ec21e2ecSJeff Kirsher sizeof(struct rxbd8) * priv->total_rx_ring_size, 1782ec21e2ecSJeff Kirsher priv->tx_queue[0]->tx_bd_base, 1783ec21e2ecSJeff Kirsher priv->tx_queue[0]->tx_bd_dma_base); 1784ec21e2ecSJeff Kirsher } 1785ec21e2ecSJeff Kirsher 1786ec21e2ecSJeff Kirsher void gfar_start(struct net_device *dev) 1787ec21e2ecSJeff Kirsher { 1788ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1789ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1790ec21e2ecSJeff Kirsher u32 tempval; 1791ec21e2ecSJeff Kirsher int i = 0; 1792ec21e2ecSJeff Kirsher 1793ec21e2ecSJeff Kirsher /* Enable Rx and Tx in MACCFG1 */ 1794ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg1); 1795ec21e2ecSJeff Kirsher tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN); 1796ec21e2ecSJeff Kirsher gfar_write(®s->maccfg1, tempval); 1797ec21e2ecSJeff Kirsher 1798ec21e2ecSJeff Kirsher /* Initialize DMACTRL to have WWR and WOP */ 1799ec21e2ecSJeff Kirsher tempval = gfar_read(®s->dmactrl); 1800ec21e2ecSJeff Kirsher tempval |= DMACTRL_INIT_SETTINGS; 1801ec21e2ecSJeff Kirsher gfar_write(®s->dmactrl, tempval); 1802ec21e2ecSJeff Kirsher 1803ec21e2ecSJeff Kirsher /* Make sure we aren't stopped */ 1804ec21e2ecSJeff Kirsher tempval = gfar_read(®s->dmactrl); 1805ec21e2ecSJeff Kirsher tempval &= ~(DMACTRL_GRS | DMACTRL_GTS); 1806ec21e2ecSJeff Kirsher gfar_write(®s->dmactrl, tempval); 1807ec21e2ecSJeff Kirsher 1808ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1809ec21e2ecSJeff Kirsher regs = priv->gfargrp[i].regs; 1810ec21e2ecSJeff Kirsher /* Clear THLT/RHLT, so that the DMA starts polling now */ 1811ec21e2ecSJeff Kirsher gfar_write(®s->tstat, priv->gfargrp[i].tstat); 1812ec21e2ecSJeff Kirsher gfar_write(®s->rstat, priv->gfargrp[i].rstat); 1813ec21e2ecSJeff Kirsher /* Unmask the interrupts we look for */ 1814ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_DEFAULT); 1815ec21e2ecSJeff Kirsher } 1816ec21e2ecSJeff Kirsher 1817ec21e2ecSJeff Kirsher dev->trans_start = jiffies; /* prevent tx timeout */ 1818ec21e2ecSJeff Kirsher } 1819ec21e2ecSJeff Kirsher 1820ec21e2ecSJeff Kirsher void gfar_configure_coalescing(struct gfar_private *priv, 1821ec21e2ecSJeff Kirsher unsigned long tx_mask, unsigned long rx_mask) 1822ec21e2ecSJeff Kirsher { 1823ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 1824ec21e2ecSJeff Kirsher u32 __iomem *baddr; 1825ec21e2ecSJeff Kirsher int i = 0; 1826ec21e2ecSJeff Kirsher 1827ec21e2ecSJeff Kirsher /* Backward compatible case ---- even if we enable 1828ec21e2ecSJeff Kirsher * multiple queues, there's only single reg to program 1829ec21e2ecSJeff Kirsher */ 1830ec21e2ecSJeff Kirsher gfar_write(®s->txic, 0); 1831ec21e2ecSJeff Kirsher if (likely(priv->tx_queue[0]->txcoalescing)) 1832ec21e2ecSJeff Kirsher gfar_write(®s->txic, priv->tx_queue[0]->txic); 1833ec21e2ecSJeff Kirsher 1834ec21e2ecSJeff Kirsher gfar_write(®s->rxic, 0); 1835ec21e2ecSJeff Kirsher if (unlikely(priv->rx_queue[0]->rxcoalescing)) 1836ec21e2ecSJeff Kirsher gfar_write(®s->rxic, priv->rx_queue[0]->rxic); 1837ec21e2ecSJeff Kirsher 1838ec21e2ecSJeff Kirsher if (priv->mode == MQ_MG_MODE) { 1839ec21e2ecSJeff Kirsher baddr = ®s->txic0; 1840ec21e2ecSJeff Kirsher for_each_set_bit(i, &tx_mask, priv->num_tx_queues) { 1841ec21e2ecSJeff Kirsher gfar_write(baddr + i, 0); 18429740e001SClaudiu Manoil if (likely(priv->tx_queue[i]->txcoalescing)) 1843ec21e2ecSJeff Kirsher gfar_write(baddr + i, priv->tx_queue[i]->txic); 1844ec21e2ecSJeff Kirsher } 1845ec21e2ecSJeff Kirsher 1846ec21e2ecSJeff Kirsher baddr = ®s->rxic0; 1847ec21e2ecSJeff Kirsher for_each_set_bit(i, &rx_mask, priv->num_rx_queues) { 1848ec21e2ecSJeff Kirsher gfar_write(baddr + i, 0); 18499740e001SClaudiu Manoil if (likely(priv->rx_queue[i]->rxcoalescing)) 1850ec21e2ecSJeff Kirsher gfar_write(baddr + i, priv->rx_queue[i]->rxic); 1851ec21e2ecSJeff Kirsher } 1852ec21e2ecSJeff Kirsher } 1853ec21e2ecSJeff Kirsher } 1854ec21e2ecSJeff Kirsher 1855ec21e2ecSJeff Kirsher static int register_grp_irqs(struct gfar_priv_grp *grp) 1856ec21e2ecSJeff Kirsher { 1857ec21e2ecSJeff Kirsher struct gfar_private *priv = grp->priv; 1858ec21e2ecSJeff Kirsher struct net_device *dev = priv->ndev; 1859ec21e2ecSJeff Kirsher int err; 1860ec21e2ecSJeff Kirsher 1861ec21e2ecSJeff Kirsher /* If the device has multiple interrupts, register for 18620977f817SJan Ceuleers * them. Otherwise, only register for the one 18630977f817SJan Ceuleers */ 1864ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 1865ec21e2ecSJeff Kirsher /* Install our interrupt handlers for Error, 18660977f817SJan Ceuleers * Transmit, and Receive 18670977f817SJan Ceuleers */ 1868ee873fdaSClaudiu Manoil err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0, 1869ee873fdaSClaudiu Manoil gfar_irq(grp, ER)->name, grp); 1870ee873fdaSClaudiu Manoil if (err < 0) { 1871ec21e2ecSJeff Kirsher netif_err(priv, intr, dev, "Can't get IRQ %d\n", 1872ee873fdaSClaudiu Manoil gfar_irq(grp, ER)->irq); 1873ec21e2ecSJeff Kirsher 1874ec21e2ecSJeff Kirsher goto err_irq_fail; 1875ec21e2ecSJeff Kirsher } 1876ee873fdaSClaudiu Manoil err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0, 1877ee873fdaSClaudiu Manoil gfar_irq(grp, TX)->name, grp); 1878ee873fdaSClaudiu Manoil if (err < 0) { 1879ec21e2ecSJeff Kirsher netif_err(priv, intr, dev, "Can't get IRQ %d\n", 1880ee873fdaSClaudiu Manoil gfar_irq(grp, TX)->irq); 1881ec21e2ecSJeff Kirsher goto tx_irq_fail; 1882ec21e2ecSJeff Kirsher } 1883ee873fdaSClaudiu Manoil err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0, 1884ee873fdaSClaudiu Manoil gfar_irq(grp, RX)->name, grp); 1885ee873fdaSClaudiu Manoil if (err < 0) { 1886ec21e2ecSJeff Kirsher netif_err(priv, intr, dev, "Can't get IRQ %d\n", 1887ee873fdaSClaudiu Manoil gfar_irq(grp, RX)->irq); 1888ec21e2ecSJeff Kirsher goto rx_irq_fail; 1889ec21e2ecSJeff Kirsher } 1890ec21e2ecSJeff Kirsher } else { 1891ee873fdaSClaudiu Manoil err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0, 1892ee873fdaSClaudiu Manoil gfar_irq(grp, TX)->name, grp); 1893ee873fdaSClaudiu Manoil if (err < 0) { 1894ec21e2ecSJeff Kirsher netif_err(priv, intr, dev, "Can't get IRQ %d\n", 1895ee873fdaSClaudiu Manoil gfar_irq(grp, TX)->irq); 1896ec21e2ecSJeff Kirsher goto err_irq_fail; 1897ec21e2ecSJeff Kirsher } 1898ec21e2ecSJeff Kirsher } 1899ec21e2ecSJeff Kirsher 1900ec21e2ecSJeff Kirsher return 0; 1901ec21e2ecSJeff Kirsher 1902ec21e2ecSJeff Kirsher rx_irq_fail: 1903ee873fdaSClaudiu Manoil free_irq(gfar_irq(grp, TX)->irq, grp); 1904ec21e2ecSJeff Kirsher tx_irq_fail: 1905ee873fdaSClaudiu Manoil free_irq(gfar_irq(grp, ER)->irq, grp); 1906ec21e2ecSJeff Kirsher err_irq_fail: 1907ec21e2ecSJeff Kirsher return err; 1908ec21e2ecSJeff Kirsher 1909ec21e2ecSJeff Kirsher } 1910ec21e2ecSJeff Kirsher 1911ec21e2ecSJeff Kirsher /* Bring the controller up and running */ 1912ec21e2ecSJeff Kirsher int startup_gfar(struct net_device *ndev) 1913ec21e2ecSJeff Kirsher { 1914ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(ndev); 1915ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 1916ec21e2ecSJeff Kirsher int err, i, j; 1917ec21e2ecSJeff Kirsher 1918ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1919ec21e2ecSJeff Kirsher regs= priv->gfargrp[i].regs; 1920ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_INIT_CLEAR); 1921ec21e2ecSJeff Kirsher } 1922ec21e2ecSJeff Kirsher 1923ec21e2ecSJeff Kirsher regs= priv->gfargrp[0].regs; 1924ec21e2ecSJeff Kirsher err = gfar_alloc_skb_resources(ndev); 1925ec21e2ecSJeff Kirsher if (err) 1926ec21e2ecSJeff Kirsher return err; 1927ec21e2ecSJeff Kirsher 1928ec21e2ecSJeff Kirsher gfar_init_mac(ndev); 1929ec21e2ecSJeff Kirsher 1930ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 1931ec21e2ecSJeff Kirsher err = register_grp_irqs(&priv->gfargrp[i]); 1932ec21e2ecSJeff Kirsher if (err) { 1933ec21e2ecSJeff Kirsher for (j = 0; j < i; j++) 1934ec21e2ecSJeff Kirsher free_grp_irqs(&priv->gfargrp[j]); 1935ec21e2ecSJeff Kirsher goto irq_fail; 1936ec21e2ecSJeff Kirsher } 1937ec21e2ecSJeff Kirsher } 1938ec21e2ecSJeff Kirsher 1939ec21e2ecSJeff Kirsher /* Start the controller */ 1940ec21e2ecSJeff Kirsher gfar_start(ndev); 1941ec21e2ecSJeff Kirsher 1942ec21e2ecSJeff Kirsher phy_start(priv->phydev); 1943ec21e2ecSJeff Kirsher 1944ec21e2ecSJeff Kirsher gfar_configure_coalescing(priv, 0xFF, 0xFF); 1945ec21e2ecSJeff Kirsher 1946ec21e2ecSJeff Kirsher return 0; 1947ec21e2ecSJeff Kirsher 1948ec21e2ecSJeff Kirsher irq_fail: 1949ec21e2ecSJeff Kirsher free_skb_resources(priv); 1950ec21e2ecSJeff Kirsher return err; 1951ec21e2ecSJeff Kirsher } 1952ec21e2ecSJeff Kirsher 19530977f817SJan Ceuleers /* Called when something needs to use the ethernet device 19540977f817SJan Ceuleers * Returns 0 for success. 19550977f817SJan Ceuleers */ 1956ec21e2ecSJeff Kirsher static int gfar_enet_open(struct net_device *dev) 1957ec21e2ecSJeff Kirsher { 1958ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 1959ec21e2ecSJeff Kirsher int err; 1960ec21e2ecSJeff Kirsher 1961ec21e2ecSJeff Kirsher enable_napi(priv); 1962ec21e2ecSJeff Kirsher 1963ec21e2ecSJeff Kirsher /* Initialize a bunch of registers */ 1964ec21e2ecSJeff Kirsher init_registers(dev); 1965ec21e2ecSJeff Kirsher 1966ec21e2ecSJeff Kirsher gfar_set_mac_address(dev); 1967ec21e2ecSJeff Kirsher 1968ec21e2ecSJeff Kirsher err = init_phy(dev); 1969ec21e2ecSJeff Kirsher 1970ec21e2ecSJeff Kirsher if (err) { 1971ec21e2ecSJeff Kirsher disable_napi(priv); 1972ec21e2ecSJeff Kirsher return err; 1973ec21e2ecSJeff Kirsher } 1974ec21e2ecSJeff Kirsher 1975ec21e2ecSJeff Kirsher err = startup_gfar(dev); 1976ec21e2ecSJeff Kirsher if (err) { 1977ec21e2ecSJeff Kirsher disable_napi(priv); 1978ec21e2ecSJeff Kirsher return err; 1979ec21e2ecSJeff Kirsher } 1980ec21e2ecSJeff Kirsher 1981ec21e2ecSJeff Kirsher netif_tx_start_all_queues(dev); 1982ec21e2ecSJeff Kirsher 1983ec21e2ecSJeff Kirsher device_set_wakeup_enable(&dev->dev, priv->wol_en); 1984ec21e2ecSJeff Kirsher 1985ec21e2ecSJeff Kirsher return err; 1986ec21e2ecSJeff Kirsher } 1987ec21e2ecSJeff Kirsher 1988ec21e2ecSJeff Kirsher static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb) 1989ec21e2ecSJeff Kirsher { 1990ec21e2ecSJeff Kirsher struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN); 1991ec21e2ecSJeff Kirsher 1992ec21e2ecSJeff Kirsher memset(fcb, 0, GMAC_FCB_LEN); 1993ec21e2ecSJeff Kirsher 1994ec21e2ecSJeff Kirsher return fcb; 1995ec21e2ecSJeff Kirsher } 1996ec21e2ecSJeff Kirsher 19979c4886e5SManfred Rudigier static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb, 19989c4886e5SManfred Rudigier int fcb_length) 1999ec21e2ecSJeff Kirsher { 2000ec21e2ecSJeff Kirsher /* If we're here, it's a IP packet with a TCP or UDP 2001ec21e2ecSJeff Kirsher * payload. We set it to checksum, using a pseudo-header 2002ec21e2ecSJeff Kirsher * we provide 2003ec21e2ecSJeff Kirsher */ 20043a2e16c8SJan Ceuleers u8 flags = TXFCB_DEFAULT; 2005ec21e2ecSJeff Kirsher 20060977f817SJan Ceuleers /* Tell the controller what the protocol is 20070977f817SJan Ceuleers * And provide the already calculated phcs 20080977f817SJan Ceuleers */ 2009ec21e2ecSJeff Kirsher if (ip_hdr(skb)->protocol == IPPROTO_UDP) { 2010ec21e2ecSJeff Kirsher flags |= TXFCB_UDP; 2011ec21e2ecSJeff Kirsher fcb->phcs = udp_hdr(skb)->check; 2012ec21e2ecSJeff Kirsher } else 2013ec21e2ecSJeff Kirsher fcb->phcs = tcp_hdr(skb)->check; 2014ec21e2ecSJeff Kirsher 2015ec21e2ecSJeff Kirsher /* l3os is the distance between the start of the 2016ec21e2ecSJeff Kirsher * frame (skb->data) and the start of the IP hdr. 2017ec21e2ecSJeff Kirsher * l4os is the distance between the start of the 20180977f817SJan Ceuleers * l3 hdr and the l4 hdr 20190977f817SJan Ceuleers */ 20209c4886e5SManfred Rudigier fcb->l3os = (u16)(skb_network_offset(skb) - fcb_length); 2021ec21e2ecSJeff Kirsher fcb->l4os = skb_network_header_len(skb); 2022ec21e2ecSJeff Kirsher 2023ec21e2ecSJeff Kirsher fcb->flags = flags; 2024ec21e2ecSJeff Kirsher } 2025ec21e2ecSJeff Kirsher 2026ec21e2ecSJeff Kirsher void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb) 2027ec21e2ecSJeff Kirsher { 2028ec21e2ecSJeff Kirsher fcb->flags |= TXFCB_VLN; 2029ec21e2ecSJeff Kirsher fcb->vlctl = vlan_tx_tag_get(skb); 2030ec21e2ecSJeff Kirsher } 2031ec21e2ecSJeff Kirsher 2032ec21e2ecSJeff Kirsher static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride, 2033ec21e2ecSJeff Kirsher struct txbd8 *base, int ring_size) 2034ec21e2ecSJeff Kirsher { 2035ec21e2ecSJeff Kirsher struct txbd8 *new_bd = bdp + stride; 2036ec21e2ecSJeff Kirsher 2037ec21e2ecSJeff Kirsher return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd; 2038ec21e2ecSJeff Kirsher } 2039ec21e2ecSJeff Kirsher 2040ec21e2ecSJeff Kirsher static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base, 2041ec21e2ecSJeff Kirsher int ring_size) 2042ec21e2ecSJeff Kirsher { 2043ec21e2ecSJeff Kirsher return skip_txbd(bdp, 1, base, ring_size); 2044ec21e2ecSJeff Kirsher } 2045ec21e2ecSJeff Kirsher 20460977f817SJan Ceuleers /* This is called by the kernel when a frame is ready for transmission. 20470977f817SJan Ceuleers * It is pointed to by the dev->hard_start_xmit function pointer 20480977f817SJan Ceuleers */ 2049ec21e2ecSJeff Kirsher static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) 2050ec21e2ecSJeff Kirsher { 2051ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2052ec21e2ecSJeff Kirsher struct gfar_priv_tx_q *tx_queue = NULL; 2053ec21e2ecSJeff Kirsher struct netdev_queue *txq; 2054ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 2055ec21e2ecSJeff Kirsher struct txfcb *fcb = NULL; 2056ec21e2ecSJeff Kirsher struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL; 2057ec21e2ecSJeff Kirsher u32 lstatus; 2058ec21e2ecSJeff Kirsher int i, rq = 0, do_tstamp = 0; 2059ec21e2ecSJeff Kirsher u32 bufaddr; 2060ec21e2ecSJeff Kirsher unsigned long flags; 20619c4886e5SManfred Rudigier unsigned int nr_frags, nr_txbds, length, fcb_length = GMAC_FCB_LEN; 2062ec21e2ecSJeff Kirsher 20630977f817SJan Ceuleers /* TOE=1 frames larger than 2500 bytes may see excess delays 2064ec21e2ecSJeff Kirsher * before start of transmission. 2065ec21e2ecSJeff Kirsher */ 2066ec21e2ecSJeff Kirsher if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_76) && 2067ec21e2ecSJeff Kirsher skb->ip_summed == CHECKSUM_PARTIAL && 2068ec21e2ecSJeff Kirsher skb->len > 2500)) { 2069ec21e2ecSJeff Kirsher int ret; 2070ec21e2ecSJeff Kirsher 2071ec21e2ecSJeff Kirsher ret = skb_checksum_help(skb); 2072ec21e2ecSJeff Kirsher if (ret) 2073ec21e2ecSJeff Kirsher return ret; 2074ec21e2ecSJeff Kirsher } 2075ec21e2ecSJeff Kirsher 2076ec21e2ecSJeff Kirsher rq = skb->queue_mapping; 2077ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[rq]; 2078ec21e2ecSJeff Kirsher txq = netdev_get_tx_queue(dev, rq); 2079ec21e2ecSJeff Kirsher base = tx_queue->tx_bd_base; 2080ec21e2ecSJeff Kirsher regs = tx_queue->grp->regs; 2081ec21e2ecSJeff Kirsher 2082ec21e2ecSJeff Kirsher /* check if time stamp should be generated */ 2083ec21e2ecSJeff Kirsher if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && 20849c4886e5SManfred Rudigier priv->hwts_tx_en)) { 2085ec21e2ecSJeff Kirsher do_tstamp = 1; 20869c4886e5SManfred Rudigier fcb_length = GMAC_FCB_LEN + GMAC_TXPAL_LEN; 20879c4886e5SManfred Rudigier } 2088ec21e2ecSJeff Kirsher 2089ec21e2ecSJeff Kirsher /* make space for additional header when fcb is needed */ 2090ec21e2ecSJeff Kirsher if (((skb->ip_summed == CHECKSUM_PARTIAL) || 2091ec21e2ecSJeff Kirsher vlan_tx_tag_present(skb) || 2092ec21e2ecSJeff Kirsher unlikely(do_tstamp)) && 20939c4886e5SManfred Rudigier (skb_headroom(skb) < fcb_length)) { 2094ec21e2ecSJeff Kirsher struct sk_buff *skb_new; 2095ec21e2ecSJeff Kirsher 20969c4886e5SManfred Rudigier skb_new = skb_realloc_headroom(skb, fcb_length); 2097ec21e2ecSJeff Kirsher if (!skb_new) { 2098ec21e2ecSJeff Kirsher dev->stats.tx_errors++; 2099ec21e2ecSJeff Kirsher kfree_skb(skb); 2100ec21e2ecSJeff Kirsher return NETDEV_TX_OK; 2101ec21e2ecSJeff Kirsher } 2102db83d136SManfred Rudigier 2103313b037cSEric Dumazet if (skb->sk) 2104313b037cSEric Dumazet skb_set_owner_w(skb_new, skb->sk); 2105313b037cSEric Dumazet consume_skb(skb); 2106ec21e2ecSJeff Kirsher skb = skb_new; 2107ec21e2ecSJeff Kirsher } 2108ec21e2ecSJeff Kirsher 2109ec21e2ecSJeff Kirsher /* total number of fragments in the SKB */ 2110ec21e2ecSJeff Kirsher nr_frags = skb_shinfo(skb)->nr_frags; 2111ec21e2ecSJeff Kirsher 2112ec21e2ecSJeff Kirsher /* calculate the required number of TxBDs for this skb */ 2113ec21e2ecSJeff Kirsher if (unlikely(do_tstamp)) 2114ec21e2ecSJeff Kirsher nr_txbds = nr_frags + 2; 2115ec21e2ecSJeff Kirsher else 2116ec21e2ecSJeff Kirsher nr_txbds = nr_frags + 1; 2117ec21e2ecSJeff Kirsher 2118ec21e2ecSJeff Kirsher /* check if there is space to queue this packet */ 2119ec21e2ecSJeff Kirsher if (nr_txbds > tx_queue->num_txbdfree) { 2120ec21e2ecSJeff Kirsher /* no space, stop the queue */ 2121ec21e2ecSJeff Kirsher netif_tx_stop_queue(txq); 2122ec21e2ecSJeff Kirsher dev->stats.tx_fifo_errors++; 2123ec21e2ecSJeff Kirsher return NETDEV_TX_BUSY; 2124ec21e2ecSJeff Kirsher } 2125ec21e2ecSJeff Kirsher 2126ec21e2ecSJeff Kirsher /* Update transmit stats */ 2127ec21e2ecSJeff Kirsher tx_queue->stats.tx_bytes += skb->len; 2128ec21e2ecSJeff Kirsher tx_queue->stats.tx_packets++; 2129ec21e2ecSJeff Kirsher 2130ec21e2ecSJeff Kirsher txbdp = txbdp_start = tx_queue->cur_tx; 2131ec21e2ecSJeff Kirsher lstatus = txbdp->lstatus; 2132ec21e2ecSJeff Kirsher 2133ec21e2ecSJeff Kirsher /* Time stamp insertion requires one additional TxBD */ 2134ec21e2ecSJeff Kirsher if (unlikely(do_tstamp)) 2135ec21e2ecSJeff Kirsher txbdp_tstamp = txbdp = next_txbd(txbdp, base, 2136ec21e2ecSJeff Kirsher tx_queue->tx_ring_size); 2137ec21e2ecSJeff Kirsher 2138ec21e2ecSJeff Kirsher if (nr_frags == 0) { 2139ec21e2ecSJeff Kirsher if (unlikely(do_tstamp)) 2140ec21e2ecSJeff Kirsher txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_LAST | 2141ec21e2ecSJeff Kirsher TXBD_INTERRUPT); 2142ec21e2ecSJeff Kirsher else 2143ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); 2144ec21e2ecSJeff Kirsher } else { 2145ec21e2ecSJeff Kirsher /* Place the fragment addresses and lengths into the TxBDs */ 2146ec21e2ecSJeff Kirsher for (i = 0; i < nr_frags; i++) { 2147ec21e2ecSJeff Kirsher /* Point at the next BD, wrapping as needed */ 2148ec21e2ecSJeff Kirsher txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size); 2149ec21e2ecSJeff Kirsher 2150ec21e2ecSJeff Kirsher length = skb_shinfo(skb)->frags[i].size; 2151ec21e2ecSJeff Kirsher 2152ec21e2ecSJeff Kirsher lstatus = txbdp->lstatus | length | 2153ec21e2ecSJeff Kirsher BD_LFLAG(TXBD_READY); 2154ec21e2ecSJeff Kirsher 2155ec21e2ecSJeff Kirsher /* Handle the last BD specially */ 2156ec21e2ecSJeff Kirsher if (i == nr_frags - 1) 2157ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); 2158ec21e2ecSJeff Kirsher 2159369ec162SClaudiu Manoil bufaddr = skb_frag_dma_map(priv->dev, 21602234a722SIan Campbell &skb_shinfo(skb)->frags[i], 21612234a722SIan Campbell 0, 2162ec21e2ecSJeff Kirsher length, 2163ec21e2ecSJeff Kirsher DMA_TO_DEVICE); 2164ec21e2ecSJeff Kirsher 2165ec21e2ecSJeff Kirsher /* set the TxBD length and buffer pointer */ 2166ec21e2ecSJeff Kirsher txbdp->bufPtr = bufaddr; 2167ec21e2ecSJeff Kirsher txbdp->lstatus = lstatus; 2168ec21e2ecSJeff Kirsher } 2169ec21e2ecSJeff Kirsher 2170ec21e2ecSJeff Kirsher lstatus = txbdp_start->lstatus; 2171ec21e2ecSJeff Kirsher } 2172ec21e2ecSJeff Kirsher 21739c4886e5SManfred Rudigier /* Add TxPAL between FCB and frame if required */ 21749c4886e5SManfred Rudigier if (unlikely(do_tstamp)) { 21759c4886e5SManfred Rudigier skb_push(skb, GMAC_TXPAL_LEN); 21769c4886e5SManfred Rudigier memset(skb->data, 0, GMAC_TXPAL_LEN); 21779c4886e5SManfred Rudigier } 21789c4886e5SManfred Rudigier 2179ec21e2ecSJeff Kirsher /* Set up checksumming */ 2180ec21e2ecSJeff Kirsher if (CHECKSUM_PARTIAL == skb->ip_summed) { 2181ec21e2ecSJeff Kirsher fcb = gfar_add_fcb(skb); 2182ec21e2ecSJeff Kirsher /* as specified by errata */ 2183bc4598bcSJan Ceuleers if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12) && 2184bc4598bcSJan Ceuleers ((unsigned long)fcb % 0x20) > 0x18)) { 2185ec21e2ecSJeff Kirsher __skb_pull(skb, GMAC_FCB_LEN); 2186ec21e2ecSJeff Kirsher skb_checksum_help(skb); 2187ec21e2ecSJeff Kirsher } else { 2188ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_TOE); 21899c4886e5SManfred Rudigier gfar_tx_checksum(skb, fcb, fcb_length); 2190ec21e2ecSJeff Kirsher } 2191ec21e2ecSJeff Kirsher } 2192ec21e2ecSJeff Kirsher 2193ec21e2ecSJeff Kirsher if (vlan_tx_tag_present(skb)) { 2194ec21e2ecSJeff Kirsher if (unlikely(NULL == fcb)) { 2195ec21e2ecSJeff Kirsher fcb = gfar_add_fcb(skb); 2196ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_TOE); 2197ec21e2ecSJeff Kirsher } 2198ec21e2ecSJeff Kirsher 2199ec21e2ecSJeff Kirsher gfar_tx_vlan(skb, fcb); 2200ec21e2ecSJeff Kirsher } 2201ec21e2ecSJeff Kirsher 2202ec21e2ecSJeff Kirsher /* Setup tx hardware time stamping if requested */ 2203ec21e2ecSJeff Kirsher if (unlikely(do_tstamp)) { 2204ec21e2ecSJeff Kirsher skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 2205ec21e2ecSJeff Kirsher if (fcb == NULL) 2206ec21e2ecSJeff Kirsher fcb = gfar_add_fcb(skb); 2207ec21e2ecSJeff Kirsher fcb->ptp = 1; 2208ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_TOE); 2209ec21e2ecSJeff Kirsher } 2210ec21e2ecSJeff Kirsher 2211369ec162SClaudiu Manoil txbdp_start->bufPtr = dma_map_single(priv->dev, skb->data, 2212ec21e2ecSJeff Kirsher skb_headlen(skb), DMA_TO_DEVICE); 2213ec21e2ecSJeff Kirsher 22140977f817SJan Ceuleers /* If time stamping is requested one additional TxBD must be set up. The 2215ec21e2ecSJeff Kirsher * first TxBD points to the FCB and must have a data length of 2216ec21e2ecSJeff Kirsher * GMAC_FCB_LEN. The second TxBD points to the actual frame data with 2217ec21e2ecSJeff Kirsher * the full frame length. 2218ec21e2ecSJeff Kirsher */ 2219ec21e2ecSJeff Kirsher if (unlikely(do_tstamp)) { 22209c4886e5SManfred Rudigier txbdp_tstamp->bufPtr = txbdp_start->bufPtr + fcb_length; 2221ec21e2ecSJeff Kirsher txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_READY) | 22229c4886e5SManfred Rudigier (skb_headlen(skb) - fcb_length); 2223ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN; 2224ec21e2ecSJeff Kirsher } else { 2225ec21e2ecSJeff Kirsher lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb); 2226ec21e2ecSJeff Kirsher } 2227ec21e2ecSJeff Kirsher 2228d8a0f1b0SPaul Gortmaker netdev_tx_sent_queue(txq, skb->len); 2229d8a0f1b0SPaul Gortmaker 22300977f817SJan Ceuleers /* We can work in parallel with gfar_clean_tx_ring(), except 2231ec21e2ecSJeff Kirsher * when modifying num_txbdfree. Note that we didn't grab the lock 2232ec21e2ecSJeff Kirsher * when we were reading the num_txbdfree and checking for available 2233ec21e2ecSJeff Kirsher * space, that's because outside of this function it can only grow, 2234ec21e2ecSJeff Kirsher * and once we've got needed space, it cannot suddenly disappear. 2235ec21e2ecSJeff Kirsher * 2236ec21e2ecSJeff Kirsher * The lock also protects us from gfar_error(), which can modify 2237ec21e2ecSJeff Kirsher * regs->tstat and thus retrigger the transfers, which is why we 2238ec21e2ecSJeff Kirsher * also must grab the lock before setting ready bit for the first 2239ec21e2ecSJeff Kirsher * to be transmitted BD. 2240ec21e2ecSJeff Kirsher */ 2241ec21e2ecSJeff Kirsher spin_lock_irqsave(&tx_queue->txlock, flags); 2242ec21e2ecSJeff Kirsher 22430977f817SJan Ceuleers /* The powerpc-specific eieio() is used, as wmb() has too strong 2244ec21e2ecSJeff Kirsher * semantics (it requires synchronization between cacheable and 2245ec21e2ecSJeff Kirsher * uncacheable mappings, which eieio doesn't provide and which we 2246ec21e2ecSJeff Kirsher * don't need), thus requiring a more expensive sync instruction. At 2247ec21e2ecSJeff Kirsher * some point, the set of architecture-independent barrier functions 2248ec21e2ecSJeff Kirsher * should be expanded to include weaker barriers. 2249ec21e2ecSJeff Kirsher */ 2250ec21e2ecSJeff Kirsher eieio(); 2251ec21e2ecSJeff Kirsher 2252ec21e2ecSJeff Kirsher txbdp_start->lstatus = lstatus; 2253ec21e2ecSJeff Kirsher 2254ec21e2ecSJeff Kirsher eieio(); /* force lstatus write before tx_skbuff */ 2255ec21e2ecSJeff Kirsher 2256ec21e2ecSJeff Kirsher tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb; 2257ec21e2ecSJeff Kirsher 2258ec21e2ecSJeff Kirsher /* Update the current skb pointer to the next entry we will use 22590977f817SJan Ceuleers * (wrapping if necessary) 22600977f817SJan Ceuleers */ 2261ec21e2ecSJeff Kirsher tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) & 2262ec21e2ecSJeff Kirsher TX_RING_MOD_MASK(tx_queue->tx_ring_size); 2263ec21e2ecSJeff Kirsher 2264ec21e2ecSJeff Kirsher tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size); 2265ec21e2ecSJeff Kirsher 2266ec21e2ecSJeff Kirsher /* reduce TxBD free count */ 2267ec21e2ecSJeff Kirsher tx_queue->num_txbdfree -= (nr_txbds); 2268ec21e2ecSJeff Kirsher 2269ec21e2ecSJeff Kirsher /* If the next BD still needs to be cleaned up, then the bds 22700977f817SJan Ceuleers * are full. We need to tell the kernel to stop sending us stuff. 22710977f817SJan Ceuleers */ 2272ec21e2ecSJeff Kirsher if (!tx_queue->num_txbdfree) { 2273ec21e2ecSJeff Kirsher netif_tx_stop_queue(txq); 2274ec21e2ecSJeff Kirsher 2275ec21e2ecSJeff Kirsher dev->stats.tx_fifo_errors++; 2276ec21e2ecSJeff Kirsher } 2277ec21e2ecSJeff Kirsher 2278ec21e2ecSJeff Kirsher /* Tell the DMA to go go go */ 2279ec21e2ecSJeff Kirsher gfar_write(®s->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex); 2280ec21e2ecSJeff Kirsher 2281ec21e2ecSJeff Kirsher /* Unlock priv */ 2282ec21e2ecSJeff Kirsher spin_unlock_irqrestore(&tx_queue->txlock, flags); 2283ec21e2ecSJeff Kirsher 2284ec21e2ecSJeff Kirsher return NETDEV_TX_OK; 2285ec21e2ecSJeff Kirsher } 2286ec21e2ecSJeff Kirsher 2287ec21e2ecSJeff Kirsher /* Stops the kernel queue, and halts the controller */ 2288ec21e2ecSJeff Kirsher static int gfar_close(struct net_device *dev) 2289ec21e2ecSJeff Kirsher { 2290ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2291ec21e2ecSJeff Kirsher 2292ec21e2ecSJeff Kirsher disable_napi(priv); 2293ec21e2ecSJeff Kirsher 2294ec21e2ecSJeff Kirsher cancel_work_sync(&priv->reset_task); 2295ec21e2ecSJeff Kirsher stop_gfar(dev); 2296ec21e2ecSJeff Kirsher 2297ec21e2ecSJeff Kirsher /* Disconnect from the PHY */ 2298ec21e2ecSJeff Kirsher phy_disconnect(priv->phydev); 2299ec21e2ecSJeff Kirsher priv->phydev = NULL; 2300ec21e2ecSJeff Kirsher 2301ec21e2ecSJeff Kirsher netif_tx_stop_all_queues(dev); 2302ec21e2ecSJeff Kirsher 2303ec21e2ecSJeff Kirsher return 0; 2304ec21e2ecSJeff Kirsher } 2305ec21e2ecSJeff Kirsher 2306ec21e2ecSJeff Kirsher /* Changes the mac address if the controller is not running. */ 2307ec21e2ecSJeff Kirsher static int gfar_set_mac_address(struct net_device *dev) 2308ec21e2ecSJeff Kirsher { 2309ec21e2ecSJeff Kirsher gfar_set_mac_for_addr(dev, 0, dev->dev_addr); 2310ec21e2ecSJeff Kirsher 2311ec21e2ecSJeff Kirsher return 0; 2312ec21e2ecSJeff Kirsher } 2313ec21e2ecSJeff Kirsher 2314ec21e2ecSJeff Kirsher /* Check if rx parser should be activated */ 2315ec21e2ecSJeff Kirsher void gfar_check_rx_parser_mode(struct gfar_private *priv) 2316ec21e2ecSJeff Kirsher { 2317ec21e2ecSJeff Kirsher struct gfar __iomem *regs; 2318ec21e2ecSJeff Kirsher u32 tempval; 2319ec21e2ecSJeff Kirsher 2320ec21e2ecSJeff Kirsher regs = priv->gfargrp[0].regs; 2321ec21e2ecSJeff Kirsher 2322ec21e2ecSJeff Kirsher tempval = gfar_read(®s->rctrl); 2323ec21e2ecSJeff Kirsher /* If parse is no longer required, then disable parser */ 2324ba779711SClaudiu Manoil if (tempval & RCTRL_REQ_PARSER) { 2325ec21e2ecSJeff Kirsher tempval |= RCTRL_PRSDEP_INIT; 2326ba779711SClaudiu Manoil priv->uses_rxfcb = 1; 2327ba779711SClaudiu Manoil } else { 2328ec21e2ecSJeff Kirsher tempval &= ~RCTRL_PRSDEP_INIT; 2329ba779711SClaudiu Manoil priv->uses_rxfcb = 0; 2330ba779711SClaudiu Manoil } 2331ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, tempval); 2332ec21e2ecSJeff Kirsher } 2333ec21e2ecSJeff Kirsher 2334ec21e2ecSJeff Kirsher /* Enables and disables VLAN insertion/extraction */ 2335c8f44affSMichał Mirosław void gfar_vlan_mode(struct net_device *dev, netdev_features_t features) 2336ec21e2ecSJeff Kirsher { 2337ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2338ec21e2ecSJeff Kirsher struct gfar __iomem *regs = NULL; 2339ec21e2ecSJeff Kirsher unsigned long flags; 2340ec21e2ecSJeff Kirsher u32 tempval; 2341ec21e2ecSJeff Kirsher 2342ec21e2ecSJeff Kirsher regs = priv->gfargrp[0].regs; 2343ec21e2ecSJeff Kirsher local_irq_save(flags); 2344ec21e2ecSJeff Kirsher lock_rx_qs(priv); 2345ec21e2ecSJeff Kirsher 2346ec21e2ecSJeff Kirsher if (features & NETIF_F_HW_VLAN_TX) { 2347ec21e2ecSJeff Kirsher /* Enable VLAN tag insertion */ 2348ec21e2ecSJeff Kirsher tempval = gfar_read(®s->tctrl); 2349ec21e2ecSJeff Kirsher tempval |= TCTRL_VLINS; 2350ec21e2ecSJeff Kirsher gfar_write(®s->tctrl, tempval); 2351ec21e2ecSJeff Kirsher } else { 2352ec21e2ecSJeff Kirsher /* Disable VLAN tag insertion */ 2353ec21e2ecSJeff Kirsher tempval = gfar_read(®s->tctrl); 2354ec21e2ecSJeff Kirsher tempval &= ~TCTRL_VLINS; 2355ec21e2ecSJeff Kirsher gfar_write(®s->tctrl, tempval); 2356ec21e2ecSJeff Kirsher } 2357ec21e2ecSJeff Kirsher 2358ec21e2ecSJeff Kirsher if (features & NETIF_F_HW_VLAN_RX) { 2359ec21e2ecSJeff Kirsher /* Enable VLAN tag extraction */ 2360ec21e2ecSJeff Kirsher tempval = gfar_read(®s->rctrl); 2361ec21e2ecSJeff Kirsher tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT); 2362ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, tempval); 2363ba779711SClaudiu Manoil priv->uses_rxfcb = 1; 2364ec21e2ecSJeff Kirsher } else { 2365ec21e2ecSJeff Kirsher /* Disable VLAN tag extraction */ 2366ec21e2ecSJeff Kirsher tempval = gfar_read(®s->rctrl); 2367ec21e2ecSJeff Kirsher tempval &= ~RCTRL_VLEX; 2368ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, tempval); 2369ec21e2ecSJeff Kirsher 2370ec21e2ecSJeff Kirsher gfar_check_rx_parser_mode(priv); 2371ec21e2ecSJeff Kirsher } 2372ec21e2ecSJeff Kirsher 2373ec21e2ecSJeff Kirsher gfar_change_mtu(dev, dev->mtu); 2374ec21e2ecSJeff Kirsher 2375ec21e2ecSJeff Kirsher unlock_rx_qs(priv); 2376ec21e2ecSJeff Kirsher local_irq_restore(flags); 2377ec21e2ecSJeff Kirsher } 2378ec21e2ecSJeff Kirsher 2379ec21e2ecSJeff Kirsher static int gfar_change_mtu(struct net_device *dev, int new_mtu) 2380ec21e2ecSJeff Kirsher { 2381ec21e2ecSJeff Kirsher int tempsize, tempval; 2382ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2383ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 2384ec21e2ecSJeff Kirsher int oldsize = priv->rx_buffer_size; 2385ec21e2ecSJeff Kirsher int frame_size = new_mtu + ETH_HLEN; 2386ec21e2ecSJeff Kirsher 2387ec21e2ecSJeff Kirsher if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) { 2388ec21e2ecSJeff Kirsher netif_err(priv, drv, dev, "Invalid MTU setting\n"); 2389ec21e2ecSJeff Kirsher return -EINVAL; 2390ec21e2ecSJeff Kirsher } 2391ec21e2ecSJeff Kirsher 2392ba779711SClaudiu Manoil if (priv->uses_rxfcb) 2393ec21e2ecSJeff Kirsher frame_size += GMAC_FCB_LEN; 2394ec21e2ecSJeff Kirsher 2395ec21e2ecSJeff Kirsher frame_size += priv->padding; 2396ec21e2ecSJeff Kirsher 2397bc4598bcSJan Ceuleers tempsize = (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) + 2398ec21e2ecSJeff Kirsher INCREMENTAL_BUFFER_SIZE; 2399ec21e2ecSJeff Kirsher 2400ec21e2ecSJeff Kirsher /* Only stop and start the controller if it isn't already 24010977f817SJan Ceuleers * stopped, and we changed something 24020977f817SJan Ceuleers */ 2403ec21e2ecSJeff Kirsher if ((oldsize != tempsize) && (dev->flags & IFF_UP)) 2404ec21e2ecSJeff Kirsher stop_gfar(dev); 2405ec21e2ecSJeff Kirsher 2406ec21e2ecSJeff Kirsher priv->rx_buffer_size = tempsize; 2407ec21e2ecSJeff Kirsher 2408ec21e2ecSJeff Kirsher dev->mtu = new_mtu; 2409ec21e2ecSJeff Kirsher 2410ec21e2ecSJeff Kirsher gfar_write(®s->mrblr, priv->rx_buffer_size); 2411ec21e2ecSJeff Kirsher gfar_write(®s->maxfrm, priv->rx_buffer_size); 2412ec21e2ecSJeff Kirsher 2413ec21e2ecSJeff Kirsher /* If the mtu is larger than the max size for standard 2414ec21e2ecSJeff Kirsher * ethernet frames (ie, a jumbo frame), then set maccfg2 24150977f817SJan Ceuleers * to allow huge frames, and to check the length 24160977f817SJan Ceuleers */ 2417ec21e2ecSJeff Kirsher tempval = gfar_read(®s->maccfg2); 2418ec21e2ecSJeff Kirsher 2419ec21e2ecSJeff Kirsher if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE || 2420ec21e2ecSJeff Kirsher gfar_has_errata(priv, GFAR_ERRATA_74)) 2421ec21e2ecSJeff Kirsher tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK); 2422ec21e2ecSJeff Kirsher else 2423ec21e2ecSJeff Kirsher tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK); 2424ec21e2ecSJeff Kirsher 2425ec21e2ecSJeff Kirsher gfar_write(®s->maccfg2, tempval); 2426ec21e2ecSJeff Kirsher 2427ec21e2ecSJeff Kirsher if ((oldsize != tempsize) && (dev->flags & IFF_UP)) 2428ec21e2ecSJeff Kirsher startup_gfar(dev); 2429ec21e2ecSJeff Kirsher 2430ec21e2ecSJeff Kirsher return 0; 2431ec21e2ecSJeff Kirsher } 2432ec21e2ecSJeff Kirsher 2433ec21e2ecSJeff Kirsher /* gfar_reset_task gets scheduled when a packet has not been 2434ec21e2ecSJeff Kirsher * transmitted after a set amount of time. 2435ec21e2ecSJeff Kirsher * For now, assume that clearing out all the structures, and 2436ec21e2ecSJeff Kirsher * starting over will fix the problem. 2437ec21e2ecSJeff Kirsher */ 2438ec21e2ecSJeff Kirsher static void gfar_reset_task(struct work_struct *work) 2439ec21e2ecSJeff Kirsher { 2440ec21e2ecSJeff Kirsher struct gfar_private *priv = container_of(work, struct gfar_private, 2441ec21e2ecSJeff Kirsher reset_task); 2442ec21e2ecSJeff Kirsher struct net_device *dev = priv->ndev; 2443ec21e2ecSJeff Kirsher 2444ec21e2ecSJeff Kirsher if (dev->flags & IFF_UP) { 2445ec21e2ecSJeff Kirsher netif_tx_stop_all_queues(dev); 2446ec21e2ecSJeff Kirsher stop_gfar(dev); 2447ec21e2ecSJeff Kirsher startup_gfar(dev); 2448ec21e2ecSJeff Kirsher netif_tx_start_all_queues(dev); 2449ec21e2ecSJeff Kirsher } 2450ec21e2ecSJeff Kirsher 2451ec21e2ecSJeff Kirsher netif_tx_schedule_all(dev); 2452ec21e2ecSJeff Kirsher } 2453ec21e2ecSJeff Kirsher 2454ec21e2ecSJeff Kirsher static void gfar_timeout(struct net_device *dev) 2455ec21e2ecSJeff Kirsher { 2456ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2457ec21e2ecSJeff Kirsher 2458ec21e2ecSJeff Kirsher dev->stats.tx_errors++; 2459ec21e2ecSJeff Kirsher schedule_work(&priv->reset_task); 2460ec21e2ecSJeff Kirsher } 2461ec21e2ecSJeff Kirsher 2462ec21e2ecSJeff Kirsher static void gfar_align_skb(struct sk_buff *skb) 2463ec21e2ecSJeff Kirsher { 2464ec21e2ecSJeff Kirsher /* We need the data buffer to be aligned properly. We will reserve 2465ec21e2ecSJeff Kirsher * as many bytes as needed to align the data properly 2466ec21e2ecSJeff Kirsher */ 2467ec21e2ecSJeff Kirsher skb_reserve(skb, RXBUF_ALIGNMENT - 2468ec21e2ecSJeff Kirsher (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1))); 2469ec21e2ecSJeff Kirsher } 2470ec21e2ecSJeff Kirsher 2471ec21e2ecSJeff Kirsher /* Interrupt Handler for Transmit complete */ 2472ec21e2ecSJeff Kirsher static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) 2473ec21e2ecSJeff Kirsher { 2474ec21e2ecSJeff Kirsher struct net_device *dev = tx_queue->dev; 2475d8a0f1b0SPaul Gortmaker struct netdev_queue *txq; 2476ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2477ec21e2ecSJeff Kirsher struct gfar_priv_rx_q *rx_queue = NULL; 2478ec21e2ecSJeff Kirsher struct txbd8 *bdp, *next = NULL; 2479ec21e2ecSJeff Kirsher struct txbd8 *lbdp = NULL; 2480ec21e2ecSJeff Kirsher struct txbd8 *base = tx_queue->tx_bd_base; 2481ec21e2ecSJeff Kirsher struct sk_buff *skb; 2482ec21e2ecSJeff Kirsher int skb_dirtytx; 2483ec21e2ecSJeff Kirsher int tx_ring_size = tx_queue->tx_ring_size; 2484ec21e2ecSJeff Kirsher int frags = 0, nr_txbds = 0; 2485ec21e2ecSJeff Kirsher int i; 2486ec21e2ecSJeff Kirsher int howmany = 0; 2487d8a0f1b0SPaul Gortmaker int tqi = tx_queue->qindex; 2488d8a0f1b0SPaul Gortmaker unsigned int bytes_sent = 0; 2489ec21e2ecSJeff Kirsher u32 lstatus; 2490ec21e2ecSJeff Kirsher size_t buflen; 2491ec21e2ecSJeff Kirsher 2492d8a0f1b0SPaul Gortmaker rx_queue = priv->rx_queue[tqi]; 2493d8a0f1b0SPaul Gortmaker txq = netdev_get_tx_queue(dev, tqi); 2494ec21e2ecSJeff Kirsher bdp = tx_queue->dirty_tx; 2495ec21e2ecSJeff Kirsher skb_dirtytx = tx_queue->skb_dirtytx; 2496ec21e2ecSJeff Kirsher 2497ec21e2ecSJeff Kirsher while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) { 2498ec21e2ecSJeff Kirsher unsigned long flags; 2499ec21e2ecSJeff Kirsher 2500ec21e2ecSJeff Kirsher frags = skb_shinfo(skb)->nr_frags; 2501ec21e2ecSJeff Kirsher 25020977f817SJan Ceuleers /* When time stamping, one additional TxBD must be freed. 2503ec21e2ecSJeff Kirsher * Also, we need to dma_unmap_single() the TxPAL. 2504ec21e2ecSJeff Kirsher */ 2505ec21e2ecSJeff Kirsher if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) 2506ec21e2ecSJeff Kirsher nr_txbds = frags + 2; 2507ec21e2ecSJeff Kirsher else 2508ec21e2ecSJeff Kirsher nr_txbds = frags + 1; 2509ec21e2ecSJeff Kirsher 2510ec21e2ecSJeff Kirsher lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size); 2511ec21e2ecSJeff Kirsher 2512ec21e2ecSJeff Kirsher lstatus = lbdp->lstatus; 2513ec21e2ecSJeff Kirsher 2514ec21e2ecSJeff Kirsher /* Only clean completed frames */ 2515ec21e2ecSJeff Kirsher if ((lstatus & BD_LFLAG(TXBD_READY)) && 2516ec21e2ecSJeff Kirsher (lstatus & BD_LENGTH_MASK)) 2517ec21e2ecSJeff Kirsher break; 2518ec21e2ecSJeff Kirsher 2519ec21e2ecSJeff Kirsher if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { 2520ec21e2ecSJeff Kirsher next = next_txbd(bdp, base, tx_ring_size); 25219c4886e5SManfred Rudigier buflen = next->length + GMAC_FCB_LEN + GMAC_TXPAL_LEN; 2522ec21e2ecSJeff Kirsher } else 2523ec21e2ecSJeff Kirsher buflen = bdp->length; 2524ec21e2ecSJeff Kirsher 2525369ec162SClaudiu Manoil dma_unmap_single(priv->dev, bdp->bufPtr, 2526ec21e2ecSJeff Kirsher buflen, DMA_TO_DEVICE); 2527ec21e2ecSJeff Kirsher 2528ec21e2ecSJeff Kirsher if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { 2529ec21e2ecSJeff Kirsher struct skb_shared_hwtstamps shhwtstamps; 2530ec21e2ecSJeff Kirsher u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7); 2531bc4598bcSJan Ceuleers 2532ec21e2ecSJeff Kirsher memset(&shhwtstamps, 0, sizeof(shhwtstamps)); 2533ec21e2ecSJeff Kirsher shhwtstamps.hwtstamp = ns_to_ktime(*ns); 25349c4886e5SManfred Rudigier skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN); 2535ec21e2ecSJeff Kirsher skb_tstamp_tx(skb, &shhwtstamps); 2536ec21e2ecSJeff Kirsher bdp->lstatus &= BD_LFLAG(TXBD_WRAP); 2537ec21e2ecSJeff Kirsher bdp = next; 2538ec21e2ecSJeff Kirsher } 2539ec21e2ecSJeff Kirsher 2540ec21e2ecSJeff Kirsher bdp->lstatus &= BD_LFLAG(TXBD_WRAP); 2541ec21e2ecSJeff Kirsher bdp = next_txbd(bdp, base, tx_ring_size); 2542ec21e2ecSJeff Kirsher 2543ec21e2ecSJeff Kirsher for (i = 0; i < frags; i++) { 2544369ec162SClaudiu Manoil dma_unmap_page(priv->dev, bdp->bufPtr, 2545bc4598bcSJan Ceuleers bdp->length, DMA_TO_DEVICE); 2546ec21e2ecSJeff Kirsher bdp->lstatus &= BD_LFLAG(TXBD_WRAP); 2547ec21e2ecSJeff Kirsher bdp = next_txbd(bdp, base, tx_ring_size); 2548ec21e2ecSJeff Kirsher } 2549ec21e2ecSJeff Kirsher 2550d8a0f1b0SPaul Gortmaker bytes_sent += skb->len; 2551d8a0f1b0SPaul Gortmaker 2552ec21e2ecSJeff Kirsher dev_kfree_skb_any(skb); 2553ec21e2ecSJeff Kirsher 2554ec21e2ecSJeff Kirsher tx_queue->tx_skbuff[skb_dirtytx] = NULL; 2555ec21e2ecSJeff Kirsher 2556ec21e2ecSJeff Kirsher skb_dirtytx = (skb_dirtytx + 1) & 2557ec21e2ecSJeff Kirsher TX_RING_MOD_MASK(tx_ring_size); 2558ec21e2ecSJeff Kirsher 2559ec21e2ecSJeff Kirsher howmany++; 2560ec21e2ecSJeff Kirsher spin_lock_irqsave(&tx_queue->txlock, flags); 2561ec21e2ecSJeff Kirsher tx_queue->num_txbdfree += nr_txbds; 2562ec21e2ecSJeff Kirsher spin_unlock_irqrestore(&tx_queue->txlock, flags); 2563ec21e2ecSJeff Kirsher } 2564ec21e2ecSJeff Kirsher 2565ec21e2ecSJeff Kirsher /* If we freed a buffer, we can restart transmission, if necessary */ 25665407b14cSPaul Gortmaker if (netif_tx_queue_stopped(txq) && tx_queue->num_txbdfree) 2567d8a0f1b0SPaul Gortmaker netif_wake_subqueue(dev, tqi); 2568ec21e2ecSJeff Kirsher 2569ec21e2ecSJeff Kirsher /* Update dirty indicators */ 2570ec21e2ecSJeff Kirsher tx_queue->skb_dirtytx = skb_dirtytx; 2571ec21e2ecSJeff Kirsher tx_queue->dirty_tx = bdp; 2572ec21e2ecSJeff Kirsher 2573d8a0f1b0SPaul Gortmaker netdev_tx_completed_queue(txq, howmany, bytes_sent); 2574d8a0f1b0SPaul Gortmaker 2575ec21e2ecSJeff Kirsher return howmany; 2576ec21e2ecSJeff Kirsher } 2577ec21e2ecSJeff Kirsher 2578ec21e2ecSJeff Kirsher static void gfar_schedule_cleanup(struct gfar_priv_grp *gfargrp) 2579ec21e2ecSJeff Kirsher { 2580ec21e2ecSJeff Kirsher unsigned long flags; 2581ec21e2ecSJeff Kirsher 2582ec21e2ecSJeff Kirsher spin_lock_irqsave(&gfargrp->grplock, flags); 2583ec21e2ecSJeff Kirsher if (napi_schedule_prep(&gfargrp->napi)) { 2584ec21e2ecSJeff Kirsher gfar_write(&gfargrp->regs->imask, IMASK_RTX_DISABLED); 2585ec21e2ecSJeff Kirsher __napi_schedule(&gfargrp->napi); 2586ec21e2ecSJeff Kirsher } else { 25870977f817SJan Ceuleers /* Clear IEVENT, so interrupts aren't called again 2588ec21e2ecSJeff Kirsher * because of the packets that have already arrived. 2589ec21e2ecSJeff Kirsher */ 2590ec21e2ecSJeff Kirsher gfar_write(&gfargrp->regs->ievent, IEVENT_RTX_MASK); 2591ec21e2ecSJeff Kirsher } 2592ec21e2ecSJeff Kirsher spin_unlock_irqrestore(&gfargrp->grplock, flags); 2593ec21e2ecSJeff Kirsher 2594ec21e2ecSJeff Kirsher } 2595ec21e2ecSJeff Kirsher 2596ec21e2ecSJeff Kirsher /* Interrupt Handler for Transmit complete */ 2597ec21e2ecSJeff Kirsher static irqreturn_t gfar_transmit(int irq, void *grp_id) 2598ec21e2ecSJeff Kirsher { 2599ec21e2ecSJeff Kirsher gfar_schedule_cleanup((struct gfar_priv_grp *)grp_id); 2600ec21e2ecSJeff Kirsher return IRQ_HANDLED; 2601ec21e2ecSJeff Kirsher } 2602ec21e2ecSJeff Kirsher 2603ec21e2ecSJeff Kirsher static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, 2604ec21e2ecSJeff Kirsher struct sk_buff *skb) 2605ec21e2ecSJeff Kirsher { 2606ec21e2ecSJeff Kirsher struct net_device *dev = rx_queue->dev; 2607ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2608ec21e2ecSJeff Kirsher dma_addr_t buf; 2609ec21e2ecSJeff Kirsher 2610369ec162SClaudiu Manoil buf = dma_map_single(priv->dev, skb->data, 2611ec21e2ecSJeff Kirsher priv->rx_buffer_size, DMA_FROM_DEVICE); 2612ec21e2ecSJeff Kirsher gfar_init_rxbdp(rx_queue, bdp, buf); 2613ec21e2ecSJeff Kirsher } 2614ec21e2ecSJeff Kirsher 2615ec21e2ecSJeff Kirsher static struct sk_buff *gfar_alloc_skb(struct net_device *dev) 2616ec21e2ecSJeff Kirsher { 2617ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2618acb600deSEric Dumazet struct sk_buff *skb; 2619ec21e2ecSJeff Kirsher 2620ec21e2ecSJeff Kirsher skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT); 2621ec21e2ecSJeff Kirsher if (!skb) 2622ec21e2ecSJeff Kirsher return NULL; 2623ec21e2ecSJeff Kirsher 2624ec21e2ecSJeff Kirsher gfar_align_skb(skb); 2625ec21e2ecSJeff Kirsher 2626ec21e2ecSJeff Kirsher return skb; 2627ec21e2ecSJeff Kirsher } 2628ec21e2ecSJeff Kirsher 2629ec21e2ecSJeff Kirsher struct sk_buff *gfar_new_skb(struct net_device *dev) 2630ec21e2ecSJeff Kirsher { 2631acb600deSEric Dumazet return gfar_alloc_skb(dev); 2632ec21e2ecSJeff Kirsher } 2633ec21e2ecSJeff Kirsher 2634ec21e2ecSJeff Kirsher static inline void count_errors(unsigned short status, struct net_device *dev) 2635ec21e2ecSJeff Kirsher { 2636ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2637ec21e2ecSJeff Kirsher struct net_device_stats *stats = &dev->stats; 2638ec21e2ecSJeff Kirsher struct gfar_extra_stats *estats = &priv->extra_stats; 2639ec21e2ecSJeff Kirsher 26400977f817SJan Ceuleers /* If the packet was truncated, none of the other errors matter */ 2641ec21e2ecSJeff Kirsher if (status & RXBD_TRUNCATED) { 2642ec21e2ecSJeff Kirsher stats->rx_length_errors++; 2643ec21e2ecSJeff Kirsher 2644212079dfSPaul Gortmaker atomic64_inc(&estats->rx_trunc); 2645ec21e2ecSJeff Kirsher 2646ec21e2ecSJeff Kirsher return; 2647ec21e2ecSJeff Kirsher } 2648ec21e2ecSJeff Kirsher /* Count the errors, if there were any */ 2649ec21e2ecSJeff Kirsher if (status & (RXBD_LARGE | RXBD_SHORT)) { 2650ec21e2ecSJeff Kirsher stats->rx_length_errors++; 2651ec21e2ecSJeff Kirsher 2652ec21e2ecSJeff Kirsher if (status & RXBD_LARGE) 2653212079dfSPaul Gortmaker atomic64_inc(&estats->rx_large); 2654ec21e2ecSJeff Kirsher else 2655212079dfSPaul Gortmaker atomic64_inc(&estats->rx_short); 2656ec21e2ecSJeff Kirsher } 2657ec21e2ecSJeff Kirsher if (status & RXBD_NONOCTET) { 2658ec21e2ecSJeff Kirsher stats->rx_frame_errors++; 2659212079dfSPaul Gortmaker atomic64_inc(&estats->rx_nonoctet); 2660ec21e2ecSJeff Kirsher } 2661ec21e2ecSJeff Kirsher if (status & RXBD_CRCERR) { 2662212079dfSPaul Gortmaker atomic64_inc(&estats->rx_crcerr); 2663ec21e2ecSJeff Kirsher stats->rx_crc_errors++; 2664ec21e2ecSJeff Kirsher } 2665ec21e2ecSJeff Kirsher if (status & RXBD_OVERRUN) { 2666212079dfSPaul Gortmaker atomic64_inc(&estats->rx_overrun); 2667ec21e2ecSJeff Kirsher stats->rx_crc_errors++; 2668ec21e2ecSJeff Kirsher } 2669ec21e2ecSJeff Kirsher } 2670ec21e2ecSJeff Kirsher 2671ec21e2ecSJeff Kirsher irqreturn_t gfar_receive(int irq, void *grp_id) 2672ec21e2ecSJeff Kirsher { 2673ec21e2ecSJeff Kirsher gfar_schedule_cleanup((struct gfar_priv_grp *)grp_id); 2674ec21e2ecSJeff Kirsher return IRQ_HANDLED; 2675ec21e2ecSJeff Kirsher } 2676ec21e2ecSJeff Kirsher 2677ec21e2ecSJeff Kirsher static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb) 2678ec21e2ecSJeff Kirsher { 2679ec21e2ecSJeff Kirsher /* If valid headers were found, and valid sums 2680ec21e2ecSJeff Kirsher * were verified, then we tell the kernel that no 26810977f817SJan Ceuleers * checksumming is necessary. Otherwise, it is [FIXME] 26820977f817SJan Ceuleers */ 2683ec21e2ecSJeff Kirsher if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU)) 2684ec21e2ecSJeff Kirsher skb->ip_summed = CHECKSUM_UNNECESSARY; 2685ec21e2ecSJeff Kirsher else 2686ec21e2ecSJeff Kirsher skb_checksum_none_assert(skb); 2687ec21e2ecSJeff Kirsher } 2688ec21e2ecSJeff Kirsher 2689ec21e2ecSJeff Kirsher 26900977f817SJan Ceuleers /* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */ 269161db26c6SClaudiu Manoil static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb, 2692cd754a57SWu Jiajun-B06378 int amount_pull, struct napi_struct *napi) 2693ec21e2ecSJeff Kirsher { 2694ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2695ec21e2ecSJeff Kirsher struct rxfcb *fcb = NULL; 2696ec21e2ecSJeff Kirsher 2697cd754a57SWu Jiajun-B06378 gro_result_t ret; 2698ec21e2ecSJeff Kirsher 2699ec21e2ecSJeff Kirsher /* fcb is at the beginning if exists */ 2700ec21e2ecSJeff Kirsher fcb = (struct rxfcb *)skb->data; 2701ec21e2ecSJeff Kirsher 27020977f817SJan Ceuleers /* Remove the FCB from the skb 27030977f817SJan Ceuleers * Remove the padded bytes, if there are any 27040977f817SJan Ceuleers */ 2705ec21e2ecSJeff Kirsher if (amount_pull) { 2706ec21e2ecSJeff Kirsher skb_record_rx_queue(skb, fcb->rq); 2707ec21e2ecSJeff Kirsher skb_pull(skb, amount_pull); 2708ec21e2ecSJeff Kirsher } 2709ec21e2ecSJeff Kirsher 2710ec21e2ecSJeff Kirsher /* Get receive timestamp from the skb */ 2711ec21e2ecSJeff Kirsher if (priv->hwts_rx_en) { 2712ec21e2ecSJeff Kirsher struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); 2713ec21e2ecSJeff Kirsher u64 *ns = (u64 *) skb->data; 2714bc4598bcSJan Ceuleers 2715ec21e2ecSJeff Kirsher memset(shhwtstamps, 0, sizeof(*shhwtstamps)); 2716ec21e2ecSJeff Kirsher shhwtstamps->hwtstamp = ns_to_ktime(*ns); 2717ec21e2ecSJeff Kirsher } 2718ec21e2ecSJeff Kirsher 2719ec21e2ecSJeff Kirsher if (priv->padding) 2720ec21e2ecSJeff Kirsher skb_pull(skb, priv->padding); 2721ec21e2ecSJeff Kirsher 2722ec21e2ecSJeff Kirsher if (dev->features & NETIF_F_RXCSUM) 2723ec21e2ecSJeff Kirsher gfar_rx_checksum(skb, fcb); 2724ec21e2ecSJeff Kirsher 2725ec21e2ecSJeff Kirsher /* Tell the skb what kind of packet this is */ 2726ec21e2ecSJeff Kirsher skb->protocol = eth_type_trans(skb, dev); 2727ec21e2ecSJeff Kirsher 27280977f817SJan Ceuleers /* There's need to check for NETIF_F_HW_VLAN_RX here. 2729823dcd25SDavid S. Miller * Even if vlan rx accel is disabled, on some chips 2730823dcd25SDavid S. Miller * RXFCB_VLN is pseudo randomly set. 2731823dcd25SDavid S. Miller */ 2732823dcd25SDavid S. Miller if (dev->features & NETIF_F_HW_VLAN_RX && 2733823dcd25SDavid S. Miller fcb->flags & RXFCB_VLN) 2734ec21e2ecSJeff Kirsher __vlan_hwaccel_put_tag(skb, fcb->vlctl); 2735ec21e2ecSJeff Kirsher 2736ec21e2ecSJeff Kirsher /* Send the packet up the stack */ 2737cd754a57SWu Jiajun-B06378 ret = napi_gro_receive(napi, skb); 2738ec21e2ecSJeff Kirsher 2739bd9e89f2SClaudiu Manoil if (unlikely(GRO_DROP == ret)) 2740212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.kernel_dropped); 2741ec21e2ecSJeff Kirsher } 2742ec21e2ecSJeff Kirsher 2743ec21e2ecSJeff Kirsher /* gfar_clean_rx_ring() -- Processes each frame in the rx ring 2744ec21e2ecSJeff Kirsher * until the budget/quota has been reached. Returns the number 2745ec21e2ecSJeff Kirsher * of frames handled 2746ec21e2ecSJeff Kirsher */ 2747ec21e2ecSJeff Kirsher int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit) 2748ec21e2ecSJeff Kirsher { 2749ec21e2ecSJeff Kirsher struct net_device *dev = rx_queue->dev; 2750ec21e2ecSJeff Kirsher struct rxbd8 *bdp, *base; 2751ec21e2ecSJeff Kirsher struct sk_buff *skb; 2752ec21e2ecSJeff Kirsher int pkt_len; 2753ec21e2ecSJeff Kirsher int amount_pull; 2754ec21e2ecSJeff Kirsher int howmany = 0; 2755ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2756ec21e2ecSJeff Kirsher 2757ec21e2ecSJeff Kirsher /* Get the first full descriptor */ 2758ec21e2ecSJeff Kirsher bdp = rx_queue->cur_rx; 2759ec21e2ecSJeff Kirsher base = rx_queue->rx_bd_base; 2760ec21e2ecSJeff Kirsher 2761ba779711SClaudiu Manoil amount_pull = priv->uses_rxfcb ? GMAC_FCB_LEN : 0; 2762ec21e2ecSJeff Kirsher 2763ec21e2ecSJeff Kirsher while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) { 2764ec21e2ecSJeff Kirsher struct sk_buff *newskb; 2765bc4598bcSJan Ceuleers 2766ec21e2ecSJeff Kirsher rmb(); 2767ec21e2ecSJeff Kirsher 2768ec21e2ecSJeff Kirsher /* Add another skb for the future */ 2769ec21e2ecSJeff Kirsher newskb = gfar_new_skb(dev); 2770ec21e2ecSJeff Kirsher 2771ec21e2ecSJeff Kirsher skb = rx_queue->rx_skbuff[rx_queue->skb_currx]; 2772ec21e2ecSJeff Kirsher 2773369ec162SClaudiu Manoil dma_unmap_single(priv->dev, bdp->bufPtr, 2774ec21e2ecSJeff Kirsher priv->rx_buffer_size, DMA_FROM_DEVICE); 2775ec21e2ecSJeff Kirsher 2776ec21e2ecSJeff Kirsher if (unlikely(!(bdp->status & RXBD_ERR) && 2777ec21e2ecSJeff Kirsher bdp->length > priv->rx_buffer_size)) 2778ec21e2ecSJeff Kirsher bdp->status = RXBD_LARGE; 2779ec21e2ecSJeff Kirsher 2780ec21e2ecSJeff Kirsher /* We drop the frame if we failed to allocate a new buffer */ 2781ec21e2ecSJeff Kirsher if (unlikely(!newskb || !(bdp->status & RXBD_LAST) || 2782ec21e2ecSJeff Kirsher bdp->status & RXBD_ERR)) { 2783ec21e2ecSJeff Kirsher count_errors(bdp->status, dev); 2784ec21e2ecSJeff Kirsher 2785ec21e2ecSJeff Kirsher if (unlikely(!newskb)) 2786ec21e2ecSJeff Kirsher newskb = skb; 2787ec21e2ecSJeff Kirsher else if (skb) 2788acb600deSEric Dumazet dev_kfree_skb(skb); 2789ec21e2ecSJeff Kirsher } else { 2790ec21e2ecSJeff Kirsher /* Increment the number of packets */ 2791ec21e2ecSJeff Kirsher rx_queue->stats.rx_packets++; 2792ec21e2ecSJeff Kirsher howmany++; 2793ec21e2ecSJeff Kirsher 2794ec21e2ecSJeff Kirsher if (likely(skb)) { 2795ec21e2ecSJeff Kirsher pkt_len = bdp->length - ETH_FCS_LEN; 2796ec21e2ecSJeff Kirsher /* Remove the FCS from the packet length */ 2797ec21e2ecSJeff Kirsher skb_put(skb, pkt_len); 2798ec21e2ecSJeff Kirsher rx_queue->stats.rx_bytes += pkt_len; 2799ec21e2ecSJeff Kirsher skb_record_rx_queue(skb, rx_queue->qindex); 2800cd754a57SWu Jiajun-B06378 gfar_process_frame(dev, skb, amount_pull, 2801cd754a57SWu Jiajun-B06378 &rx_queue->grp->napi); 2802ec21e2ecSJeff Kirsher 2803ec21e2ecSJeff Kirsher } else { 2804ec21e2ecSJeff Kirsher netif_warn(priv, rx_err, dev, "Missing skb!\n"); 2805ec21e2ecSJeff Kirsher rx_queue->stats.rx_dropped++; 2806212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.rx_skbmissing); 2807ec21e2ecSJeff Kirsher } 2808ec21e2ecSJeff Kirsher 2809ec21e2ecSJeff Kirsher } 2810ec21e2ecSJeff Kirsher 2811ec21e2ecSJeff Kirsher rx_queue->rx_skbuff[rx_queue->skb_currx] = newskb; 2812ec21e2ecSJeff Kirsher 2813ec21e2ecSJeff Kirsher /* Setup the new bdp */ 2814ec21e2ecSJeff Kirsher gfar_new_rxbdp(rx_queue, bdp, newskb); 2815ec21e2ecSJeff Kirsher 2816ec21e2ecSJeff Kirsher /* Update to the next pointer */ 2817ec21e2ecSJeff Kirsher bdp = next_bd(bdp, base, rx_queue->rx_ring_size); 2818ec21e2ecSJeff Kirsher 2819ec21e2ecSJeff Kirsher /* update to point at the next skb */ 2820bc4598bcSJan Ceuleers rx_queue->skb_currx = (rx_queue->skb_currx + 1) & 2821ec21e2ecSJeff Kirsher RX_RING_MOD_MASK(rx_queue->rx_ring_size); 2822ec21e2ecSJeff Kirsher } 2823ec21e2ecSJeff Kirsher 2824ec21e2ecSJeff Kirsher /* Update the current rxbd pointer to be the next one */ 2825ec21e2ecSJeff Kirsher rx_queue->cur_rx = bdp; 2826ec21e2ecSJeff Kirsher 2827ec21e2ecSJeff Kirsher return howmany; 2828ec21e2ecSJeff Kirsher } 2829ec21e2ecSJeff Kirsher 2830ec21e2ecSJeff Kirsher static int gfar_poll(struct napi_struct *napi, int budget) 2831ec21e2ecSJeff Kirsher { 2832bc4598bcSJan Ceuleers struct gfar_priv_grp *gfargrp = 2833bc4598bcSJan Ceuleers container_of(napi, struct gfar_priv_grp, napi); 2834ec21e2ecSJeff Kirsher struct gfar_private *priv = gfargrp->priv; 2835ec21e2ecSJeff Kirsher struct gfar __iomem *regs = gfargrp->regs; 2836ec21e2ecSJeff Kirsher struct gfar_priv_tx_q *tx_queue = NULL; 2837ec21e2ecSJeff Kirsher struct gfar_priv_rx_q *rx_queue = NULL; 2838ec21e2ecSJeff Kirsher int rx_cleaned = 0, budget_per_queue = 0, rx_cleaned_per_queue = 0; 2839ec21e2ecSJeff Kirsher int tx_cleaned = 0, i, left_over_budget = budget; 2840ec21e2ecSJeff Kirsher unsigned long serviced_queues = 0; 2841ec21e2ecSJeff Kirsher int num_queues = 0; 2842ec21e2ecSJeff Kirsher 2843ec21e2ecSJeff Kirsher num_queues = gfargrp->num_rx_queues; 2844ec21e2ecSJeff Kirsher budget_per_queue = budget/num_queues; 2845ec21e2ecSJeff Kirsher 2846ec21e2ecSJeff Kirsher /* Clear IEVENT, so interrupts aren't called again 28470977f817SJan Ceuleers * because of the packets that have already arrived 28480977f817SJan Ceuleers */ 2849ec21e2ecSJeff Kirsher gfar_write(®s->ievent, IEVENT_RTX_MASK); 2850ec21e2ecSJeff Kirsher 2851ec21e2ecSJeff Kirsher while (num_queues && left_over_budget) { 2852ec21e2ecSJeff Kirsher budget_per_queue = left_over_budget/num_queues; 2853ec21e2ecSJeff Kirsher left_over_budget = 0; 2854ec21e2ecSJeff Kirsher 2855ec21e2ecSJeff Kirsher for_each_set_bit(i, &gfargrp->rx_bit_map, priv->num_rx_queues) { 2856ec21e2ecSJeff Kirsher if (test_bit(i, &serviced_queues)) 2857ec21e2ecSJeff Kirsher continue; 2858ec21e2ecSJeff Kirsher rx_queue = priv->rx_queue[i]; 2859ec21e2ecSJeff Kirsher tx_queue = priv->tx_queue[rx_queue->qindex]; 2860ec21e2ecSJeff Kirsher 2861ec21e2ecSJeff Kirsher tx_cleaned += gfar_clean_tx_ring(tx_queue); 2862bc4598bcSJan Ceuleers rx_cleaned_per_queue = 2863bc4598bcSJan Ceuleers gfar_clean_rx_ring(rx_queue, budget_per_queue); 2864ec21e2ecSJeff Kirsher rx_cleaned += rx_cleaned_per_queue; 2865ec21e2ecSJeff Kirsher if (rx_cleaned_per_queue < budget_per_queue) { 2866ec21e2ecSJeff Kirsher left_over_budget = left_over_budget + 2867bc4598bcSJan Ceuleers (budget_per_queue - 2868bc4598bcSJan Ceuleers rx_cleaned_per_queue); 2869ec21e2ecSJeff Kirsher set_bit(i, &serviced_queues); 2870ec21e2ecSJeff Kirsher num_queues--; 2871ec21e2ecSJeff Kirsher } 2872ec21e2ecSJeff Kirsher } 2873ec21e2ecSJeff Kirsher } 2874ec21e2ecSJeff Kirsher 2875ec21e2ecSJeff Kirsher if (tx_cleaned) 2876ec21e2ecSJeff Kirsher return budget; 2877ec21e2ecSJeff Kirsher 2878ec21e2ecSJeff Kirsher if (rx_cleaned < budget) { 2879ec21e2ecSJeff Kirsher napi_complete(napi); 2880ec21e2ecSJeff Kirsher 2881ec21e2ecSJeff Kirsher /* Clear the halt bit in RSTAT */ 2882ec21e2ecSJeff Kirsher gfar_write(®s->rstat, gfargrp->rstat); 2883ec21e2ecSJeff Kirsher 2884ec21e2ecSJeff Kirsher gfar_write(®s->imask, IMASK_DEFAULT); 2885ec21e2ecSJeff Kirsher 28860977f817SJan Ceuleers /* If we are coalescing interrupts, update the timer 28870977f817SJan Ceuleers * Otherwise, clear it 28880977f817SJan Ceuleers */ 2889bc4598bcSJan Ceuleers gfar_configure_coalescing(priv, gfargrp->rx_bit_map, 2890bc4598bcSJan Ceuleers gfargrp->tx_bit_map); 2891ec21e2ecSJeff Kirsher } 2892ec21e2ecSJeff Kirsher 2893ec21e2ecSJeff Kirsher return rx_cleaned; 2894ec21e2ecSJeff Kirsher } 2895ec21e2ecSJeff Kirsher 2896ec21e2ecSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 28970977f817SJan Ceuleers /* Polling 'interrupt' - used by things like netconsole to send skbs 2898ec21e2ecSJeff Kirsher * without having to re-enable interrupts. It's not called while 2899ec21e2ecSJeff Kirsher * the interrupt routine is executing. 2900ec21e2ecSJeff Kirsher */ 2901ec21e2ecSJeff Kirsher static void gfar_netpoll(struct net_device *dev) 2902ec21e2ecSJeff Kirsher { 2903ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 29043a2e16c8SJan Ceuleers int i; 2905ec21e2ecSJeff Kirsher 2906ec21e2ecSJeff Kirsher /* If the device has multiple interrupts, run tx/rx */ 2907ec21e2ecSJeff Kirsher if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 2908ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 2909*62ed839dSPaul Gortmaker struct gfar_priv_grp *grp = &priv->gfargrp[i]; 2910*62ed839dSPaul Gortmaker 2911*62ed839dSPaul Gortmaker disable_irq(gfar_irq(grp, TX)->irq); 2912*62ed839dSPaul Gortmaker disable_irq(gfar_irq(grp, RX)->irq); 2913*62ed839dSPaul Gortmaker disable_irq(gfar_irq(grp, ER)->irq); 2914*62ed839dSPaul Gortmaker gfar_interrupt(gfar_irq(grp, TX)->irq, grp); 2915*62ed839dSPaul Gortmaker enable_irq(gfar_irq(grp, ER)->irq); 2916*62ed839dSPaul Gortmaker enable_irq(gfar_irq(grp, RX)->irq); 2917*62ed839dSPaul Gortmaker enable_irq(gfar_irq(grp, TX)->irq); 2918ec21e2ecSJeff Kirsher } 2919ec21e2ecSJeff Kirsher } else { 2920ec21e2ecSJeff Kirsher for (i = 0; i < priv->num_grps; i++) { 2921*62ed839dSPaul Gortmaker struct gfar_priv_grp *grp = &priv->gfargrp[i]; 2922*62ed839dSPaul Gortmaker 2923*62ed839dSPaul Gortmaker disable_irq(gfar_irq(grp, TX)->irq); 2924*62ed839dSPaul Gortmaker gfar_interrupt(gfar_irq(grp, TX)->irq, grp); 2925*62ed839dSPaul Gortmaker enable_irq(gfar_irq(grp, TX)->irq); 2926ec21e2ecSJeff Kirsher } 2927ec21e2ecSJeff Kirsher } 2928ec21e2ecSJeff Kirsher } 2929ec21e2ecSJeff Kirsher #endif 2930ec21e2ecSJeff Kirsher 2931ec21e2ecSJeff Kirsher /* The interrupt handler for devices with one interrupt */ 2932ec21e2ecSJeff Kirsher static irqreturn_t gfar_interrupt(int irq, void *grp_id) 2933ec21e2ecSJeff Kirsher { 2934ec21e2ecSJeff Kirsher struct gfar_priv_grp *gfargrp = grp_id; 2935ec21e2ecSJeff Kirsher 2936ec21e2ecSJeff Kirsher /* Save ievent for future reference */ 2937ec21e2ecSJeff Kirsher u32 events = gfar_read(&gfargrp->regs->ievent); 2938ec21e2ecSJeff Kirsher 2939ec21e2ecSJeff Kirsher /* Check for reception */ 2940ec21e2ecSJeff Kirsher if (events & IEVENT_RX_MASK) 2941ec21e2ecSJeff Kirsher gfar_receive(irq, grp_id); 2942ec21e2ecSJeff Kirsher 2943ec21e2ecSJeff Kirsher /* Check for transmit completion */ 2944ec21e2ecSJeff Kirsher if (events & IEVENT_TX_MASK) 2945ec21e2ecSJeff Kirsher gfar_transmit(irq, grp_id); 2946ec21e2ecSJeff Kirsher 2947ec21e2ecSJeff Kirsher /* Check for errors */ 2948ec21e2ecSJeff Kirsher if (events & IEVENT_ERR_MASK) 2949ec21e2ecSJeff Kirsher gfar_error(irq, grp_id); 2950ec21e2ecSJeff Kirsher 2951ec21e2ecSJeff Kirsher return IRQ_HANDLED; 2952ec21e2ecSJeff Kirsher } 2953ec21e2ecSJeff Kirsher 2954ec21e2ecSJeff Kirsher /* Called every time the controller might need to be made 2955ec21e2ecSJeff Kirsher * aware of new link state. The PHY code conveys this 2956ec21e2ecSJeff Kirsher * information through variables in the phydev structure, and this 2957ec21e2ecSJeff Kirsher * function converts those variables into the appropriate 2958ec21e2ecSJeff Kirsher * register values, and can bring down the device if needed. 2959ec21e2ecSJeff Kirsher */ 2960ec21e2ecSJeff Kirsher static void adjust_link(struct net_device *dev) 2961ec21e2ecSJeff Kirsher { 2962ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 2963ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 2964ec21e2ecSJeff Kirsher unsigned long flags; 2965ec21e2ecSJeff Kirsher struct phy_device *phydev = priv->phydev; 2966ec21e2ecSJeff Kirsher int new_state = 0; 2967ec21e2ecSJeff Kirsher 2968ec21e2ecSJeff Kirsher local_irq_save(flags); 2969ec21e2ecSJeff Kirsher lock_tx_qs(priv); 2970ec21e2ecSJeff Kirsher 2971ec21e2ecSJeff Kirsher if (phydev->link) { 2972ec21e2ecSJeff Kirsher u32 tempval = gfar_read(®s->maccfg2); 2973ec21e2ecSJeff Kirsher u32 ecntrl = gfar_read(®s->ecntrl); 2974ec21e2ecSJeff Kirsher 2975ec21e2ecSJeff Kirsher /* Now we make sure that we can be in full duplex mode. 29760977f817SJan Ceuleers * If not, we operate in half-duplex mode. 29770977f817SJan Ceuleers */ 2978ec21e2ecSJeff Kirsher if (phydev->duplex != priv->oldduplex) { 2979ec21e2ecSJeff Kirsher new_state = 1; 2980ec21e2ecSJeff Kirsher if (!(phydev->duplex)) 2981ec21e2ecSJeff Kirsher tempval &= ~(MACCFG2_FULL_DUPLEX); 2982ec21e2ecSJeff Kirsher else 2983ec21e2ecSJeff Kirsher tempval |= MACCFG2_FULL_DUPLEX; 2984ec21e2ecSJeff Kirsher 2985ec21e2ecSJeff Kirsher priv->oldduplex = phydev->duplex; 2986ec21e2ecSJeff Kirsher } 2987ec21e2ecSJeff Kirsher 2988ec21e2ecSJeff Kirsher if (phydev->speed != priv->oldspeed) { 2989ec21e2ecSJeff Kirsher new_state = 1; 2990ec21e2ecSJeff Kirsher switch (phydev->speed) { 2991ec21e2ecSJeff Kirsher case 1000: 2992ec21e2ecSJeff Kirsher tempval = 2993ec21e2ecSJeff Kirsher ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII); 2994ec21e2ecSJeff Kirsher 2995ec21e2ecSJeff Kirsher ecntrl &= ~(ECNTRL_R100); 2996ec21e2ecSJeff Kirsher break; 2997ec21e2ecSJeff Kirsher case 100: 2998ec21e2ecSJeff Kirsher case 10: 2999ec21e2ecSJeff Kirsher tempval = 3000ec21e2ecSJeff Kirsher ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); 3001ec21e2ecSJeff Kirsher 3002ec21e2ecSJeff Kirsher /* Reduced mode distinguishes 30030977f817SJan Ceuleers * between 10 and 100 30040977f817SJan Ceuleers */ 3005ec21e2ecSJeff Kirsher if (phydev->speed == SPEED_100) 3006ec21e2ecSJeff Kirsher ecntrl |= ECNTRL_R100; 3007ec21e2ecSJeff Kirsher else 3008ec21e2ecSJeff Kirsher ecntrl &= ~(ECNTRL_R100); 3009ec21e2ecSJeff Kirsher break; 3010ec21e2ecSJeff Kirsher default: 3011ec21e2ecSJeff Kirsher netif_warn(priv, link, dev, 3012ec21e2ecSJeff Kirsher "Ack! Speed (%d) is not 10/100/1000!\n", 3013ec21e2ecSJeff Kirsher phydev->speed); 3014ec21e2ecSJeff Kirsher break; 3015ec21e2ecSJeff Kirsher } 3016ec21e2ecSJeff Kirsher 3017ec21e2ecSJeff Kirsher priv->oldspeed = phydev->speed; 3018ec21e2ecSJeff Kirsher } 3019ec21e2ecSJeff Kirsher 3020ec21e2ecSJeff Kirsher gfar_write(®s->maccfg2, tempval); 3021ec21e2ecSJeff Kirsher gfar_write(®s->ecntrl, ecntrl); 3022ec21e2ecSJeff Kirsher 3023ec21e2ecSJeff Kirsher if (!priv->oldlink) { 3024ec21e2ecSJeff Kirsher new_state = 1; 3025ec21e2ecSJeff Kirsher priv->oldlink = 1; 3026ec21e2ecSJeff Kirsher } 3027ec21e2ecSJeff Kirsher } else if (priv->oldlink) { 3028ec21e2ecSJeff Kirsher new_state = 1; 3029ec21e2ecSJeff Kirsher priv->oldlink = 0; 3030ec21e2ecSJeff Kirsher priv->oldspeed = 0; 3031ec21e2ecSJeff Kirsher priv->oldduplex = -1; 3032ec21e2ecSJeff Kirsher } 3033ec21e2ecSJeff Kirsher 3034ec21e2ecSJeff Kirsher if (new_state && netif_msg_link(priv)) 3035ec21e2ecSJeff Kirsher phy_print_status(phydev); 3036ec21e2ecSJeff Kirsher unlock_tx_qs(priv); 3037ec21e2ecSJeff Kirsher local_irq_restore(flags); 3038ec21e2ecSJeff Kirsher } 3039ec21e2ecSJeff Kirsher 3040ec21e2ecSJeff Kirsher /* Update the hash table based on the current list of multicast 3041ec21e2ecSJeff Kirsher * addresses we subscribe to. Also, change the promiscuity of 3042ec21e2ecSJeff Kirsher * the device based on the flags (this function is called 30430977f817SJan Ceuleers * whenever dev->flags is changed 30440977f817SJan Ceuleers */ 3045ec21e2ecSJeff Kirsher static void gfar_set_multi(struct net_device *dev) 3046ec21e2ecSJeff Kirsher { 3047ec21e2ecSJeff Kirsher struct netdev_hw_addr *ha; 3048ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 3049ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 3050ec21e2ecSJeff Kirsher u32 tempval; 3051ec21e2ecSJeff Kirsher 3052ec21e2ecSJeff Kirsher if (dev->flags & IFF_PROMISC) { 3053ec21e2ecSJeff Kirsher /* Set RCTRL to PROM */ 3054ec21e2ecSJeff Kirsher tempval = gfar_read(®s->rctrl); 3055ec21e2ecSJeff Kirsher tempval |= RCTRL_PROM; 3056ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, tempval); 3057ec21e2ecSJeff Kirsher } else { 3058ec21e2ecSJeff Kirsher /* Set RCTRL to not PROM */ 3059ec21e2ecSJeff Kirsher tempval = gfar_read(®s->rctrl); 3060ec21e2ecSJeff Kirsher tempval &= ~(RCTRL_PROM); 3061ec21e2ecSJeff Kirsher gfar_write(®s->rctrl, tempval); 3062ec21e2ecSJeff Kirsher } 3063ec21e2ecSJeff Kirsher 3064ec21e2ecSJeff Kirsher if (dev->flags & IFF_ALLMULTI) { 3065ec21e2ecSJeff Kirsher /* Set the hash to rx all multicast frames */ 3066ec21e2ecSJeff Kirsher gfar_write(®s->igaddr0, 0xffffffff); 3067ec21e2ecSJeff Kirsher gfar_write(®s->igaddr1, 0xffffffff); 3068ec21e2ecSJeff Kirsher gfar_write(®s->igaddr2, 0xffffffff); 3069ec21e2ecSJeff Kirsher gfar_write(®s->igaddr3, 0xffffffff); 3070ec21e2ecSJeff Kirsher gfar_write(®s->igaddr4, 0xffffffff); 3071ec21e2ecSJeff Kirsher gfar_write(®s->igaddr5, 0xffffffff); 3072ec21e2ecSJeff Kirsher gfar_write(®s->igaddr6, 0xffffffff); 3073ec21e2ecSJeff Kirsher gfar_write(®s->igaddr7, 0xffffffff); 3074ec21e2ecSJeff Kirsher gfar_write(®s->gaddr0, 0xffffffff); 3075ec21e2ecSJeff Kirsher gfar_write(®s->gaddr1, 0xffffffff); 3076ec21e2ecSJeff Kirsher gfar_write(®s->gaddr2, 0xffffffff); 3077ec21e2ecSJeff Kirsher gfar_write(®s->gaddr3, 0xffffffff); 3078ec21e2ecSJeff Kirsher gfar_write(®s->gaddr4, 0xffffffff); 3079ec21e2ecSJeff Kirsher gfar_write(®s->gaddr5, 0xffffffff); 3080ec21e2ecSJeff Kirsher gfar_write(®s->gaddr6, 0xffffffff); 3081ec21e2ecSJeff Kirsher gfar_write(®s->gaddr7, 0xffffffff); 3082ec21e2ecSJeff Kirsher } else { 3083ec21e2ecSJeff Kirsher int em_num; 3084ec21e2ecSJeff Kirsher int idx; 3085ec21e2ecSJeff Kirsher 3086ec21e2ecSJeff Kirsher /* zero out the hash */ 3087ec21e2ecSJeff Kirsher gfar_write(®s->igaddr0, 0x0); 3088ec21e2ecSJeff Kirsher gfar_write(®s->igaddr1, 0x0); 3089ec21e2ecSJeff Kirsher gfar_write(®s->igaddr2, 0x0); 3090ec21e2ecSJeff Kirsher gfar_write(®s->igaddr3, 0x0); 3091ec21e2ecSJeff Kirsher gfar_write(®s->igaddr4, 0x0); 3092ec21e2ecSJeff Kirsher gfar_write(®s->igaddr5, 0x0); 3093ec21e2ecSJeff Kirsher gfar_write(®s->igaddr6, 0x0); 3094ec21e2ecSJeff Kirsher gfar_write(®s->igaddr7, 0x0); 3095ec21e2ecSJeff Kirsher gfar_write(®s->gaddr0, 0x0); 3096ec21e2ecSJeff Kirsher gfar_write(®s->gaddr1, 0x0); 3097ec21e2ecSJeff Kirsher gfar_write(®s->gaddr2, 0x0); 3098ec21e2ecSJeff Kirsher gfar_write(®s->gaddr3, 0x0); 3099ec21e2ecSJeff Kirsher gfar_write(®s->gaddr4, 0x0); 3100ec21e2ecSJeff Kirsher gfar_write(®s->gaddr5, 0x0); 3101ec21e2ecSJeff Kirsher gfar_write(®s->gaddr6, 0x0); 3102ec21e2ecSJeff Kirsher gfar_write(®s->gaddr7, 0x0); 3103ec21e2ecSJeff Kirsher 3104ec21e2ecSJeff Kirsher /* If we have extended hash tables, we need to 3105ec21e2ecSJeff Kirsher * clear the exact match registers to prepare for 31060977f817SJan Ceuleers * setting them 31070977f817SJan Ceuleers */ 3108ec21e2ecSJeff Kirsher if (priv->extended_hash) { 3109ec21e2ecSJeff Kirsher em_num = GFAR_EM_NUM + 1; 3110ec21e2ecSJeff Kirsher gfar_clear_exact_match(dev); 3111ec21e2ecSJeff Kirsher idx = 1; 3112ec21e2ecSJeff Kirsher } else { 3113ec21e2ecSJeff Kirsher idx = 0; 3114ec21e2ecSJeff Kirsher em_num = 0; 3115ec21e2ecSJeff Kirsher } 3116ec21e2ecSJeff Kirsher 3117ec21e2ecSJeff Kirsher if (netdev_mc_empty(dev)) 3118ec21e2ecSJeff Kirsher return; 3119ec21e2ecSJeff Kirsher 3120ec21e2ecSJeff Kirsher /* Parse the list, and set the appropriate bits */ 3121ec21e2ecSJeff Kirsher netdev_for_each_mc_addr(ha, dev) { 3122ec21e2ecSJeff Kirsher if (idx < em_num) { 3123ec21e2ecSJeff Kirsher gfar_set_mac_for_addr(dev, idx, ha->addr); 3124ec21e2ecSJeff Kirsher idx++; 3125ec21e2ecSJeff Kirsher } else 3126ec21e2ecSJeff Kirsher gfar_set_hash_for_addr(dev, ha->addr); 3127ec21e2ecSJeff Kirsher } 3128ec21e2ecSJeff Kirsher } 3129ec21e2ecSJeff Kirsher } 3130ec21e2ecSJeff Kirsher 3131ec21e2ecSJeff Kirsher 3132ec21e2ecSJeff Kirsher /* Clears each of the exact match registers to zero, so they 31330977f817SJan Ceuleers * don't interfere with normal reception 31340977f817SJan Ceuleers */ 3135ec21e2ecSJeff Kirsher static void gfar_clear_exact_match(struct net_device *dev) 3136ec21e2ecSJeff Kirsher { 3137ec21e2ecSJeff Kirsher int idx; 31386a3c910cSJoe Perches static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; 3139ec21e2ecSJeff Kirsher 3140ec21e2ecSJeff Kirsher for (idx = 1; idx < GFAR_EM_NUM + 1; idx++) 3141ec21e2ecSJeff Kirsher gfar_set_mac_for_addr(dev, idx, zero_arr); 3142ec21e2ecSJeff Kirsher } 3143ec21e2ecSJeff Kirsher 3144ec21e2ecSJeff Kirsher /* Set the appropriate hash bit for the given addr */ 3145ec21e2ecSJeff Kirsher /* The algorithm works like so: 3146ec21e2ecSJeff Kirsher * 1) Take the Destination Address (ie the multicast address), and 3147ec21e2ecSJeff Kirsher * do a CRC on it (little endian), and reverse the bits of the 3148ec21e2ecSJeff Kirsher * result. 3149ec21e2ecSJeff Kirsher * 2) Use the 8 most significant bits as a hash into a 256-entry 3150ec21e2ecSJeff Kirsher * table. The table is controlled through 8 32-bit registers: 3151ec21e2ecSJeff Kirsher * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is 3152ec21e2ecSJeff Kirsher * gaddr7. This means that the 3 most significant bits in the 3153ec21e2ecSJeff Kirsher * hash index which gaddr register to use, and the 5 other bits 3154ec21e2ecSJeff Kirsher * indicate which bit (assuming an IBM numbering scheme, which 3155ec21e2ecSJeff Kirsher * for PowerPC (tm) is usually the case) in the register holds 31560977f817SJan Ceuleers * the entry. 31570977f817SJan Ceuleers */ 3158ec21e2ecSJeff Kirsher static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr) 3159ec21e2ecSJeff Kirsher { 3160ec21e2ecSJeff Kirsher u32 tempval; 3161ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 31626a3c910cSJoe Perches u32 result = ether_crc(ETH_ALEN, addr); 3163ec21e2ecSJeff Kirsher int width = priv->hash_width; 3164ec21e2ecSJeff Kirsher u8 whichbit = (result >> (32 - width)) & 0x1f; 3165ec21e2ecSJeff Kirsher u8 whichreg = result >> (32 - width + 5); 3166ec21e2ecSJeff Kirsher u32 value = (1 << (31-whichbit)); 3167ec21e2ecSJeff Kirsher 3168ec21e2ecSJeff Kirsher tempval = gfar_read(priv->hash_regs[whichreg]); 3169ec21e2ecSJeff Kirsher tempval |= value; 3170ec21e2ecSJeff Kirsher gfar_write(priv->hash_regs[whichreg], tempval); 3171ec21e2ecSJeff Kirsher } 3172ec21e2ecSJeff Kirsher 3173ec21e2ecSJeff Kirsher 3174ec21e2ecSJeff Kirsher /* There are multiple MAC Address register pairs on some controllers 3175ec21e2ecSJeff Kirsher * This function sets the numth pair to a given address 3176ec21e2ecSJeff Kirsher */ 3177ec21e2ecSJeff Kirsher static void gfar_set_mac_for_addr(struct net_device *dev, int num, 3178ec21e2ecSJeff Kirsher const u8 *addr) 3179ec21e2ecSJeff Kirsher { 3180ec21e2ecSJeff Kirsher struct gfar_private *priv = netdev_priv(dev); 3181ec21e2ecSJeff Kirsher struct gfar __iomem *regs = priv->gfargrp[0].regs; 3182ec21e2ecSJeff Kirsher int idx; 31836a3c910cSJoe Perches char tmpbuf[ETH_ALEN]; 3184ec21e2ecSJeff Kirsher u32 tempval; 3185ec21e2ecSJeff Kirsher u32 __iomem *macptr = ®s->macstnaddr1; 3186ec21e2ecSJeff Kirsher 3187ec21e2ecSJeff Kirsher macptr += num*2; 3188ec21e2ecSJeff Kirsher 31890977f817SJan Ceuleers /* Now copy it into the mac registers backwards, cuz 31900977f817SJan Ceuleers * little endian is silly 31910977f817SJan Ceuleers */ 31926a3c910cSJoe Perches for (idx = 0; idx < ETH_ALEN; idx++) 31936a3c910cSJoe Perches tmpbuf[ETH_ALEN - 1 - idx] = addr[idx]; 3194ec21e2ecSJeff Kirsher 3195ec21e2ecSJeff Kirsher gfar_write(macptr, *((u32 *) (tmpbuf))); 3196ec21e2ecSJeff Kirsher 3197ec21e2ecSJeff Kirsher tempval = *((u32 *) (tmpbuf + 4)); 3198ec21e2ecSJeff Kirsher 3199ec21e2ecSJeff Kirsher gfar_write(macptr+1, tempval); 3200ec21e2ecSJeff Kirsher } 3201ec21e2ecSJeff Kirsher 3202ec21e2ecSJeff Kirsher /* GFAR error interrupt handler */ 3203ec21e2ecSJeff Kirsher static irqreturn_t gfar_error(int irq, void *grp_id) 3204ec21e2ecSJeff Kirsher { 3205ec21e2ecSJeff Kirsher struct gfar_priv_grp *gfargrp = grp_id; 3206ec21e2ecSJeff Kirsher struct gfar __iomem *regs = gfargrp->regs; 3207ec21e2ecSJeff Kirsher struct gfar_private *priv= gfargrp->priv; 3208ec21e2ecSJeff Kirsher struct net_device *dev = priv->ndev; 3209ec21e2ecSJeff Kirsher 3210ec21e2ecSJeff Kirsher /* Save ievent for future reference */ 3211ec21e2ecSJeff Kirsher u32 events = gfar_read(®s->ievent); 3212ec21e2ecSJeff Kirsher 3213ec21e2ecSJeff Kirsher /* Clear IEVENT */ 3214ec21e2ecSJeff Kirsher gfar_write(®s->ievent, events & IEVENT_ERR_MASK); 3215ec21e2ecSJeff Kirsher 3216ec21e2ecSJeff Kirsher /* Magic Packet is not an error. */ 3217ec21e2ecSJeff Kirsher if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && 3218ec21e2ecSJeff Kirsher (events & IEVENT_MAG)) 3219ec21e2ecSJeff Kirsher events &= ~IEVENT_MAG; 3220ec21e2ecSJeff Kirsher 3221ec21e2ecSJeff Kirsher /* Hmm... */ 3222ec21e2ecSJeff Kirsher if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv)) 3223bc4598bcSJan Ceuleers netdev_dbg(dev, 3224bc4598bcSJan Ceuleers "error interrupt (ievent=0x%08x imask=0x%08x)\n", 3225ec21e2ecSJeff Kirsher events, gfar_read(®s->imask)); 3226ec21e2ecSJeff Kirsher 3227ec21e2ecSJeff Kirsher /* Update the error counters */ 3228ec21e2ecSJeff Kirsher if (events & IEVENT_TXE) { 3229ec21e2ecSJeff Kirsher dev->stats.tx_errors++; 3230ec21e2ecSJeff Kirsher 3231ec21e2ecSJeff Kirsher if (events & IEVENT_LC) 3232ec21e2ecSJeff Kirsher dev->stats.tx_window_errors++; 3233ec21e2ecSJeff Kirsher if (events & IEVENT_CRL) 3234ec21e2ecSJeff Kirsher dev->stats.tx_aborted_errors++; 3235ec21e2ecSJeff Kirsher if (events & IEVENT_XFUN) { 3236ec21e2ecSJeff Kirsher unsigned long flags; 3237ec21e2ecSJeff Kirsher 3238ec21e2ecSJeff Kirsher netif_dbg(priv, tx_err, dev, 3239ec21e2ecSJeff Kirsher "TX FIFO underrun, packet dropped\n"); 3240ec21e2ecSJeff Kirsher dev->stats.tx_dropped++; 3241212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.tx_underrun); 3242ec21e2ecSJeff Kirsher 3243ec21e2ecSJeff Kirsher local_irq_save(flags); 3244ec21e2ecSJeff Kirsher lock_tx_qs(priv); 3245ec21e2ecSJeff Kirsher 3246ec21e2ecSJeff Kirsher /* Reactivate the Tx Queues */ 3247ec21e2ecSJeff Kirsher gfar_write(®s->tstat, gfargrp->tstat); 3248ec21e2ecSJeff Kirsher 3249ec21e2ecSJeff Kirsher unlock_tx_qs(priv); 3250ec21e2ecSJeff Kirsher local_irq_restore(flags); 3251ec21e2ecSJeff Kirsher } 3252ec21e2ecSJeff Kirsher netif_dbg(priv, tx_err, dev, "Transmit Error\n"); 3253ec21e2ecSJeff Kirsher } 3254ec21e2ecSJeff Kirsher if (events & IEVENT_BSY) { 3255ec21e2ecSJeff Kirsher dev->stats.rx_errors++; 3256212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.rx_bsy); 3257ec21e2ecSJeff Kirsher 3258ec21e2ecSJeff Kirsher gfar_receive(irq, grp_id); 3259ec21e2ecSJeff Kirsher 3260ec21e2ecSJeff Kirsher netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n", 3261ec21e2ecSJeff Kirsher gfar_read(®s->rstat)); 3262ec21e2ecSJeff Kirsher } 3263ec21e2ecSJeff Kirsher if (events & IEVENT_BABR) { 3264ec21e2ecSJeff Kirsher dev->stats.rx_errors++; 3265212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.rx_babr); 3266ec21e2ecSJeff Kirsher 3267ec21e2ecSJeff Kirsher netif_dbg(priv, rx_err, dev, "babbling RX error\n"); 3268ec21e2ecSJeff Kirsher } 3269ec21e2ecSJeff Kirsher if (events & IEVENT_EBERR) { 3270212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.eberr); 3271ec21e2ecSJeff Kirsher netif_dbg(priv, rx_err, dev, "bus error\n"); 3272ec21e2ecSJeff Kirsher } 3273ec21e2ecSJeff Kirsher if (events & IEVENT_RXC) 3274ec21e2ecSJeff Kirsher netif_dbg(priv, rx_status, dev, "control frame\n"); 3275ec21e2ecSJeff Kirsher 3276ec21e2ecSJeff Kirsher if (events & IEVENT_BABT) { 3277212079dfSPaul Gortmaker atomic64_inc(&priv->extra_stats.tx_babt); 3278ec21e2ecSJeff Kirsher netif_dbg(priv, tx_err, dev, "babbling TX error\n"); 3279ec21e2ecSJeff Kirsher } 3280ec21e2ecSJeff Kirsher return IRQ_HANDLED; 3281ec21e2ecSJeff Kirsher } 3282ec21e2ecSJeff Kirsher 3283ec21e2ecSJeff Kirsher static struct of_device_id gfar_match[] = 3284ec21e2ecSJeff Kirsher { 3285ec21e2ecSJeff Kirsher { 3286ec21e2ecSJeff Kirsher .type = "network", 3287ec21e2ecSJeff Kirsher .compatible = "gianfar", 3288ec21e2ecSJeff Kirsher }, 3289ec21e2ecSJeff Kirsher { 3290ec21e2ecSJeff Kirsher .compatible = "fsl,etsec2", 3291ec21e2ecSJeff Kirsher }, 3292ec21e2ecSJeff Kirsher {}, 3293ec21e2ecSJeff Kirsher }; 3294ec21e2ecSJeff Kirsher MODULE_DEVICE_TABLE(of, gfar_match); 3295ec21e2ecSJeff Kirsher 3296ec21e2ecSJeff Kirsher /* Structure for a device driver */ 3297ec21e2ecSJeff Kirsher static struct platform_driver gfar_driver = { 3298ec21e2ecSJeff Kirsher .driver = { 3299ec21e2ecSJeff Kirsher .name = "fsl-gianfar", 3300ec21e2ecSJeff Kirsher .owner = THIS_MODULE, 3301ec21e2ecSJeff Kirsher .pm = GFAR_PM_OPS, 3302ec21e2ecSJeff Kirsher .of_match_table = gfar_match, 3303ec21e2ecSJeff Kirsher }, 3304ec21e2ecSJeff Kirsher .probe = gfar_probe, 3305ec21e2ecSJeff Kirsher .remove = gfar_remove, 3306ec21e2ecSJeff Kirsher }; 3307ec21e2ecSJeff Kirsher 3308db62f684SAxel Lin module_platform_driver(gfar_driver); 3309